Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const ChecklistWidget = () => {

return (
<CollapsibleWithMargin collapsed={!hasItems || !loaded}>
<HoverCard outlineAnimation="rainbow">
<HoverCard id="storybook-checklist-widget" outlineAnimation="rainbow">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the ID is purely for testing purposes, we should prefer to use something like data-test-id instead. For the future

<Collapsible
collapsed={!hasItems}
disabled={!hasItems}
Expand Down
27 changes: 24 additions & 3 deletions code/core/src/manager/components/sidebar/Sidebar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite';

import type { IndexHash } from 'storybook/manager-api';
import { ManagerContext } from 'storybook/manager-api';
import { expect, fn, userEvent, within } from 'storybook/test';
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';

import { initialState } from '../../../shared/checklist-store/checklistData.state';
import {
Expand Down Expand Up @@ -182,7 +182,16 @@ const refsEmpty = {
},
};

export const Simple: Story = {};
const waitForChecklistWidget = () =>
waitFor(
() =>
expect(document.getElementById('storybook-checklist-widget')?.checkVisibility()).toBe(true),
{ timeout: 5000 }
);

export const Simple: Story = {
play: waitForChecklistWidget,
};

export const SimpleInProduction: Story = {
args: {
Expand All @@ -200,6 +209,7 @@ export const SimpleInProduction: Story = {
export const Mobile: Story = {
decorators: [mobileLayoutDecorator],
globals: { sb_theme: 'light', viewport: { value: 'mobile1' } },
play: waitForChecklistWidget,
};

export const Loading: Story = {
Expand All @@ -219,12 +229,14 @@ export const Empty: Story = {
args: {
index: {},
},
play: waitForChecklistWidget,
};

export const EmptyMobile: Story = {
args: Empty.args,
decorators: [mobileLayoutDecorator],
globals: { sb_theme: 'light', viewport: { value: 'mobile1' } },
play: waitForChecklistWidget,
};

export const EmptyIndex: Story = {
Expand All @@ -235,18 +247,21 @@ export const EmptyIndex: Story = {
v: 6,
},
},
play: waitForChecklistWidget,
};

export const IndexError: Story = {
args: {
indexError,
},
play: waitForChecklistWidget,
};

export const WithRefs: Story = {
args: {
refs,
},
play: waitForChecklistWidget,
};

export const WithRefsNarrow: Story = {
Expand Down Expand Up @@ -283,12 +298,14 @@ export const WithRefsNarrow: Story = {
value: 'narrow',
},
},
play: waitForChecklistWidget,
};

export const WithRefsMobile: Story = {
args: WithRefs.args,
decorators: [mobileLayoutDecorator],
globals: { sb_theme: 'light', viewport: { value: 'mobile1' } },
play: waitForChecklistWidget,
};

export const LoadingWithRefs: Story = {
Expand Down Expand Up @@ -316,6 +333,7 @@ export const WithRefEmpty: Story = {
...Empty.args,
refs: refsEmpty,
},
play: waitForChecklistWidget,
};

export const StatusesCollapsed: Story = {
Expand Down Expand Up @@ -349,6 +367,7 @@ export const StatusesCollapsed: Story = {
return acc;
}, {} as StatusesByStoryIdAndTypeId),
},
play: waitForChecklistWidget,
};

export const StatusesOpen: Story = {
Expand Down Expand Up @@ -380,6 +399,7 @@ export const StatusesOpen: Story = {
} satisfies StatusesByStoryIdAndTypeId;
}, {} as StatusesByStoryIdAndTypeId),
},
play: waitForChecklistWidget,
};

export const Searching: Story = {
Expand All @@ -394,7 +414,7 @@ export const Searching: Story = {
),
],
play: async ({ canvasElement, step }) => {
await step('wait 2000ms', () => wait(2000));
await waitForChecklistWidget();
const canvas = await within(canvasElement);
const search = await canvas.findByPlaceholderText('Find components');
userEvent.clear(search);
Expand Down Expand Up @@ -473,6 +493,7 @@ export const Scrolled: Story = {
);
},
play: async ({ canvasElement, step }) => {
await waitForChecklistWidget();
const canvas = await within(canvasElement);
const scrollable = await canvasElement.querySelector('[data-radix-scroll-area-viewport]');
await step('expand component', async () => {
Expand Down
Loading