From 50362efc4198ed662d99b5471c4933292a4e008e Mon Sep 17 00:00:00 2001 From: SauradipGhosh Date: Mon, 12 Feb 2024 00:01:13 +0530 Subject: [PATCH] Insert the linkMocked to MOCKS and mockEventData is place to the orignal Position --- .../OrganizationDashboard.test.tsx | 59 +++++++++++++++++++ .../OrganizationDashboardMocks.ts | 13 ++++ 2 files changed, 72 insertions(+) diff --git a/src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx b/src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx index 68ebae86e8..bcbd7cde88 100644 --- a/src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx +++ b/src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx @@ -150,4 +150,63 @@ describe('Organisation Dashboard Page', () => { await wait(); expect(window.location).toBeAt('/orglist'); }); + test('Testing useEffect hook and error redirection', async () => { + // eslint-disable-next-line jest/no-export + const mockEventData = { + eventsByOrganizationConnection: [ + { startDate: new Date().toISOString() }, // Assuming an event is upcoming + ], + }; + // Render the component with mock data + await act(async () => { + render( + + + + + + + + + + ); + }); + + // Wait for useEffect to be executed + await wait(); + + // Check if the hook updates the state with upcoming events + expect(screen.getByText('Upcoming Events')).toBeInTheDocument(); + expect(screen.getByText('Latest Posts')).toBeInTheDocument(); + + // Check if tempUpcomingEvents logic is executed correctly + const startDate = new Date( + mockEventData.eventsByOrganizationConnection[0].startDate + ); + const now = new Date(); + const tempUpcomingEvents = []; + if (startDate > now) { + tempUpcomingEvents.push(mockEventData.eventsByOrganizationConnection[0]); + } + expect(tempUpcomingEvents).toHaveLength(0); + + // Test conditional redirection when there's an error + await act(async () => { + render( + + + + + + + + + + ); + }); + + await wait(); + + expect(window.location.pathname).toBe('/orglist'); + }); }); diff --git a/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts b/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts index 7f9959efd5..4a3732d6a9 100644 --- a/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts +++ b/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts @@ -74,6 +74,19 @@ export const MOCKS = [ }, }, }, + { + request: { + query: ORGANIZATION_EVENT_CONNECTION_LIST, + variables: { organization_id: 'your_organization_id' }, + }, + result: { + data: { + eventsByOrganizationConnection: [ + { startDate: new Date().toISOString() }, // Assuming an event is upcoming + ], + }, + }, + }, { request: { query: ORGANIZATION_POST_CONNECTION_LIST,