Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎨 refactored IDV failure #37

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React from 'react';

import { act, render, screen, waitFor } from '@testing-library/react';
import IdvFailed from '../idv-failed';
import { idv_error_statuses } from '@deriv/shared';

jest.mock('@deriv/shared', () => ({
...jest.requireActual('@deriv/shared'),
WS: {
wait: jest.fn().mockResolvedValue(true),
},
filterObjProperties: jest.fn(() => ({
document_type: {
id: '',
text: '',
value: '',
example_format: '',
sample_image: '',
},
document_number: '',
first_name: '',
last_name: '',
date_of_birth: '',
})),
}));

jest.mock('Components/forms/personal-details-form', () => jest.fn(() => <div>PersonalDetailsForm</div>));
jest.mock('Components/forms/idv-form', () => jest.fn(() => <div>IDVForm</div>));
jest.mock('Assets/ic-poi-name-example.svg', () => jest.fn(() => 'PoiNameExample'));
jest.mock('Assets/ic-poi-dob-example.svg', () => jest.fn(() => 'PoiDobExample'));
jest.mock('Assets/ic-poi-name-dob-example.svg', () => jest.fn(() => 'PoiNameDobExample'));

describe('<IdvFailed/>', () => {
const mock_props = {
getChangeableFields: jest.fn(() => []),
is_from_external: false,
residence_list: [],
handleSubmit: jest.fn(),
account_settings: {
citizen: 'gh',
},
mismatch_status: idv_error_statuses.poi_name_mismatch,
};

it('should render IDVfailed component with name mismatch message', async () => {
render(<IdvFailed {...mock_props} />);

await waitFor(() => {
expect(screen.getByTestId(idv_error_statuses.poi_name_mismatch)).toBeInTheDocument();
expect(screen.getByText('PersonalDetailsForm')).toBeInTheDocument();
});
});

it('should render IDVfailed component with dob mismatch message', async () => {
const new_props = { ...mock_props, mismatch_status: idv_error_statuses.poi_dob_mismatch };
render(<IdvFailed {...new_props} />);

await waitFor(() => {
expect(screen.getByTestId(idv_error_statuses.poi_dob_mismatch)).toBeInTheDocument();
expect(screen.queryByText('IDVForm')).not.toBeInTheDocument();
});
});

it('should render IDVfailed component with name & DOB mismatch message', async () => {
const new_props = { ...mock_props, mismatch_status: idv_error_statuses.poi_name_dob_mismatch };
render(<IdvFailed {...new_props} />);

await waitFor(() => {
expect(screen.getByTestId(idv_error_statuses.poi_name_dob_mismatch)).toBeInTheDocument();
expect(screen.getByRole('button', { name: /Update profile/i })).toBeInTheDocument();
});
});

it('should render IDVfailed component with expired message', async () => {
const new_props = { ...mock_props, mismatch_status: idv_error_statuses.poi_expired };
render(<IdvFailed {...new_props} />);

await waitFor(() => {
expect(screen.getByTestId(idv_error_statuses.poi_expired)).toBeInTheDocument();
expect(screen.getByText('IDVForm')).toBeInTheDocument();
expect(screen.getByText('PersonalDetailsForm')).toBeInTheDocument();
});
});

it('should render IDVfailed component with verification failed message', async () => {
const new_props = { ...mock_props, mismatch_status: idv_error_statuses.poi_failed };
render(<IdvFailed {...new_props} />);

await waitFor(() => {
expect(screen.getByTestId(idv_error_statuses.poi_failed)).toBeInTheDocument();
expect(screen.getByRole('button', { name: /Verify/i })).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type TIdvFailed = {

type TIDVFailureConfig = {
required_fields: string[];
side_note_image: React.ReactElement;
side_note_image: JSX.Element;
failure_message: React.ReactNode;
inline_note_text: React.ReactNode;
};
Expand Down Expand Up @@ -200,7 +200,7 @@ const IdvFailed = ({
setRestState({
form_initial_values: {},
changeable_fields: [],
api_error: e.error.message,
api_error: e?.error?.message,
});
});
}, [mismatch_status, account_settings, is_document_upload_required, getChangeableFields]);
Expand Down Expand Up @@ -279,15 +279,15 @@ const IdvFailed = ({
return removeEmptyPropertiesFromObject(errors);
};

const citizen = account_settings?.citizen;
const selected_country = residence_list.find(residence_data => residence_data.value === citizen) || {};

if (rest_state?.api_error) return <LoadErrorMessage error_message={rest_state.api_error} />;

if (is_loading && Object.keys(rest_state?.form_initial_values ?? {}).length === 0) {
return <Loading is_fullscreen={false} className='account__initial-loader' />;
}

const citizen = account_settings?.citizen;
const selected_country = residence_list.find(residence_data => residence_data.value === citizen) || {};

return (
<Formik
initialValues={rest_state?.form_initial_values ?? {}}
Expand All @@ -311,7 +311,7 @@ const IdvFailed = ({
icon_height={16}
icon_width={16}
message={
<Text as='p' size='xs'>
<Text as='p' size='xs' data-testid={mismatch_status}>
{idv_failure?.failure_message}
</Text>
}
Expand Down