forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from suisin-deriv/update_api_token_test_case_ba…
…sed_on_comments Update api token test case based on comments
- Loading branch information
Showing
3 changed files
with
26 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 10 additions & 28 deletions
38
packages/account/src/Components/api-token/_tests_/api-token-card.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,35 @@ | ||
import React from 'react'; | ||
import { Formik, Form } from 'formik'; | ||
import { screen, render } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import ApiTokenCard from '../api-token-card'; | ||
import { Formik, Form } from 'formik'; | ||
|
||
describe('<ApiTokenCard />', () => { | ||
const mock_props = { | ||
name: 'Api_token_card_test_case', | ||
value: false, | ||
display_name: 'API Token Card', | ||
description: 'API Token Description', | ||
setFieldValue: jest.fn(), | ||
display_name: <div>API Token Card</div>, | ||
description: <div>API Token Description</div>, | ||
}; | ||
|
||
it('should render ApiTokenCard', () => { | ||
const renderComponent = (children?: JSX.Element) => { | ||
render( | ||
<Formik initialValues={{ [mock_props.name]: mock_props.value }} onSubmit={jest.fn()}> | ||
<Form> | ||
<ApiTokenCard {...mock_props} /> | ||
<ApiTokenCard {...mock_props}>{children}</ApiTokenCard> | ||
</Form> | ||
</Formik> | ||
); | ||
}; | ||
|
||
it('should render ApiTokenCard', () => { | ||
renderComponent(); | ||
expect(screen.getByText('API Token Card')).toBeInTheDocument(); | ||
expect(screen.getByText('API Token Description')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render ApiTokenCard with children', () => { | ||
const children = <div>API Token Children</div>; | ||
|
||
render( | ||
<Formik initialValues={{ [mock_props.name]: mock_props.value }} onSubmit={jest.fn()}> | ||
<Form> | ||
<ApiTokenCard {...mock_props}>{children}</ApiTokenCard> | ||
</Form> | ||
</Formik> | ||
); | ||
renderComponent(children); | ||
expect(screen.getByText('API Token Children')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should run setFieldValue after clicking on checkbox', () => { | ||
render( | ||
<Formik initialValues={{ [mock_props.name]: mock_props.value }} onSubmit={jest.fn()}> | ||
<Form> | ||
<ApiTokenCard {...mock_props} /> | ||
</Form> | ||
</Formik> | ||
); | ||
const message = screen.getByText('API Token Card'); | ||
userEvent.click(message); | ||
expect(mock_props.setFieldValue).toBeCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters