Skip to content

Commit 1bcc729

Browse files
committed
Merge branch 'jakehwll/implement-storybook' into jakehwll/implement-chromatic
2 parents 8a9836a + f05a685 commit 1bcc729

2 files changed

Lines changed: 54 additions & 28 deletions

File tree

.storybook/preview.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ if (
3535
document.head.appendChild(link);
3636
}
3737

38+
// This allows the system viewing the storybook to use the same font
39+
// stack as vscode, which is important for accurate rendering of text.
40+
const getDefaultFontStack = () => {
41+
if (navigator.userAgent.includes("Linux")) {
42+
return 'system-ui, "Ubuntu", "Droid Sans", sans-serif';
43+
} else if (navigator.userAgent.includes("Mac")) {
44+
return "-apple-system, BlinkMacSystemFont, sans-serif";
45+
} else if (navigator.userAgent.includes("Windows")) {
46+
return '"Segoe WPC", "Segoe UI", sans-serif';
47+
} else {
48+
return "sans-serif";
49+
}
50+
};
51+
3852
const preview: Preview = {
3953
parameters: {
4054
layout: "centered",
@@ -77,6 +91,9 @@ const preview: Preview = {
7791
"div",
7892
{
7993
id: "root",
94+
style: {
95+
fontFamily: getDefaultFontStack(),
96+
},
8097
},
8198
createElement(Story),
8299
);

packages/tasks/src/components/TasksPanel.stories.tsx

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { task } from "@repo/mocks";
22
import { withQueryClient } from "@repo/storybook-utils";
3-
import { expect, fn, userEvent } from "@storybook/test";
3+
import { expect, fn, userEvent, waitFor } from "@storybook/test";
44

55
import { withTasksStyles } from "../utils/storybook";
66

@@ -36,36 +36,45 @@ export const Default: Story = {
3636
},
3737
};
3838

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);
5660

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);
5964

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);
6371

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+
};
6978

7079
export const TaskSelection: Story = {
7180
args: {

0 commit comments

Comments
 (0)