-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test for current behaviour
- Desired behaviour TBD in PR & Slack
- Loading branch information
1 parent
f31c81b
commit 6f74eca
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
editor.planx.uk/src/pages/FlowEditor/lib/__tests__/computePassport.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) | ||
); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
...src/pages/FlowEditor/lib/__tests__/mocks/computePassport/flowWithDuplicatePassportVars.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}; |