mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 00:31:05 +08:00
36 lines
887 B
Plaintext
36 lines
887 B
Plaintext
```ts
|
|
// NoteUI.stories.ts
|
|
import { Meta, StoryObj } from '@storybook/react';
|
|
import { expect, userEvent, within } from '@storybook/test';
|
|
|
|
// 👇 Must use this import path to have mocks typed correctly
|
|
import { saveNote } from '#app/actions.mock';
|
|
import { createNotes } from '#mocks/notes';
|
|
|
|
const meta: Meta = {
|
|
title: 'Mocked/NoteUI',
|
|
component: 'note-ui',
|
|
};
|
|
export default meta;
|
|
|
|
type Story = StoryObj;
|
|
|
|
const notes = createNotes();
|
|
|
|
export const SaveFlow: Story = {
|
|
name: 'Save Flow ▶',
|
|
args: {
|
|
isEditing: true,
|
|
note: notes[0],
|
|
},
|
|
play: async ({ canvasElement, step }) => {
|
|
const canvas = within(canvasElement);
|
|
|
|
const saveButton = canvas.getByRole('menuitem', { name: /done/i });
|
|
await userEvent.click(saveButton);
|
|
// 👇 This is the mock function, so you can assert its behavior
|
|
await expect(saveNote).toHaveBeenCalled();
|
|
},
|
|
};
|
|
```
|