Skip to content

Commit 47c0e3b

Browse files
authored
Migrated src/screens/ManageTag from Jest to Vitest (#2742)
* Refactor: Migrated src/screens/ManageTag from Jest to Vitest * fix: removed imports for Jest
1 parent cd0b041 commit 47c0e3b

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

src/screens/ManageTag/ManageTag.test.tsx renamed to src/screens/ManageTag/ManageTag.spec.tsx

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
waitForElementToBeRemoved,
1212
} from '@testing-library/react';
1313
import userEvent from '@testing-library/user-event';
14-
import 'jest-location-mock';
1514
import { I18nextProvider } from 'react-i18next';
1615
import { Provider } from 'react-redux';
1716
import { MemoryRouter, Route, Routes } from 'react-router-dom';
@@ -22,6 +21,7 @@ import i18n from 'utils/i18nForTest';
2221
import ManageTag from './ManageTag';
2322
import { MOCKS, MOCKS_ERROR_ASSIGNED_MEMBERS } from './ManageTagMocks';
2423
import { type ApolloLink } from '@apollo/client';
24+
import { vi, beforeEach, afterEach, expect, it } from 'vitest';
2525

2626
const translations = {
2727
...JSON.parse(
@@ -42,21 +42,21 @@ async function wait(ms = 500): Promise<void> {
4242
});
4343
}
4444

