Skip to content

Commit

Permalink
Merge branch 'develop-postgres' into UpcomingEvents-jest-to-vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
abbi4code authored Dec 12, 2024
2 parents 76a8c24 + 316c3cb commit bcb573d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Testing component for managing and displaying Volunteer Membership requests for an event.
*
* This component allows users to view, filter, sort, and create action items. It also allows users to accept or reject volunteer membership requests.
*
*
*/
import React, { act } from 'react';
import { MockedProvider } from '@apollo/react-testing';
import { LocalizationProvider } from '@mui/x-date-pickers';
Expand All @@ -20,11 +27,12 @@ import {
UPDATE_ERROR_MOCKS,
} from './Requests.mocks';
import { toast } from 'react-toastify';
import { vi } from 'vitest';

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 @@ -74,14 +82,14 @@ const renderRequests = (link: ApolloLink): RenderResult => {

describe('Testing Requests Screen', () => {
beforeAll(() => {
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
vi.mock('react-router-dom', async () => ({
...(await vi.importActual('react-router-dom')),
useParams: () => ({ orgId: 'orgId', eventId: 'eventId' }),
}));
});

afterAll(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it('should redirect to fallback URL if URL params are undefined', async () => {
Expand All @@ -102,10 +110,7 @@ describe('Testing Requests Screen', () => {
</MemoryRouter>
</MockedProvider>,
);

await waitFor(() => {
expect(screen.getByTestId('paramsError')).toBeInTheDocument();
});
expect(window.location.pathname).toBe('/');
});

it('should render Requests screen', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/**
* Unit tests for the Donate component.
*
* This file contains tests for the Donate component to ensure it behaves as expected
* under various scenarios.
*/
import React, { act } from 'react';
import { render, screen } from '@testing-library/react';
import { MockedProvider } from '@apollo/react-testing';
import { I18nextProvider } from 'react-i18next';

import { vi } from 'vitest';
import {
ORGANIZATION_DONATION_CONNECTION_LIST,
USER_ORGANIZATION_CONNECTION,
Expand Down Expand Up @@ -132,35 +138,35 @@ async function wait(ms = 100): Promise<void> {
});
}

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({ orgId: '' }),
vi.mock('react-router-dom', async () => ({
...(await vi.importActual('react-router-dom')),
useParams: vi.fn(() => ({ orgId: '' })),
}));

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

describe('Testing Donate 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(),
})),
});

beforeEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

test('Screen should be rendered properly', async () => {
Expand Down

0 comments on commit bcb573d

Please sign in to comment.