From 37a228326b642fe4763d7c6bb8c5e14d53532b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 16 Oct 2024 09:25:41 +0100 Subject: [PATCH] test: Find property --- .../Search/SearchResultCard/allFacets.test.ts | 46 +++++++++++++++++-- .../getDisplayDetailsForResult.tsx | 4 ++ .../Sidebar/Search/mocks/allFacetFlow.ts | 23 ++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/allFacets.test.ts b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/allFacets.test.ts index f0ff6a9578..209c50eb13 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/allFacets.test.ts +++ b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/allFacets.test.ts @@ -1,7 +1,7 @@ import { ComponentType } from "@opensystemslab/planx-core/types"; import { useStore } from "pages/FlowEditor/lib/store"; -import { mockChecklistOptionResult, mockChecklistResult, mockConfirmationResult, mockContentResult, mockFileUploadAndLabelResult, mockFlow, mockNextStepsOptionResult, mockNumberInputResult, mockPayResult, mockQuestionResult, mockSchemaResult, mockTaskListResult } from "../mocks/allFacetFlow"; +import { mockChecklistOptionResult, mockChecklistResult, mockConfirmationResult, mockContentResult, mockFileUploadAndLabelResult, mockFindPropertyResult, mockFlow, mockNextStepsOptionResult, mockNumberInputResult, mockPayResult, mockQuestionResult, mockSchemaResult, mockTaskListResult } from "../mocks/allFacetFlow"; import { getDisplayDetailsForResult } from "./getDisplayDetailsForResult"; type Output = ReturnType; @@ -453,9 +453,47 @@ describe("confirmation fields", () => { }); describe("findProperty fields", () => { - it.todo("renders data.newAddressTitle"); - it.todo("renders data.newAddressDescription"); - it.todo("renders data.newAddressDescriptionLabel"); + it("renders data.newAddressTitle", () => { + const output = getDisplayDetailsForResult(mockFindPropertyResult); + + expect(output).toStrictEqual({ + key: "Title (new address)", + iconKey: ComponentType.FindProperty, + componentType: "Find property", + title: ".", + headline: "Mouse", + }); + }); + + it("renders data.newAddressDescription", () => { + const output = getDisplayDetailsForResult({ + ...mockFindPropertyResult, + key: "data.newAddressDescription", + }); + + expect(output).toStrictEqual({ + key: "Description (new address)", + iconKey: ComponentType.FindProperty, + componentType: "Find property", + title: ".", + headline: "

Stingray

", + }); + }); + + it("renders data.newAddressDescriptionLabel", () => { + const output = getDisplayDetailsForResult({ + ...mockFindPropertyResult, + key: "data.newAddressDescriptionLabel", + }); + + expect(output).toStrictEqual({ + key: "Description label (new address)", + iconKey: ComponentType.FindProperty, + componentType: "Find property", + title: ".", + headline: "Scorpion", + }); + }); }); describe("drawBoundary fields", () => { diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/getDisplayDetailsForResult.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/getDisplayDetailsForResult.tsx index b97e73767a..425ec7526c 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/getDisplayDetailsForResult.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/getDisplayDetailsForResult.tsx @@ -275,6 +275,10 @@ const componentFormatters: ComponentMap = { return formatted; } }, + // Find property is referred to internally as "find-property-merged" + [ComponentType.FindProperty]: { + getComponentType: () => "Find property", + } }; /** diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/mocks/allFacetFlow.ts b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/mocks/allFacetFlow.ts index 9c6462ef49..e4857d7f2d 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/mocks/allFacetFlow.ts +++ b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/mocks/allFacetFlow.ts @@ -525,3 +525,26 @@ export const mockConfirmationResult: SearchResult = { matchIndices: [[0, 4]], refIndex: 0, }; + +export const mockFindPropertyResult: SearchResult = { + item: { + id: "uUQq7w7zDy", + parentId: "_root", + type: 9, + data: { + title: ".", + newAddressTitle: "Mouse", + allowNewAddresses: true, + newAddressDescription: "

Stingray

", + newAddressDescriptionLabel: "Scorpion" + } + }, + key: "data.newAddressTitle", + matchIndices: [ + [ + 0, + 4 + ] + ], + refIndex: 0 +}; \ No newline at end of file