-
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.
fix: Handle multiple external portals as siblings
- Loading branch information
1 parent
dc46e96
commit 45edb4c
Showing
6 changed files
with
372 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
63 changes: 63 additions & 0 deletions
63
editor.planx.uk/src/pages/FlowEditor/lib/__tests__/externalPortals.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,63 @@ | ||
import { FullStore, vanillaStore } from "../store"; | ||
import multipleExternalPortals from "./mocks/multipleExternalPortals.json"; | ||
import singleExternalPortal from "./mocks/singleExternalPortal.json"; | ||
|
||
const { getState, setState } = vanillaStore; | ||
const { upcomingCardIds, record } = getState(); | ||
|
||
let initialState: FullStore; | ||
|
||
beforeEach(() => { | ||
initialState = getState(); | ||
}); | ||
|
||
describe("A flow with a single external portal can be navigated as expected", () => { | ||
beforeEach(() => setState({ flow: singleExternalPortal })); | ||
afterEach(() => setState(initialState)); | ||
|
||
it("without entering the portal", () => { | ||
expect(upcomingCardIds()[0]).toEqual("firstNode"); | ||
// Navigate down branch avoiding external portal | ||
record("firstNode", { answers: ["option2"] }); | ||
expect(upcomingCardIds()[0]).toEqual("finalNode"); | ||
}); | ||
|
||
it("via the portal", () => { | ||
expect(upcomingCardIds()[0]).toEqual("firstNode"); | ||
// Navigate down branch via external portal | ||
record("firstNode", { answers: ["option1"] }); | ||
expect(upcomingCardIds()[0]).toEqual("withinExternalPortal"); | ||
record("withinExternalPortal", { answers: [] }); | ||
expect(upcomingCardIds()[0]).toEqual("finalNode"); | ||
}); | ||
}); | ||
|
||
describe("A flow with repeated external portals can be navigated as expected", () => { | ||
beforeEach(() => setState({ flow: multipleExternalPortals })); | ||
afterEach(() => setState(initialState)); | ||
|
||
it("without entering the portal", () => { | ||
expect(upcomingCardIds()[0]).toEqual("firstNode"); | ||
// Navigate down branch avoiding external portal | ||
record("firstNode", { answers: ["option3"] }); | ||
expect(upcomingCardIds()[0]).toEqual("finalNode"); | ||
}); | ||
|
||
it("via the first portal", () => { | ||
expect(upcomingCardIds()[0]).toEqual("firstNode"); | ||
// Navigate down branch via first external portal | ||
record("firstNode", { answers: ["option1"] }); | ||
expect(upcomingCardIds()[0]).toEqual("withinExternalPortal"); | ||
record("withinExternalPortal", { answers: [] }); | ||
expect(upcomingCardIds()[0]).toEqual("finalNode"); | ||
}); | ||
|
||
it("via the second portal", () => { | ||
expect(upcomingCardIds()[0]).toEqual("firstNode"); | ||
// Navigate down branch via second external portal | ||
record("firstNode", { answers: ["option2"] }); | ||
expect(upcomingCardIds()[0]).toEqual("withinExternalPortal"); | ||
record("withinExternalPortal", { answers: [] }); | ||
expect(upcomingCardIds()[0]).toEqual("finalNode"); | ||
}); | ||
}); |
81 changes: 81 additions & 0 deletions
81
editor.planx.uk/src/pages/FlowEditor/lib/__tests__/mocks/multipleExternalPortals.json
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,81 @@ | ||
{ | ||
"_root": { | ||
"edges": [ | ||
"firstNode", | ||
"finalNode" | ||
] | ||
}, | ||
"externalPortal1": { | ||
"type": 300, | ||
"edges": [ | ||
"externalFlowId" | ||
] | ||
}, | ||
"option3": { | ||
"data": { | ||
"text": "Option 3" | ||
}, | ||
"type": 200 | ||
}, | ||
"externalPortal2": { | ||
"type": 300, | ||
"edges": [ | ||
"externalFlowId" | ||
] | ||
}, | ||
"firstNode": { | ||
"data": { | ||
"text": "This is a question" | ||
}, | ||
"type": 100, | ||
"edges": [ | ||
"option1", | ||
"option2", | ||
"option3" | ||
] | ||
}, | ||
"option2": { | ||
"data": { | ||
"text": "Option 2" | ||
}, | ||
"type": 200, | ||
"edges": [ | ||
"externalPortal2" | ||
] | ||
}, | ||
"finalNode": { | ||
"data": { | ||
"color": "#EFEFEF", | ||
"title": "This is the end", | ||
"resetButton": false | ||
}, | ||
"type": 8 | ||
}, | ||
"withinExternalPortal": { | ||
"data": { | ||
"color": "#EFEFEF", | ||
"title": "This is inside the portal", | ||
"description": "<p>Hello there 👋</p>", | ||
"resetButton": false | ||
}, | ||
"type": 8 | ||
}, | ||
"option1": { | ||
"data": { | ||
"text": "Option 1" | ||
}, | ||
"type": 200, | ||
"edges": [ | ||
"externalPortal1" | ||
] | ||
}, | ||
"externalFlowId": { | ||
"data": { | ||
"text": "daf-external-portal-test" | ||
}, | ||
"type": 300, | ||
"edges": [ | ||
"withinExternalPortal" | ||
] | ||
} | ||
} |
Oops, something went wrong.