Skip to content

Commit

Permalink
Refacted : src/components/LeftDrawer/LeftDrawer.test.tsx from Jest to…
Browse files Browse the repository at this point in the history
… Vitest (#3134)

* refactor: migrate LeftDrawer.test.tsx from Jest to Vitest -(#3119)
  • Loading branch information
aryanrule authored Jan 4, 2025
1 parent 7a27af0 commit fb48e16
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import React, { act } from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import 'jest-localstorage-mock';
import { I18nextProvider } from 'react-i18next';
import { BrowserRouter } from 'react-router-dom';

import i18nForTest from 'utils/i18nForTest';
import type { InterfaceLeftDrawerProps } from './LeftDrawer';
import LeftDrawer from './LeftDrawer';
import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations';
import { StaticMockLink } from 'utils/StaticMockLink';
import { MockedProvider } from '@apollo/react-testing';
import useLocalStorage from 'utils/useLocalstorage';
import { vi, it, describe, beforeEach, afterEach, expect } from 'vitest';

const { setItem } = useLocalStorage();

const props = {
hideDrawer: true,
setHideDrawer: jest.fn(),
setHideDrawer: vi.fn(),
};

const resizeWindow = (width: number): void => {
Expand All @@ -40,11 +39,11 @@ const MOCKS = [

const link = new StaticMockLink(MOCKS, true);

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

Expand All @@ -58,12 +57,12 @@ beforeEach(() => {
});

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

describe('Testing Left Drawer component for SUPERADMIN', () => {
test('Component should be rendered properly', async () => {
it('Component should be rendered properly', async () => {
setItem('UserImage', '');
setItem('SuperAdmin', true);
setItem('FirstName', 'John');
Expand Down Expand Up @@ -113,7 +112,7 @@ describe('Testing Left Drawer component for SUPERADMIN', () => {
});
});

test('Testing Drawer when hideDrawer is null', async () => {
it('Testing Drawer when hideDrawer is null', async () => {
const tempProps: InterfaceLeftDrawerProps = {
...props,
hideDrawer: false,
Expand All @@ -132,7 +131,7 @@ describe('Testing Left Drawer component for SUPERADMIN', () => {
});
});

test('Testing Drawer when hideDrawer is false', async () => {
it('Testing Drawer when hideDrawer is false', async () => {
const tempProps: InterfaceLeftDrawerProps = {
...props,
hideDrawer: false,
Expand All @@ -151,7 +150,7 @@ describe('Testing Left Drawer component for SUPERADMIN', () => {
});
});

test('Testing Drawer when the screen size is less than or equal to 820px', async () => {
it('Testing Drawer when the screen size is less than or equal to 820px', async () => {
const tempProps: InterfaceLeftDrawerProps = {
...props,
hideDrawer: false,
Expand Down Expand Up @@ -184,7 +183,7 @@ describe('Testing Left Drawer component for SUPERADMIN', () => {
});

describe('Testing Left Drawer component for ADMIN', () => {
test('Components should be rendered properly', async () => {
it('Components should be rendered properly', async () => {
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
Expand Down

0 comments on commit fb48e16

Please sign in to comment.