|
1 | 1 | import type { Meta, StoryObj } from '@storybook/react-vite'; |
2 | | -import { DsPanel } from './ds-panel'; |
| 2 | +import { DsPanel } from './'; |
3 | 3 | import { DsButton } from '../ds-button/'; |
4 | 4 | import { DsStepper, DsStep, DsStepContent, DsNextStepButton } from '../ds-stepper'; |
5 | 5 | import { useState } from 'react'; |
6 | | -import { expect, userEvent } from 'storybook/test'; |
7 | 6 | import type { DsPanelVariant } from './ds-panel.types'; |
8 | 7 |
|
9 | 8 | export default { |
@@ -36,31 +35,24 @@ export const Default: Story = { |
36 | 35 | </> |
37 | 36 | ); |
38 | 37 | }, |
| 38 | +}; |
39 | 39 |
|
40 | | - play: async ({ canvas, step, args, initialArgs }) => { |
41 | | - const panelTrigger = canvas.getByLabelText('Toggle panel'); |
42 | | - |
43 | | - const testVariant = async (variant: DsPanelVariant) => { |
44 | | - args.variant = variant; |
45 | | - |
46 | | - await step(`Close Panel - ${variant}`, async () => { |
47 | | - await userEvent.click(panelTrigger); |
48 | | - |
49 | | - await expect(canvas.queryByText(/This is a panel/)).not.toBeVisible(); |
50 | | - }); |
| 40 | +export const Responsive: Story = { |
| 41 | + render: function Render() { |
| 42 | + const [open, setOpen] = useState(true); |
51 | 43 |
|
52 | | - await step(`Open Panel - ${variant}`, async () => { |
53 | | - await userEvent.click(canvas.getByText('Open Panel')); |
| 44 | + return ( |
| 45 | + <> |
| 46 | + {!open && <DsButton onClick={() => setOpen(true)}>Open Panel</DsButton>} |
54 | 47 |
|
55 | | - await expect(canvas.getByText(/This is a panel/)).toBeVisible(); |
56 | | - }); |
| 48 | + <DsPanel open={open} onOpenChange={setOpen} width={{ lg: 480, md: 240 }}> |
| 49 | + <p>This panel uses a responsive width.</p> |
| 50 | + <p>Large screens: 480px. Medium screens: 240px.</p> |
57 | 51 |
|
58 | | - // Reset state. |
59 | | - args.variant = initialArgs.variant; |
60 | | - }; |
61 | | - |
62 | | - await testVariant('docked'); |
63 | | - await testVariant('floating'); |
| 52 | + <DsButton size="small">Primary Action</DsButton> |
| 53 | + </DsPanel> |
| 54 | + </> |
| 55 | + ); |
64 | 56 | }, |
65 | 57 | }; |
66 | 58 |
|
@@ -119,85 +111,4 @@ export const Draggable: Story = { |
119 | 111 | </div> |
120 | 112 | ); |
121 | 113 | }, |
122 | | - |
123 | | - play: async ({ canvas, step }) => { |
124 | | - const togglePanel = async () => { |
125 | | - await userEvent.click(canvas.getByLabelText('Toggle panel')); |
126 | | - }; |
127 | | - |
128 | | - const getPanel = () => canvas.getByText('Configure network').closest('[data-state]') as HTMLElement; |
129 | | - |
130 | | - const dockedRect = getPanel().getBoundingClientRect(); |
131 | | - |
132 | | - await step('Docked - all steps and descriptions visible', async () => { |
133 | | - await expect(canvas.getByText('Configure network')).toBeVisible(); |
134 | | - await expect(canvas.getByText('Assign resources')).toBeVisible(); |
135 | | - await expect(canvas.getByText('Review & deploy')).toBeVisible(); |
136 | | - await expect(canvas.getByText(/Set up interfaces/)).toBeVisible(); |
137 | | - }); |
138 | | - |
139 | | - await step('Collapse to floating - single step with drag handle', async () => { |
140 | | - await togglePanel(); |
141 | | - |
142 | | - await expect(canvas.getByText('Configure network')).toBeVisible(); |
143 | | - await expect(canvas.getByText('drag_indicator')).toBeVisible(); |
144 | | - await expect(canvas.queryByText(/Set up interfaces/)).not.toBeInTheDocument(); |
145 | | - }); |
146 | | - |
147 | | - await step('Drag floating panel', async () => { |
148 | | - const handle = canvas.getByText('drag_indicator'); |
149 | | - const panel = getPanel(); |
150 | | - const rectBefore = panel.getBoundingClientRect(); |
151 | | - |
152 | | - await userEvent.pointer([ |
153 | | - { target: handle, keys: '[MouseLeft>]', coords: { clientX: 100, clientY: 100 } }, |
154 | | - { coords: { clientX: 200, clientY: 150 } }, |
155 | | - { keys: '[/MouseLeft]' }, |
156 | | - ]); |
157 | | - |
158 | | - const rectAfter = panel.getBoundingClientRect(); |
159 | | - |
160 | | - await expect(Math.round(rectAfter.left - rectBefore.left)).toBe(100); |
161 | | - await expect(Math.round(rectAfter.top - rectBefore.top)).toBe(50); |
162 | | - }); |
163 | | - |
164 | | - await step('Non-handle area does not trigger drag', async () => { |
165 | | - const label = canvas.getByText('Configure network'); |
166 | | - const panel = getPanel(); |
167 | | - const rectBefore = panel.getBoundingClientRect(); |
168 | | - |
169 | | - await userEvent.pointer([ |
170 | | - { target: label, keys: '[MouseLeft>]', coords: { clientX: 0, clientY: 0 } }, |
171 | | - { coords: { clientX: 200, clientY: 200 } }, |
172 | | - { keys: '[/MouseLeft]' }, |
173 | | - ]); |
174 | | - |
175 | | - const rectAfter = panel.getBoundingClientRect(); |
176 | | - |
177 | | - await expect(rectAfter.left).toBe(rectBefore.left); |
178 | | - await expect(rectAfter.top).toBe(rectBefore.top); |
179 | | - }); |
180 | | - |
181 | | - await step('Navigate steps while floating', async () => { |
182 | | - await userEvent.click(canvas.getByRole('button', { name: /next/i })); |
183 | | - |
184 | | - await expect(canvas.getByText('Assign resources')).toBeVisible(); |
185 | | - }); |
186 | | - |
187 | | - await step('Expand back to docked - full content restored', async () => { |
188 | | - await togglePanel(); |
189 | | - |
190 | | - await expect(canvas.getByText('Configure network')).toBeVisible(); |
191 | | - await expect(canvas.getByText('Assign resources')).toBeVisible(); |
192 | | - await expect(canvas.getByText('Review & deploy')).toBeVisible(); |
193 | | - await expect(canvas.queryByText('drag_indicator')).not.toBeInTheDocument(); |
194 | | - }); |
195 | | - |
196 | | - await step('Drag position resets after expanding', async () => { |
197 | | - const resetRect = getPanel().getBoundingClientRect(); |
198 | | - |
199 | | - await expect(resetRect.left).toBe(dockedRect.left); |
200 | | - await expect(resetRect.top).toBe(dockedRect.top); |
201 | | - }); |
202 | | - }, |
203 | 114 | }; |
0 commit comments