@bitrise/bitkit 10.36.2 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/package.json +17 -38
  2. package/src/Components/Menu/MenuItem.tsx +1 -1
  3. package/tsconfig.json +0 -5
  4. package/src/Components/Accordion/Accordion.stories.tsx +0 -63
  5. package/src/Components/Accordion/Accordion.test.tsx +0 -34
  6. package/src/Components/AspectRatio/AspectRatio.stories.tsx +0 -24
  7. package/src/Components/Avatar/Avatar.stories.tsx +0 -15
  8. package/src/Components/Badge/Badge.stories.tsx +0 -13
  9. package/src/Components/Box/Box.stories.tsx +0 -20
  10. package/src/Components/Breadcrumb/Breadcrumb.stories.tsx +0 -49
  11. package/src/Components/Button/Button.stories.tsx +0 -25
  12. package/src/Components/ButtonGroup/ButtonGroup.stories.tsx +0 -21
  13. package/src/Components/Card/Card.stories.tsx +0 -44
  14. package/src/Components/ColorButton/ColorButton.stories.tsx +0 -30
  15. package/src/Components/DatePicker/DatePicker.stories.tsx +0 -16
  16. package/src/Components/DatePicker/DatePicker.test.tsx +0 -94
  17. package/src/Components/Dialog/Dialog.stories.tsx +0 -82
  18. package/src/Components/Divider/Divider.stories.tsx +0 -18
  19. package/src/Components/Dot/Dot.stories.tsx +0 -15
  20. package/src/Components/Dropdown/Dropdown.stories.tsx +0 -154
  21. package/src/Components/Dropdown/Dropdown.test.tsx +0 -626
  22. package/src/Components/EmptyState/EmptyState.stories.tsx +0 -18
  23. package/src/Components/Fade/Fade.stories.tsx +0 -5
  24. package/src/Components/Form/Checkbox/Checkbox.stories.tsx +0 -43
  25. package/src/Components/Form/Input/Input.stories.tsx +0 -71
  26. package/src/Components/Form/Radio/Radio.stories.tsx +0 -35
  27. package/src/Components/Form/Textarea/Textarea.stories.tsx +0 -20
  28. package/src/Components/Form/Textarea/Textarea.test.tsx +0 -35
  29. package/src/Components/Icon/Icon.stories.tsx +0 -10
  30. package/src/Components/IconButton/IconButton.stories.tsx +0 -27
  31. package/src/Components/Icons/index.stories.tsx +0 -60
  32. package/src/Components/Image/Image.stories.tsx +0 -15
  33. package/src/Components/LightBox/LightBox.stories.tsx +0 -39
  34. package/src/Components/Link/Link.stories.tsx +0 -28
  35. package/src/Components/List/List.stories.tsx +0 -24
  36. package/src/Components/Menu/Menu.stories.tsx +0 -90
  37. package/src/Components/Notification/Notification.stories.tsx +0 -84
  38. package/src/Components/OverflowMenu/OverflowMenu.stories.tsx +0 -30
  39. package/src/Components/Popover/Popover.stories.tsx +0 -19
  40. package/src/Components/ProgressBar/ProgressBar.stories.tsx +0 -11
  41. package/src/Components/ProgressBitbot/ProgressBitbot.stories.tsx +0 -12
  42. package/src/Components/ProgressSpinner/ProgressSpinner.stories.tsx +0 -12
  43. package/src/Components/Ribbon/Ribbon.stories.tsx +0 -35
  44. package/src/Components/Select/Select.stories.tsx +0 -100
  45. package/src/Components/Select/Select.test.tsx +0 -96
  46. package/src/Components/Skeleton/Skeleton.stories.tsx +0 -18
  47. package/src/Components/Table/Table.stories.tsx +0 -216
  48. package/src/Components/Tabs/Tabs.stories.tsx +0 -65
  49. package/src/Components/Tabs/Tabs.test.tsx +0 -36
  50. package/src/Components/Text/Text.stories.tsx +0 -22
  51. package/src/Components/Toast/Toast.stories.tsx +0 -30
  52. package/src/Components/Toggle/Toggle.stories.tsx +0 -19
  53. package/src/Foundations/Colors/Colors.stories.mdx +0 -9
  54. package/src/Foundations/Radii/Radii.examples.tsx +0 -25
  55. package/src/Foundations/Radii/Radii.stories.mdx +0 -6
  56. package/src/Foundations/Responsive/Responsive.examples.tsx +0 -95
  57. package/src/Foundations/Responsive/Responsive.stories.mdx +0 -6
  58. package/src/Foundations/Shadows/Shadows.examples.tsx +0 -24
  59. package/src/Foundations/Shadows/Shadows.stories.mdx +0 -6
  60. package/src/Foundations/Sizes/Sizes.examples.tsx +0 -25
  61. package/src/Foundations/Sizes/Sizes.stories.mdx +0 -6
  62. package/src/Foundations/Typography/Typography.examples.tsx +0 -63
  63. package/src/Foundations/Typography/Typography.stories.mdx +0 -8
  64. package/src/tsconfig.tsbuildinfo +0 -1
