-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add toggle to optionally format Calculate output for automations #2468
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
812b88e
add toggle to optionally format calculate output for automations
jessicamcinchak 92b371a
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
jessicamcinchak e1f4476
add tests, simpler file structure
jessicamcinchak 31d02ae
fix import
jessicamcinchak 391b93e
logic tests should be ts extension not tsx
jessicamcinchak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions
23
editor.planx.uk/src/@planx/components/Calculate/Public.test.tsx
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,23 @@ | ||
import React from "react"; | ||
import { setup } from "testUtils"; | ||
|
||
import Public from "./Public"; | ||
|
||
describe("Calculate component", () => { | ||
it("renders correctly", () => { | ||
const handleSubmit = jest.fn(); | ||
setup( | ||
<Public | ||
output="testGroup" | ||
formula="pickRandom([1,2])" | ||
formatOutputForAutomations={true} | ||
defaults={{}} | ||
samples={{}} | ||
handleSubmit={handleSubmit} | ||
/>, | ||
); | ||
|
||
// Calculate should be auto-answered and never shown to user | ||
expect(handleSubmit).toHaveBeenCalled(); | ||
}); | ||
}); |
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
185 changes: 185 additions & 0 deletions
185
editor.planx.uk/src/@planx/components/Calculate/logic.test.tsx
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,185 @@ | ||
import { TYPES } from "@planx/components/types"; | ||
import { Store, vanillaStore } from "pages/FlowEditor/lib/store"; | ||
|
||
const { getState, setState } = vanillaStore; | ||
const { upcomingCardIds, resetPreview, record, currentCard } = getState(); | ||
|
||
// Helper method | ||
const visitedNodes = () => Object.keys(getState().breadcrumbs); | ||
|
||
beforeEach(() => { | ||
resetPreview(); | ||
}); | ||
|
||
test("When formatOutputForAutomations is true, Calculate writes an array and future questions are auto-answered", () => { | ||
// Setup | ||
setState({ flow: flowWithAutomation }); | ||
expect(upcomingCardIds()).toEqual([ | ||
"Calculate", | ||
"Question", | ||
]); | ||
|
||
// Step forwards through the Calculate | ||
record("Calculate", { data: { testGroup: ["2"] }, auto: true }); | ||
upcomingCardIds(); | ||
|
||
// The Question has been auto-answered | ||
expect(visitedNodes()).toEqual([ | ||
"Calculate", | ||
"Question", | ||
]); | ||
|
||
expect(upcomingCardIds()).toEqual([ | ||
"Group2Notice", | ||
]); | ||
}); | ||
|
||
test("When formatOutputForAutomations is false, Calculate writes a number and future questions are not auto-answered", () => { | ||
// Setup | ||
setState({ flow: flowWithoutAutomation }); | ||
expect(upcomingCardIds()).toEqual([ | ||
"Calculate", | ||
"Question", | ||
]); | ||
|
||
// Step forwards through the Calculate | ||
record("Calculate", { data: { testGroup: 2 }, auto: true }); | ||
upcomingCardIds(); | ||
|
||
// The Question has NOT been auto-answered | ||
expect(visitedNodes()).toEqual([ | ||
"Calculate", | ||
]); | ||
|
||
expect(upcomingCardIds()).toEqual([ | ||
"Question" | ||
]); | ||
}); | ||
|
||
const flowWithAutomation: Store.flow = { | ||
"_root": { | ||
"edges": [ | ||
"Calculate", | ||
"Question" | ||
] | ||
}, | ||
"Group2Notice": { | ||
"data": { | ||
"color": "#EFEFEF", | ||
"title": "You are Group 2", | ||
"resetButton": false | ||
}, | ||
"type": TYPES.Notice | ||
}, | ||
"Calculate": { | ||
"data": { | ||
"output": "testGroup", | ||
"formula": "pickRandom([1,2])", | ||
"formatOutputForAutomations": true | ||
}, | ||
"type": TYPES.Calculate | ||
}, | ||
"Group1Notice": { | ||
"data": { | ||
"color": "#EFEFEF", | ||
"title": "You are Group 1", | ||
"resetButton": false | ||
}, | ||
"type": TYPES.Notice | ||
}, | ||
"Group1Response": { | ||
"data": { | ||
"val": "1", | ||
"text": "1" | ||
}, | ||
"type": TYPES.Response, | ||
"edges": [ | ||
"Group1Notice" | ||
] | ||
}, | ||
"Question": { | ||
"data": { | ||
"fn": "testGroup", | ||
"text": "Which test group? " | ||
}, | ||
"type": TYPES.Statement, | ||
"edges": [ | ||
"Group1Response", | ||
"Group2Response" | ||
] | ||
}, | ||
"Group2Response": { | ||
"data": { | ||
"val": "2", | ||
"text": "2" | ||
}, | ||
"type": TYPES.Response, | ||
"edges": [ | ||
"Group2Notice" | ||
] | ||
} | ||
}; | ||
|
||
const flowWithoutAutomation: Store.flow = { | ||
"_root": { | ||
"edges": [ | ||
"Calculate", | ||
"Question" | ||
] | ||
}, | ||
"Group2Notice": { | ||
"data": { | ||
"color": "#EFEFEF", | ||
"title": "You are Group 2", | ||
"resetButton": false | ||
}, | ||
"type": TYPES.Notice | ||
}, | ||
"Calculate": { | ||
"data": { | ||
"output": "testGroup", | ||
"formula": "pickRandom([1,2])", | ||
"formatOutputForAutomations": false | ||
}, | ||
"type": TYPES.Calculate | ||
}, | ||
"Group1Notice": { | ||
"data": { | ||
"color": "#EFEFEF", | ||
"title": "You are Group 1", | ||
"resetButton": false | ||
}, | ||
"type": TYPES.Notice | ||
}, | ||
"Group1Response": { | ||
"data": { | ||
"val": "1", | ||
"text": "1" | ||
}, | ||
"type": TYPES.Response, | ||
"edges": [ | ||
"Group1Notice" | ||
] | ||
}, | ||
"Question": { | ||
"data": { | ||
"fn": "testGroup", | ||
"text": "Which test group? " | ||
}, | ||
"type": TYPES.Statement, | ||
"edges": [ | ||
"Group1Response", | ||
"Group2Response" | ||
] | ||
}, | ||
"Group2Response": { | ||
"data": { | ||
"val": "2", | ||
"text": "2" | ||
}, | ||
"type": TYPES.Response, | ||
"edges": [ | ||
"Group2Notice" | ||
] | ||
} | ||
}; | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a
logic.test.ts
isn't really an existing pattern in@planx/components/
, but I think this feels like a more meaningful organisation than adding more noise to the preview store tests?