Skip to content

Commit

Permalink
fixed lint issue (#3420)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaan-aly246 authored Jan 25, 2025
1 parent 18cd1f0 commit ee5e754
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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<void> {
await act(() => {
return new Promise((resolve) => {
Expand All @@ -41,10 +42,10 @@ async function wait(ms = 500): Promise<void> {
});
}

jest.mock('react-toastify', () => ({
vi.mock('react-toastify', () => ({
toast: {
success: jest.fn(),
error: jest.fn(),
success: vi.fn(),
error: vi.fn(),
},
}));

Expand Down Expand Up @@ -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();
});

Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
192 changes: 192 additions & 0 deletions src/components/TagActions/TagActionsMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
},
];

0 comments on commit ee5e754

Please sign in to comment.