Skip to content

Commit

Permalink
unit test part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ailZhou committed Nov 8, 2024
1 parent 27f3012 commit 758e443
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { render, screen } from "@testing-library/react";
import { ExportedReportBanner } from "./ExportedReportBanner";
import userEvent from "@testing-library/user-event";
import qmVerbiage from "verbiage/export/qm-export";

describe("ExportedReportBanner", () => {
beforeEach(() => {
render(<ExportedReportBanner></ExportedReportBanner>);
jest.spyOn(window, "print").mockImplementation(() => {});
});
it("ExportedReportBanner is visible", () => {
expect(screen.getByText(qmVerbiage.reportBanner.intro)).toBeInTheDocument();
});
it("Test click of print button", async () => {
const pdfButton = screen.getByText("Download PDF");
await userEvent.click(pdfButton);
expect(window.print).toBeCalled();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { screen, render } from "@testing-library/react";
import { useStore } from "utils";
import { ExportedReportPage } from "./ExportedReportPage";

jest.mock("utils", () => ({
useStore: jest.fn(),
}));

const report = {
type: "QM",
id: "mock-report-id",
state: "CO",
title: "mock-title",
pages: [
{ childPageIds: ["1", "2"] },
{ title: "Section 1", id: "id-1" },
{ title: "Section 2", id: "id-2" },
],
};

describe("ExportedReportPage", () => {
beforeEach(() => {
jest.clearAllMocks();
(useStore as unknown as jest.Mock).mockReturnValue({
report: report,
});
});
it("ExportReportPage is visible", () => {
render(<ExportedReportPage></ExportedReportPage>);
expect(screen.getByText("CO mock-title")).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ export const renderReportSections = (
)
.map(
(
section: ParentPageTemplate | FormPageTemplate | MeasurePageTemplate
section: ParentPageTemplate | FormPageTemplate | MeasurePageTemplate,
idx
) => (
<Box key={section.id} mt="3.5rem">
<Box key={`${section.id}.${idx}`} mt="3.5rem">
{renderSection(section)}
</Box>
)
Expand Down
2 changes: 1 addition & 1 deletion services/ui-src/src/types/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type ParentPageTemplate = {
id: PageId;
childPageIds: PageId[];
title?: undefined;
type?: undefined;
type?: PageElement;
elements?: undefined;
sidebar?: undefined;
hideNavButtons?: undefined;
Expand Down

0 comments on commit 758e443

Please sign in to comment.