Skip to content

Commit

Permalink
Add key definitons
Browse files Browse the repository at this point in the history
  • Loading branch information
EshaanAgg committed Oct 4, 2023
1 parent 800f9cb commit 246b0ef
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
45 changes: 43 additions & 2 deletions src/components/EventStats/EventStats.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render, waitFor } from '@testing-library/react';
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';

// 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 All @@ -12,16 +13,56 @@ jest.mock('@mui/x-charts/PieChart', () => ({
pieArcClasses: jest.fn(),
}));

const mockData = [
{
request: {
query: EVENT_FEEDBACKS,
variables: {
id: 'eventStats123',
},
},
result: {
data: {
event: {
_id: 'eventStats123',
feedback: [
{
_id: 'feedback1',
review: 'review1',
rating: 5,
},
],
},
},
},
},
{
request: {
query: EVENT_FEEDBACK_SCORE,
variables: {
id: 'eventStats123',
},
},
result: {
data: {
event: {
_id: 'eventStats123',
averageFeedbackScore: 5,
},
},
},
},
];
describe('Testing Event Stats', () => {
const props = {
eventId: 'event123',
eventId: 'eventStats123',
show: true,
handleClose: jest.fn(),
};

test('The stats should be rendered properly', async () => {
const { queryByText } = render(
<MockedProvider addTypename={false}>
<MockedProvider addTypename={false} mocks={mockData}>
<BrowserRouter>
<EventStats {...props} />
</BrowserRouter>
Expand Down
10 changes: 5 additions & 5 deletions src/components/EventStats/EventStatsWrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ const mockData = [
request: {
query: EVENT_FEEDBACKS,
variables: {
id: '1234',
id: 'eventStatsWrapper123',
},
},
result: {
data: {
event: {
_id: '1234',
_id: 'eventStatsWrapper123',
feedback: [
{
_id: 'feedback1',
Expand All @@ -39,13 +39,13 @@ const mockData = [
request: {
query: EVENT_FEEDBACK_SCORE,
variables: {
id: '1234',
id: 'eventStatsWrapper123',
},
},
result: {
data: {
event: {
_id: '1234',
_id: 'eventStatsWrapper123',
averageFeedbackScore: 5,
},
},
Expand All @@ -63,7 +63,7 @@ jest.mock('@mui/x-charts/PieChart', () => ({

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

test('The button to open and close the modal should work properly', async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const httpLink = new HttpLink({
const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
cache: new InMemoryCache({
typePolicies: {
event: {
Event: {
keyFields: ['_id'],
},
Feedback: {
keyFields: ['_id'],
},
},
Expand Down

0 comments on commit 246b0ef

Please sign in to comment.