Skip to content

Commit db7b2ba

Browse files
committed
chore: cleanup
1 parent 97967b8 commit db7b2ba

3 files changed

Lines changed: 41 additions & 48 deletions

File tree

bc_obps/service/tests/test_report_service_past_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
USER_GUID = "00000000-0000-0000-0000-000000000000"
16-
REPORTING_YEAR = 2023
16+
REPORTING_YEAR = 2024
1717

1818

1919
def make_past_report_data(
@@ -68,7 +68,7 @@ def test_create_report_for_reporting_year_uses_selected_registration_purpose(
6868
"registration.tests.utils.operation_designated_operator_timeline",
6969
operator=operator,
7070
operation=operation,
71-
start_date="2023-01-01",
71+
start_date="2024-01-01",
7272
end_date=None,
7373
)
7474

bciers/apps/reporting/src/app/components/report/StartReportForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default function StartReportForm({
9090
<div className="flex justify-start gap-3 pt-6">
9191
<Button
9292
variant="outlined"
93-
onClick={() => router.back()}
93+
onClick={() => router.push(`/reports/previous-years`)}
9494
className="min-w-[82px] border-bc-blue px-6 py-2.5 text-bc-links hover:border-bc-primary-blue"
9595
>
9696
Cancel
Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { render, screen, waitFor } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
3-
import { RJSFSchema, UiSchema } from "@rjsf/utils";
43
import StartReportForm from "@reporting/src/app/components/report/StartReportForm";
54
import { actionHandler } from "@bciers/actions";
65
import { useRouter } from "next/navigation";
76
import expectComboBox from "@bciers/testConfig/helpers/expectComboBox";
87
import { selectComboboxOption } from "@bciers/testConfig/helpers/selectComboboxOption";
8+
import { createStartReportSchemas } from "@reporting/src/data/jsonSchema/report/startReport";
9+
import getPreviousReportableOperations from "@reporting/src/app/utils/getPreviousReportableOperations";
910

1011
vi.mock("@bciers/actions", () => ({
1112
actionHandler: vi.fn(),
@@ -15,53 +16,41 @@ vi.mock("next/navigation", () => ({
1516
useRouter: vi.fn(),
1617
}));
1718

19+
vi.mock("@reporting/src/app/utils/getPreviousReportableOperations", () => ({
20+
default: vi.fn(),
21+
}));
22+
1823
const mockPush = vi.fn();
1924
const mockBack = vi.fn();
2025

2126
const mockActionHandler = vi.mocked(actionHandler);
2227
const mockUseRouter = vi.mocked(useRouter);
28+
const mockGetPreviousReportableOperations = vi.mocked(
29+
getPreviousReportableOperations,
30+
);
2331

24-
const schema: RJSFSchema = {
25-
type: "object",
26-
required: ["reporting_year", "operation_id", "registration_purpose"],
27-
properties: {
28-
reporting_year: {
29-
type: "number",
30-
title: "Reporting year",
31-
enum: [2023],
32-
},
33-
operation_id: {
34-
type: "string",
35-
title: "Operation",
36-
enum: ["operation-1"],
37-
},
38-
registration_purpose: {
39-
type: "string",
40-
title: "Registration purpose",
41-
enum: ["Reporting Operation"],
42-
},
43-
},
44-
};
45-
46-
const uiSchema: UiSchema = {};
32+
const renderForm = async () => {
33+
const { schema, uiSchema } = await createStartReportSchemas();
4734

48-
const renderForm = () => {
4935
render(<StartReportForm schema={schema} uiSchema={uiSchema} />);
5036
};
5137

5238
const expectForm = () => {
53-
expectComboBox(/Reporting year/i);
54-
expectComboBox(/Operation/i);
55-
expectComboBox(/Registration purpose/i);
39+
expectComboBox(/Select reporting year/i);
40+
expectComboBox(/Select operation/i);
41+
expectComboBox(/Select the registration purpose/i);
5642

5743
expect(screen.getByRole("button", { name: /start/i })).toBeVisible();
5844
expect(screen.getByRole("button", { name: /cancel/i })).toBeVisible();
5945
};
6046

6147
const fillForm = async () => {
62-
await selectComboboxOption(/Reporting year/i, "2023");
63-
await selectComboboxOption(/Operation/i, "operation-1");
64-
await selectComboboxOption(/Registration purpose/i, "Reporting Operation");
48+
await selectComboboxOption(/Select reporting year/i, "2023");
49+
await selectComboboxOption(/Select operation/i, "Operation 1");
50+
await selectComboboxOption(
51+
/Select the registration purpose/i,
52+
"Reporting Operation",
53+
);
6554
};
6655

6756
describe("StartReportForm", () => {
@@ -70,21 +59,28 @@ describe("StartReportForm", () => {
7059

7160
mockUseRouter.mockReturnValue({
7261
push: mockPush,
73-
back: mockBack,
7462
} as unknown as ReturnType<typeof useRouter>);
63+
64+
mockGetPreviousReportableOperations.mockResolvedValue([
65+
{
66+
reporting_year: 2023,
67+
operation_id: "operation-1",
68+
operation_name: "Operation 1",
69+
registration_purposes: ["Reporting Operation"],
70+
},
71+
]);
7572
});
7673

77-
it("renders the form", () => {
78-
renderForm();
74+
it("renders the generated start report form", async () => {
75+
await renderForm();
7976

8077
expectForm();
8178
});
8279

8380
it("submits the selected report data and redirects to review operation information", async () => {
8481
mockActionHandler.mockResolvedValue(123);
8582

86-
renderForm();
87-
83+
await renderForm();
8884
await fillForm();
8985

9086
await userEvent.click(screen.getByRole("button", { name: /start/i }));
@@ -125,14 +121,12 @@ describe("StartReportForm", () => {
125121
},
126122
});
127123

128-
renderForm();
129-
124+
await renderForm();
130125
await fillForm();
131126

132127
await userEvent.click(screen.getByRole("button", { name: /start/i }));
133128

134129
expect(await screen.findByText("Unable to create report.")).toBeVisible();
135-
136130
expect(mockPush).not.toHaveBeenCalled();
137131
});
138132

@@ -141,22 +135,21 @@ describe("StartReportForm", () => {
141135
error: "Unable to create report.",
142136
});
143137

144-
renderForm();
145-
138+
await renderForm();
146139
await fillForm();
147140

148141
await userEvent.click(screen.getByRole("button", { name: /start/i }));
149142

150143
expect(await screen.findByText("Unable to create report.")).toBeVisible();
151-
152144
expect(mockPush).not.toHaveBeenCalled();
153145
});
154146

155-
it("goes back when Cancel is clicked", async () => {
156-
renderForm();
147+
it("returns to the previous reports page when Cancel is clicked", async () => {
148+
await renderForm();
157149

158150
await userEvent.click(screen.getByRole("button", { name: /cancel/i }));
159151

160-
expect(mockBack).toHaveBeenCalledOnce();
152+
expect(mockPush).toHaveBeenCalledWith("/reports/previous-years");
153+
expect(mockBack).not.toHaveBeenCalled();
161154
});
162155
});

0 commit comments

Comments
 (0)