From a7f59f8fd0b73d249c30b9a6472ec56c066a0117 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Mon, 10 Jun 2024 22:39:00 +0200 Subject: [PATCH] stub out generic units test --- .../components/List/Public/index.test.tsx | 31 ++++++++- .../List/schemas/GenericUnitsTest.ts | 67 +++++++++++++++++++ .../List/schemas/ResidentialUnits/GLA/New.ts | 7 +- .../schemas/ResidentialUnits/GLA/Rebuilt.ts | 7 +- .../schemas/ResidentialUnits/GLA/Removed.ts | 7 +- .../schemas/ResidentialUnits/GLA/Retained.ts | 7 +- 6 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 editor.planx.uk/src/@planx/components/List/schemas/GenericUnitsTest.ts 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 ee007bca9d..248d83dc80 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 @@ -5,6 +5,7 @@ import React from "react"; import { axe, setup } from "testUtils"; import ListComponent, { Props } from "../Public"; +import { GenericUnitsTest } from "../schemas/GenericUnitsTest"; import { Zoo } from "../schemas/Zoo"; const mockProps: Props = { @@ -47,6 +48,19 @@ const mockPayload = { }, }; +const mockPropsUnits: Props = { + fn: "proposal.units.residential", + schema: GenericUnitsTest, + schemaName: "Generic residential units", + title: "Describe residential units", +}; + +const mockPayloadUnits = { + data: { + "proposal.units.residential": [], + }, +}; + jest.setTimeout(20_000); describe("Basic UI", () => { @@ -378,7 +392,7 @@ describe("Form validation and error handling", () => { }); describe("Payload generation", () => { - it("generates a valid payload on submission", async () => { + it("generates a valid payload on submission (Zoo)", async () => { const handleSubmit = jest.fn(); const { getByTestId, user } = setup( , @@ -395,6 +409,21 @@ describe("Payload generation", () => { expect(handleSubmit).toHaveBeenCalled(); expect(handleSubmit.mock.calls[0][0]).toMatchObject(mockPayload); }); + + it.skip("generates a valid payload with summary stats on submission (Units)", async () => { + const handleSubmit = jest.fn(); + const { getByTestId, user } = setup( + , + ); + const addItemButton = getByTestId("list-add-button"); + + // fill in three unique responses + + await user.click(screen.getByTestId("continue-button")); + + expect(handleSubmit).toHaveBeenCalled(); + expect(handleSubmit.mock.calls[0][0]).toMatchObject(mockPayloadUnits); + }); }); describe("Navigating back", () => { diff --git a/editor.planx.uk/src/@planx/components/List/schemas/GenericUnitsTest.ts b/editor.planx.uk/src/@planx/components/List/schemas/GenericUnitsTest.ts new file mode 100644 index 0000000000..e7551a41ac --- /dev/null +++ b/editor.planx.uk/src/@planx/components/List/schemas/GenericUnitsTest.ts @@ -0,0 +1,67 @@ +import { Schema } from "@planx/components/List/model"; + +export const GenericUnitsTest: Schema = { + type: "Unit", + fields: [ + // fn = "development" triggers summary stat + { + type: "question", + data: { + title: "What development does this unit result from?", + fn: "development", + options: [ + { id: "newBuild", data: { text: "New build", val: "newBuild" } }, + { + id: "changeOfUseFrom", + data: { + text: "Change of use of existing single home", + val: "changeOfUseFrom", + }, + }, + { + id: "changeOfUseTo", + data: { text: "Change of use to a home", val: "changeOfUseTo" }, + }, + ], + }, + }, + // options set "val" + { + type: "question", + data: { + title: "What best describes the type of this unit?", + fn: "type", + options: [ + { id: "terraced", data: { text: "Terraced home", val: "terraced" } }, + { + id: "semiDetached", + data: { text: "Semi detached home", val: "semiDetached" }, + }, + { id: "detached", data: { text: "Detached home", val: "detached" } }, + ], + }, + }, + // options set "text" only + { + type: "question", + data: { + title: "Is this unit built on garden land?", + fn: "garden", + options: [ + { id: "true", data: { text: "Yes" } }, + { id: "false", data: { text: "No" } }, + ], + }, + }, + // fn = "identicalUnits" triggers summary stat + { + type: "number", + data: { + title: "How many identical units does the description above apply to?", + fn: "identicalUnits", + allowNegatives: false, + }, + }, + ], + min: 1, +} as const; diff --git a/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/New.ts b/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/New.ts index 8b4e305ab6..88f92a1aee 100644 --- a/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/New.ts +++ b/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/New.ts @@ -46,10 +46,13 @@ export const ResidentialUnitsGLANew: Schema = { title: "Which best describes the tenure of this unit?", fn: "tenure", options: [ - { id: "LAR", data: { text: "London Affordable Rent" } }, + { id: "LAR", data: { text: "London Affordable Rent", val: "LAR" } }, { id: "AR", - data: { text: "Affordable rent (not at LAR benchmark rents)" }, + data: { + text: "Affordable rent (not at LAR benchmark rents)", + val: "AR", + }, }, { id: "SR", data: { text: "Social rent", val: "SR" } }, { id: "LRR", data: { text: "London Living Rent", val: "LRR" } }, diff --git a/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Rebuilt.ts b/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Rebuilt.ts index 753034fbcb..485d0aa04e 100644 --- a/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Rebuilt.ts +++ b/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Rebuilt.ts @@ -46,10 +46,13 @@ export const ResidentialUnitsGLARebuilt: Schema = { title: "Which best describes the tenure of this unit?", fn: "tenure", options: [ - { id: "LAR", data: { text: "London Affordable Rent" } }, + { id: "LAR", data: { text: "London Affordable Rent", val: "LAR" } }, { id: "AR", - data: { text: "Affordable rent (not at LAR benchmark rents)" }, + data: { + text: "Affordable rent (not at LAR benchmark rents)", + val: "AR", + }, }, { id: "SR", data: { text: "Social rent", val: "SR" } }, { id: "LRR", data: { text: "London Living Rent", val: "LRR" } }, diff --git a/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Removed.ts b/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Removed.ts index 2c27776df0..ee7027875c 100644 --- a/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Removed.ts +++ b/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Removed.ts @@ -25,10 +25,13 @@ export const ResidentialUnitsGLARemoved: Schema = { title: "Which best describes the tenure of this unit?", fn: "tenure", options: [ - { id: "LAR", data: { text: "London Affordable Rent" } }, + { id: "LAR", data: { text: "London Affordable Rent", val: "LAR" } }, { id: "AR", - data: { text: "Affordable rent (not at LAR benchmark rents)" }, + data: { + text: "Affordable rent (not at LAR benchmark rents)", + val: "AR", + }, }, { id: "SR", data: { text: "Social rent", val: "SR" } }, { id: "LRR", data: { text: "London Living Rent", val: "LRR" } }, diff --git a/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Retained.ts b/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Retained.ts index 013ba653c7..70c4bbfbe8 100644 --- a/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Retained.ts +++ b/editor.planx.uk/src/@planx/components/List/schemas/ResidentialUnits/GLA/Retained.ts @@ -17,10 +17,13 @@ export const ResidentialUnitsGLARetained: Schema = { title: "Which best describes the tenure of this unit?", fn: "tenure", options: [ - { id: "LAR", data: { text: "London Affordable Rent" } }, + { id: "LAR", data: { text: "London Affordable Rent", val: "LAR" } }, { id: "AR", - data: { text: "Affordable rent (not at LAR benchmark rents)" }, + data: { + text: "Affordable rent (not at LAR benchmark rents)", + val: "AR", + }, }, { id: "SR", data: { text: "Social rent", val: "SR" } }, { id: "LRR", data: { text: "London Living Rent", val: "LRR" } },