|
1 | 1 | import { task } from "@repo/mocks"; |
2 | 2 | import { withQueryClient } from "@repo/storybook-utils"; |
3 | | -import { expect, fn, userEvent } from "@storybook/test"; |
| 3 | +import { expect, fn, userEvent, waitFor } from "@storybook/test"; |
4 | 4 |
|
5 | 5 | import { withTasksStyles } from "../utils/storybook"; |
6 | 6 |
|
@@ -36,36 +36,45 @@ export const Default: Story = { |
36 | 36 | }, |
37 | 37 | }; |
38 | 38 |
|
39 | | -// export const CollapsibleToggle: Story = { |
40 | | -// args: { |
41 | | -// tasks: [ |
42 | | -// task({ id: "task-1" }), |
43 | | -// task({ id: "task-2" }), |
44 | | -// task({ id: "task-3" }), |
45 | | -// ], |
46 | | -// templates: [], |
47 | | -// persisted: { |
48 | | -// initialCreateExpanded: false, |
49 | | -// initialHistoryExpanded: false, |
50 | | -// save: fn(), |
51 | | -// }, |
52 | | -// }, |
53 | | -// play: async ({ canvasElement }) => { |
54 | | -// // Find all vscode-collapsible elements |
55 | | -// const collapsibles = canvasElement.querySelectorAll("vscode-collapsible"); |
| 39 | +export const CollapsibleToggle: Story = { |
| 40 | + args: { |
| 41 | + tasks: [ |
| 42 | + task({ id: "task-1" }), |
| 43 | + task({ id: "task-2" }), |
| 44 | + task({ id: "task-3" }), |
| 45 | + ], |
| 46 | + templates: [], |
| 47 | + persisted: { |
| 48 | + initialCreateExpanded: false, |
| 49 | + initialHistoryExpanded: false, |
| 50 | + save: fn(), |
| 51 | + }, |
| 52 | + }, |
| 53 | + play: async ({ canvasElement }) => { |
| 54 | + // Find all vscode-collapsible elements |
| 55 | + const collapsibles = |
| 56 | + canvasElement.querySelectorAll<HTMLElement>("vscode-collapsible"); |
| 57 | + |
| 58 | + // Should have two collapsible sections |
| 59 | + await expect(collapsibles.length).toBe(2); |
56 | 60 |
|
57 | | -// // Should have two collapsible sections |
58 | | -// await expect(collapsibles.length).toBe(2); |
| 61 | + // Both should be initially closed |
| 62 | + await expect(collapsibles[0].hasAttribute("open")).toBe(false); |
| 63 | + await expect(collapsibles[1].hasAttribute("open")).toBe(false); |
59 | 64 |
|
60 | | -// // Both should be initially closed |
61 | | -// await expect(collapsibles[0].hasAttribute("open")).toBe(false); |
62 | | -// await expect(collapsibles[1].hasAttribute("open")).toBe(false); |
| 65 | + // Simulate the collapsible toggle event that would be fired when clicking |
| 66 | + const toggleEvent = new CustomEvent("vsc-collapsible-toggle", { |
| 67 | + detail: { open: true }, |
| 68 | + bubbles: true, |
| 69 | + }); |
| 70 | + collapsibles[0].dispatchEvent(toggleEvent); |
63 | 71 |
|
64 | | -// // Click the first collapsible to toggle it |
65 | | -// await userEvent.click(collapsibles[0]); |
66 | | -// await expect(collapsibles[0].hasAttribute("open")).toBe(true); |
67 | | -// }, |
68 | | -// }; |
| 72 | + // Wait for the state to update and the open attribute to be set |
| 73 | + await waitFor(() => { |
| 74 | + expect(collapsibles[0].hasAttribute("open")).toBe(true); |
| 75 | + }); |
| 76 | + }, |
| 77 | +}; |
69 | 78 |
|
70 | 79 | export const TaskSelection: Story = { |
71 | 80 | args: { |
|
0 commit comments