From 167a84649ad1f3810d8a97cbb0b61599e400f2b9 Mon Sep 17 00:00:00 2001 From: Aaditya Agarwal Date: Fri, 27 Dec 2024 01:57:08 +0530 Subject: [PATCH] Cleared localstorage to solve flickering (#2937) * cleared localstorage to solve flickering * fixed tests --- src/screens/OrgList/OrgList.test.tsx | 57 ++++++++++++++--------- src/screens/OrgList/OrgList.tsx | 2 + src/screens/OrgList/OrganizationModal.tsx | 2 +- 3 files changed, 37 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 37a4276982..f30bb8f1ea 100644 --- a/src/screens/OrgList/OrgList.tsx +++ b/src/screens/OrgList/OrgList.tsx @@ -233,6 +233,8 @@ 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) && (