From 1041a71c5b4dc43995e952078290925c8cd64922 Mon Sep 17 00:00:00 2001 From: Dylan Leard Date: Thu, 21 Nov 2024 13:28:23 -0800 Subject: [PATCH] test: add vi test for ComplianceSummary component --- .../src/data/jsonSchema/complianceSummary.ts | 2 +- .../ComplianceSummary.test.tsx | 147 ++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 bciers/apps/reporting/src/tests/components/complianceSummary/ComplianceSummary.test.tsx diff --git a/bciers/apps/reporting/src/data/jsonSchema/complianceSummary.ts b/bciers/apps/reporting/src/data/jsonSchema/complianceSummary.ts index 56f92ed44a..bfa9cb3a60 100644 --- a/bciers/apps/reporting/src/data/jsonSchema/complianceSummary.ts +++ b/bciers/apps/reporting/src/data/jsonSchema/complianceSummary.ts @@ -44,7 +44,7 @@ export const complianceSummarySchema: RJSFSchema = { }, compliancePeriod: { type: "string", - title: "Compliance Period", + title: "Compliance period", }, }, }, diff --git a/bciers/apps/reporting/src/tests/components/complianceSummary/ComplianceSummary.test.tsx b/bciers/apps/reporting/src/tests/components/complianceSummary/ComplianceSummary.test.tsx new file mode 100644 index 0000000000..3c4853b52b --- /dev/null +++ b/bciers/apps/reporting/src/tests/components/complianceSummary/ComplianceSummary.test.tsx @@ -0,0 +1,147 @@ +import React from "react"; +import { render, screen } from "@testing-library/react"; +import ComplianceSummary from "@reporting/src/app/components/complianceSummary/ComplianceSummary"; +import { vi, Mock } from "vitest"; // If you are using Vitest for mocking + +import { actionHandler } from "@bciers/actions"; + +vi.mock("@bciers/actions", () => ({ + actionHandler: vi.fn(), +})); + +const mockSummaryData = { + attributableForReporting: "1000", + reportingOnlyEmission: "1000", + emissionsLimit: "1000", + excessEmissions: "1000", + creditedEmissions: "1000", + regulatoryValues: { + reductionFactor: "1000", + tighteningRate: "1000", + initialCompliancePeriod: "1000", + compliancePeriod: "1000", + }, + products: [ + { + name: "Pucks", + customUnit: "Goals", + annualProduction: "1000", + emissionIntensity: "1000", + allocatedIndustrialProcessEmissions: "1000", + allocatedComplianceEmissions: "1000", + }, + ], +}; + +beforeEach(() => { + window.alert = vi.fn(); // or vi.fn() if using Vitest + vi.mock("next/navigation", () => { + const actual = vi.importActual("next/navigation"); + return { + ...actual, + useRouter: vi.fn(() => ({ + push: vi.fn(), + })), + useSearchParams: vi.fn(() => ({ + get: vi.fn(), + })), + usePathname: vi.fn(), + }; + }); +}); + +describe("ComplianceSummary", () => { + beforeEach(() => { + (actionHandler as Mock).mockClear(); + }); + + it("should render the calculation summary data", async () => { + render( + , + ); + + expect( + screen.getByLabelText("Emissions attributable for reporting").value, + ).toBe("1000"); + expect(screen.getByLabelText("Reporting-only emissions").value).toBe( + "1000", + ); + expect(screen.getByLabelText("Emissions limit").value).toBe("1000"); + expect(screen.getByLabelText("Excess emissions").value).toBe("1000"); + expect(screen.getByLabelText("Credited emissions").value).toBe("1000"); + }); + + it("should render the regulatory values summary data", async () => { + render( + , + ); + + expect(screen.getByLabelText("Reduction factor").value).toBe("1000"); + expect(screen.getByLabelText("Tightening rate").value).toBe("1000"); + expect(screen.getByLabelText("Initial compliance period").value).toBe( + "1000", + ); + expect(screen.getByLabelText("Compliance period").value).toBe("1000"); + }); + + it("should render the production summary data", async () => { + render( + , + ); + + expect(screen.getByLabelText("Annual production").value).toBe("1000"); + expect( + screen.getByLabelText("Weighted average emission intensity").value, + ).toBe("1000"); + expect( + screen.getByLabelText("Emissions allocated to industrial process").value, + ).toBe("1000"); + expect( + screen.getByLabelText("Emissions allocated to compliance").value, + ).toBe("1000"); + }); + + it("should render a back button that navigates to the additional information page", async () => { + render( + , + ); + + expect( + screen.getByRole("link", { + name: /back/i, + }), + ).toHaveAttribute("href", "/reports/1/additional-reporting-data"); + }); + + it("should render a continue button that navigates to the signoff page", async () => { + render( + , + ); + + expect( + screen.getByRole("link", { + name: /continue/i, + }), + ).toHaveAttribute("href", "/reports/1/sign-off"); + }); +});