Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: src/screens/OrganizationVenues from Jest to Vitest #2665

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
02eb9d4
Refactored some code
Dec 12, 2024
0cbb62f
Merge branch 'develop-postgres' of https://github.com/PalisadoesFound…
Dec 14, 2024
b4fa1ef
Migrate src/screens/OrganizationVenues from jest to vitest
Dec 14, 2024
4acf452
Revert "Refactored some code"
Dec 14, 2024
60002f1
replaced vi.mock with vi.doMock
Dec 14, 2024
9c87ad3
Add comments
Dec 14, 2024
a0838af
Merge branch 'develop-postgres' into code-refactor
im-vedant Dec 15, 2024
99caf14
Suppressed Css error
Dec 16, 2024
4529421
Merge branch 'code-refactor' of https://github.com/im-vedant/talawa-a…
Dec 16, 2024
e32116e
Merge branch 'develop-postgres' into code-refactor
im-vedant Dec 16, 2024
0edc76e
Fix customTableCell issue
Dec 16, 2024
326226b
Merge branch 'code-refactor' of https://github.com/im-vedant/talawa-a…
Dec 16, 2024
b9f0830
add data-testid attributes for toggle state for improved testability
Dec 16, 2024
18cc26b
feat: updated jest config and package-lock.json to include identity-o…
Dec 16, 2024
8aea843
Fix linting errors
Dec 16, 2024
650f431
refactor : src\components\MemberDetail\customTableCell.test.tsx and s…
Dec 17, 2024
5c51ce9
Merge branch 'develop-postgres' of https://github.com/PalisadoesFound…
Dec 21, 2024
88aad8d
Removed data-expanded attribute from mainpageright div
Dec 21, 2024
c9a8468
Merge branch 'develop-postgres' of https://github.com/PalisadoesFound…
Dec 21, 2024
ef049f3
Merge branch 'develop-postgres' of https://github.com/PalisadoesFound…
Dec 21, 2024
4b41c47
Merge branch 'develop-postgres' into code-refactor
palisadoes Dec 21, 2024
93d969e
Add test cases in src/components/MemberDetail/CustomTableCell
Dec 22, 2024
1d577df
Merge branch 'code-refactor' of https://github.com/im-vedant/talawa-a…
Dec 22, 2024
27e8807
Merge branch 'develop-postgres' of https://github.com/PalisadoesFound…
Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/MemberDetail/customTableCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@
await waitFor(() => screen.getByTestId('custom-row'));

expect(screen.getByText('Test Event')).toBeInTheDocument();
expect(screen.getByText('May 1, 2023')).toBeInTheDocument();
expect(
screen.getByText(
new Date('2023-05-01').toLocaleDateString(undefined, {
year: 'numeric',
month: 'long',
im-vedant marked this conversation as resolved.
Show resolved Hide resolved
day: 'numeric',
timeZone: 'UTC',
}),
),
).toBeInTheDocument();
expect(screen.getByText('Yes')).toBeInTheDocument();
expect(screen.getByText('2')).toBeInTheDocument();

Expand All @@ -87,7 +96,7 @@
expect(screen.getByRole('progressbar')).toBeInTheDocument();
});

// it('displays error state', async () => {

Check warning on line 99 in src/components/MemberDetail/customTableCell.test.tsx

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Some tests seem to be commented
// const errorMock = [
// {
// request: {
Expand Down Expand Up @@ -121,7 +130,7 @@
// expect(toast.error).toHaveBeenCalledWith('An error occurred');
// });

// it('displays no event found message', async () => {

Check warning on line 133 in src/components/MemberDetail/customTableCell.test.tsx

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Some tests seem to be commented
// const noEventMock = [
// {
// request: {
Expand Down
10 changes: 6 additions & 4 deletions src/components/OrganizationScreen/OrganizationScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,17 @@ describe('Testing OrganizationScreen', () => {
fireEvent.click(closeButton);

// Check for contract class after closing
expect(screen.getByTestId('mainpageright')).toHaveClass('_expand_ccl5z_8');
expect(
screen.getByTestId('mainpageright').className.includes('expand'),
).toBeTruthy();

const openButton = screen.getByTestId('openMenu');
fireEvent.click(openButton);

// Check for expand class after opening
expect(screen.getByTestId('mainpageright')).toHaveClass(
'_contract_ccl5z_61',
im-vedant marked this conversation as resolved.
Show resolved Hide resolved
);
expect(
screen.getByTestId('mainpageright').className.includes('contract'),
).toBeTruthy();
im-vedant marked this conversation as resolved.
Show resolved Hide resolved
});

