Skip to content

Commit

Permalink
Refactor: src/screens/OrganizationTags/OrganizationTags.test.tsx from…
Browse files Browse the repository at this point in the history
… Jest to Vitest (#3078)

* Added test for prior calender update

* updated jest to vitest

* resolved conflicts v2
  • Loading branch information
arpit-chakraborty authored Dec 31, 2024
1 parent f190f74 commit ff5663e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
waitForElementToBeRemoved,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import 'jest-location-mock';
import { vi } from 'vitest';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
Expand Down Expand Up @@ -44,10 +44,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 @@ -77,14 +77,17 @@ const renderOrganizationTags = (link: ApolloLink): RenderResult => {

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 actual = await vi.importActual('react-router-dom');
return {
...actual,
useParams: () => ({ orgId: 'orgId' }),
};
});
});

afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
cleanup();
});

Expand Down Expand Up @@ -129,7 +132,6 @@ describe('Organisation Tags Page', () => {
screen.queryByTestId('closeCreateTagModal'),
);
});

test('navigates to sub tags screen after clicking on a tag', async () => {
renderOrganizationTags(link);

Expand Down
12 changes: 6 additions & 6 deletions src/screens/OrganizationTags/OrganizationTagsMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const MOCKS = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
where: { name: { starts_with: '' } },
sortedBy: { id: 'DESCENDING' },
Expand Down Expand Up @@ -187,7 +187,7 @@ export const MOCKS = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
after: '10',
where: { name: { starts_with: '' } },
Expand Down Expand Up @@ -248,7 +248,7 @@ export const MOCKS = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
where: { name: { starts_with: 'searchUserTag' } },
sortedBy: { id: 'DESCENDING' },
Expand Down Expand Up @@ -322,7 +322,7 @@ export const MOCKS = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
where: { name: { starts_with: 'searchUserTag' } },
sortedBy: { id: 'ASCENDING' },
Expand Down Expand Up @@ -397,7 +397,7 @@ export const MOCKS = [
query: CREATE_USER_TAG,
variables: {
name: 'userTag 12',
organizationId: '123',
organizationId: 'orgId',
},
},
result: {
Expand All @@ -415,7 +415,7 @@ export const MOCKS_ERROR = [
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
id: 'orgId',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
where: { name: { starts_with: '' } },
sortedBy: { id: 'DESCENDING' },
Expand Down

0 comments on commit ff5663e

Please sign in to comment.