Skip to content

Commit

Permalink
Cleared localstorage to solve flickering (#2937)
Browse files Browse the repository at this point in the history
* cleared localstorage to solve flickering

* fixed tests
  • Loading branch information
Aad1tya27 authored Dec 26, 2024
1 parent 1e445f6 commit 167a846
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
57 changes: 34 additions & 23 deletions src/screens/OrgList/OrgList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ async function wait(ms = 100): Promise<void> {
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);
Expand Down Expand Up @@ -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);
Expand All @@ -501,35 +500,47 @@ describe('Organisations Page testing as Admin', () => {
setItem('SuperAdmin', false);
setItem('AdminFor', [{ name: 'adi', _id: 'a0', image: '' }]);

await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<OrgList />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);

await wait();
});
const sortDropdown = await waitFor(() => screen.getByTestId('sort'));
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<OrgList />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);

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();
});
});
2 changes: 2 additions & 0 deletions src/screens/OrgList/OrgList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ function orgList(): JSX.Element {
};

if (errorList || errorUser) {
errorHandler(t, errorList || errorUser);
localStorage.clear();
window.location.assign('/');
}

Expand Down
2 changes: 1 addition & 1 deletion src/screens/OrgList/OrganizationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ const OrganizationModal: React.FC<InterfaceOrganizationModalProps> = ({
<hr />
<span className={styles.orText}>{tCommon('OR')}</span>
</div>
{(adminFor.length > 0 || superAdmin) && (
{((adminFor && adminFor.length > 0) || superAdmin) && (
<div className={styles.sampleOrgSection}>
<Button
className={styles.sampleOrgCreationBtn}
Expand Down

0 comments on commit 167a846

Please sign in to comment.