From d2aed30d63ea9c848821f6e4df1b030dffb881e9 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Thu, 6 Jun 2024 20:49:55 +0200 Subject: [PATCH] adjust mock data --- .../src/@planx/components/List/Public/Context.tsx | 6 ++++-- .../src/@planx/components/List/Public/index.test.tsx | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/List/Public/Context.tsx b/editor.planx.uk/src/@planx/components/List/Public/Context.tsx index 3b6ec49e48..8ea9e68ddf 100644 --- a/editor.planx.uk/src/@planx/components/List/Public/Context.tsx +++ b/editor.planx.uk/src/@planx/components/List/Public/Context.tsx @@ -141,12 +141,14 @@ export const ListProvider: React.FC = (props) => { // basic example of general summary stats we can add onSubmit let sumIdenticalUnits = 0; defaultPassportData[`${props.fn}`].map( - (item) => (sumIdenticalUnits += parseInt(item.identicalUnits)), + (item) => (sumIdenticalUnits += parseInt(item?.identicalUnits)), ); const summaries = { [`${props.fn}.total.listItems`]: defaultPassportData[`${props.fn}`].length, - [`${props.fn}.total.units`]: sumIdenticalUnits, + ...(sumIdenticalUnits > 0 && { + [`${props.fn}.total.units`]: sumIdenticalUnits, + }), }; handleSubmit?.({ 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 83073e6250..ee007bca9d 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 @@ -43,7 +43,7 @@ const mockPayload = { "mockFn.two.email": "richard.parker@pi.com", "mockFn.two.name": "Richard Parker", "mockFn.two.size": "Medium", - "mockFn.count": 2, + "mockFn.total.listItems": 2, }, };