|
1 | 1 | import React from 'react'; |
2 | 2 | import { rest } from 'msw'; |
| 3 | +import { within, userEvent, findByRole } from '@storybook/testing-library'; |
| 4 | +import { expect } from '@storybook/jest'; |
3 | 5 | import { InboxScreen } from './InboxScreen'; |
4 | 6 | import { Default as TaskListDefault } from './components/TaskList.stories'; |
5 | 7 |
|
@@ -34,3 +36,51 @@ Error.parameters = { |
34 | 36 | ], |
35 | 37 | }, |
36 | 38 | }; |
| 39 | + |
| 40 | +export const PinTask = Template.bind({}); |
| 41 | +PinTask.parameters = Default.parameters; |
| 42 | +PinTask.play = async ({ canvasElement }) => { |
| 43 | + const canvas = within(canvasElement); |
| 44 | + const getTask = (name) => canvas.findByRole('listitem', { name }); |
| 45 | + |
| 46 | + // Find the task to pin |
| 47 | + const itemToPin = await getTask('Export logo'); |
| 48 | + |
| 49 | + // Find the pin button |
| 50 | + const pinButton = await findByRole(itemToPin, 'button', { name: 'pin' }); |
| 51 | + |
| 52 | + // Click the pin button |
| 53 | + await userEvent.click(pinButton); |
| 54 | + |
| 55 | + // Check that the pin button is now a unpin button |
| 56 | + const unpinButton = within(itemToPin).getByRole('button', { name: 'unpin' }); |
| 57 | + await expect(unpinButton).toBeInTheDocument(); |
| 58 | +}; |
| 59 | + |
| 60 | +export const ArchiveTask = Template.bind({}); |
| 61 | +ArchiveTask.parameters = Default.parameters; |
| 62 | +ArchiveTask.play = async ({ canvasElement }) => { |
| 63 | + const canvas = within(canvasElement); |
| 64 | + const getTask = (name) => canvas.findByRole('listitem', { name }); |
| 65 | + |
| 66 | + const itemToArchive = await getTask('QA dropdown'); |
| 67 | + const archiveCheckbox = await findByRole(itemToArchive, 'checkbox'); |
| 68 | + await userEvent.click(archiveCheckbox); |
| 69 | + |
| 70 | + await expect(archiveCheckbox.checked).toBe(true); |
| 71 | +}; |
| 72 | + |
| 73 | +export const EditTask = Template.bind({}); |
| 74 | +EditTask.parameters = Default.parameters; |
| 75 | +EditTask.play = async ({ canvasElement }) => { |
| 76 | + const canvas = within(canvasElement); |
| 77 | + const getTask = (name) => canvas.findByRole('listitem', { name }); |
| 78 | + |
| 79 | + const itemToEdit = await getTask('Fix bug in input error state'); |
| 80 | + const taskInput = await findByRole(itemToEdit, 'textbox'); |
| 81 | + |
| 82 | + userEvent.type(taskInput, ' and disabled state'); |
| 83 | + await expect(taskInput.value).toBe( |
| 84 | + 'Fix bug in input error state and disabled state' |
| 85 | + ); |
| 86 | +}; |
0 commit comments