-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathmodal.stories.ts
More file actions
52 lines (46 loc) · 1.46 KB
/
modal.stories.ts
File metadata and controls
52 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type {Meta, StoryObj} from '@storybook/web-components-vite';
import {expect} from 'storybook/test';
import {html} from 'lit';
import './modal.js';
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
const meta = {
title: 'Components/Modal',
component: 'craft-modal',
args: {},
parameters: {
layout: 'centered',
},
render: function (args) {
return html`
<craft-modal>
<craft-button slot="invoker">Open Modal</craft-button>
<div slot="content">
This is the body content
<craft-button
@click="${(event: Event) =>
event.target?.dispatchEvent(
new Event('close-overlay', {bubbles: true})
)}"
>Close</craft-button
>
</div>
</craft-modal>
`;
},
} satisfies Meta<any>;
export default meta;
type Story = StoryObj<any>;
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Default: Story = {
args: {},
play: async ({canvas, userEvent}) => {
const openBtn = canvas.getByShadowText(/Open Modal/i);
const closeBtn = canvas.getByText(/Close/i);
await userEvent.click(openBtn);
const modal = canvas.getByShadowRole('dialog');
await expect(modal).toHaveClass('overlays__overlay');
await userEvent.click(closeBtn);
await expect(modal).not.toHaveClass('overlays__overlay');
await expect(openBtn).toHaveFocus();
},
};