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 all 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
160 changes: 160 additions & 0 deletions src/components/MemberDetail/customTableCell.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { MockedProvider } from '@apollo/client/testing';
import { BrowserRouter } from 'react-router-dom';
import { CustomTableCell } from './customTableCell';
import { EVENT_DETAILS } from 'GraphQl/Queries/Queries';
import { vi } from 'vitest';
vi.mock('react-toastify', () => ({
toast: {
success: vi.fn(),
error: vi.fn(),
},
}));

const mocks = [
{
request: {
query: EVENT_DETAILS,
variables: { id: 'event123' },
},
result: {
data: {
event: {
_id: 'event123',
title: 'Test Event',
description: 'This is a test event description',
startDate: '2023-05-01',
endDate: '2023-05-02',
startTime: '09:00:00',
endTime: '17:00:00',
allDay: false,
location: 'Test Location',
recurring: true,
baseRecurringEvent: {
_id: 'recurringEvent123',
},
organization: {
_id: 'org456',
members: [
{ _id: 'member1', firstName: 'John', lastName: 'Doe' },
{ _id: 'member2', firstName: 'Jane', lastName: 'Smith' },
],
},
attendees: [{ _id: 'user1' }, { _id: 'user2' }],
},
},
},
},
];

describe('CustomTableCell', () => {
it('renders event details correctly', async () => {
render(
<MockedProvider mocks={mocks} addTypename={false}>
<BrowserRouter>
<table>
<tbody>
<CustomTableCell eventId="event123" />
</tbody>
</table>
</BrowserRouter>
</MockedProvider>,
);

await waitFor(() => screen.getByTestId('custom-row'));

expect(screen.getByText('Test Event')).toBeInTheDocument();
expect(
screen.getByText(
new Date('2023-05-01').toLocaleDateString(undefined, {
year: 'numeric',
month: 'long',
day: 'numeric',
timeZone: 'UTC',
}),
),
).toBeInTheDocument();
expect(screen.getByText('Yes')).toBeInTheDocument();
expect(screen.getByText('2')).toBeInTheDocument();

const link = screen.getByRole('link', { name: 'Test Event' });
expect(link).toHaveAttribute('href', '/event/org456/event123');
});

it('displays loading state', () => {
render(
<MockedProvider mocks={[]} addTypename={false}>
<table>
<tbody>
<CustomTableCell eventId="event123" />
</tbody>
</table>
</MockedProvider>,
);

expect(screen.getByRole('progressbar')).toBeInTheDocument();
});

it('displays error state', async () => {
const errorMock = [
{
request: {
query: EVENT_DETAILS,
variables: { id: 'event123' },
},
error: new Error('An error occurred'),
},
];

render(
<MockedProvider mocks={errorMock} addTypename={false}>
<table>
<tbody>
<CustomTableCell eventId="event123" />
</tbody>
</table>
</MockedProvider>,
);

await waitFor(() => {
expect(
screen.getByText(
'Unable to load event details. Please try again later.',
),
).toBeInTheDocument();
});
});

it('displays no event found message', async () => {
const noEventMock = [
{
request: {
query: EVENT_DETAILS,
variables: { id: 'event123' },
},
result: {
data: {
event: null,
},
},
},
];

render(
<MockedProvider mocks={noEventMock} addTypename={false}>
<table>
<tbody>
<CustomTableCell eventId="event123" />
</tbody>
</table>
</MockedProvider>,
);

await waitFor(() => {
expect(
screen.getByText('Event not found or has been deleted'),
).toBeInTheDocument();
});
});
});
171 changes: 0 additions & 171 deletions src/components/MemberDetail/customTableCell.test.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { MockedProvider } from '@apollo/react-testing';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { I18nextProvider } from 'react-i18next';
import 'jest-location-mock';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { store } from 'state/store';
Expand All @@ -11,10 +10,10 @@ import OrganizationScreen from './OrganizationScreen';
import { ORGANIZATION_EVENT_LIST } from 'GraphQl/Queries/Queries';
import { StaticMockLink } from 'utils/StaticMockLink';
import styles from './OrganizationScreen.module.css';

import { vi } from 'vitest';
const mockID: string | undefined = '123';
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
vi.mock('react-router-dom', async () => ({
...(await vi.importActual('react-router-dom')),
useParams: () => ({ orgId: mockID }),
useMatch: () => ({ params: { eventId: 'event123', orgId: '123' } }),
}));
Expand Down
Loading
Loading