Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix skipped List component test #3321

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions editor.planx.uk/src/@planx/components/List/Public/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,48 +413,62 @@ describe("Payload generation", () => {
expect(handleSubmit.mock.calls[0][0]).toMatchObject(mockZooPayload);
});

it.skip("generates a valid payload with summary stats on submission (Units)", async () => {
it("generates a valid payload with summary stats on submission (Units)", async () => {
const handleSubmit = jest.fn();
const { getByTestId, user } = setup(
const { getByTestId, user, getByRole, getAllByRole, getByLabelText } = setup(
<ListComponent {...mockUnitsProps} handleSubmit={handleSubmit} />,
);

const saveButton = screen.getByRole("button", { name: /Save/ });
const addItemButton = getByTestId("list-add-button");
const developmentSelect = screen.getByRole("combobox");
const gardenYesRadio = screen.getAllByRole("radio")[0];
const gardenNoRadio = screen.getAllByRole("radio")[1];
const unitsNumberInput = screen.getByLabelText(/identical units/);

// Response 1
let saveButton = getByRole("button", { name: /Save/ });
let developmentSelect = getByRole("combobox");
let gardenYesRadio = getAllByRole("radio")[0];
let gardenNoRadio = getAllByRole("radio")[1];
let unitsNumberInput = getByLabelText(/identical units/);

await user.click(developmentSelect);
await user.click(screen.getByRole("option", { name: /New build/ }));
await user.click(getByRole("option", { name: /New build/ }));
await user.click(gardenYesRadio);
await user.type(unitsNumberInput, "1");
await user.click(saveButton);

// Response 2
await user.click(addItemButton);

saveButton = getByRole("button", { name: /Save/ });
developmentSelect = getByRole("combobox");
gardenYesRadio = getAllByRole("radio")[0];
gardenNoRadio = getAllByRole("radio")[1];
unitsNumberInput = getByLabelText(/identical units/);

await user.click(developmentSelect);
await user.click(screen.getByRole("option", { name: /New build/ }));
await user.click(getByRole("option", { name: /New build/ }));
await user.click(gardenNoRadio);
await user.type(unitsNumberInput, "2");
await user.click(saveButton);

// Response 3
await user.click(addItemButton);

saveButton = getByRole("button", { name: /Save/ });
developmentSelect = getByRole("combobox");
gardenYesRadio = getAllByRole("radio")[0];
gardenNoRadio = getAllByRole("radio")[1];
unitsNumberInput = getByLabelText(/identical units/);

await user.click(developmentSelect);
await user.click(
screen.getByRole("option", { name: /Change of use to a home/ }),
);
await user.click(getByRole("option", { name: /Change of use to a home/ }));
await user.click(gardenNoRadio);
await user.type(unitsNumberInput, "2");
await user.click(saveButton);

await user.click(screen.getByTestId("continue-button"));
await user.click(getByTestId("continue-button"));

expect(handleSubmit).toHaveBeenCalled();
expect(handleSubmit.mock.calls[0][0]).toMatchObject(mockUnitsPayload);
const output = handleSubmit.mock.calls[0][0]
expect(output).toMatchObject(mockUnitsPayload);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const mockUnitsPayload = {
"proposal.units.residential.three.identicalUnits": 2,
"proposal.units.residential.total.listItems": 3,
"proposal.units.residential.total.units": 5,
"proposal.units.residential.total.units.newBuid": 3,
"proposal.units.residential.total.units.changeOfUseTo": 2,
"proposal.units.residential.total.units.development.newBuild": 3,
"proposal.units.residential.total.units.development.changeOfUseTo": 2,
Comment on lines +92 to +93
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may look like I'm "fixing" the expected output to make the test pass, but in this instance it's actually an incorrect payload.

This now matches the other (already passing) test example here -

"proposal.units.residential.total.units.development.newBuild": 3,
"proposal.units.residential.total.units.development.changeOfUseTo": 2,

And we can see that development is added to the path here -

Object.entries(baseSums).forEach(([k, v]) => {
if (v > 0) {
formattedSums[`${fn}.total.units.development.${k}`] = v;
}
});

},
};
Loading