Skip to content

Commit

Permalink
stub out generic units test
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Jun 10, 2024
1 parent 85e851e commit a7f59f8
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 9 deletions.
31 changes: 30 additions & 1 deletion editor.planx.uk/src/@planx/components/List/Public/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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(
<ListComponent {...mockProps} handleSubmit={handleSubmit} />,
Expand All @@ -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(
<ListComponent {...mockPropsUnits} handleSubmit={handleSubmit} />,
);
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", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" } },
Expand Down

0 comments on commit a7f59f8

Please sign in to comment.