From e7c6b446c1658a713d6a3171e8a52260adb6704a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 26 Jun 2024 10:49:58 +0100 Subject: [PATCH] test: Fix skipped List component test --- .../components/List/Public/index.test.tsx | 42 ++++++++++++------- .../List/schemas/mocks/GenericUnits.ts | 4 +- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/List/Public/index.test.tsx b/editor.planx.uk/src/@planx/components/List/Public/index.test.tsx index aa47784682..343cabc39d 100644 --- a/editor.planx.uk/src/@planx/components/List/Public/index.test.tsx +++ b/editor.planx.uk/src/@planx/components/List/Public/index.test.tsx @@ -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( , ); - 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); }); }); diff --git a/editor.planx.uk/src/@planx/components/List/schemas/mocks/GenericUnits.ts b/editor.planx.uk/src/@planx/components/List/schemas/mocks/GenericUnits.ts index 808da9a921..344851ab8c 100644 --- a/editor.planx.uk/src/@planx/components/List/schemas/mocks/GenericUnits.ts +++ b/editor.planx.uk/src/@planx/components/List/schemas/mocks/GenericUnits.ts @@ -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, }, };