Skip to content

Commit

Permalink
test: Add test for current behaviour
Browse files Browse the repository at this point in the history
- Desired behaviour TBD in PR & Slack
  • Loading branch information
DafyddLlyr committed Sep 26, 2024
1 parent f31c81b commit 6f74eca
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"])
);
});
});
Original file line number Diff line number Diff line change
@@ -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
}
};

0 comments on commit 6f74eca

Please sign in to comment.