@@ -1,626 +0,0 @@
1
- import { ComponentProps, forwardRef, MutableRefObject, StrictMode, useState } from 'react';
2
- import { setTimeout } from 'timers/promises';
3
- import { render as renderRTL, screen, waitFor } from '@testing-library/react';
4
- import userEvent from '@testing-library/user-event';
5
- import { useForm } from 'react-hook-form';
6
- import Avatar from '../Avatar/Avatar';
7
- import Dropdown, { DropdownGroup, DropdownOption } from './Dropdown';
8
- import { CustomSearch, InsideDialog } from './Dropdown.stories';
9
- import { DropdownDetailedOption } from './DropdownOption';
10
-
11
- const render = (ui: React.ReactElement) => {
12
- return renderRTL(<StrictMode>{ui}</StrictMode>);
13
- };
14
-
15
- const TestComponent = forwardRef<
16
- HTMLFormElement,
17
- { submit: (data: unknown) => void } & ComponentProps<typeof Dropdown>
18
- >(({ submit, ...props }, ref) => {
19
- const { register, handleSubmit } = useForm({ defaultValues: { dropdown: 'unset' } });
20
-
21
- return (
22
- <form onSubmit={handleSubmit(submit)} ref={ref}>
23
- <Dropdown {...props} aria-label="Test" {...register('dropdown')}>
24
- <DropdownOption value="x">Test Opt1</DropdownOption>
25
- <DropdownOption value="y">Test Opt2</DropdownOption>
26
- <DropdownOption value="z">Test Opt3</DropdownOption>
27
- </Dropdown>
28
- <button type="submit">Send</button>
29
- </form>
30
- );
31
- });
32
-
33
- describe('Dropdown', () => {
34
- it('sets ref to the button', async () => {
35
- const handler = jest.fn();
36
- render(<Dropdown ref={handler} />);
37
- const button = await screen.findByRole('combobox');
38
- expect(handler).toHaveBeenCalledWith(button);
39
- });
40
-
41
- it('shows option on button', async () => {
42
- render(<TestComponent submit={() => {}} />);
43
- const button = await screen.findByRole('combobox', { name: 'Test' });
44
- await userEvent.click(button);
45
- const opt = await screen.findByRole('listbox');
46
- await userEvent.selectOptions(opt, 'Test Opt1');
47
- expect(button).toHaveTextContent('Test Opt1');
48
- });
49
-
50
- describe('supports null value', () => {
51
- it('can be selected', async () => {
52
- const handler = jest.fn();
53
- const Test = () => {
54
- return (
55
- <Dropdown onChange={(ev) => handler(ev.target.value)}>
56
- <DropdownOption value={null}>null</DropdownOption>
57
- </Dropdown>
58
- );
59
- };
60
- render(<Test />);
61
- const button = await screen.findByRole('combobox');
62
- await userEvent.click(button);
63
- const opt = await screen.findByRole('listbox');
64
- await userEvent.selectOptions(opt, 'null');
65
- expect(handler).toHaveBeenCalledWith(null);
66
- expect(handler).toHaveBeenCalledTimes(1);
67
- });
68
- it('works as defaultValue', async () => {
69
- const handler = jest.fn();
70
- const Test = () => {
71
- return (
72
- <Dropdown defaultValue={null} onChange={(ev) => handler(ev.target.value)}>
73
- <DropdownOption value={null}>null</DropdownOption>
74
- </Dropdown>
75
- );
76
- };
77
- render(<Test />);
78
- const button = await screen.findByRole('combobox');
79
- expect(button).toHaveTextContent('null');
80
- });
81
- });
82
-
83
- it('search field can be disabled', async () => {
84
- render(
85
- <Dropdown search={false}>
86
- <DropdownOption value="x">Test Opt1</DropdownOption>
87
- <DropdownOption value="y">Test Opt2</DropdownOption>
88
- <DropdownOption value="z">Test Opt3</DropdownOption>
89
- </Dropdown>,
90
- );
91
-
92
- const button = await screen.findByRole('combobox');
93
- await userEvent.click(button);
94
- await screen.findByRole('listbox');
95
- expect(screen.queryByRole('search')).toBeNull();
96
- });
97
-
98
- it('works in controlled mode (from the outside)', async () => {
99
- const Test = () => {
100
- const [value, setValue] = useState('x');
101
- return (
102
- <>
103
- <button type="button" onClick={() => setValue('y')}>
104
- Test
105
- </button>
106
- <Dropdown value={value}>
107
- <DropdownOption value="x">Test Opt1</DropdownOption>
108
- <DropdownOption value="y">Test Opt2</DropdownOption>
109
- <DropdownOption value="z">Test Opt3</DropdownOption>
110
- </Dropdown>
111
- </>
112
- );
113
- };
114
- render(<Test />);
115
- const button = await screen.findByRole('combobox');
116
- expect(button).toHaveTextContent('Test Opt1');
117
- const testBtn = await screen.findByRole('button');
118
- await userEvent.click(testBtn);
119
- expect(button).toHaveTextContent('Test Opt2');
120
- });
121
-
122
- it('works in controlled mode (from the inside)', async () => {
123
- const Test = ({ valueRef }: { valueRef: MutableRefObject<string | null> }) => {
124
- const [value, setValue] = useState<string | null>('x');
125
- valueRef.current = value;
126
- return (
127
- <Dropdown value={value} onChange={(ev) => setValue(ev.target.value)}>
128
- <DropdownOption value="x">Test Opt1</DropdownOption>
129
- <DropdownOption value="y">Test Opt2</DropdownOption>
130
- <DropdownOption value="z">Test Opt3</DropdownOption>
131
- </Dropdown>
132
- );
133
- };
134
- const valueRef: { current: string } = { current: '' };
135
- render(<Test valueRef={valueRef} />);
136
- const button = await screen.findByRole('combobox');
137
- expect(button).toHaveTextContent('Test Opt1');
138
- await userEvent.click(button);
139
- const opt = await screen.findByRole('listbox');
140
- await userEvent.selectOptions(opt, 'Test Opt2');
141
- expect(button).toHaveTextContent('Test Opt2');
142
- expect(valueRef.current).toBe('y');
143
- });
144
-
145
- it('works in uncontrolled mode', async () => {
146
- const handler = jest.fn();
147
- const Test = () => {
148
- return (
149
- <Dropdown defaultValue="y" onChange={(ev) => handler(ev.target.value)}>
150
- <DropdownOption value="x">Test Opt1</DropdownOption>
151
- <DropdownOption value="y">Test Opt2</DropdownOption>
152
- <DropdownOption value="z">Test Opt3</DropdownOption>
153
- </Dropdown>
154
- );
155
- };
156
- render(<Test />);
157
- const button = await screen.findByRole('combobox');
158
- expect(button).toHaveTextContent('Test Opt2');
159
- await userEvent.click(button);
160
- const opt = await screen.findByRole('listbox');
161
- await userEvent.selectOptions(opt, 'Test Opt1');
162
- expect(button).toHaveTextContent('Test Opt1');
163
- expect(handler).toHaveBeenCalledTimes(1);
164
- expect(handler).toHaveBeenCalledWith('x');
165
- });
166
-
167
- describe('react-hook-form support', () => {
168
- it('sends data when submitted', async () => {
169
- const handler = jest.fn();
170
- render(<TestComponent submit={(data: unknown) => handler(data)} />);
171
- const button = await screen.findByRole('combobox', { name: 'Test' });
172
- const submit = await screen.findByRole('button', { name: 'Send' });
173
- await userEvent.click(button);
174
- const opt = await screen.findByRole('listbox');
175
- await userEvent.selectOptions(opt, 'Test Opt1');
176
- await userEvent.click(submit);
177
-
178
- expect(handler).toHaveBeenCalledWith({ dropdown: 'x' });
179
- expect(handler).toHaveBeenCalledTimes(1);
180
- });
181
-
182
- it('works with click', async () => {
183
- const handler = jest.fn();
184
- render(<TestComponent submit={(data: unknown) => handler(data)} />);
185
- const button = await screen.findByRole('combobox', { name: 'Test' });
186
- const submit = await screen.findByRole('button', { name: 'Send' });
187
- await userEvent.click(button);
188
- const option = await screen.findByRole('option', { name: 'Test Opt1' });
189
- await userEvent.click(option);
190
- await userEvent.click(submit);
191
-
192
- expect(handler).toHaveBeenCalledWith({ dropdown: 'x' });
193
- expect(handler).toHaveBeenCalledTimes(1);
194
- });
195
-
196
- it('does not send data at all when not submitted', async () => {
197
- const handler = jest.fn();
198
- render(<TestComponent submit={(data: unknown) => handler(data)} />);
199
- const button = await screen.findByRole('combobox', { name: 'Test' });
200
- await userEvent.click(button);
201
- const opt = await screen.findByRole('listbox');
202
- await userEvent.selectOptions(opt, 'Test Opt1');
203
-
204
- expect(handler).not.toHaveBeenCalled();
205
- });
206
- });
207
-
208
- describe('readOnly', () => {
209
- it('does not open when clicked', async () => {
210
- render(<Dropdown readOnly />);
211
- const button = await screen.findByRole('combobox');
212
- await userEvent.click(button);
213
- await waitFor(() => setTimeout(50));
214
- const list = screen.queryByRole('listbox');
215
- expect(list).not.toBeInTheDocument();
216
- });
217
-
218
- it('does not open when activated with keyboard', async () => {
219
- render(<Dropdown readOnly />);
220
- await userEvent.keyboard('{Tab}');
221
- await userEvent.keyboard('{ArrowDown}');
222
- await waitFor(() => setTimeout(50));
223
- const list = screen.queryByRole('listbox');
224
- expect(list).not.toBeInTheDocument();
225
- });
226
- });
227
-
228
- describe('detailed option', () => {
229
- it('shows up as default value', async () => {
230
- const Test = () => {
231
- return (
232
- <Dropdown defaultValue="y">
233
- <DropdownDetailedOption value="y" icon={<Avatar name="hello" />} subtitle="ok" title="test" />
234
- </Dropdown>
235
- );
236
- };
237
- render(<Test />);
238
- const button = await screen.findByRole('combobox');
239
- expect(button).toHaveTextContent('hotestok');
240
- });
241
-
242
- it('is searchable', async () => {
243
- const Test = () => {
244
- return (
245
- <Dropdown>
246
- <DropdownDetailedOption value="y" icon={<Avatar name="hello" />} subtitle="ok" title="testx" />
247
- <DropdownDetailedOption value="x" icon={<Avatar name="hello" />} subtitle="ok" title="test" />
248
- </Dropdown>
249
- );
250
- };
251
- render(<Test />);
252
- const button = await screen.findByRole('combobox');
253
- await userEvent.click(button);
254
- const search = await screen.findByRole('search');
255
- await userEvent.type(search, 'testx');
256
- const option1 = screen.queryByRole('option', { name: 'testx' });
257
- const option2 = screen.queryByRole('option', { name: 'test' });
258
- expect(option1).toBeInTheDocument();
259
- expect(option2).not.toBeInTheDocument();
260
- });
261
-
262
- it('works with keyboard navigation', async () => {
263
- const handler = jest.fn();
264
- const Test = () => {
265
- return (
266
- <Dropdown onChange={(ev) => handler(ev.target.value)}>
267
- <DropdownDetailedOption value="y" icon={<Avatar name="hello" />} subtitle="ok" title="testx" />
268
- <DropdownDetailedOption value="x" icon={<Avatar name="hello" />} subtitle="ok" title="test" />
269
- <DropdownDetailedOption value="z" icon={<Avatar name="hello" />} subtitle="ok" title="test" />
270
- </Dropdown>
271
- );
272
- };
273
- render(<Test />);
274
- const button = await screen.findByRole('combobox');
275
- await userEvent.click(button);
276
- const search = await screen.findByRole('search');
277
- await waitFor(() => expect(search).toHaveFocus());
278
- await userEvent.keyboard('{ArrowDown}');
279
- await userEvent.keyboard('{ArrowDown}');
280
- await userEvent.keyboard('{Enter}');
281
- expect(handler).toHaveBeenCalledWith('x');
282
- expect(handler).toHaveBeenCalledTimes(1);
283
- });
284
- });
285
-
286
- describe('search', () => {
287
- describe('custom search', () => {
288
- it('works', async () => {
289
- render(<CustomSearch />);
290
- const button = await screen.findByRole('combobox');
291
-
292
- await userEvent.click(button);
293
- const search = await screen.findByRole('search');
294
- await userEvent.type(search, 'text1');
295
- let option1 = screen.queryByRole('option', { name: 'text1' });
296
- let option2 = screen.queryByRole('option', { name: 'text2' });
297
- let option3 = screen.queryByRole('option', { name: 'text3' });
298
- let option4 = screen.queryByRole('option', { name: 'text4' });
299
- expect(option1).toBeInTheDocument();
300
- expect(option2).not.toBeInTheDocument();
301
- expect(option3).not.toBeInTheDocument();
302
- expect(option4).not.toBeInTheDocument();
303
- await userEvent.clear(search);
304
- option1 = screen.queryByRole('option', { name: 'text1' });
305
- option2 = screen.queryByRole('option', { name: 'text2' });
306
- option3 = screen.queryByRole('option', { name: 'text3' });
307
- option4 = screen.queryByRole('option', { name: 'text4' });
308
- expect(option1).toBeInTheDocument();
309
- expect(option2).toBeInTheDocument();
310
- expect(option3).toBeInTheDocument();
311
- expect(option4).toBeInTheDocument();
312
- });
313
-
314
- it('resets after closing', async () => {
315
- render(<CustomSearch />);
316
- const button = await screen.findByRole('combobox');
317
-
318
- await userEvent.click(button);
319
- const search = await screen.findByRole('search');
320
- await userEvent.type(search, 'text1');
321
- await userEvent.click(button);
322
- await userEvent.click(button);
323
- const option1 = screen.queryByRole('option', { name: 'text1' });
324
- const option2 = screen.queryByRole('option', { name: 'text2' });
325
- expect(option1).toBeInTheDocument();
326
- expect(option2).toBeInTheDocument();
327
- });
328
- });
329
-
330
- it('removes group when items are filtered', async () => {
331
- render(
332
- <Dropdown>
333
- <DropdownOption value="x">Test Opt1</DropdownOption>
334
- <DropdownGroup label="hey">
335
- <DropdownOption value="y">Test Opt2</DropdownOption>
336
- <DropdownOption value="z">Test Opt3</DropdownOption>
337
- </DropdownGroup>
338
- </Dropdown>,
339
- );
340
- const button = await screen.findByRole('combobox');
341
-
342
- await userEvent.click(button);
343
- const search = await screen.findByRole('search');
344
- await userEvent.type(search, 'opt1');
345
- const option1 = screen.queryByRole('option', { name: 'Test Opt1' });
346
- const option2 = screen.queryByRole('option', { name: 'Test Opt2' });
347
- const option3 = screen.queryByRole('option', { name: 'Test Opt3' });
348
- const group = screen.queryByText('hey');
349
- expect(option1).toBeInTheDocument();
350
- expect(option2).not.toBeInTheDocument();
351
- expect(option3).not.toBeInTheDocument();
352
- expect(group).not.toBeInTheDocument();
353
- });
354
-
355
- it('filters inside group', async () => {
356
- render(
357
- <Dropdown>
358
- <DropdownOption value="x">Test Opt1</DropdownOption>
359
- <DropdownGroup label="hey">
360
- <DropdownOption value="y">Test Opt2</DropdownOption>
361
- <DropdownOption value="z">Test Opt3</DropdownOption>
362
- </DropdownGroup>
363
- </Dropdown>,
364
- );
365
- const button = await screen.findByRole('combobox');
366
-
367
- await userEvent.click(button);
368
- const search = await screen.findByRole('search');
369
- await userEvent.type(search, 'opt2');
370
- const option1 = screen.queryByRole('option', { name: 'Test Opt1' });
371
- const option2 = screen.queryByRole('option', { name: 'Test Opt2' });
372
- const option3 = screen.queryByRole('option', { name: 'Test Opt3' });
373
- const group = screen.queryByText('hey');
374
- expect(option1).not.toBeInTheDocument();
375
- expect(option2).toBeInTheDocument();
376
- expect(option3).not.toBeInTheDocument();
377
- expect(group).toBeInTheDocument();
378
- });
379
-
380
- it('filters options', async () => {
381
- render(<TestComponent submit={() => {}} />);
382
- const button = await screen.findByRole('combobox', { name: 'Test' });
383
-
384
- await userEvent.click(button);
385
- const search = await screen.findByRole('search');
386
- await userEvent.type(search, 'opt3');
387
- const option1 = screen.queryByRole('option', { name: 'Test Opt1' });
388
- const option2 = screen.queryByRole('option', { name: 'Test Opt2' });
389
- const option3 = screen.queryByRole('option', { name: 'Test Opt3' });
390
- expect(option1).not.toBeInTheDocument();
391
- expect(option2).not.toBeInTheDocument();
392
- expect(option3).toBeInTheDocument();
393
- });
394
-
395
- it('showns no results found', async () => {
396
- render(<TestComponent submit={() => {}} />);
397
- const button = await screen.findByRole('combobox', { name: 'Test' });
398
-
399
- await userEvent.click(button);
400
- const search = await screen.findByRole('search');
401
- await userEvent.type(search, 'x');
402
- const notFoundMessage = await screen.findByText('No results found for `x`');
403
- expect(notFoundMessage).toBeInTheDocument();
404
- });
405
-
406
- it('resets after closing', async () => {
407
- render(<TestComponent submit={() => {}} />);
408
- const button = await screen.findByRole('combobox', { name: 'Test' });
409
-
410
- await userEvent.click(button);
411
- const search = await screen.findByRole('search');
412
- const option = await screen.findByRole('option', { name: 'Test Opt1' });
413
- await userEvent.type(search, 'x');
414
- await waitFor(() => expect(option).not.toBeInTheDocument());
415
- await userEvent.click(button);
416
- await userEvent.click(button);
417
- const option2 = await screen.findByRole('option', { name: 'Test Opt1' });
418
- expect(option2).toBeInTheDocument();
419
- });
420
- });
421
-
422
- describe('keyboard navigation', () => {
423
- it('the initial value is the active element', async () => {
424
- const handler = jest.fn();
425
- const Test = () => {
426
- return (
427
- <Dropdown defaultValue="y" onChange={(ev) => handler(ev.target.value)}>
428
- <DropdownOption value="x">Test Opt1</DropdownOption>
429
- <DropdownOption value="y">Test Opt2</DropdownOption>
430
- <DropdownOption value="z">Test Opt3</DropdownOption>
431
- </Dropdown>
432
- );
433
- };
434
- render(<Test />);
435
- const button = await screen.findByRole('combobox');
436
- await userEvent.click(button);
437
- const search = await screen.findByRole('search');
438
- await waitFor(() => expect(search).toHaveFocus());
439
- await screen.findByRole('listbox');
440
- await userEvent.keyboard('{ArrowDown}');
441
- await userEvent.keyboard('{Enter}');
442
- expect(handler).toHaveBeenCalledWith('z');
443
- });
444
-
445
- it('the selected value is the active element', async () => {
446
- const handler = jest.fn();
447
- render(<TestComponent submit={(data: unknown) => handler(data)} />);
448
- const button = await screen.findByRole('combobox', { name: 'Test' });
449
- const submit = await screen.findByRole('button', { name: 'Send' });
450
-
451
- await userEvent.click(button);
452
- const search = await screen.findByRole('search');
453
- await waitFor(() => expect(search).toHaveFocus());
454
- await screen.findByRole('listbox');
455
- await userEvent.keyboard('{ArrowDown}');
456
- await userEvent.keyboard('{Enter}');
457
- await userEvent.click(button);
458
- await userEvent.keyboard('{ArrowDown}');
459
- await userEvent.keyboard('{Enter}');
460
- await userEvent.click(submit);
461
- expect(handler).toHaveBeenCalledTimes(1);
462
- expect(handler).toHaveBeenCalledWith({ dropdown: 'y' });
463
- });
464
-
465
- it('works', async () => {
466
- const handler = jest.fn();
467
- render(<TestComponent submit={(data: unknown) => handler(data)} />);
468
- const button = await screen.findByRole('combobox', { name: 'Test' });
469
- const submit = await screen.findByRole('button', { name: 'Send' });
470
-
471
- await userEvent.click(button);
472
- const search = await screen.findByRole('search');
473
- await waitFor(() => expect(search).toHaveFocus());
474
- await userEvent.keyboard('{ArrowDown}');
475
- await userEvent.keyboard('{ArrowDown}');
476
- await userEvent.keyboard('{Enter}');
477
- await userEvent.click(submit);
478
- expect(handler).toHaveBeenCalledWith({ dropdown: 'y' });
479
- expect(handler).toHaveBeenCalledTimes(1);
480
- });
481
-
482
- it('works without search', async () => {
483
- const handler = jest.fn();
484
- render(<TestComponent search={false} submit={(data: unknown) => handler(data)} />);
485
- const button = await screen.findByRole('combobox', { name: 'Test' });
486
- const submit = await screen.findByRole('button', { name: 'Send' });
487
-
488
- await userEvent.click(button);
489
- await screen.findByRole('listbox');
490
- await userEvent.keyboard('{ArrowDown}');
491
- await userEvent.keyboard('{ArrowDown}');
492
- await userEvent.keyboard('{Enter}');
493
- await userEvent.click(submit);
494
- expect(handler).toHaveBeenCalledWith({ dropdown: 'y' });
495
- expect(handler).toHaveBeenCalledTimes(1);
496
- });
497
-
498
- it('works with groups', async () => {
499
- const handler = jest.fn();
500
- const Test = () => {
501
- return (
502
- <Dropdown onChange={(ev) => handler(ev.target.value)}>
503
- <DropdownOption value="x">Test Opt1</DropdownOption>
504
- <DropdownGroup label="hey">
505
- <DropdownOption value="y">Test Opt2</DropdownOption>
506
- <DropdownOption value="z">Test Opt3</DropdownOption>
507
- </DropdownGroup>
508
- </Dropdown>
509
- );
510
- };
511
- render(<Test />);
512
- const button = await screen.findByRole('combobox');
513
- await userEvent.click(button);
514
- let search = await screen.findByRole('search');
515
- await waitFor(() => expect(search).toHaveFocus());
516
- await screen.findByRole('listbox');
517
- await userEvent.keyboard('{ArrowDown}');
518
- await userEvent.keyboard('{ArrowDown}');
519
- await userEvent.keyboard('{Enter}');
520
- expect(handler).toHaveBeenCalledWith('y');
521
- await userEvent.click(button);
522
- search = await screen.findByRole('search');
523
- await waitFor(() => expect(search).toHaveFocus());
524
- await userEvent.keyboard('{ArrowDown}');
525
- await userEvent.keyboard('{ArrowDown}');
526
- await userEvent.keyboard('{Enter}');
527
- expect(handler).toHaveBeenCalledWith('x');
528
- });
529
-
530
- describe('dismiss with esc', () => {
531
- it('works', async () => {
532
- const Test = () => {
533
- return (
534
- <Dropdown>
535
- <DropdownOption value="x">Test Opt1</DropdownOption>
536
- </Dropdown>
537
- );
538
- };
539
- render(<Test />);
540
-
541
- const button = await screen.findByRole('combobox');
542
- await userEvent.click(button);
543
- const list = await screen.findByRole('listbox');
544
- await userEvent.keyboard('{Escape}');
545
- expect(list).not.toBeInTheDocument();
546
- });
547
- it('works in dialog', async () => {
548
- render(<InsideDialog />);
549
-
550
- const button = await screen.findByRole('combobox');
551
- await userEvent.click(button);
552
- const list = await screen.findByRole('listbox');
553
- await userEvent.keyboard('{Escape}');
554
- expect(list).not.toBeVisible();
555
- expect(button).toBeVisible();
556
- });
557
- });
558
- });
559
-
560
- describe('label', () => {
561
- it('renders label associated with the selected option', async () => {
562
- render(
563
- <Dropdown defaultValue="Test option 2">
564
- <DropdownOption value="Test option 1">Test option 1</DropdownOption>
565
- <DropdownOption value="Test option 2">Test option 2</DropdownOption>
566
- </Dropdown>,
567
- );
568
-
569
- const button = await screen.findByRole('combobox');
570
- expect(button).toHaveTextContent('Test option 2');
571
- });
572
-
573
- it('renders custom label if provided', async () => {
574
- render(
575
- <Dropdown formLabel="Custom label">
576
- <DropdownOption>Test option</DropdownOption>
577
- </Dropdown>,
578
- );
579
-
580
- const button = await screen.findByRole('combobox');
581
- expect(button).toHaveTextContent('Custom label');
582
- });
583
- });
584
-
585
- describe('option onClick support', () => {
586
- it('calls onClick handler on option', async () => {
587
- const onChangeHandler = jest.fn();
588
- const onClickHandler = jest.fn();
589
-
590
- render(
591
- <Dropdown onChange={onChangeHandler}>
592
- <DropdownOption value="Test option 1">Test option 1</DropdownOption>
593
- <DropdownOption value="Test option 2" onClick={onClickHandler}>
594
- Test option 2
595
- </DropdownOption>
596
- </Dropdown>,
597
- );
598
-
599
- const button = await screen.findByRole('combobox');
600
- await userEvent.click(button);
601
- const option2 = await screen.findByRole('option', { name: 'Test option 2' });
602
- await userEvent.click(option2);
603
- expect(onClickHandler).toHaveBeenCalled();
604
- expect(onChangeHandler).toHaveBeenCalled();
605
- });
606
-
607
- it("doesn't call onChange handler if option's onClick handler prevented it", async () => {
608
- const onChangeHandler = jest.fn();
609
-
610
- render(
611
- <Dropdown onChange={onChangeHandler}>
612
- <DropdownOption value="Test option 1">Test option 1</DropdownOption>
613
- <DropdownOption value="Test option 2" onClick={(event) => event.preventDefault()}>
614
- Test option 2
615
- </DropdownOption>
616
- </Dropdown>,
617
- );
618
-
619
- const button = await screen.findByRole('combobox');
620
- await userEvent.click(button);
621
- const option2 = await screen.findByRole('option', { name: 'Test option 2' });
622
- await userEvent.click(option2);
623
- expect(onChangeHandler).not.toHaveBeenCalled();
624
- });
625
- });
626
- });
@@ -1,18 +0,0 @@
1
- import { ComponentStory, ComponentMeta } from '@storybook/react';
2
- import Button from '../Button/Button';
3
- import EmptyState, { EmptyStateProps } from './EmptyState';
4
-
5
- export default {
6
- title: 'Components/EmptyState',
7
- component: EmptyState,
8
- } as ComponentMeta<typeof EmptyState>;
9
-
10
- export const WithProps: ComponentStory<typeof EmptyState> = (props) => <EmptyState {...props} />;
11
- WithProps.args = {
12
- children: <Button variant="secondary">This is added as children</Button>,
13
- description:
14
- 'After you have created a group, you will be able to add group members, and assign access for the group to apps in this Workspace.',
15
- iconName: 'Wow',
16
- maxContentWidth: '35rem',
17
- title: 'Your groups will appear here',
18
- } as EmptyStateProps;
@@ -1,5 +0,0 @@
1
- import { ComponentMeta } from '@storybook/react';
2
- import Fade from './Fade';
3
-
4
- export default { component: Fade, args: { children: 'test content', in: false } } as ComponentMeta<typeof Fade>;
5
- export const Default = {};