Skip to content

Commit

Permalink
SELC-5920 unit test for on click of dehazeIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
OraldoDoci committed Nov 6, 2024
1 parent b2056fa commit 414b17a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/pages/dashboard/__tests__/Dashboard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useMediaQuery from '@mui/material/useMediaQuery';
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import React from 'react';
import { Provider } from 'react-redux';
Expand Down Expand Up @@ -27,12 +27,17 @@ afterAll(() => {
Object.defineProperty(window, 'location', { value: oldWindowLocation });
});

afterEach(() => {
jest.clearAllMocks();
cleanup();
});

const renderDashboard = (
injectedStore?: ReturnType<typeof createStore>,
injectedHistory?: ReturnType<typeof createMemoryHistory>
) => {
const store = injectedStore ? injectedStore : createStore();
const history = injectedHistory ? injectedHistory : createMemoryHistory();
const store = injectedStore || createStore();
const history = injectedHistory || createMemoryHistory();
render(
<Router history={history}>
<Provider store={store}>
Expand Down Expand Up @@ -87,6 +92,8 @@ test('Test rendering on mobile', async () => {
const drawer = await waitFor(() => screen.getByRole('presentation'));
expect(drawer).toBeInTheDocument();

fireEvent.click(drawer);

const drawerNav = within(drawer).getByRole('navigation');

const overviewButtonInDrawer = within(drawerNav).getByText('Panoramica');
Expand All @@ -98,3 +105,14 @@ test('Test rendering on mobile', async () => {
expect(screen.queryByRole('presentation')).not.toBeInTheDocument();
});
});

test('Test rendering on desktop', async () => {
(useMediaQuery as jest.Mock).mockReturnValue(false);

renderDashboard();

const sideBarCloseIcon = await screen.findByTestId('DehazeIcon');

fireEvent.click(sideBarCloseIcon);

});
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function DashboardSidenavItem({
isPtSelected,
handleClickPtPage,
hideLabels,
}: Props) {
}: Readonly<Props>) {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('lg'));
return (
Expand Down

0 comments on commit 414b17a

Please sign in to comment.