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

Migrated src/components/EventStats/* from Jest to Vitest #2992

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { MockedProvider } from '@apollo/react-testing';
import { EventStats } from './EventStats';
import { BrowserRouter } from 'react-router-dom';
import { EVENT_FEEDBACKS } from 'GraphQl/Queries/Queries';
import { vi, describe, expect, it } from 'vitest';

// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Jest)
// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Vitest)
// These modules are used by the Feedback component
jest.mock('@mui/x-charts/PieChart', () => ({
pieArcLabelClasses: jest.fn(),
PieChart: jest.fn().mockImplementation(() => <>Test</>),
pieArcClasses: jest.fn(),
vi.mock('@mui/x-charts/PieChart', async () => ({
...(await vi.importActual('@mui/x-charts/PieChart')),
pieArcLabelClasses: vi.fn(),
PieChart: vi.fn().mockImplementation(() => <>Test</>),
pieArcClasses: vi.fn(),
}));

const mockData = [
Expand Down Expand Up @@ -43,10 +45,10 @@ describe('Testing Event Stats', () => {
const props = {
eventId: 'eventStats123',
show: true,
handleClose: jest.fn(),
handleClose: vi.fn(),
};

test('The stats should be rendered properly', async () => {
it('The stats should be rendered properly', async () => {
const { queryByText } = render(
<MockedProvider mocks={mockData} addTypename={false}>
<BrowserRouter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { MockedProvider } from '@apollo/react-testing';
import { EventStatsWrapper } from './EventStatsWrapper';
import { BrowserRouter } from 'react-router-dom';
import { EVENT_FEEDBACKS } from 'GraphQl/Queries/Queries';
import { vi, describe, expect, it } from 'vitest';

// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Jest)
jest.mock('@mui/x-charts/PieChart', () => ({
pieArcLabelClasses: jest.fn(),
PieChart: jest.fn().mockImplementation(() => <>Test</>),
pieArcClasses: jest.fn(),
// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Vitest)
vi.mock('@mui/x-charts/PieChart', async () => ({
...(await vi.importActual('@mui/x-charts/PieChart')),
pieArcLabelClasses: vi.fn(),
PieChart: vi.fn().mockImplementation(() => <>Test</>),
pieArcClasses: vi.fn(),
}));

const mockData = [
Expand Down Expand Up @@ -38,20 +40,21 @@ const mockData = [
},
];

// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Jest)
// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Vitest)
// These modules are used by the Feedback component
jest.mock('@mui/x-charts/PieChart', () => ({
pieArcLabelClasses: jest.fn(),
PieChart: jest.fn().mockImplementation(() => <>Test</>),
pieArcClasses: jest.fn(),
vi.mock('@mui/x-charts/PieChart', async () => ({
...(await vi.importActual('@mui/x-charts/PieChart')),
pieArcLabelClasses: vi.fn(),
PieChart: vi.fn().mockImplementation(() => <>Test</>),
pieArcClasses: vi.fn(),
}));

describe('Testing Event Stats Wrapper', () => {
const props = {
eventId: 'eventStats123',
};

test('The button to open and close the modal should work properly', async () => {
it('The button to open and close the modal should work properly', async () => {
const { queryByText, queryByRole } = render(
<MockedProvider mocks={mockData} addTypename={false}>
<BrowserRouter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { store } from 'state/store';
import { I18nextProvider } from 'react-i18next';
import i18nForTest from 'utils/i18nForTest';
import { ToastContainer } from 'react-toastify';
import { describe, expect, it } from 'vitest';

const props = {
data: {
Expand Down Expand Up @@ -35,7 +36,7 @@ const props = {
};

describe('Testing Average Rating Card', () => {
test('The component should be rendered and the Score should be shown', async () => {
it('The component should be rendered and the Score should be shown', async () => {
const { queryByText } = render(
<BrowserRouter>
<Provider store={store}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { store } from 'state/store';
import { I18nextProvider } from 'react-i18next';
import i18nForTest from 'utils/i18nForTest';
import { ToastContainer } from 'react-toastify';
import { vi, describe, expect, it } from 'vitest';

// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Jest)
jest.mock('@mui/x-charts/PieChart', () => ({
pieArcLabelClasses: jest.fn(),
PieChart: jest.fn().mockImplementation(() => <>Test</>),
pieArcClasses: jest.fn(),
// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Vitest)
vi.mock('@mui/x-charts/PieChart', async () => ({
...(await vi.importActual('@mui/x-charts/PieChart')),
pieArcLabelClasses: vi.fn(),
PieChart: vi.fn().mockImplementation(() => <>Test</>),
pieArcClasses: vi.fn(),
}));

const nonEmptyProps = {
Expand Down Expand Up @@ -52,7 +54,7 @@ const emptyProps = {
};

describe('Testing Feedback Statistics Card', () => {
test('The component should be rendered and the feedback should be shown if present', async () => {
it('The component should be rendered and the feedback should be shown if present', async () => {
const { queryByText } = render(
<BrowserRouter>
<Provider store={store}>
Expand All @@ -79,7 +81,7 @@ describe('Testing Feedback Statistics Card', () => {
});
});

test('The component should be rendered and message should be shown if no feedback is present', async () => {
it('The component should be rendered and message should be shown if no feedback is present', async () => {
const { queryByText } = render(
<BrowserRouter>
<Provider store={store}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { store } from 'state/store';
import { I18nextProvider } from 'react-i18next';
import i18nForTest from 'utils/i18nForTest';
import { ToastContainer } from 'react-toastify';
import { describe, expect, it } from 'vitest';

const nonEmptyReviewProps = {
data: {
Expand Down Expand Up @@ -51,7 +52,7 @@ const emptyReviewProps = {
};

describe('Testing Review Statistics Card', () => {
test('The component should be rendered and the reviews should be shown if present', async () => {
it('The component should be rendered and the reviews should be shown if present', async () => {
const { queryByText } = render(
<BrowserRouter>
<Provider store={store}>
Expand All @@ -72,7 +73,7 @@ describe('Testing Review Statistics Card', () => {
await waitFor(() => expect(queryByText('review2')).toBeInTheDocument());
});

test('The component should be rendered and message should be shown if no review is present', async () => {
it('The component should be rendered and message should be shown if no review is present', async () => {
const { queryByText } = render(
<BrowserRouter>
<Provider store={store}>
Expand Down
Loading