test('handles window resize', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Tests for the OrganizationVenues component.
* These tests include:
* - Ensuring the component renders correctly with default props.
* - Handling the absence of `orgId` by redirecting to the homepage.
* - Fetching and displaying venues via Apollo GraphQL queries.
* - Allowing users to search venues by name or description.
* - Sorting venues by capacity in ascending or descending order.
* - Verifying that long venue names or descriptions are handled gracefully.
* - Testing loading states and edge cases for Apollo queries.
* - Mocking GraphQL mutations for venue-related actions and validating their behavior.
*/
import React from 'react';
import { MockedProvider } from '@apollo/react-testing';
import type { RenderResult } from '@testing-library/react';
Expand All @@ -10,7 +22,6 @@ import {
} from '@testing-library/react';
import { Provider } from 'react-redux';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import 'jest-location-mock';
import { I18nextProvider } from 'react-i18next';
import OrganizationVenues from './OrganizationVenues';
import { store } from 'state/store';
Expand All @@ -19,7 +30,7 @@ import { StaticMockLink } from 'utils/StaticMockLink';
import { VENUE_LIST } from 'GraphQl/Queries/OrganizationQueries';
import type { ApolloLink } from '@apollo/client';
import { DELETE_VENUE_MUTATION } from 'GraphQl/Mutations/VenueMutations';

import { vi } from 'vitest';
const MOCKS = [
{
request: {
Expand Down Expand Up @@ -239,11 +250,11 @@ async function wait(ms = 100): Promise<void> {
});
}

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

Expand Down Expand Up @@ -272,14 +283,14 @@ const renderOrganizationVenue = (link: ApolloLink): RenderResult => {

describe('OrganizationVenue with missing orgId', () => {
beforeAll(() => {
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
vi.doMock('react-router-dom', async () => ({
...(await vi.importActual('react-router-dom')),
useParams: () => ({ orgId: undefined }),
}));
});

afterAll(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});
test('Redirect to /orglist when orgId is falsy/undefined', async () => {
render(
Expand All @@ -299,7 +310,6 @@ describe('OrganizationVenue with missing orgId', () => {
</MemoryRouter>
</MockedProvider>,
);

await waitFor(() => {
const paramsError = screen.getByTestId('paramsError');
expect(paramsError).toBeInTheDocument();
Expand All @@ -308,17 +318,17 @@ describe('OrganizationVenue with missing orgId', () => {
});

describe('Organisation Venues', () => {
global.alert = jest.fn();
global.alert = vi.fn();

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

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

test('searches the venue list correctly by Name', async () => {
Expand Down
13 changes: 11 additions & 2 deletions src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@

import { format } from 'util';

global.console.error = function (...args): void {
throw new Error(format(...args));
const jsDomCssError = 'Error: Could not parse CSS stylesheet';

Check warning on line 11 in src/setupTests.ts

View check run for this annotation

Codecov / codecov/patch

src/setupTests.ts#L11

Added line #L11 was not covered by tests

// Override console.error to suppress the CSS parsing error
global.console.error = (...params) => {

Check warning on line 14 in src/setupTests.ts

View check run for this annotation

Codecov / codecov/patch

src/setupTests.ts#L14

Added line #L14 was not covered by tests
// If the error message is related to CSS parsing, suppress it
if (params.find((p) => p.toString().includes(jsDomCssError))) {
return; // Do nothing for this error

Check warning on line 17 in src/setupTests.ts

View check run for this annotation

Codecov / codecov/patch

src/setupTests.ts#L17

Added line #L17 was not covered by tests
}

// Otherwise, throw an error or log the message
throw new Error(format(...params)); // You can choose to throw or log here

Check warning on line 21 in src/setupTests.ts

View check run for this annotation

Codecov / codecov/patch

src/setupTests.ts#L21

Added line #L21 was not covered by tests
};

global.console.warn = function (...args): void {
Expand Down
Loading