Skip to content

Commit

Permalink
add/update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian committed Dec 12, 2024
1 parent a4c3d8a commit f9aa787
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
10 changes: 2 additions & 8 deletions services/ui-src/src/components/layout/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,19 @@ const mockedUseStore = useStore as jest.MockedFunction<typeof useStore>;
const headerComponent = (
<RouterWrappedComponent>
<ReportContext.Provider value={mockReportMethods}>
<Header handleLogout={() => {}} />
<Header />
</ReportContext.Provider>
</RouterWrappedComponent>
);

const reportComponent = (
<RouterWrappedComponent>
<ReportContext.Provider value={mockReportMethods}>
<Header handleLogout={() => {}} />
<Header />
</ReportContext.Provider>
</RouterWrappedComponent>
);

/*
* jest.mock("utils/reports/routing", () => ({
* isReportFormPage: jest.fn(() => true),
* }));
*/

describe("<Header />", () => {
describe("Test Header", () => {
beforeEach(() => {
Expand Down
27 changes: 24 additions & 3 deletions services/ui-src/src/components/menus/Menu.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { render, screen } from "@testing-library/react";
// utils
import { RouterWrappedComponent } from "utils/testing/setupJest";
import userEvent from "@testing-library/user-event";
//components
import { Menu } from "components";
// utils
import {
mockUserContext,
RouterWrappedComponent,
} from "utils/testing/setupJest";
import { UserContext } from "utils";
import { testA11y } from "utils/testing/commonTests";

const mockLogout = jest.fn();

const mockContext = {
...mockUserContext,
logout: mockLogout,
};

const menuComponent = (
<RouterWrappedComponent>
<Menu handleLogout={() => {}} />
<UserContext.Provider value={mockContext}>
<Menu />
</UserContext.Provider>
</RouterWrappedComponent>
);

Expand All @@ -17,5 +31,12 @@ describe("<Menu />", () => {
expect(screen.getByTestId("header-menu-dropdown-button")).toBeVisible();
});

test("Menu button logout fires logout function", async () => {
render(menuComponent);
const logoutButton = screen.getByText("Log Out");
await userEvent.click(logoutButton);
expect(mockLogout).toHaveBeenCalledTimes(1);
});

testA11y(menuComponent);
});

0 comments on commit f9aa787

Please sign in to comment.