From cd308b06b57ec5c03765ee43bdc24cf922f4db3e Mon Sep 17 00:00:00 2001 From: SauradipGhosh Date: Wed, 7 Feb 2024 20:48:42 +0530 Subject: [PATCH] Mocks Moved to OrganizationDashboardMocks -done --- .../OrganizationDashboard.test.tsx | 29 +++++-------------- .../OrganizationDashboardMocks.ts | 21 ++++++++++++++ 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx b/src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx index 5f2b0b1ec8..ca5fd1363a 100644 --- a/src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx +++ b/src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx @@ -9,11 +9,16 @@ import { BrowserRouter } from 'react-router-dom'; import { store } from 'state/store'; import { StaticMockLink } from 'utils/StaticMockLink'; import OrganizationDashboard from './OrganizationDashboard'; -import { EMPTY_MOCKS, ERROR_MOCKS, MOCKS } from './OrganizationDashboardMocks'; +import { + EMPTY_MOCKS, + ERROR_MOCKS, + MOCKS, + linkMocked, + mockEventData, +} from './OrganizationDashboardMocks'; import i18nForTest from 'utils/i18nForTest'; import { toast } from 'react-toastify'; import userEvent from '@testing-library/user-event'; -import { ORGANIZATION_EVENT_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; async function wait(ms = 100): Promise { await act(() => { @@ -150,26 +155,6 @@ describe('Organisation Dashboard Page', () => { }); test('Testing useEffect hook and error redirection', async () => { - const mockEventData = { - eventsByOrganizationConnection: [ - { startDate: new Date().toISOString() }, // Assuming an event is upcoming - ], - }; - - // Mocking the response for the organization event query - const linkMocked = new StaticMockLink( - [ - { - request: { - query: ORGANIZATION_EVENT_CONNECTION_LIST, - variables: { organization_id: 'your_organization_id' }, - }, - result: { data: mockEventData }, - }, - ], - true - ); - // Render the component with mock data await act(async () => { render( diff --git a/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts b/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts index 7f9959efd5..f7bcbdd4c8 100644 --- a/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts +++ b/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts @@ -4,6 +4,7 @@ import { ORGANIZATION_POST_CONNECTION_LIST, } from 'GraphQl/Queries/Queries'; import dayjs from 'dayjs'; +import { StaticMockLink } from 'utils/StaticMockLink'; export const MOCKS = [ { @@ -298,3 +299,23 @@ export const ERROR_MOCKS = [ error: new Error('Mock Graphql ORGANIZATION_EVENT_LIST Error'), }, ]; + +export const mockEventData = { + eventsByOrganizationConnection: [ + { startDate: new Date().toISOString() }, // Assuming an event is upcoming + ], +}; + +// Mocking the response for the organization event query +export const linkMocked = new StaticMockLink( + [ + { + request: { + query: ORGANIZATION_EVENT_CONNECTION_LIST, + variables: { organization_id: 'your_organization_id' }, + }, + result: { data: mockEventData }, + }, + ], + true +);