-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not autocomplete flows with incomplete steps
- Loading branch information
1 parent
95f66cd
commit 96a7862
Showing
4 changed files
with
89 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@frigade/js": patch | ||
"@frigade/react": patch | ||
--- | ||
|
||
Fixes an issue where checklists complete when finishing the last step |
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 |
---|---|---|
|
@@ -64,7 +64,6 @@ export const Collapsible = { | |
test: TestStep, | ||
}, | ||
width: "500px", | ||
forceMount: true, | ||
dismissible: true, | ||
}, | ||
}; |
74 changes: 74 additions & 0 deletions
74
apps/smithy/src/stories/Checklist/ChecklistInteractionTests.stories.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,74 @@ | ||
import { Checklist, useFlow } from "@frigade/react"; | ||
import { type Meta, type StoryObj } from "@storybook/react"; | ||
import { expect, userEvent, within } from "@storybook/test"; | ||
|
||
type ChecklistStory = StoryObj<typeof Checklist>; | ||
|
||
function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
const StoryMeta: Meta<typeof Checklist.Collapsible> = { | ||
title: "Components/Checklist", | ||
component: Checklist.Collapsible, | ||
}; | ||
|
||
export default StoryMeta; | ||
|
||
export const InteractionTests: ChecklistStory = { | ||
args: { | ||
flowId: "flow_K2dmIlteW8eGbGoo", | ||
}, | ||
decorators: [ | ||
(Story, { args }) => { | ||
const { flow } = useFlow(args.flowId); | ||
|
||
return ( | ||
<> | ||
<Story {...args} /> | ||
<button | ||
id="reset-flow" | ||
onClick={() => { | ||
flow?.restart(); | ||
}} | ||
style={{ marginTop: "36px" }} | ||
> | ||
Reset Flow | ||
</button> | ||
</> | ||
); | ||
}, | ||
], | ||
|
||
play: async ({ step, canvasElement }) => { | ||
await sleep(1000); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
const canvas = within(canvasElement); | ||
const checklistElement = document.querySelector(".fr-checklist"); | ||
|
||
await step("Test interactions", async () => { | ||
// test that checklistElement is in the document | ||
expect(checklistElement).toBeInTheDocument(); | ||
|
||
const lastHeader = canvas.getByText("Donec id diam lectus"); | ||
let checkboxes = document.querySelectorAll(".fr-field-radio-value"); | ||
|
||
// expectd lastCheckbox to not have any children | ||
expect(checkboxes[checkboxes.length - 1]?.childNodes.length).toBe(0); | ||
// click last header | ||
await userEvent.click(lastHeader); | ||
// Click the primary button that says "Testing" | ||
await userEvent.click(canvas.getByText("Testing")); | ||
await sleep(100); | ||
|
||
checkboxes = document.querySelectorAll(".fr-field-radio-value"); | ||
// expect lastCheckbox to have a child (it is checked) | ||
expect( | ||
checkboxes[checkboxes.length - 1]?.childNodes.length | ||
).toBeGreaterThanOrEqual(1); | ||
await sleep(1000); | ||
expect(checklistElement).toBeInTheDocument(); | ||
|
||
await userEvent.click(canvas.getByText("Reset Flow")); | ||
}); | ||
}, | ||
}; |
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
Instead of sleeping, I think you can do:
to wait for the initial render.