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.
fix: 🎨 resolved TS migration issues (#27)
* fix: 🎨 resolved TS migration issues * feat: ✅ added testcaes * refactor: idv forms to useFormikContext to reduce prop drilling (#26) * refactor: idv forms to useFormikContext to reduce prop drilling * refactor: removed unused props from personal-details * feat: resolved the issues with idv testcases * feat: 🎨 incorporated image change based on status --------- Co-authored-by: Shahzaib <shahzaib@deriv.com>
- Loading branch information
1 parent
c7d4caa
commit 673637d
Showing
14 changed files
with
352 additions
and
217 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 125 additions & 0 deletions
125
packages/account/src/Components/forms/__tests__/idv-form.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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import React from 'react'; | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
import IDVForm from '../idv-form'; | ||
import { Formik } from 'formik'; | ||
import { isDesktop, isMobile } from '@deriv/shared'; | ||
|
||
jest.mock('Helpers/utils', () => ({ | ||
...jest.requireActual('Helpers/utils'), | ||
getDocumentData: jest.fn((country_code, key) => { | ||
const data = { | ||
tc: { | ||
document_1: { | ||
new_display_name: '', | ||
example_format: '5436454364243', | ||
sample_image: '', | ||
}, | ||
document_2: { | ||
new_display_name: '', | ||
example_format: 'A-52431', | ||
sample_image: '', | ||
}, | ||
}, | ||
}; | ||
return data[country_code][key]; | ||
}), | ||
})); | ||
|
||
jest.mock('formik', () => ({ | ||
...jest.requireActual('formik'), | ||
useFormikContext: jest.fn(() => ({ | ||
values: { | ||
document_type: { | ||
// display_name: 'Test document 1 name', | ||
// format: '5436454364243', | ||
// id: '1', | ||
// value: 'Test document 1 name', | ||
}, | ||
document_number: '', | ||
}, | ||
errors: {}, | ||
touched: {}, | ||
setFieldValue: jest.fn(), | ||
setFieldTouched: jest.fn(), | ||
validateForm: jest.fn(), | ||
validateField: jest.fn(), | ||
handleBlur: jest.fn(), | ||
handleChange: jest.fn(), | ||
})), | ||
})); | ||
|
||
jest.mock('@deriv/shared', () => ({ | ||
...jest.requireActual('@deriv/shared'), | ||
isDesktop: jest.fn(() => true), | ||
isMobile: jest.fn(() => false), | ||
})); | ||
|
||
describe('<IDVForm/>', () => { | ||
const mock_props = { | ||
selected_country: { | ||
value: 'tc', | ||
identity: { | ||
services: { | ||
idv: { | ||
documents_supported: { | ||
document_1: { | ||
display_name: 'Test document 1 name', | ||
format: '5436454364243', | ||
}, | ||
document_2: { | ||
display_name: 'Test document 2 name', | ||
format: 'A54321', | ||
}, | ||
}, | ||
has_visual_sample: '1', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const mock_values = { | ||
document_type: { | ||
display_name: 'Test document 1 name', | ||
format: '5436454364243', | ||
id: '1', | ||
value: 'document_1', | ||
}, | ||
document_number: '5436454364243', | ||
}; | ||
|
||
it('should render IDVForm component', () => { | ||
render(<IDVForm {...mock_props} />, { | ||
wrapper: ({ children }) => ( | ||
<Formik initialValues={mock_values} onSubmit={() => undefined}> | ||
{() => children} | ||
</Formik> | ||
), | ||
}); | ||
|
||
const document_type_input = screen.getByLabelText('Choose the document type'); | ||
const document_number_input = screen.getByPlaceholderText('Enter your document number'); | ||
|
||
expect(document_type_input).toBeInTheDocument(); | ||
expect(document_number_input).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should change the document type value when document type is changed', async () => { | ||
render(<IDVForm {...mock_props} />, { | ||
wrapper: ({ children }) => ( | ||
<Formik initialValues={mock_values} onSubmit={() => undefined}> | ||
{() => children} | ||
</Formik> | ||
), | ||
}); | ||
|
||
const document_type_input = screen.getByLabelText('Choose the document type'); | ||
|
||
fireEvent.click(document_type_input); | ||
expect(await screen.findByText('Test document 1 name')).toBeInTheDocument(); | ||
fireEvent.blur(document_type_input); | ||
await waitFor(() => { | ||
expect(screen.queryByText('Test document 1 name')).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.