From 9b522e668debbc19c9970302adf067d0e7560f6f Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Mon, 28 Oct 2024 15:09:29 +0100 Subject: [PATCH] tidy up --- .../__tests__/preview/autoAnswerableFlag.test.ts | 8 ++------ .../preview/autoAnswerableOptions.test.ts | 14 +++++++------- .../src/pages/FlowEditor/lib/store/preview.ts | 9 +++------ 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview/autoAnswerableFlag.test.ts b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview/autoAnswerableFlag.test.ts index def2d8a812..8fe7424d57 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview/autoAnswerableFlag.test.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview/autoAnswerableFlag.test.ts @@ -7,6 +7,8 @@ beforeEach(() => { resetPreview(); }); +// Additionally see src/pages/FlowEditor/lib/filters.test.ts for positive autoAnswerableFlag test cases !! + describe("Returns undefined and does not auto-answer any flag paths", () => { test("If the node is not a Filter type", () => { setState({ flow: { @@ -33,12 +35,6 @@ describe("Returns undefined and does not auto-answer any flag paths", () => { expect(autoAnswerableFlag("Filter")).not.toBeDefined(); }); -describe("Filters", () => { - test.todo("Auto-answer the single highest order flag path when many flags are collected"); - - test.todo("Auto-answer the blank path (no flag result) when no matching flags have been collected"); -}); - const flowWithFilter: Store.Flow = { "_root": { "edges": [ diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview/autoAnswerableOptions.test.ts b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview/autoAnswerableOptions.test.ts index 32901e1f8b..a11cd2d9b1 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview/autoAnswerableOptions.test.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview/autoAnswerableOptions.test.ts @@ -7,6 +7,10 @@ beforeEach(() => { resetPreview(); }); +// Find additional auto-answering tests at: +// - src/pages/FlowEditor/lib/automations.blanks.test.ts +// - src/pages/FlowEditor/lib/automations.parentChild.test.ts + describe("Returns undefined and does not auto-answer any options", () => { test("If the node is not a Question or Checklist type", () => { setState({ @@ -29,7 +33,7 @@ describe("Returns undefined and does not auto-answer any options", () => { describe("Questions", () => { test.todo("Auto-answer the option that exactly matches a passport value"); - test.todo("Auto-answer the less granular option when there's a single more granular passport value"); + test.todo("Auto-answer the less granular option when there's a single more granular passport value and no more granular options available"); test.todo("Auto-answer the single most granular, left-most option when there are many matching passport values"); @@ -41,13 +45,9 @@ describe("Questions", () => { describe("Checklists", () => { test.todo("Auto-answer all options that exactly match passport values"); - test.todo("Auto-answer all less granular options when there are more granular passport values"); + test.todo("Auto-answer all less granular options when there are more granular passport values and not more granular options available"); - test.todo("Auto-answer through the blank path when we have seen thsi node `fn` but there are no matching passport values"); + test.todo("Auto-answer through the blank path when we have seen this node `fn` but there are no matching passport values"); test.todo("Auto-answer through the blank path when we have not seen this node `fn` but we have seen all possible option `val`"); }); - -describe("Blanks and `_nots`", () => { - test.todo("TODO"); -}); diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts index fdfc3111b1..4501feffc8 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts @@ -4,12 +4,11 @@ import type { GovUKPayment, Node, NodeId, - Value, } from "@opensystemslab/planx-core/types"; import { - ComponentType as TYPES, DEFAULT_FLAG_CATEGORY, flatFlags, + ComponentType as TYPES, } from "@opensystemslab/planx-core/types"; import { FileList } from "@planx/components/FileUploadAndLabel/model"; import { SetValue } from "@planx/components/SetValue/model"; @@ -17,8 +16,6 @@ import { handleSetValue } from "@planx/components/SetValue/utils"; import { sortIdsDepthFirst } from "@planx/graph"; import { logger } from "airbrake"; import { objectWithoutNullishValues } from "lib/objectHelpers"; -import difference from "lodash/difference"; -import flatten from "lodash/flatten"; import isEqual from "lodash/isEqual"; import omit from "lodash/omit"; import pick from "lodash/pick"; @@ -26,9 +23,9 @@ import uniq from "lodash/uniq"; import { v4 as uuidV4 } from "uuid"; import type { StateCreator } from "zustand"; +import type { Store } from "."; import type { Session } from "./../../../../types"; import { ApplicationPath } from "./../../../../types"; -import type { Store } from "."; import { NavigationStore } from "./navigation"; import type { SharedStore } from "./shared"; @@ -448,7 +445,7 @@ export const previewStore: StateCreator< const { type, data, edges } = flow[id]; // Only Question & Checklist nodes that have an fn & edges are eligible for auto-answering - if (!type || ![TYPES.Question, TYPES.Checklist].includes(type) || !data?.fn || !edges) return; + if (!type || !SUPPORTED_DECISION_TYPES.includes(type) || !data?.fn || !edges) return; // Only proceed if the user has seen at least one node with this fn before const visitedFns = Object.entries(breadcrumbs).filter(([nodeId, _breadcrumb]) => flow[nodeId].data?.fn === data.fn);