Skip to content

Commit 48eb52f

Browse files
committed
test: frontend
1 parent 447838d commit 48eb52f

4 files changed

Lines changed: 50 additions & 40 deletions

File tree

bc_obps/poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bciers/apps/registration/app/components/operations/registration/OperationInformationForm.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ const OperationInformationForm = ({
150150
continueRegistration || !selectedOperation;
151151

152152
const handleSubmit = async (e: IChangeEvent) => {
153-
console.error(
154-
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
155-
createUnnestedFormData(e.formData, ["section1", "section2", "section3"]),
156-
);
157-
158153
const formData = e.formData;
159154
const isCreating = !formData?.section1?.operation;
160155
const creatingEndpoint = `registration/operations`;

bciers/apps/registration/tests/components/operations/registration/NewEntrantOperationForm.test.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("the NewEntrantOperationForm component", () => {
6464
new_entrant_application: JSON.stringify({
6565
id: 1,
6666
name: "test_file.pdf",
67-
status: "Unscanned",
67+
status: "Clean",
6868
}),
6969
}}
7070
operation="002d5a9e-32a6-4191-938c-2c02bfec592d"
@@ -74,7 +74,7 @@ describe("the NewEntrantOperationForm component", () => {
7474
/>,
7575
);
7676

77-
expect(screen.getByText("testpdf.pdf")).toBeVisible();
77+
expect(screen.getByText("test_file.pdf")).toBeVisible();
7878
});
7979

8080
it("should display the correct url and message for new entrant operations", () => {
@@ -178,8 +178,17 @@ describe("the NewEntrantOperationForm component", () => {
178178
);
179179

180180
const submittedFormData = Object.fromEntries(callArgs[3].body);
181-
expect(submittedFormData.payload).toEqual("123");
182-
expect(typeof submittedFormData.new_entrant_application).toBe("File");
181+
expect(submittedFormData.payload).toEqual(
182+
JSON.stringify({
183+
new_entrant_application: JSON.stringify({
184+
name: "test.pdf",
185+
status: "Unscanned",
186+
}),
187+
}),
188+
);
189+
expect(submittedFormData.new_entrant_application instanceof File).toBe(
190+
true,
191+
);
183192

184193
await waitFor(() => {
185194
expect(mockPush).toHaveBeenCalledWith(

bciers/apps/registration/tests/components/operations/registration/OperationInformationForm.test.tsx

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ describe("the OperationInformationForm component", () => {
170170
boundary_map: JSON.stringify({
171171
id: 1,
172172
name: "testpdf.pdf",
173-
status: "Unscanned",
173+
status: "Clean",
174174
}),
175175
process_flow_diagram: JSON.stringify({
176176
id: 2,
177-
name: "testpdf.pdf",
178-
status: "Unscanned",
177+
name: "testpdf2.pdf",
178+
status: "Clean",
179179
}),
180180
registration_purpose: "Reporting Operation",
181181
activities: [1],
@@ -212,9 +212,10 @@ describe("the OperationInformationForm component", () => {
212212
"211110 - Oil and gas extraction (except oil sands)",
213213
);
214214

215-
expect(screen.getAllByText(/testpdf.pdf/i)).toHaveLength(2);
215+
expect(screen.getAllByText(/testpdf.pdf/i)).toHaveLength(1);
216+
expect(screen.getAllByText(/testpdf2.pdf/i)).toHaveLength(1);
216217
expect(
217-
screen.getAllByRole("link", {
218+
screen.getAllByRole("button", {
218219
name: /preview/i,
219220
}),
220221
).toHaveLength(2);
@@ -235,32 +236,37 @@ describe("the OperationInformationForm component", () => {
235236

236237
await waitFor(() => {
237238
// LastCalledWith because we mock the actionHandler multiple times to populate the dropdown options and operation info
238-
expect(actionHandler).toHaveBeenLastCalledWith(
239+
const lastCall =
240+
actionHandler.mock.calls[actionHandler.mock.calls.length - 1];
241+
expect(lastCall.length).toBe(4);
242+
expect(lastCall[0]).toBe(
239243
"registration/operations/b974a7fc-ff63-41aa-9d57-509ebe2553a4/registration/operation",
240-
"PUT",
244+
);
245+
expect(lastCall[1]).toBe("POST");
246+
expect(lastCall[2]).toBe(
241247
"/register-an-operation/b974a7fc-ff63-41aa-9d57-509ebe2553a4/1",
242-
{
243-
body: JSON.stringify({
244-
registration_purpose: "Reporting Operation",
245-
operation: "b974a7fc-ff63-41aa-9d57-509ebe2553a4",
246-
activities: [1],
247-
name: "Existing Operation edited",
248-
type: "Single Facility Operation",
249-
naics_code_id: 1,
250-
process_flow_diagram: JSON.stringify({
251-
id: 2,
252-
name: "testpdf2.pdf",
253-
status: "Unscanned",
254-
}),
255-
boundary_map: JSON.stringify({
256-
id: 912,
257-
name: "aaaaaaaa.pdf",
258-
status: "Clean",
259-
}),
260-
operation_has_multiple_operators: false,
261-
}),
262-
},
263248
);
249+
expect(Object.fromEntries(lastCall[3].body || [])).toEqual({
250+
payload: JSON.stringify({
251+
registration_purpose: "Reporting Operation",
252+
operation: "b974a7fc-ff63-41aa-9d57-509ebe2553a4",
253+
activities: [1],
254+
name: "Existing Operation edited",
255+
type: "Single Facility Operation",
256+
naics_code_id: 1,
257+
process_flow_diagram: JSON.stringify({
258+
id: 2,
259+
name: "testpdf2.pdf",
260+
status: "Clean",
261+
}),
262+
boundary_map: JSON.stringify({
263+
id: 1,
264+
name: "testpdf.pdf",
265+
status: "Clean",
266+
}),
267+
operation_has_multiple_operators: false,
268+
}),
269+
});
264270

265271
expect(mockPush).toHaveBeenCalledWith(
266272
`/register-an-operation/b974a7fc-ff63-41aa-9d57-509ebe2553a4/2?operations_title=${encodeURIComponent(

0 commit comments

Comments
 (0)