Skip to content

Commit

Permalink
Added Interaction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniebigodes committed Dec 22, 2023
1 parent e8a81c9 commit 4aff15f
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/InboxScreen.stories.jsx
Expand Up @@ -4,6 +4,8 @@ import InboxScreen from "./InboxScreen";

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

import { expect, userEvent, findByRole, within } from "@storybook/test";

export default {
component: InboxScreen,
title: "InboxScreen",
Expand Down Expand Up @@ -35,3 +37,57 @@ export const Error = {
},
},
};

export const PinTask = {
parameters: {
...Default.parameters,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const getTask = (id) => canvas.findByRole("listitem", { name: id });

const itemToPin = await getTask("task-4");
// Find the pin button
const pinButton = await findByRole(itemToPin, "button", { name: "pin" });
// Click the pin button
await userEvent.click(pinButton);
// Check that the pin button is now a unpin button
const unpinButton = within(itemToPin).getByRole("button", {
name: "unpin",
});
await expect(unpinButton).toBeInTheDocument();
},
};

export const ArchiveTask = {
parameters: {
...Default.parameters,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const getTask = (id) => canvas.findByRole("listitem", { name: id });

const itemToArchive = await getTask("task-2");
const archiveButton = await findByRole(itemToArchive, "button", {
name: "archiveButton-2",
});
await userEvent.click(archiveButton);
},
};

export const EditTask = {
parameters: {
...Default.parameters,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const getTask = (id) => canvas.findByRole("listitem", { name: id });

const itemToEdit = await getTask("task-5");
const taskInput = await findByRole(itemToEdit, "textbox");
await userEvent.type(taskInput, " and disabled state");
await expect(taskInput.value).toBe(
"Fix bug in input error state and disabled state"
);
},
};

0 comments on commit 4aff15f

Please sign in to comment.