Skip to content

Commit 38918a4

Browse files
committed
test: fix most vitests
1 parent 7cb67f5 commit 38918a4

File tree

10 files changed

+160
-137
lines changed

10 files changed

+160
-137
lines changed

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

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010
import {
1111
downloadUrl,
1212
downloadUrl2,
13-
} from "libs/components/src/form/widgets/FileWidget.test";
13+
mock21MBFile,
14+
mockFile,
15+
mockFile2,
16+
mockFileUnaccepted,
17+
} from "libs/testConfig/src/constants";
1418

1519
import { createAdministrationOperationInformationSchema } from "apps/administration/app/data/jsonSchema/operationInformation/administrationOperationInformation";
1620
import { Apps, FrontEndRoles, OperationStatus } from "@bciers/utils/src/enums";
@@ -30,10 +34,6 @@ useSearchParams.mockReturnValue({
3034
get: vi.fn(),
3135
});
3236

33-
global.URL.createObjectURL = vi.fn(
34-
() => "this is the link to download the File",
35-
);
36-
3737
// Just using a simple schema for testing purposes
3838
const testSchema: RJSFSchema = {
3939
type: "object",
@@ -176,6 +176,9 @@ const newEntrantFormData = {
176176
const operationId = "8be4c7aa-6ab3-4aad-9206-0ef914fea063";
177177

178178
describe("the OperationInformationForm component", () => {
179+
global.URL.createObjectURL = vi.fn(
180+
() => "this is the link to download the File",
181+
);
179182
beforeEach(() => {
180183
vi.clearAllMocks();
181184
});
@@ -346,15 +349,15 @@ describe("the OperationInformationForm component", () => {
346349
expect(actionHandler).toHaveBeenCalledTimes(1);
347350
expect(actionHandler).toHaveBeenCalledWith(
348351
`registration/operations/${operationId}`,
349-
"PUT",
352+
"POST",
350353
"",
351354
{
352-
body: JSON.stringify({
353-
name: "Operation 4",
354-
type: "Single Facility Operation",
355-
}),
355+
body: expect.any(FormData),
356356
},
357357
);
358+
const formData = actionHandler.mock.calls[0][3].body;
359+
expect(formData.get("name")).toBe("Operation 4");
360+
expect(formData.get("type")).toBe("Single Facility Operation");
358361

359362
// Expect the form to be submitted
360363
expect(screen.getByText(/Operation 4/i)).toBeVisible();
@@ -835,9 +838,7 @@ describe("the OperationInformationForm component", () => {
835838
);
836839

837840
await userEvent.click(afterAprilRadioButton);
838-
const mockFile = new File(["test"], "mock_file.pdf", {
839-
type: "application/pdf",
840-
});
841+
841842
const newEntrantApplicationDocument = screen.getByLabelText(
842843
/new entrant application and statutory declaration/i,
843844
);
@@ -850,19 +851,21 @@ describe("the OperationInformationForm component", () => {
850851
expect(actionHandler).toHaveBeenCalledTimes(1);
851852
expect(actionHandler).toHaveBeenCalledWith(
852853
`registration/operations/${operationId}`,
853-
"PUT",
854+
"POST",
854855
"",
855856
{
856-
body: JSON.stringify({
857-
name: "Operation 5",
858-
type: "Single Facility Operation",
859-
registration_purpose: "New Entrant Operation",
860-
date_of_first_shipment: "On or after April 1, 2024",
861-
new_entrant_application:
862-
"data:application/pdf;name=mock_file.pdf;base64,dGVzdA==",
863-
}),
857+
body: expect.any(FormData),
864858
},
865859
);
860+
const formData = actionHandler.mock.calls[0][3].body;
861+
862+
expect(formData.get("name ")).toBe("Operation 5");
863+
expect(formData.get("type ")).toBe("Single Facility Operation");
864+
expect(formData.get("registration_purpose ")).toBe("New Entrant Operation");
865+
expect(formData.get("date_of_first_shipment ")).toBe(
866+
"On or after April 1, 2024",
867+
);
868+
expect(formData.get("new_entrant_application")).toBe(mockFile);
866869
});
867870

868871
it("should not allow external users to remove their operation rep", async () => {
@@ -903,7 +906,7 @@ describe("the OperationInformationForm component", () => {
903906
expect(screen.getByText(/Must not have fewer than 1 items/i)).toBeVisible();
904907
});
905908

906-
it(
909+
it.only(
907910
"should allow external users to replace their operation rep",
908911
{ timeout: 100000 },
909912
async () => {
@@ -919,7 +922,7 @@ describe("the OperationInformationForm component", () => {
919922
opt_in: false,
920923
operation_representatives: [1],
921924
boundary_map: downloadUrl,
922-
process_flow_diagram: downloadUrl,
925+
process_flow_diagram: downloadUrl2,
923926
};
924927
useSession.mockReturnValue({
925928
data: {
@@ -970,23 +973,25 @@ describe("the OperationInformationForm component", () => {
970973
expect(actionHandler).toHaveBeenCalledTimes(1);
971974
expect(actionHandler).toHaveBeenCalledWith(
972975
`registration/operations/${operationId}`,
973-
"PUT",
976+
"POST",
974977
"",
975978
{
976-
body: JSON.stringify({
977-
name: "Operation 3",
978-
type: "Single Facility Operation",
979-
naics_code_id: 1,
980-
secondary_naics_code_id: 2,
981-
process_flow_diagram: downloadUrl,
982-
boundary_map: downloadUrl2,
983-
operation_has_multiple_operators: false,
984-
registration_purpose: "Reporting Operation",
985-
operation_representatives: [2],
986-
activities: [1, 2],
987-
}),
979+
body: expect.any(FormData),
988980
},
989981
);
982+
const formData = actionHandler.mock.calls[0][3].body;
983+
984+
expect(formData.get("name")).toBe("Operation 3");
985+
expect(formData.get("type")).toBe("Single Facility Operation");
986+
expect(formData.get("naics_code_id")).toBe("1");
987+
expect(formData.get("secondary_naics_code_id")).toBe("2");
988+
expect(formData.get("boundary_map")).toBe(downloadUrl);
989+
expect(formData.get("process_flow_diagram")).toBe(downloadUrl2);
990+
expect(formData.get("operation_has_multiple_operators")).toBe("false");
991+
expect(formData.get("registration_purpose")).toBe("Reporting Operation"),
992+
expect(formData.get("operation_representatives")).toBe("2");
993+
expect(formData.get("activities")).toBe("1");
994+
expect(formData.get("activities")).toBe("2");
990995
},
991996
);
992997

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ const OperationInformationForm = ({
290290
setConfirmedFormState(e.formData);
291291
}}
292292
uiSchema={currentUiSchema}
293-
// customValidate={customValidate}
293+
customValidate={customValidate}
294294
/>
295295
</>
296296
);

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import { actionHandler, useRouter, useSession } from "@bciers/testConfig/mocks";
1515
import {
1616
downloadUrl,
1717
downloadUrl2,
18-
} from "libs/components/src/form/widgets/FileWidget.test";
18+
mock21MBFile,
19+
mockFile,
20+
mockFile2,
21+
mockFileUnaccepted,
22+
} from "libs/testConfig/src/constants";
1923

2024
useSession.mockReturnValue({
2125
data: {
@@ -31,15 +35,12 @@ useRouter.mockReturnValue({
3135
push: mockPush,
3236
});
3337

34-
global.URL.createObjectURL = vi.fn(
35-
() => "this is the link to download the File",
36-
);
37-
38-
const mockFile = new File(["test"], "test.pdf", { type: "application/pdf" });
39-
4038
describe("the NewEntrantOperationForm component", () => {
4139
beforeEach(() => {
4240
vi.clearAllMocks();
41+
global.URL.createObjectURL = vi.fn(
42+
() => "this is the link to download the File",
43+
);
4344
});
4445

4546
it("should render the NewEntrantOperationForm component", () => {
@@ -199,12 +200,17 @@ describe("the NewEntrantOperationForm component", () => {
199200

200201
expect(actionHandler).toHaveBeenCalledWith(
201202
"registration/operations/002d5a9e-32a6-4191-938c-2c02bfec592d/registration/new-entrant-application",
202-
"PUT",
203+
"POST",
203204
"/register-an-operation/002d5a9e-32a6-4191-938c-2c02bfec592d",
204205
{
205-
body: '{"new_entrant_application":"data:application/pdf;name=test.pdf;base64,dGVzdA==","date_of_first_shipment":"On or before March 31, 2024"}',
206+
body: expect.any(FormData),
206207
},
207208
);
209+
const formData = actionHandler.mock.calls[0][3].body;
210+
expect(formData.get("new_entrant_application")).toBe(mockFile);
211+
expect(formData.get("date_of_first_shipment")).toBe(
212+
"On or before March 31, 2024",
213+
);
208214
await waitFor(() => {
209215
expect(mockPush).toHaveBeenCalledWith(
210216
"/register-an-operation/002d5a9e-32a6-4191-938c-2c02bfec592d/5",

0 commit comments

Comments
 (0)