From e9c8ae7b2ff8bbfe39dace47333a95c24aca14d5 Mon Sep 17 00:00:00 2001 From: abhishek Date: Tue, 24 Dec 2024 14:37:59 +0530 Subject: [PATCH] UserPortal/People component test migrated jest to vitest --- .../{People.test.tsx => People.spec.tsx} | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) rename src/screens/UserPortal/People/{People.test.tsx => People.spec.tsx} (82%) diff --git a/src/screens/UserPortal/People/People.test.tsx b/src/screens/UserPortal/People/People.spec.tsx similarity index 82% rename from src/screens/UserPortal/People/People.test.tsx rename to src/screens/UserPortal/People/People.spec.tsx index c978a0a5a3..11051538db 100644 --- a/src/screens/UserPortal/People/People.test.tsx +++ b/src/screens/UserPortal/People/People.spec.tsx @@ -13,6 +13,19 @@ import i18nForTest from 'utils/i18nForTest'; import { StaticMockLink } from 'utils/StaticMockLink'; import People from './People'; import userEvent from '@testing-library/user-event'; +import { vi } from 'vitest'; + +/** + * This file contains unit tests for the People component. + * + * The tests cover: + * - Proper rendering of the People screen and its elements. + * - Functionality of the search input and search button. + * - Correct behavior when switching between member and admin modes. + * - Integration with mocked GraphQL queries for testing data fetching. + * + * These tests use Vitest for test execution, MockedProvider for mocking GraphQL queries, and react-testing-library for rendering and interactions. + */ const MOCKS = [ { @@ -113,27 +126,30 @@ async function wait(ms = 100): Promise { }); } -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useParams: () => ({ orgId: '' }), -})); +vi.mock('react-router-dom', async () => { + const actual = await vi.importActual('react-router-dom'); + return { + ...actual, + useParams: () => ({ orgId: '' }), + }; +}); describe('Testing People Screen [User Portal]', () => { Object.defineProperty(window, 'matchMedia', { writable: true, - value: jest.fn().mockImplementation((query) => ({ + value: vi.fn().mockImplementation((query) => ({ matches: false, media: query, onchange: null, - addListener: jest.fn(), // Deprecated - removeListener: jest.fn(), // Deprecated - addEventListener: jest.fn(), - removeEventListener: jest.fn(), - dispatchEvent: jest.fn(), + addListener: vi.fn(), // Deprecated + removeListener: vi.fn(), // Deprecated + addEventListener: vi.fn(), + removeEventListener: vi.fn(), + dispatchEvent: vi.fn(), })), }); - test('Screen should be rendered properly', async () => { + it('Screen should be rendered properly', async () => { render( @@ -151,7 +167,7 @@ describe('Testing People Screen [User Portal]', () => { expect(screen.queryAllByText('Noble Mittal')).not.toBe([]); }); - test('Search works properly by pressing enter', async () => { + it('Search works properly by pressing enter', async () => { render( @@ -173,7 +189,7 @@ describe('Testing People Screen [User Portal]', () => { expect(screen.queryByText('Noble Mittal')).not.toBeInTheDocument(); }); - test('Search works properly by clicking search Btn', async () => { + it('Search works properly by clicking search Btn', async () => { render( @@ -199,7 +215,7 @@ describe('Testing People Screen [User Portal]', () => { expect(screen.queryByText('Noble Mittal')).not.toBeInTheDocument(); }); - test('Mode is changed to Admins', async () => { + it('Mode is changed to Admins', async () => { render(