Skip to content

Commit

Permalink
Added tests for Visiblity in both LeftDrawer and LeftDrawerOrg
Browse files Browse the repository at this point in the history
  • Loading branch information
aadhil2k4 committed Jan 10, 2025
1 parent 06375b2 commit 96bbb2a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
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();
});
});

0 comments on commit 96bbb2a

Please sign in to comment.