45-
jest.mock('react-toastify', () => ({
45+
vi.mock('react-toastify', () => ({
4646
toast: {
47-
success: jest.fn(),
48-
info: jest.fn(),
49-
error: jest.fn(),
47+
success: vi.fn(),
48+
info: vi.fn(),
49+
error: vi.fn(),
5050
},
5151
}));
5252

5353
/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */
54-
jest.mock('../../components/AddPeopleToTag/AddPeopleToTag', () => {
55-
return require('./ManageTagMockComponents/MockAddPeopleToTag').default;
54+
vi.mock('../../components/AddPeopleToTag/AddPeopleToTag', async () => {
55+
return await import('./ManageTagMockComponents/MockAddPeopleToTag');
5656
});
5757

58-
jest.mock('../../components/TagActions/TagActions', () => {
59-
return require('./ManageTagMockComponents/MockTagActions').default;
58+
vi.mock('../../components/TagActions/TagActions', async () => {
59+
return await import('./ManageTagMockComponents/MockTagActions');
6060
});
6161
/* eslint-enable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */
6262

@@ -93,18 +93,17 @@ const renderManageTag = (link: ApolloLink): RenderResult => {
9393

9494
describe('Manage Tag Page', () => {
9595
beforeEach(() => {
96-
jest.mock('react-router-dom', () => ({
97-
...jest.requireActual('react-router-dom'),
98-
useParams: () => ({ orgId: 'orgId' }),
96+
vi.mock('react-router-dom', async () => ({
97+
...(await vi.importActual('react-router-dom')),
9998
}));
10099
});
101100

102101
afterEach(() => {
103-
jest.clearAllMocks();
102+
vi.clearAllMocks();
104103
cleanup();
105104
});
106105

107-
test('Component loads correctly', async () => {
106+
it('Component loads correctly', async () => {
108107
const { getByText } = renderManageTag(link);
109108

110109
await wait();
@@ -114,7 +113,7 @@ describe('Manage Tag Page', () => {
114113
});
115114
});
116115

117-
test('renders error component on unsuccessful userTag assigned members query', async () => {
116+
it('renders error component on unsuccessful userTag assigned members query', async () => {
118117
const { queryByText } = renderManageTag(link2);
119118

120119
await wait();
@@ -124,7 +123,7 @@ describe('Manage Tag Page', () => {
124123
});
125124
});
126125

127-
test('opens and closes the add people to tag modal', async () => {
126+
it('opens and closes the add people to tag modal', async () => {
128127
renderManageTag(link);
129128

130129
await waitFor(() => {
@@ -146,7 +145,7 @@ describe('Manage Tag Page', () => {
146145
});
147146
});
148147

149-
test('opens and closes the unassign tag modal', async () => {
148+
it('opens and closes the unassign tag modal', async () => {
150149
renderManageTag(link);
151150

152151
await wait();
@@ -168,7 +167,7 @@ describe('Manage Tag Page', () => {
168167
);
169168
});
170169

171-
test('opens and closes the assignToTags modal', async () => {
170+
it('opens and closes the assignToTags modal', async () => {
172171
renderManageTag(link);
173172

174173
// Wait for the assignToTags button to be present
@@ -193,7 +192,7 @@ describe('Manage Tag Page', () => {
193192
});
194193
});
195194

196-
test('opens and closes the removeFromTags modal', async () => {
195+
it('opens and closes the removeFromTags modal', async () => {
197196
renderManageTag(link);
198197

199198
// Wait for the removeFromTags button to be present
@@ -218,7 +217,7 @@ describe('Manage Tag Page', () => {
218217
});
219218
});
220219

221-
test('opens and closes the edit tag modal', async () => {
220+
it('opens and closes the edit tag modal', async () => {
222221
renderManageTag(link);
223222

224223
await wait();
@@ -240,7 +239,7 @@ describe('Manage Tag Page', () => {
240239
);
241240
});
242241

243-
test('opens and closes the remove tag modal', async () => {
242+
it('opens and closes the remove tag modal', async () => {
244243
renderManageTag(link);
245244

246245
await wait();
@@ -262,7 +261,7 @@ describe('Manage Tag Page', () => {
262261
);
263262
});
264263

265-
test("navigates to the member's profile after clicking the view option", async () => {
264+
it("navigates to the member's profile after clicking the view option", async () => {
266265
renderManageTag(link);
267266

268267
await wait();
@@ -277,7 +276,7 @@ describe('Manage Tag Page', () => {
277276
});
278277
});
279278

280-
test('navigates to the subTags screen after clicking the subTags option', async () => {
279+
it('navigates to the subTags screen after clicking the subTags option', async () => {
281280
renderManageTag(link);
282281

283282
await wait();
@@ -292,7 +291,7 @@ describe('Manage Tag Page', () => {
292291
});
293292
});
294293

295-
test('navigates to the manageTag screen after clicking a tag in the breadcrumbs', async () => {
294+
it('navigates to the manageTag screen after clicking a tag in the breadcrumbs', async () => {
296295
renderManageTag(link);
297296

298297
await wait();
@@ -309,7 +308,7 @@ describe('Manage Tag Page', () => {
309308
});
310309
});
311310

312-
test('navigates to organization tags screen screen after clicking tha all tags option in the breadcrumbs', async () => {
311+
it('navigates to organization tags screen screen after clicking tha all tags option in the breadcrumbs', async () => {
313312
renderManageTag(link);
314313

315314
await wait();
@@ -324,7 +323,7 @@ describe('Manage Tag Page', () => {
324323
});
325324
});
326325

327-
test('searchs for tags where the name matches the provided search input', async () => {
326+
it('searchs for tags where the name matches the provided search input', async () => {
328327
renderManageTag(link);
329328

330329
await wait();
@@ -345,7 +344,7 @@ describe('Manage Tag Page', () => {
345344
});
346345
});
347346

348-
test('fetches the tags by the sort order, i.e. latest or oldest first', async () => {
347+
it('fetches the tags by the sort order, i.e. latest or oldest first', async () => {
349348
renderManageTag(link);
350349

351350
await wait();
@@ -402,7 +401,7 @@ describe('Manage Tag Page', () => {
402401
});
403402
});
404403

405-
test('Fetches more assigned members with infinite scroll', async () => {
404+
it('Fetches more assigned members with infinite scroll', async () => {
406405
const { getByText } = renderManageTag(link);
407406

408407
await wait();
@@ -433,7 +432,7 @@ describe('Manage Tag Page', () => {
433432
});
434433
});
435434

436-
test('unassigns a tag from a member', async () => {
435+
it('unassigns a tag from a member', async () => {
437436
renderManageTag(link);
438437

439438
await wait();
@@ -452,7 +451,7 @@ describe('Manage Tag Page', () => {
452451
});
453452
});
454453

455-
test('successfully edits the tag name', async () => {
454+
it('successfully edits the tag name', async () => {
456455
renderManageTag(link);
457456

458457
await wait();
@@ -482,7 +481,7 @@ describe('Manage Tag Page', () => {
482481
});
483482
});
484483

485-
test('successfully removes the tag and redirects to orgTags page', async () => {
484+
it('successfully removes the tag and redirects to orgTags page', async () => {
486485
renderManageTag(link);
487486

488487
await wait();

src/screens/ManageTag/ManageTag.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ function ManageTag(): JSX.Element {
132132
};
133133
},
134134
) => {
135-
if (!fetchMoreResult) /* istanbul ignore next */ return prevResult;
135+
/* istanbul ignore next -- @preserve */
136+
if (!fetchMoreResult) return prevResult;
136137

137138
return {
138139
getAssignedUsers: {
@@ -174,7 +175,7 @@ function ManageTag(): JSX.Element {
174175
toggleUnassignUserTagModal();
175176
toast.success(t('successfullyUnassigned') as string);
176177
} catch (error: unknown) {
177-
/* istanbul ignore next */
178+
/* istanbul ignore next -- @preserve */
178179
if (error instanceof Error) {
179180
toast.error(error.message);
180181
}
@@ -209,13 +210,14 @@ function ManageTag(): JSX.Element {
209210
},
210211
});
211212

213+
/* istanbul ignore else -- @preserve */
212214
if (data) {
213215
toast.success(t('tagUpdationSuccess'));
214216
userTagAssignedMembersRefetch();
215217
setEditUserTagModalIsOpen(false);
216218
}
217219
} catch (error: unknown) {
218-
/* istanbul ignore next */
220+
/* istanbul ignore next -- @preserve */
219221
if (error instanceof Error) {
220222
toast.error(error.message);
221223
}
@@ -235,7 +237,7 @@ function ManageTag(): JSX.Element {
235237
toggleRemoveUserTagModal();
236238
toast.success(t('tagRemovalSuccess') as string);
237239
} catch (error: unknown) {
238-
/* istanbul ignore next */
240+
/* istanbul ignore next -- @preserve */
239241
if (error instanceof Error) {
240242
toast.error(error.message);
241243
}
@@ -258,7 +260,7 @@ function ManageTag(): JSX.Element {
258260
const userTagAssignedMembers =
259261
userTagAssignedMembersData?.getAssignedUsers.usersAssignedTo.edges.map(
260262
(edge) => edge.node,
261-
) ?? /* istanbul ignore next */ [];
263+
) ?? /* istanbul ignore next -- @preserve */ [];
262264

263265
// get the ancestorTags array and push the current tag in it
264266
// used for the tag breadcrumbs
@@ -452,7 +454,7 @@ function ManageTag(): JSX.Element {
452454
>
453455
{tag.name}
454456
{orgUserTagAncestors.length - 1 !== index && (
455-
/* istanbul ignore next */
457+
/* istanbul ignore next -- @preserve */
456458
<i className={'mx-2 fa fa-caret-right'} />
457459
)}
458460
</div>
@@ -469,7 +471,7 @@ function ManageTag(): JSX.Element {
469471
hasMore={
470472
userTagAssignedMembersData?.getAssignedUsers
471473
.usersAssignedTo.pageInfo.hasNextPage ??
472-
/* istanbul ignore next */ false
474+
/* istanbul ignore next -- @preserve */ false
473475
}
474476
loader={<InfiniteScrollLoader />}
475477
scrollableTarget="manageTagScrollableDiv"
@@ -480,15 +482,16 @@ function ManageTag(): JSX.Element {
480482
hideFooter={true}
481483
getRowId={(row) => row.id}
482484
slots={{
483-
noRowsOverlay: /* istanbul ignore next */ () => (
484-
<Stack
485-
height="100%"
486-
alignItems="center"
487-
justifyContent="center"
488-
>
489-
{t('noAssignedMembersFound')}
490-
</Stack>
491-
),
485+
noRowsOverlay:
486+
/* istanbul ignore next -- @preserve */ () => (
487+
<Stack
488+
height="100%"
489+
alignItems="center"
490+
justifyContent="center"
491+
>
492+
{t('noAssignedMembersFound')}
493+
</Stack>
494+
),
492495
}}
493496
sx={dataGridStyle}
494497
getRowClassName={() => `${styles.rowBackground}`}

0 commit comments

Comments
 (0)