Skip to content

Commit 8f4a749

Browse files
test(packages/kit-headless/select): add story
Co-authored-by: Igal Klebanov <[email protected]>
1 parent 6d0389e commit 8f4a749

File tree

2 files changed

+113
-1
lines changed

2 files changed

+113
-1
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { Meta, StoryObj } from 'storybook-framework-qwik';
2+
import { within, userEvent, waitFor } from '@storybook/testing-library';
3+
import {
4+
Root,
5+
ListBox,
6+
Trigger,
7+
Option,
8+
TriggerProps,
9+
Value,
10+
Marker,
11+
Group,
12+
Label,
13+
} from './select';
14+
import { expect } from '@storybook/jest';
15+
16+
const meta: Meta<TriggerProps> = {
17+
component: Trigger,
18+
};
19+
20+
export default meta;
21+
22+
type Story = StoryObj<TriggerProps>;
23+
24+
interface TVSeries {
25+
title: string;
26+
disabled?: boolean;
27+
}
28+
29+
const comedies: TVSeries[] = [
30+
{ title: 'The Office' },
31+
{ title: 'Brooklyn 99' },
32+
{ title: 'Superstore' },
33+
{ title: 'The Good Place' },
34+
{ title: 'Parks and Recreation' },
35+
{ title: 'Community' },
36+
{ title: 'Arrested Development' },
37+
{ title: '30 Rock' },
38+
{ title: 'The Simpsons' },
39+
{ title: 'Futurama' },
40+
{ title: 'Family Guy' },
41+
{ title: 'South Park', disabled: true },
42+
];
43+
44+
const dramas: TVSeries[] = [
45+
{ title: 'The Wire' },
46+
{ title: 'Law & Order' },
47+
{ title: 'The Sopranos' },
48+
{ title: 'Breaking Bad' },
49+
];
50+
51+
export const Primary: Story = {
52+
render: () => (
53+
<Root>
54+
<Label style="margin-right: 12px">What's your favorite TV show?</Label>
55+
56+
<Trigger>
57+
<Value data-testid="select-value" placeholder="Pick an option" />
58+
59+
<Marker>
60+
<svg
61+
xmlns="http://www.w3.org/2000/svg"
62+
viewBox="0 0 24 24"
63+
fill="none"
64+
stroke="currentColor"
65+
stroke-width="2"
66+
stroke-linecap="round"
67+
stroke-linejoin="round"
68+
style="width: 20px; height: 20px;"
69+
>
70+
<polyline points="6 9 12 15 18 9"></polyline>
71+
</svg>
72+
</Marker>
73+
</Trigger>
74+
75+
<ListBox>
76+
<Group>
77+
<Label>Comedies</Label>
78+
{comedies.map((comedy, index) => (
79+
<Option
80+
key={`comedy-${index}`}
81+
value={comedy.title}
82+
disabled={comedy.disabled}
83+
/>
84+
))}
85+
</Group>
86+
87+
<Group>
88+
<Label>Dramas</Label>
89+
{dramas.map((drama, index) => (
90+
<Option
91+
key={`drama-${index}`}
92+
value={drama.title}
93+
disabled={drama.disabled}
94+
/>
95+
))}
96+
</Group>
97+
</ListBox>
98+
</Root>
99+
),
100+
play: async ({ canvasElement }) => {
101+
const canvas = within(canvasElement);
102+
103+
await userEvent.click(canvas.getByText('Pick an option'));
104+
await userEvent.click(canvas.getByText('The Office'));
105+
106+
await waitFor(() => {
107+
return expect(canvas.getByTestId('select-value')).toHaveTextContent(
108+
'The Office'
109+
);
110+
});
111+
},
112+
};

packages/kit-headless/src/components/select/select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const Root = component$(({ defaultValue, ...props }: RootProps) => {
111111
);
112112
});
113113

114-
interface TriggerProps extends StyleProps {
114+
export interface TriggerProps extends StyleProps {
115115
disabled?: boolean;
116116
}
117117

0 commit comments

Comments
 (0)