From 559edd023b6053f7fdbdd2fcbd80646aef31785a Mon Sep 17 00:00:00 2001 From: kanhaiya04 Date: Tue, 23 Jan 2024 00:35:44 +0530 Subject: [PATCH] increased the code coverage to 100% --- .../OrgProfileFieldSettings.test.tsx | 83 +++++++++++++++---- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/src/components/OrgProfileFieldSettings/OrgProfileFieldSettings.test.tsx b/src/components/OrgProfileFieldSettings/OrgProfileFieldSettings.test.tsx index 3684ae88da..be6cf6740b 100644 --- a/src/components/OrgProfileFieldSettings/OrgProfileFieldSettings.test.tsx +++ b/src/components/OrgProfileFieldSettings/OrgProfileFieldSettings.test.tsx @@ -11,6 +11,7 @@ import { REMOVE_CUSTOM_FIELD, } from 'GraphQl/Mutations/mutations'; import { ORGANIZATION_CUSTOM_FIELDS } from 'GraphQl/Queries/Queries'; +import { ToastContainer, toast } from 'react-toastify'; const MOCKS = [ { @@ -34,7 +35,7 @@ const MOCKS = [ { request: { query: REMOVE_CUSTOM_FIELD, - variables: {}, + variables: { customFieldId: 'adsdasdsa334343yiu423434' }, }, result: { data: { @@ -74,21 +75,13 @@ const ERROR_MOCKS = [ name: '', }, }, - result: { - data: { - addOrganizationCustomField: { - name: 'Custom Field Name', - type: 'string', - }, - }, - }, + error: new Error('Failed to add custom field'), }, { request: { query: REMOVE_CUSTOM_FIELD, variables: { - organizationId: '', - customFieldId: '', + customFieldId: 'adsdasdsa334343yiu423434', }, }, error: new Error('Failed to remove custom field'), @@ -112,6 +105,16 @@ const ERROR_MOCKS = [ }, ]; +const ORGANIZATION_CUSTOM_FIELDS_ERROR_MOCKS = [ + { + request: { + query: ORGANIZATION_CUSTOM_FIELDS, + variables: {}, + }, + error: new Error('Failed to fetch custom field'), + }, +]; + const NO_C_FIELD_MOCK = [ { request: { @@ -147,6 +150,7 @@ const NO_C_FIELD_MOCK = [ const link = new StaticMockLink(MOCKS, true); const link2 = new StaticMockLink(NO_C_FIELD_MOCK, true); const link3 = new StaticMockLink(ERROR_MOCKS, true); +const link4 = new StaticMockLink(ORGANIZATION_CUSTOM_FIELDS_ERROR_MOCKS, true); async function wait(ms = 100): Promise { await act(() => { @@ -157,10 +161,29 @@ async function wait(ms = 100): Promise { } describe('Testing Save Button', () => { + test('Testing Failure Case For Fetching Custom field', async () => { + render( + + + + + + ); + + await wait(); + expect( + screen.queryByText('Failed to fetch custom field') + ).toBeInTheDocument(); + }); test('Saving Organization Custom Field', async () => { render( + @@ -168,6 +191,25 @@ describe('Testing Save Button', () => { await wait(); userEvent.click(screen.getByTestId('saveChangesBtn')); + await wait(); + expect(screen.queryByText('Field added successfully')).toBeInTheDocument(); + }); + + test('Testing Failure Case For Saving Custom Field', async () => { + render( + + + + + + + ); + await wait(); + userEvent.click(screen.getByTestId('saveChangesBtn')); + await wait(); + expect( + screen.queryByText('Failed to add custom field') + ).toBeInTheDocument(); }); test('Testing Typing Organization Custom Field Name', async () => { @@ -198,8 +240,9 @@ describe('Testing Save Button', () => { }); test('Testing Remove Custom Field Button', async () => { render( - + + @@ -207,17 +250,25 @@ describe('Testing Save Button', () => { await wait(); userEvent.click(screen.getByTestId('removeCustomFieldBtn')); + await wait(); + expect( + screen.queryByText('Field removed successfully') + ).toBeInTheDocument(); }); - test('Testing Failure Case for Removing Custom Field', async () => { - const { getByText } = render( - + test('Testing Failure Case For Removing Custom Field', async () => { + const toastSpy = jest.spyOn(toast, 'error'); + render( + + ); await wait(); - expect(getByText('Field Type')).toBeInTheDocument(); + userEvent.click(screen.getByTestId('removeCustomFieldBtn')); + await wait(); + expect(toastSpy).toHaveBeenCalledWith('Failed to remove custom field'); }); });