Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed LeftDrawerOrg Visibility #3239

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/components/LeftDrawer/LeftDrawer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,40 @@ describe('Testing Left Drawer component for ADMIN', () => {

expect(global.window.location.pathname).toContain('/orglist');
});

it('Should set hideDrawer to false when initially null', async () => {
const mockSetHideDrawer = vi.fn();
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<LeftDrawer hideDrawer={null} setHideDrawer={mockSetHideDrawer} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);
});
expect(mockSetHideDrawer).toHaveBeenCalledWith(false);
expect(mockSetHideDrawer).toHaveBeenCalledTimes(1);
});

it('Should not call setHideDrawer when hideDrawer has a value', async () => {
const mockSetHideDrawer = vi.fn();
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<LeftDrawer
hideDrawer={false}
setHideDrawer={mockSetHideDrawer}
/>
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);
});
expect(mockSetHideDrawer).not.toHaveBeenCalled();
});
});
43 changes: 43 additions & 0 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,47 @@ describe('Testing LeftDrawerOrg component for SUPERADMIN', () => {
</MockedProvider>,
);
});

test('Should set hideDrawer to false when initially null', async () => {
const mockSetHideDrawer = vi.fn();
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LeftDrawerOrg
{...props}
hideDrawer={null}
setHideDrawer={mockSetHideDrawer}
/>
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
await wait();
expect(mockSetHideDrawer).toHaveBeenCalledWith(false);
expect(mockSetHideDrawer).toHaveBeenCalledTimes(1);
});

test('Should not call setHideDrawer when hideDrawer has a value', async () => {
const mockSetHideDrawer = vi.fn();
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LeftDrawerOrg
{...props}
hideDrawer={false}
setHideDrawer={mockSetHideDrawer}
/>
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
await wait();
expect(mockSetHideDrawer).not.toHaveBeenCalled();
});
});
7 changes: 7 additions & 0 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ const leftDrawerOrg = ({
() => getIdFromPath(location.pathname),
[location.pathname],
);

useEffect(() => {
if (hideDrawer === null) {
setHideDrawer(false);
}
}, []);

// Check if the current page is admin profile page

useEffect(() => {
Expand Down
Loading