From 7fc5386baa5a36d4f48e39a291dd8827085dff51 Mon Sep 17 00:00:00 2001 From: Aad1tya27 Date: Thu, 26 Dec 2024 21:00:20 +0530 Subject: [PATCH 1/2] cleared localstorage to solve flickering --- src/screens/OrgList/OrgList.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/screens/OrgList/OrgList.tsx b/src/screens/OrgList/OrgList.tsx index 37a4276982..c90dc5791a 100644 --- a/src/screens/OrgList/OrgList.tsx +++ b/src/screens/OrgList/OrgList.tsx @@ -233,6 +233,7 @@ function orgList(): JSX.Element { }; if (errorList || errorUser) { + localStorage.clear(); window.location.assign('/'); } From 38d1286c62673fa4684419e7e1f694c98bea84a8 Mon Sep 17 00:00:00 2001 From: Aad1tya27 Date: Fri, 27 Dec 2024 01:10:18 +0530 Subject: [PATCH 2/2] fixed tests --- src/screens/OrgList/OrgList.test.tsx | 57 ++++++++++++++--------- src/screens/OrgList/OrgList.tsx | 1 + src/screens/OrgList/OrganizationModal.tsx | 2 +- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/screens/OrgList/OrgList.test.tsx b/src/screens/OrgList/OrgList.test.tsx index 5b889ff07d..2b2809c7c9 100644 --- a/src/screens/OrgList/OrgList.test.tsx +++ b/src/screens/OrgList/OrgList.test.tsx @@ -44,11 +44,11 @@ async function wait(ms = 100): Promise { afterEach(() => { localStorage.clear(); cleanup(); + jest.clearAllMocks(); }); describe('Organisations Page testing as SuperAdmin', () => { setItem('id', '123'); - const link = new StaticMockLink(MOCKS, true); const link2 = new StaticMockLink(MOCKS_EMPTY, true); const link3 = new StaticMockLink(MOCKS_WITH_ERROR, true); @@ -475,7 +475,6 @@ describe('Organisations Page testing as SuperAdmin', () => { describe('Organisations Page testing as Admin', () => { const link = new StaticMockLink(MOCKS_ADMIN, true); - test('Create organization modal should not be present in the page for Admin', async () => { setItem('id', '123'); setItem('SuperAdmin', false); @@ -501,35 +500,47 @@ describe('Organisations Page testing as Admin', () => { setItem('SuperAdmin', false); setItem('AdminFor', [{ name: 'adi', _id: 'a0', image: '' }]); - await act(async () => { - render( - - - - - - - - - , - ); - - await wait(); - }); - const sortDropdown = await waitFor(() => screen.getByTestId('sort')); + render( + + + + + + + + + , + ); + + await wait(); + + const sortDropdown = screen.getByTestId('sort'); expect(sortDropdown).toBeInTheDocument(); const sortToggle = screen.getByTestId('sortOrgs'); - fireEvent.click(sortToggle); - const latestOption = await waitFor(() => screen.getByTestId('latest')); + await act(async () => { + fireEvent.click(sortToggle); + }); + + const latestOption = screen.getByTestId('latest'); - fireEvent.click(latestOption); + await act(async () => { + fireEvent.click(latestOption); + }); expect(sortDropdown).toBeInTheDocument(); - fireEvent.click(sortToggle); + + await act(async () => { + fireEvent.click(sortToggle); + }); + const oldestOption = await waitFor(() => screen.getByTestId('oldest')); - fireEvent.click(oldestOption); + + await act(async () => { + fireEvent.click(oldestOption); + }); + expect(sortDropdown).toBeInTheDocument(); }); }); diff --git a/src/screens/OrgList/OrgList.tsx b/src/screens/OrgList/OrgList.tsx index c90dc5791a..f30bb8f1ea 100644 --- a/src/screens/OrgList/OrgList.tsx +++ b/src/screens/OrgList/OrgList.tsx @@ -233,6 +233,7 @@ function orgList(): JSX.Element { }; if (errorList || errorUser) { + errorHandler(t, errorList || errorUser); localStorage.clear(); window.location.assign('/'); } diff --git a/src/screens/OrgList/OrganizationModal.tsx b/src/screens/OrgList/OrganizationModal.tsx index fb3589d1e5..20b131eeb9 100644 --- a/src/screens/OrgList/OrganizationModal.tsx +++ b/src/screens/OrgList/OrganizationModal.tsx @@ -301,7 +301,7 @@ const OrganizationModal: React.FC = ({
{tCommon('OR')} - {(adminFor.length > 0 || superAdmin) && ( + {((adminFor && adminFor.length > 0) || superAdmin) && (