From ee5e754a515f2bdc16c3d9c71d6ff098d9b93efd Mon Sep 17 00:00:00 2001 From: Amaan ali Date: Sat, 25 Jan 2025 18:50:39 +0530 Subject: [PATCH] fixed lint issue (#3420) --- .../MOCKS_ERROR_ASSIGN_OR_REMOVAL_TAGS.md | 9 + ...agActions.test.tsx => TagActions.spec.tsx} | 37 +++- src/components/TagActions/TagActionsMocks.ts | 192 ++++++++++++++++++ 3 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 docs/docs/auto-docs/components/TagActions/TagActionsMocks/variables/MOCKS_ERROR_ASSIGN_OR_REMOVAL_TAGS.md rename src/components/TagActions/{TagActions.test.tsx => TagActions.spec.tsx} (92%) diff --git a/docs/docs/auto-docs/components/TagActions/TagActionsMocks/variables/MOCKS_ERROR_ASSIGN_OR_REMOVAL_TAGS.md b/docs/docs/auto-docs/components/TagActions/TagActionsMocks/variables/MOCKS_ERROR_ASSIGN_OR_REMOVAL_TAGS.md new file mode 100644 index 0000000000..ef1225d326 --- /dev/null +++ b/docs/docs/auto-docs/components/TagActions/TagActionsMocks/variables/MOCKS_ERROR_ASSIGN_OR_REMOVAL_TAGS.md @@ -0,0 +1,9 @@ +[Admin Docs](/) + +*** + +# Variable: MOCKS\_ERROR\_ASSIGN\_OR\_REMOVAL\_TAGS + +> `const` **MOCKS\_ERROR\_ASSIGN\_OR\_REMOVAL\_TAGS**: (\{ `error`: `undefined`; `request`: \{ `query`: `DocumentNode`; `variables`: \{ `currentTagId`: `undefined`; `first`: `number`; `id`: `string`; `selectedTagIds`: `undefined`; `where`: \{ `name`: \{ `starts_with`: `string`; \}; \}; \}; \}; `result`: \{ `data`: \{ `organizations`: `object`[]; \}; \}; \} \| \{ `error`: `Error`; `request`: \{ `query`: `DocumentNode`; `variables`: \{ `currentTagId`: `string`; `first`: `undefined`; `id`: `undefined`; `selectedTagIds`: `string`[]; `where`: `undefined`; \}; \}; `result`: `undefined`; \})[] + +Defined in: [src/components/TagActions/TagActionsMocks.ts:708](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/components/TagActions/TagActionsMocks.ts#L708) diff --git a/src/components/TagActions/TagActions.test.tsx b/src/components/TagActions/TagActions.spec.tsx similarity index 92% rename from src/components/TagActions/TagActions.test.tsx rename to src/components/TagActions/TagActions.spec.tsx index d27f177ebe..a6f54160f1 100644 --- a/src/components/TagActions/TagActions.test.tsx +++ b/src/components/TagActions/TagActions.spec.tsx @@ -11,7 +11,6 @@ import { } from '@testing-library/react'; import { Provider } from 'react-redux'; import { MemoryRouter, Route, Routes } from 'react-router-dom'; -import 'jest-location-mock'; import { I18nextProvider } from 'react-i18next'; import { store } from 'state/store'; @@ -22,8 +21,10 @@ import type { ApolloLink } from '@apollo/client'; import type { InterfaceTagActionsProps } from './TagActions'; import TagActions from './TagActions'; import i18n from 'utils/i18nForTest'; +import { vi } from 'vitest'; import { MOCKS, + MOCKS_ERROR_ASSIGN_OR_REMOVAL_TAGS, MOCKS_ERROR_ORGANIZATION_TAGS_QUERY, MOCKS_ERROR_SUBTAGS_QUERY, } from './TagActionsMocks'; @@ -32,7 +33,7 @@ import type { TFunction } from 'i18next'; const link = new StaticMockLink(MOCKS, true); const link2 = new StaticMockLink(MOCKS_ERROR_ORGANIZATION_TAGS_QUERY, true); const link3 = new StaticMockLink(MOCKS_ERROR_SUBTAGS_QUERY, true); - +const link4 = new StaticMockLink(MOCKS_ERROR_ASSIGN_OR_REMOVAL_TAGS); async function wait(ms = 500): Promise { await act(() => { return new Promise((resolve) => { @@ -41,10 +42,10 @@ async function wait(ms = 500): Promise { }); } -jest.mock('react-toastify', () => ({ +vi.mock('react-toastify', () => ({ toast: { - success: jest.fn(), - error: jest.fn(), + success: vi.fn(), + error: vi.fn(), }, })); @@ -109,14 +110,16 @@ const renderTagActionsModal = ( describe('Organisation Tags Page', () => { beforeEach(() => { - jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useParams: () => ({ orgId: 'orgId' }), - })); + vi.mock('react-router-dom', async () => { + const actualModule = await vi.importActual('react-router-dom'); + return { + ...actualModule, + }; + }); }); afterEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); cleanup(); }); @@ -141,7 +144,7 @@ describe('Organisation Tags Page', () => { }); test('Component calls hideTagActionsModal when modal is closed', async () => { - const hideTagActionsModalMock = jest.fn(); + const hideTagActionsModalMock = vi.fn(); const props2: InterfaceTagActionsProps = { tagActionsModalIsOpen: true, @@ -352,6 +355,18 @@ describe('Organisation Tags Page', () => { expect(toast.error).toHaveBeenCalledWith(translations.noTagSelected); }); }); + test('Toasts error when something wrong happen while assigning/removing tag', async () => { + renderTagActionsModal(props[0], link4); + await wait(); + + await waitFor(() => { + expect(screen.getByTestId('tagActionSubmitBtn')).toBeInTheDocument(); + }); + userEvent.click(screen.getByTestId('tagActionSubmitBtn')); + await waitFor(() => { + expect(toast.error).toHaveBeenCalled(); + }); + }); test('Successfully assigns to tags', async () => { renderTagActionsModal(props[0], link); diff --git a/src/components/TagActions/TagActionsMocks.ts b/src/components/TagActions/TagActionsMocks.ts index f22458fa53..35e170977b 100644 --- a/src/components/TagActions/TagActionsMocks.ts +++ b/src/components/TagActions/TagActionsMocks.ts @@ -704,3 +704,195 @@ export const MOCKS_ERROR_SUBTAGS_QUERY = [ error: new Error('Mock Graphql Error for subTags query'), }, ]; + +export const MOCKS_ERROR_ASSIGN_OR_REMOVAL_TAGS = [ + { + request: { + query: ORGANIZATION_USER_TAGS_LIST, + variables: { + id: '123', + first: TAGS_QUERY_DATA_CHUNK_SIZE, + where: { name: { starts_with: '' } }, + }, + }, + result: { + data: { + organizations: [ + { + userTags: { + edges: [ + { + node: { + _id: '1', + name: 'userTag 1', + parentTag: null, + usersAssignedTo: { + totalCount: 5, + }, + childTags: { + totalCount: 11, + }, + ancestorTags: [], + }, + cursor: '1', + }, + { + node: { + _id: '2', + name: 'userTag 2', + parentTag: null, + usersAssignedTo: { + totalCount: 5, + }, + childTags: { + totalCount: 0, + }, + ancestorTags: [], + }, + cursor: '2', + }, + { + node: { + _id: '3', + name: 'userTag 3', + parentTag: null, + usersAssignedTo: { + totalCount: 0, + }, + childTags: { + totalCount: 5, + }, + ancestorTags: [], + }, + cursor: '3', + }, + { + node: { + _id: '4', + name: 'userTag 4', + parentTag: null, + usersAssignedTo: { + totalCount: 0, + }, + childTags: { + totalCount: 0, + }, + ancestorTags: [], + }, + cursor: '4', + }, + { + node: { + _id: '5', + name: 'userTag 5', + parentTag: null, + usersAssignedTo: { + totalCount: 5, + }, + childTags: { + totalCount: 5, + }, + ancestorTags: [], + }, + cursor: '5', + }, + { + node: { + _id: '6', + name: 'userTag 6', + parentTag: null, + usersAssignedTo: { + totalCount: 6, + }, + childTags: { + totalCount: 6, + }, + ancestorTags: [], + }, + cursor: '6', + }, + { + node: { + _id: '7', + name: 'userTag 7', + parentTag: null, + usersAssignedTo: { + totalCount: 7, + }, + childTags: { + totalCount: 7, + }, + ancestorTags: [], + }, + cursor: '7', + }, + { + node: { + _id: '8', + name: 'userTag 8', + parentTag: null, + usersAssignedTo: { + totalCount: 8, + }, + childTags: { + totalCount: 8, + }, + ancestorTags: [], + }, + cursor: '8', + }, + { + node: { + _id: '9', + name: 'userTag 9', + parentTag: null, + usersAssignedTo: { + totalCount: 9, + }, + childTags: { + totalCount: 9, + }, + ancestorTags: [], + }, + cursor: '9', + }, + { + node: { + _id: '10', + name: 'userTag 10', + parentTag: null, + usersAssignedTo: { + totalCount: 10, + }, + childTags: { + totalCount: 10, + }, + ancestorTags: [], + }, + cursor: '10', + }, + ], + pageInfo: { + startCursor: '1', + endCursor: '10', + hasNextPage: true, + hasPreviousPage: false, + }, + totalCount: 12, + }, + }, + ], + }, + }, + }, + { + request: { + query: ASSIGN_TO_TAGS, + variables: { + currentTagId: '1', + selectedTagIds: ['2', '3'], + }, + }, + error: new Error('Mock Graphql Error While assigning/removing tags'), + }, +];