|
10 | 10 | * governing permissions and limitations under the License.
|
11 | 11 | */
|
12 | 12 |
|
| 13 | +import {AsyncComboBoxStory, ContextualHelpExample, CustomWidth, Dynamic, EmptyCombobox, Example, Sections, WithIcons} from '../stories/ComboBox.stories'; |
13 | 14 | import {ComboBox} from '../src';
|
14 |
| -import {ContextualHelpExample, CustomWidth, Dynamic, Example, Sections, WithIcons} from '../stories/ComboBox.stories'; |
| 15 | +import {expect} from '@storybook/jest'; |
15 | 16 | import type {Meta, StoryObj} from '@storybook/react';
|
16 |
| -import {userEvent, within} from '@storybook/testing-library'; |
| 17 | +import {userEvent, waitFor, within} from '@storybook/testing-library'; |
17 | 18 |
|
18 | 19 | const meta: Meta<typeof ComboBox<any>> = {
|
19 | 20 | component: ComboBox,
|
20 | 21 | parameters: {
|
21 |
| - chromaticProvider: {colorSchemes: ['light'], backgrounds: ['base'], locales: ['en-US'], disableAnimations: true} |
| 22 | + chromaticProvider: {colorSchemes: ['light'], backgrounds: ['base'], locales: ['en-US'], disableAnimations: true}, |
| 23 | + chromatic: {ignoreSelectors: ['[role="progressbar"]']} |
22 | 24 | },
|
23 | 25 | tags: ['autodocs'],
|
24 | 26 | title: 'S2 Chromatic/ComboBox'
|
@@ -69,3 +71,89 @@ export const WithCustomWidth = {
|
69 | 71 | ...CustomWidth,
|
70 | 72 | play: async (context) => await Static.play!(context)
|
71 | 73 | } as StoryObj;
|
| 74 | + |
| 75 | +export const WithEmptyState = { |
| 76 | + ...EmptyCombobox, |
| 77 | + play: async ({canvasElement}) => { |
| 78 | + await userEvent.tab(); |
| 79 | + await userEvent.keyboard('{ArrowDown}'); |
| 80 | + let body = canvasElement.ownerDocument.body; |
| 81 | + let listbox = await within(body).findByRole('listbox'); |
| 82 | + await within(listbox).findByText('No results'); |
| 83 | + } |
| 84 | +}; |
| 85 | + |
| 86 | +export const WithInitialLoading = { |
| 87 | + ...EmptyCombobox, |
| 88 | + args: { |
| 89 | + loadingState: 'loading', |
| 90 | + label: 'Initial loading' |
| 91 | + }, |
| 92 | + play: async ({canvasElement}) => { |
| 93 | + await userEvent.tab(); |
| 94 | + await userEvent.keyboard('{ArrowDown}'); |
| 95 | + let body = canvasElement.ownerDocument.body; |
| 96 | + let listbox = await within(body).findByRole('listbox'); |
| 97 | + await within(listbox).findByText('Loading', {exact: false}); |
| 98 | + } |
| 99 | +}; |
| 100 | + |
| 101 | +export const WithLoadMore = { |
| 102 | + ...Example, |
| 103 | + args: { |
| 104 | + loadingState: 'loadingMore', |
| 105 | + label: 'Loading more' |
| 106 | + }, |
| 107 | + play: async ({canvasElement}) => { |
| 108 | + await userEvent.tab(); |
| 109 | + await userEvent.keyboard('{ArrowDown}'); |
| 110 | + let body = canvasElement.ownerDocument.body; |
| 111 | + let listbox = await within(body).findByRole('listbox'); |
| 112 | + await within(listbox).findByRole('progressbar'); |
| 113 | + } |
| 114 | +}; |
| 115 | + |
| 116 | +export const AsyncResults = { |
| 117 | + ...AsyncComboBoxStory, |
| 118 | + args: { |
| 119 | + ...AsyncComboBoxStory.args, |
| 120 | + delay: 2000 |
| 121 | + }, |
| 122 | + play: async ({canvasElement}) => { |
| 123 | + await userEvent.tab(); |
| 124 | + await userEvent.keyboard('{ArrowDown}'); |
| 125 | + let body = canvasElement.ownerDocument.body; |
| 126 | + let listbox = await within(body).findByRole('listbox'); |
| 127 | + await waitFor(() => { |
| 128 | + expect(within(listbox).getByText('Luke', {exact: false})).toBeInTheDocument(); |
| 129 | + }, {timeout: 5000}); |
| 130 | + } |
| 131 | +}; |
| 132 | + |
| 133 | +export const Filtering = { |
| 134 | + ...AsyncComboBoxStory, |
| 135 | + args: { |
| 136 | + ...AsyncComboBoxStory.args, |
| 137 | + delay: 2000 |
| 138 | + }, |
| 139 | + play: async ({canvasElement}) => { |
| 140 | + await userEvent.tab(); |
| 141 | + await userEvent.keyboard('{ArrowDown}'); |
| 142 | + let body = canvasElement.ownerDocument.body; |
| 143 | + let listbox = await within(body).findByRole('listbox'); |
| 144 | + await waitFor(() => { |
| 145 | + expect(within(listbox).getByText('Luke', {exact: false})).toBeInTheDocument(); |
| 146 | + }, {timeout: 5000}); |
| 147 | + |
| 148 | + let combobox = await within(body).findByRole('combobox'); |
| 149 | + await userEvent.type(combobox, 'R2'); |
| 150 | + |
| 151 | + await waitFor(() => { |
| 152 | + expect(within(body).getByRole('progressbar', {hidden: true})).toBeInTheDocument(); |
| 153 | + }, {timeout: 5000}); |
| 154 | + |
| 155 | + await waitFor(() => { |
| 156 | + expect(within(listbox).queryByRole('progressbar', {hidden: true})).toBeFalsy(); |
| 157 | + }, {timeout: 5000}); |
| 158 | + } |
| 159 | +}; |
0 commit comments