Skip to content

Commit

Permalink
Add custom merge policy to all the Event Stat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EshaanAgg committed Oct 4, 2023
1 parent 00efe91 commit 7d83ac3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/components/EventStats/EventStats.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { MockedProvider } from '@apollo/react-testing';
import { EventStats } from './EventStats';
import { BrowserRouter } from 'react-router-dom';
import { EVENT_FEEDBACKS, EVENT_FEEDBACK_SCORE } from 'GraphQl/Queries/Queries';
import { InMemoryCache } from '@apollo/client';

const cache = new InMemoryCache({
typePolicies: {
'Query.event': {
merge: true,
},
},
});

// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Jest)
// These modules are used by the Feedback component
Expand Down Expand Up @@ -53,6 +62,7 @@ const mockData = [
},
},
];

describe('Testing Event Stats', () => {
const props = {
eventId: 'eventStats123',
Expand All @@ -62,7 +72,7 @@ describe('Testing Event Stats', () => {

test('The stats should be rendered properly', async () => {
const { queryByText } = render(
<MockedProvider addTypename={false} mocks={mockData}>
<MockedProvider mocks={mockData} cache={cache}>
<BrowserRouter>
<EventStats {...props} />
</BrowserRouter>
Expand Down
11 changes: 10 additions & 1 deletion src/components/EventStats/EventStatsWrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { MockedProvider } from '@apollo/react-testing';
import { EventStatsWrapper } from './EventStatsWrapper';
import { BrowserRouter } from 'react-router-dom';
import { EVENT_FEEDBACKS, EVENT_FEEDBACK_SCORE } from 'GraphQl/Queries/Queries';
import { InMemoryCache } from '@apollo/client';

const cache = new InMemoryCache({
typePolicies: {
'Query.event': {
merge: true,
},
},
});

// 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', () => ({
Expand Down Expand Up @@ -68,7 +77,7 @@ describe('Testing Event Stats Wrapper', () => {

test('The button to open and close the modal should work properly', async () => {
const { queryByText, queryByRole } = render(
<MockedProvider addTypename={false} mocks={mockData}>
<MockedProvider mocks={mockData} cache={cache}>
<BrowserRouter>
<EventStatsWrapper {...props} />
</BrowserRouter>
Expand Down

0 comments on commit 7d83ac3

Please sign in to comment.