diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/computePassport.test.ts b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/computePassport.test.ts new file mode 100644 index 0000000000..8d4299a0e8 --- /dev/null +++ b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/computePassport.test.ts @@ -0,0 +1,67 @@ +import { FullStore, useStore } from "../store"; +import { flowWithDuplicatePassportVars } from "./mocks/computePassport/flowWithDuplicatePassportVars"; + +const { getState, setState } = useStore; + +const { computePassport } = getState(); + +let initialState: FullStore; + +beforeEach(() => { + initialState = getState(); +}); + +afterEach(() => setState(initialState)); + +describe("breadcrumbs where multiple nodes set the same passport value", () => { + const breadcrumbs = { + sIipiCHueb: { + auto: false, + data: { + "application.information.sensitive": "test", + }, + }, + "4oH6eI9TMm": { + auto: false, + answers: ["XZlpeuJt9o"], + }, + }; + + it("returns an array of both values", () => { + setState({ flow: flowWithDuplicatePassportVars, breadcrumbs }); + const duplicateKey = "application.information.sensitive"; + + const output = computePassport(); + expect(output.data).toHaveProperty(duplicateKey); + expect(output.data?.[duplicateKey]).toEqual(expect.arrayContaining(["test", "true"])); + }); + + it.skip("returns an array of both values, irrespective of the order of the breadcrumbs", () => { + const breadcrumbs = { + "4oH6eI9TMm": { + auto: false, + answers: ["XZlpeuJt9o"], + }, + sIipiCHueb: { + auto: false, + data: { + "application.information.sensitive": "test", + }, + }, + }; + + setState({ flow: flowWithDuplicatePassportVars, breadcrumbs }); + const duplicateKey = "application.information.sensitive"; + + const output = computePassport(); + expect(output.data).toHaveProperty(duplicateKey); + + // Currently returning this value + expect(output.data?.[duplicateKey]).toEqual("test") + + // But I think we should expect this? + expect(output.data?.[duplicateKey]).toEqual( + expect.arrayContaining(["test", "true"]) + ); + }); +}); \ No newline at end of file diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/computePassport/flowWithDuplicatePassportVars.ts b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/computePassport/flowWithDuplicatePassportVars.ts new file mode 100644 index 0000000000..4fa4ba46a4 --- /dev/null +++ b/editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/computePassport/flowWithDuplicatePassportVars.ts @@ -0,0 +1,54 @@ +import { Store } from "pages/FlowEditor/lib/store" + +export const flowWithDuplicatePassportVars: Store.Flow = { + _root: { + edges: [ + "4oH6eI9TMm", + "CTW66QO1Aq" + ] + }, + "4oH6eI9TMm": { + data: { + fn: "application.information.sensitive", + text: "Is any of the information you have provided sensitive?" + }, + type: 100, + edges: [ + "XZlpeuJt9o", + "5fh40KCyTJ" + ] + }, + "5fh40KCyTJ": { + data: { + val: "false", + text: "No" + }, + type: 200 + }, + CTW66QO1Aq: { + data: { + color: "#EFEFEF", + title: "The end", + resetButton: false + }, + type: 8 + }, + XZlpeuJt9o: { + data: { + val: "true", + text: "Yes" + }, + type: 200, + edges: [ + "sIipiCHueb" + ] + }, + sIipiCHueb: { + data: { + fn: "application.information.sensitive", + type: "long", + title: "What is it about the information that makes it sensitive?" + }, + type: 110 + } +}; \ No newline at end of file