Skip to content

Commit

Permalink
test: vitest EIOs
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Jan 29, 2025
1 parent e207412 commit 3cc3ec0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe("the OperationInformationForm component", () => {
expect(screen.getByRole("button", { name: "Edit" })).toBeVisible();
});

it("should render the form with the correct values when formData is provided", async () => {
it("should render the form with the correct values for a non-EIO when formData is provided", async () => {
fetchFormEnums();
const createdFormSchema =
await createAdministrationOperationInformationSchema(
Expand Down Expand Up @@ -310,6 +310,36 @@ describe("the OperationInformationForm component", () => {
expect(screen.getByText(/Reporting Operation/i)).toBeVisible();
});

it("should render the form with the correct form for an EIO when formData is provided", async () => {
fetchFormEnums();
const createdFormSchema =
await createAdministrationOperationInformationSchema(
RegistrationPurposes.ELECTRICITY_IMPORT_OPERATION,
OperationStatus.REGISTERED,
);
render(
<OperationInformationForm
formData={{ name: "Operation 3", type: "Electricity Import Operation" }}
schema={createdFormSchema}
operationId={operationId}
/>,
);
//name
expect(screen.getByText(/Operation 3/i)).toBeVisible();
// type
expect(screen.getByText(/Electricity Import Operation/i)).toBeVisible();
// primary naics code
expect(screen.queryByText(/naics/i)).not.toBeInTheDocument();

// registration info & purpose
expect(
screen.getByText(
/The purpose of this registration is to register as a\:/i,
),
).toBeVisible();
expect(screen.getByText(/Electricity Import Operation/i)).toBeVisible();
});

it("should enable editing when the Edit button is clicked", async () => {
render(
<OperationInformationForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ describe("the OperationRegistrationPage component", () => {
);
});

it("should render the Operation Representative Form and 4 steps", async () => {
it("should render the Operation Representative Form and 3 steps if the purpose is Electricity Import Operation", async () => {
// purpose
actionHandler.mockResolvedValueOnce({
registration_purpose: "OBPS Regulated Operation",
registration_purpose: "Electricity Import Operation",
});

// contacts
Expand All @@ -164,7 +164,7 @@ describe("the OperationRegistrationPage component", () => {
render(
await OperationRegistrationPage({
operation: "002d5a9e-32a6-4191-938c-2c02bfec592d",
step: 3,
step: 2,
searchParams: {},
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe("the OperationInformationForm component", () => {
);

it(
"should submit a new operation with regulated products and multiple operators",
"should submit a new OBPS regulated operation with regulated products and multiple operators",
{
timeout: 60000,
},
Expand Down Expand Up @@ -349,6 +349,67 @@ describe("the OperationInformationForm component", () => {
},
);

it(
"should submit a new EIO operation",
{
timeout: 60000,
},
async () => {
fetchFormEnums();
actionHandler.mockResolvedValueOnce({
id: "b974a7fc-ff63-41aa-9d57-509ebe2553a4",
name: "EIO Op Name",
}); // mock the POST response from the submit handler
render(
<OperationInformationForm
rawFormData={{}}
schema={await createRegistrationOperationInformationSchema()}
step={1}
steps={allOperationRegistrationSteps}
/>,
);

const purposeInput = screen.getByRole("combobox", {
name: /The purpose of this registration+/i,
});
await fillComboboxWidgetField(
purposeInput,
"Electricity Import Operation",
);

await userEvent.type(
screen.getByLabelText(/Operation Name/i),
"EIO Op Name",
);

// EIO is the default operation type if purpose is EIO so we don't have to fill it in

// submit

await userEvent.click(
screen.getByRole("button", { name: /save and continue/i }),
);
await waitFor(() => {
expect(actionHandler).toHaveBeenLastCalledWith(
"registration/operations",
"POST",
"",
{
body: JSON.stringify({
registration_purpose: "Electricity Import Operation",
name: "EIO Op Name",
type: "Electricity Import Operation",
operation_has_multiple_operators: false,
}),
},
);
});
expect(mockPush).toHaveBeenCalledWith(
"/register-an-operation/b974a7fc-ff63-41aa-9d57-509ebe2553a4/2?operations_title=EIO%20Op%20Name",
);
},
);

it("should show the correct help text when selecting a purpose", async () => {
fetchFormEnums();
render(
Expand Down

0 comments on commit 3cc3ec0

Please sign in to comment.