Skip to content

Commit 4aff15f

Browse files
committed
Added Interaction tests
1 parent e8a81c9 commit 4aff15f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/InboxScreen.stories.jsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import InboxScreen from "./InboxScreen";
44

55
import { Default as TaskListDefault } from "./components/TaskList.stories";
66

7+
import { expect, userEvent, findByRole, within } from "@storybook/test";
8+
79
export default {
810
component: InboxScreen,
911
title: "InboxScreen",
@@ -35,3 +37,57 @@ export const Error = {
3537
},
3638
},
3739
};
40+
41+
export const PinTask = {
42+
parameters: {
43+
...Default.parameters,
44+
},
45+
play: async ({ canvasElement }) => {
46+
const canvas = within(canvasElement);
47+
const getTask = (id) => canvas.findByRole("listitem", { name: id });
48+
49+
const itemToPin = await getTask("task-4");
50+
// Find the pin button
51+
const pinButton = await findByRole(itemToPin, "button", { name: "pin" });
52+
// Click the pin button
53+
await userEvent.click(pinButton);
54+
// Check that the pin button is now a unpin button
55+
const unpinButton = within(itemToPin).getByRole("button", {
56+
name: "unpin",
57+
});
58+
await expect(unpinButton).toBeInTheDocument();
59+
},
60+
};
61+
62+
export const ArchiveTask = {
63+
parameters: {
64+
...Default.parameters,
65+
},
66+
play: async ({ canvasElement }) => {
67+
const canvas = within(canvasElement);
68+
const getTask = (id) => canvas.findByRole("listitem", { name: id });
69+
70+
const itemToArchive = await getTask("task-2");
71+
const archiveButton = await findByRole(itemToArchive, "button", {
72+
name: "archiveButton-2",
73+
});
74+
await userEvent.click(archiveButton);
75+
},
76+
};
77+
78+
export const EditTask = {
79+
parameters: {
80+
...Default.parameters,
81+
},
82+
play: async ({ canvasElement }) => {
83+
const canvas = within(canvasElement);
84+
const getTask = (id) => canvas.findByRole("listitem", { name: id });
85+
86+
const itemToEdit = await getTask("task-5");
87+
const taskInput = await findByRole(itemToEdit, "textbox");
88+
await userEvent.type(taskInput, " and disabled state");
89+
await expect(taskInput.value).toBe(
90+
"Fix bug in input error state and disabled state"
91+
);
92+
},
93+
};

0 commit comments

Comments
 (0)