Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
chore: prettier

chore: prettier

chore: cleanup
  • Loading branch information
shon-button committed Dec 17, 2024
1 parent 22a7c63 commit 195b0b3
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 3 deletions.
1 change: 0 additions & 1 deletion bc_obps/reporting/api/compliance_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from decimal import Decimal
from typing import Literal, Tuple
from common.permissions import authorize
from typing import Literal, Tuple
from django.http import HttpRequest
from registration.decorators import handle_http_errors
from reporting.constants import EMISSIONS_REPORT_TAGS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default async function FacilityEmissionAllocationPage({
}) {
const orderedActivities = await getOrderedActivities(version_id, facility_id);
const initialData = await getEmissionAllocations(version_id, facility_id);
console.log(initialData);
return (
<Form
version_id={version_id}
Expand Down
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,
},
{},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("VerificationPage component", () => {
verificationSchema,
);
// Render the page with the `versionId` prop
render(await VerificationPage({ versionId: mockVersionId }));
render(await VerificationPage({ version_id: mockVersionId }));

// Assert the VerificationForm is rendered
await waitFor(() => {
Expand Down

0 comments on commit 195b0b3

Please sign in to comment.