Skip to content

Commit

Permalink
refactor:vitest to CheckIn/TableRow (#2785)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivasankaran18 authored Dec 24, 2024
1 parent 9e5d64e commit 9848bae
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { MockedProvider } from '@apollo/react-testing';
import { checkInMutationSuccess, checkInMutationUnsuccess } from './mocks';
import { vi } from 'vitest';

/**
* Test suite for the `TableRow` component, focusing on the CheckIn table functionality.
*/

describe('Testing Table Row for CheckIn Table', () => {
beforeEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

test('If the user is not checked in, button to check in should be displayed, and the user should be able to check in successfully', async () => {
Expand All @@ -26,7 +31,7 @@ describe('Testing Table Row for CheckIn Table', () => {
checkIn: null,
eventId: `event123`,
},
refetch: jest.fn(),
refetch: vi.fn(),
};

const { findByText } = render(
Expand Down Expand Up @@ -63,7 +68,7 @@ describe('Testing Table Row for CheckIn Table', () => {
},
eventId: 'event123',
},
refetch: jest.fn(),
refetch: vi.fn(),
};

const { findByText } = render(
Expand All @@ -81,8 +86,8 @@ describe('Testing Table Row for CheckIn Table', () => {
</BrowserRouter>,
);

global.URL.createObjectURL = jest.fn(() => 'mockURL');
global.window.open = jest.fn();
global.URL.createObjectURL = vi.fn(() => 'mockURL');
global.window.open = vi.fn();

expect(await findByText('Checked In')).toBeInTheDocument();
expect(await findByText('Download Tag')).toBeInTheDocument();
Expand All @@ -93,7 +98,7 @@ describe('Testing Table Row for CheckIn Table', () => {
expect(await findByText('PDF generated successfully!')).toBeInTheDocument();

// Cleanup mocks
jest.clearAllMocks();
vi.clearAllMocks();
});

test('Upon failing of check in mutation, the appropriate error message should be shown', async () => {
Expand All @@ -105,7 +110,7 @@ describe('Testing Table Row for CheckIn Table', () => {
checkIn: null,
eventId: `event123`,
},
refetch: jest.fn(),
refetch: vi.fn(),
};

const { findByText } = render(
Expand Down Expand Up @@ -143,7 +148,7 @@ describe('Testing Table Row for CheckIn Table', () => {
},
eventId: `event123`,
},
refetch: jest.fn(),
refetch: vi.fn(),
};

const { findByText } = render(
Expand All @@ -162,8 +167,8 @@ describe('Testing Table Row for CheckIn Table', () => {
);

// Mocking the PDF generation function to throw an error
global.URL.createObjectURL = jest.fn(() => 'mockURL');
global.window.open = jest.fn();
global.URL.createObjectURL = vi.fn(() => 'mockURL');
global.window.open = vi.fn();

fireEvent.click(await findByText('Download Tag'));

Expand Down

0 comments on commit 9848bae

Please sign in to comment.