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 8fe7424d57..fbb019a06c 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 @@ -3,18 +3,20 @@ import { Store, useStore } from "../../store"; const { getState, setState } = useStore; const { resetPreview, autoAnswerableFlag } = getState(); -beforeEach(() => { - resetPreview(); -}); - -// Additionally see src/pages/FlowEditor/lib/filters.test.ts for positive autoAnswerableFlag test cases !! +// 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", () => { + beforeEach(() => { + resetPreview(); + }); + test("If the node is not a Filter type", () => { - setState({ flow: { + setState({ + flow: { "_root": { "edges": ["SetValue"] }, "SetValue": { "type": 380, "data": { "fn": "projectType", "val": "alter", "operation": "replace" } }, - }}); + } + }); expect(autoAnswerableFlag("SetValue")).not.toBeDefined(); }); @@ -28,49 +30,49 @@ describe("Returns undefined and does not auto-answer any flag paths", () => { }); test("If the node does not have any flag paths (aka options)"); - const alteredFlow = structuredClone(flowWithFilter); - delete alteredFlow["Filter"].edges; - setState({ flow: alteredFlow }); + const alteredFlow = structuredClone(flowWithFilter); + delete alteredFlow["Filter"].edges; + setState({ flow: alteredFlow }); - expect(autoAnswerableFlag("Filter")).not.toBeDefined(); + expect(autoAnswerableFlag("Filter")).not.toBeDefined(); }); const flowWithFilter: Store.Flow = { "_root": { - "edges": [ - "Filter" - ] + "edges": [ + "Filter" + ] }, "Filter": { - "type": 500, - "data": { - "fn": "flag", - "category": "Material change of use" - }, - "edges": [ - "Flag1", - "Flag2", - "Flag3" - ] + "type": 500, + "data": { + "fn": "flag", + "category": "Material change of use" + }, + "edges": [ + "Flag1", + "Flag2", + "Flag3" + ] }, "Flag1": { - "type": 200, - "data": { - "text": "Material change of use", - "val": "MCOU_TRUE" - } + "type": 200, + "data": { + "text": "Material change of use", + "val": "MCOU_TRUE" + } }, "Flag2": { - "type": 200, - "data": { - "text": "Not material change of use", - "val": "MCOU_FALSE" - } + "type": 200, + "data": { + "text": "Not material change of use", + "val": "MCOU_FALSE" + } }, "Flag3": { - "type": 200, - "data": { - "text": "No flag result" - } + "type": 200, + "data": { + "text": "No flag result" + } } }; 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 a11cd2d9b1..17dd4d107a 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 @@ -1,17 +1,18 @@ -import { useStore } from "../../store"; +import { Store, useStore } from "../../store"; const { getState, setState } = useStore; const { resetPreview, autoAnswerableOptions } = getState(); -beforeEach(() => { - resetPreview(); -}); - // Find additional auto-answering tests at: // - src/pages/FlowEditor/lib/automations.blanks.test.ts // - src/pages/FlowEditor/lib/automations.parentChild.test.ts +// - src/pages/FlowEditor/lib/automations.planningConstraintNots.test.ts describe("Returns undefined and does not auto-answer any options", () => { + beforeEach(() => { + resetPreview(); + }); + test("If the node is not a Question or Checklist type", () => { setState({ flow: { @@ -23,11 +24,30 @@ describe("Returns undefined and does not auto-answer any options", () => { expect(autoAnswerableOptions("SetValue")).not.toBeDefined(); }); - test.todo("If the node is a 'sticky note' Question without edges"); + test("If the node is a 'sticky note' Question without edges", () => { + const alteredFlow = structuredClone(singleNodeFlow); + delete alteredFlow["Question"]?.edges; + setState({ flow: alteredFlow }); - test.todo("If the node does not set a `fn`"); + expect(autoAnswerableOptions("Question")).not.toBeDefined(); + }); + + test("If the node does not set a `fn`", () => { + const alteredFlow = structuredClone(singleNodeFlow); + delete alteredFlow["Question"]?.data?.fn; + setState({ flow: alteredFlow }); - test.todo("If we've never seen another node with this `fn` before"); + expect(autoAnswerableOptions("Question")).not.toBeDefined(); + }); + + test("If we've never seen another node with this `fn` before", () => { + setState({ + flow: singleNodeFlow, + breadcrumbs: {} + }); + + expect(autoAnswerableOptions("Question")).not.toBeDefined(); + }); }); describe("Questions", () => { @@ -51,3 +71,37 @@ describe("Checklists", () => { test.todo("Auto-answer through the blank path when we have not seen this node `fn` but we have seen all possible option `val`"); }); + +const singleNodeFlow: Store.Flow = { + "_root": { + "edges": [ + "Question" + ] + }, + "Question": { + "type": 100, + "data": { + "fn": "direction", + "text": "Which direction?", + "forceSelection": false + }, + "edges": [ + "Option1", + "Option2" + ] + }, + "Option1": { + "type": 200, + "data": { + "text": "Left", + "val": "left" + } + }, + "Option2": { + "type": 200, + "data": { + "text": "Right", + "val": "right" + } + } +}; \ No newline at end of file