-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: prettier chore: prettier chore: cleanup
- Loading branch information
1 parent
22a7c63
commit 195b0b3
Showing
4 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
bciers/apps/reporting/src/tests/components/complianceSummary/ComplianceSummaryPage.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { render } from "@testing-library/react"; | ||
import ComplianceSummaryForm from "@reporting/src/app/components/complianceSummary/ComplianceSummaryForm"; | ||
import ComplianceSummaryPage from "@reporting/src/app/components/complianceSummary/ComplianceSummaryPage"; | ||
import { actionHandler } from "@bciers/actions"; | ||
import { getRegistrationPurpose } from "@reporting/src/app/utils/getRegistrationPurpose"; | ||
import { getAttributableEmissions } from "@reporting/src/app/utils/getAttributableEmissions"; | ||
import { tasklistData } from "@reporting/src/app/components/complianceSummary/TaskListElements"; | ||
import { RegistrationPurposes } from "@/registration/app/components/operations/registration/enums"; | ||
|
||
import { vi } from "vitest"; | ||
|
||
// ✨ Mocks | ||
vi.mock( | ||
"@reporting/src/app/components/complianceSummary/ComplianceSummaryForm", | ||
() => ({ | ||
default: vi.fn(), | ||
}), | ||
); | ||
|
||
vi.mock("@bciers/actions", () => ({ | ||
actionHandler: vi.fn(), | ||
})); | ||
|
||
vi.mock("@reporting/src/app/utils/getRegistrationPurpose", () => ({ | ||
getRegistrationPurpose: vi.fn(), | ||
})); | ||
|
||
vi.mock("@reporting/src/app/utils/getAttributableEmissions", () => ({ | ||
getAttributableEmissions: vi.fn(), | ||
})); | ||
|
||
const mockComplianceSummaryForm = ComplianceSummaryForm as ReturnType< | ||
typeof vi.fn | ||
>; | ||
const mockActionHandler = actionHandler as ReturnType<typeof vi.fn>; | ||
const mockGetRegistrationPurpose = getRegistrationPurpose as ReturnType< | ||
typeof vi.fn | ||
>; | ||
const mockGetAttributableEmissions = getAttributableEmissions as ReturnType< | ||
typeof vi.fn | ||
>; | ||
|
||
describe("ComplianceSummaryPage", () => { | ||
it("renders ComplianceSummaryForm with needsVerification = false for non-regulated purpose below emissions threshold", async () => { | ||
const versionId = 12345; | ||
|
||
// Mock the data for the test | ||
const complianceData = { some: "data" }; | ||
const registrationPurpose = RegistrationPurposes.REPORTING_OPERATION; | ||
const attributableEmissions = 10000000; // Below the threshold | ||
|
||
mockActionHandler.mockResolvedValue(complianceData); | ||
mockGetRegistrationPurpose.mockResolvedValue({ | ||
registration_purpose: registrationPurpose, | ||
}); | ||
mockGetAttributableEmissions.mockResolvedValue(attributableEmissions); | ||
|
||
// Render the page | ||
render(await ComplianceSummaryPage({ version_id: versionId })); | ||
|
||
// Validate that ComplianceSummaryForm was called with the expected props | ||
expect(mockComplianceSummaryForm).toHaveBeenCalledWith( | ||
{ | ||
versionId, | ||
needsVerification: false, | ||
summaryFormData: complianceData, | ||
taskListElements: tasklistData, | ||
}, | ||
{}, | ||
); | ||
}); | ||
|
||
it("renders ComplianceSummaryForm with needsVerification = true for regulated purpose", async () => { | ||
const versionId = 12345; | ||
|
||
// Mock the data for the test | ||
const complianceData = { some: "data" }; | ||
const registrationPurpose = RegistrationPurposes.OBPS_REGULATED_OPERATION; | ||
|
||
mockActionHandler.mockResolvedValue(complianceData); | ||
mockGetRegistrationPurpose.mockResolvedValue({ | ||
registration_purpose: registrationPurpose, | ||
}); | ||
|
||
// Render the page | ||
render(await ComplianceSummaryPage({ version_id: versionId })); | ||
|
||
// Validate that ComplianceSummaryForm was called with the expected props | ||
expect(mockComplianceSummaryForm).toHaveBeenCalledWith( | ||
{ | ||
versionId, | ||
needsVerification: true, | ||
summaryFormData: complianceData, | ||
taskListElements: tasklistData, | ||
}, | ||
{}, | ||
); | ||
}); | ||
|
||
it("renders ComplianceSummaryForm with needsVerification = true for high emissions", async () => { | ||
const versionId = 12345; | ||
|
||
// Mock the data for the test | ||
const complianceData = { some: "data" }; | ||
const registrationPurpose = | ||
RegistrationPurposes.ELECTRICITY_IMPORT_OPERATION; | ||
const attributableEmissions = 30000000; // Above the threshold | ||
|
||
mockActionHandler.mockResolvedValue(complianceData); | ||
mockGetRegistrationPurpose.mockResolvedValue({ | ||
registration_purpose: registrationPurpose, | ||
}); | ||
mockGetAttributableEmissions.mockResolvedValue(attributableEmissions); | ||
|
||
// Render the page | ||
render(await ComplianceSummaryPage({ version_id: versionId })); | ||
|
||
// Validate that ComplianceSummaryForm was called with the expected props | ||
expect(mockComplianceSummaryForm).toHaveBeenCalledWith( | ||
{ | ||
versionId, | ||
needsVerification: true, | ||
summaryFormData: complianceData, | ||
taskListElements: tasklistData, | ||
}, | ||
{}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters