From 246b0efffe62d5b44e02d08d95928a69af7e516b Mon Sep 17 00:00:00 2001 From: Eshaan Aggarwal <96648934+EshaanAgg@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:37:19 +0530 Subject: [PATCH] Add key definitons --- src/components/EventStats/EventStats.test.tsx | 45 ++++++++++++++++++- .../EventStats/EventStatsWrapper.test.tsx | 10 ++--- src/index.tsx | 5 ++- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/components/EventStats/EventStats.test.tsx b/src/components/EventStats/EventStats.test.tsx index f5b5693929..371f62d6c6 100644 --- a/src/components/EventStats/EventStats.test.tsx +++ b/src/components/EventStats/EventStats.test.tsx @@ -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 @@ -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( - + diff --git a/src/components/EventStats/EventStatsWrapper.test.tsx b/src/components/EventStats/EventStatsWrapper.test.tsx index 00909087c7..fcfdd4ade5 100644 --- a/src/components/EventStats/EventStatsWrapper.test.tsx +++ b/src/components/EventStats/EventStatsWrapper.test.tsx @@ -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', @@ -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, }, }, @@ -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 () => { diff --git a/src/index.tsx b/src/index.tsx index 3af89ed9e1..3ae178c245 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -39,7 +39,10 @@ const httpLink = new HttpLink({ const client: ApolloClient = new ApolloClient({ cache: new InMemoryCache({ typePolicies: { - event: { + Event: { + keyFields: ['_id'], + }, + Feedback: { keyFields: ['_id'], }, },