Skip to content

Commit 2f179cb

Browse files
committed
add interaction tests
1 parent d43d03c commit 2f179cb

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

apps/smithy/src/stories/Tour/TourInteractionTests.stories.tsx

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ const StoryMeta: Meta<typeof Tour> = {
1616

1717
export default StoryMeta;
1818

19-
export const InteractionTests: TourStory = {
19+
export const AnchorFoundInteractionTests: TourStory = {
2020
args: {
2121
flowId: "flow_U63A5pndRrvCwxNs",
2222
},
2323

2424
decorators: [
2525
(Story, { args }) => {
2626
const { flow } = useFlow(args.flowId);
27+
args.flow = flow;
2728

2829
const lateAnchorRef = useRef(null);
2930

@@ -52,7 +53,7 @@ export const InteractionTests: TourStory = {
5253
<button
5354
id="reset-flow"
5455
onClick={() => {
55-
flow.restart();
56+
flow?.restart();
5657
}}
5758
style={{ marginTop: "36px" }}
5859
>
@@ -103,12 +104,22 @@ export const InteractionTests: TourStory = {
103104
},
104105
],
105106

106-
play: async ({ step }) => {
107+
play: async ({ step, args }) => {
108+
console.log("args", args);
109+
107110
await step("Test paginating through the Tour", async () => {
108111
const canvas = within(document.body);
112+
await waitFor(() => {
113+
expect(args.flow).toBeDefined();
114+
});
115+
109116
let TourElement = await canvas.findByRole("dialog");
110117
let Tour = within(TourElement);
111118

119+
await waitFor(() => {
120+
expect(args.flow?.isStarted).toBe(true);
121+
});
122+
112123
await userEvent.click(Tour.getByRole("button", { name: "Let's go!" }));
113124
await sleep(100);
114125

@@ -120,7 +131,6 @@ export const InteractionTests: TourStory = {
120131
);
121132

122133
await sleep(100);
123-
124134
TourElement = await canvas.findByRole("dialog");
125135
Tour = within(TourElement);
126136

@@ -140,3 +150,46 @@ export const InteractionTests: TourStory = {
140150
});
141151
},
142152
};
153+
154+
export const AnchorNotFoundInteractionTests: TourStory = {
155+
args: {
156+
flowId: "flow_U63A5pndRrvCwxNs",
157+
},
158+
159+
decorators: [
160+
(Story, { args }) => {
161+
const { flow } = useFlow(args.flowId);
162+
args.flow = flow;
163+
164+
return (
165+
<>
166+
<Story {...args} />
167+
<button
168+
id="reset-flow"
169+
onClick={() => {
170+
flow?.restart();
171+
}}
172+
style={{ marginTop: "36px" }}
173+
>
174+
Reset Flow
175+
</button>
176+
<Box id="anchor-not-found" />
177+
</>
178+
);
179+
},
180+
],
181+
182+
play: async ({ step, args }) => {
183+
console.log("args", args);
184+
185+
await step("Test Anchor Not Found", async () => {
186+
// Wait for flow to be defined
187+
await waitFor(() => {
188+
expect(args.flow).toBeDefined();
189+
});
190+
191+
// Verify the flow is started
192+
expect(args.flow?.isStarted).toBe(false);
193+
});
194+
},
195+
};

0 commit comments

Comments
 (0)