@patternfly/react-templates 6.0.0-alpha.4 → 6.0.0-alpha.41
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.
- package/CHANGELOG.md +154 -0
- package/README.md +4 -17
- package/components/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -0
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/dynamic-modules.json +15 -0
- package/dist/esm/components/Dropdown/SimpleDropdown.d.ts +48 -0
- package/dist/esm/components/Dropdown/SimpleDropdown.d.ts.map +1 -0
- package/dist/esm/components/Dropdown/SimpleDropdown.js +33 -0
- package/dist/esm/components/Dropdown/SimpleDropdown.js.map +1 -0
- package/dist/esm/components/Dropdown/index.d.ts +2 -0
- package/dist/esm/components/Dropdown/index.d.ts.map +1 -0
- package/dist/esm/components/Dropdown/index.js +2 -0
- package/dist/esm/components/Dropdown/index.js.map +1 -0
- package/dist/esm/components/Select/CheckboxSelect.d.ts +7 -3
- package/dist/esm/components/Select/CheckboxSelect.d.ts.map +1 -1
- package/dist/esm/components/Select/CheckboxSelect.js +9 -6
- package/dist/esm/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/esm/components/Select/{SelectSimple.d.ts → SimpleSelect.d.ts} +10 -7
- package/dist/esm/components/Select/SimpleSelect.d.ts.map +1 -0
- package/dist/esm/components/Select/{SelectSimple.js → SimpleSelect.js} +13 -9
- package/dist/esm/components/Select/SimpleSelect.js.map +1 -0
- package/dist/esm/components/Select/TypeaheadSelect.d.ts +33 -0
- package/dist/esm/components/Select/TypeaheadSelect.d.ts.map +1 -0
- package/dist/esm/components/Select/TypeaheadSelect.js +180 -0
- package/dist/esm/components/Select/TypeaheadSelect.js.map +1 -0
- package/dist/esm/components/Select/index.d.ts +2 -1
- package/dist/esm/components/Select/index.d.ts.map +1 -1
- package/dist/esm/components/Select/index.js +2 -1
- package/dist/esm/components/Select/index.js.map +1 -1
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/js/components/Dropdown/SimpleDropdown.d.ts +48 -0
- package/dist/js/components/Dropdown/SimpleDropdown.d.ts.map +1 -0
- package/dist/js/components/Dropdown/SimpleDropdown.js +36 -0
- package/dist/js/components/Dropdown/SimpleDropdown.js.map +1 -0
- package/dist/js/components/Dropdown/index.d.ts +2 -0
- package/dist/js/components/Dropdown/index.d.ts.map +1 -0
- package/dist/js/components/Dropdown/index.js +5 -0
- package/dist/js/components/Dropdown/index.js.map +1 -0
- package/dist/js/components/Select/CheckboxSelect.d.ts +7 -3
- package/dist/js/components/Select/CheckboxSelect.d.ts.map +1 -1
- package/dist/js/components/Select/CheckboxSelect.js +9 -6
- package/dist/js/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/js/components/Select/{SelectSimple.d.ts → SimpleSelect.d.ts} +10 -7
- package/dist/js/components/Select/SimpleSelect.d.ts.map +1 -0
- package/dist/js/components/Select/{SelectSimple.js → SimpleSelect.js} +14 -10
- package/dist/js/components/Select/SimpleSelect.js.map +1 -0
- package/dist/js/components/Select/TypeaheadSelect.d.ts +33 -0
- package/dist/js/components/Select/TypeaheadSelect.d.ts.map +1 -0
- package/dist/js/components/Select/TypeaheadSelect.js +184 -0
- package/dist/js/components/Select/TypeaheadSelect.js.map +1 -0
- package/dist/js/components/Select/index.d.ts +2 -1
- package/dist/js/components/Select/index.d.ts.map +1 -1
- package/dist/js/components/Select/index.js +2 -1
- package/dist/js/components/Select/index.js.map +1 -1
- package/dist/js/components/index.d.ts +1 -0
- package/dist/js/components/index.d.ts.map +1 -1
- package/dist/js/components/index.js +1 -0
- package/dist/js/components/index.js.map +1 -1
- package/dist/umd/assets/output-CgjuKcp1.css +23288 -0
- package/dist/umd/react-templates.min.js +1 -1
- package/package.json +7 -11
- package/rollup.config.mjs +8 -0
- package/src/components/Dropdown/SimpleDropdown.tsx +139 -0
- package/src/components/Dropdown/__tests__/SimpleDropdown.test.tsx +266 -0
- package/src/components/Dropdown/__tests__/__snapshots__/SimpleDropdown.test.tsx.snap +81 -0
- package/src/components/Dropdown/examples/DropdownTemplates.md +24 -0
- package/src/components/Dropdown/examples/SimpleDropdownExample.tsx +53 -0
- package/src/components/Dropdown/index.ts +1 -0
- package/src/components/Select/CheckboxSelect.tsx +18 -7
- package/src/components/Select/{SelectSimple.tsx → SimpleSelect.tsx} +27 -14
- package/src/components/Select/TypeaheadSelect.tsx +329 -0
- package/src/components/Select/{CheckboxSelect.test.tsx → __tests__/CheckboxSelect.test.tsx} +29 -1
- package/src/components/Select/{CheckboxSelectSnapshots.test.tsx → __tests__/CheckboxSelectSnapshots.test.tsx} +1 -1
- package/src/components/Select/__tests__/SimpleSelect.test.tsx +241 -0
- package/src/components/Select/__tests__/TypeaheadSelect.test.tsx +408 -0
- package/src/components/Select/__tests__/__snapshots__/CheckboxSelectSnapshots.test.tsx.snap +83 -0
- package/src/components/Select/__tests__/__snapshots__/SimpleSelect.test.tsx.snap +83 -0
- package/src/components/Select/__tests__/__snapshots__/TypeaheadSelect.test.tsx.snap +97 -0
- package/src/components/Select/examples/CheckboxSelectDemo.tsx +1 -1
- package/src/components/Select/examples/SelectTemplates.md +11 -4
- package/src/components/Select/examples/{SelectSimpleDemo.tsx → SimpleSelectDemo.tsx} +6 -6
- package/src/components/Select/examples/TypeaheadSelectDemo.tsx +21 -0
- package/src/components/Select/index.ts +2 -1
- package/src/components/index.ts +1 -0
- package/dist/esm/components/Select/SelectSimple.d.ts.map +0 -1
- package/dist/esm/components/Select/SelectSimple.js.map +0 -1
- package/dist/js/components/Select/SelectSimple.d.ts.map +0 -1
- package/dist/js/components/Select/SelectSimple.js.map +0 -1
- package/src/components/Select/__snapshots__/CheckboxSelectSnapshots.test.tsx.snap +0 -212
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { TypeaheadSelect } from '../TypeaheadSelect';
|
|
5
|
+
import styles from '@patternfly/react-styles/css/components/Menu/menu';
|
|
6
|
+
|
|
7
|
+
test('renders typeahead select with options', async () => {
|
|
8
|
+
const initialOptions = [
|
|
9
|
+
{ content: 'Option 1', value: 'option1' },
|
|
10
|
+
{ content: 'Option 2', value: 'option2' },
|
|
11
|
+
{ content: 'Option 3', value: 'option3' }
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const user = userEvent.setup();
|
|
15
|
+
|
|
16
|
+
render(<TypeaheadSelect initialOptions={initialOptions} />);
|
|
17
|
+
|
|
18
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
19
|
+
|
|
20
|
+
await user.click(toggle);
|
|
21
|
+
|
|
22
|
+
const option1 = screen.getByText('Option 1');
|
|
23
|
+
const option2 = screen.getByText('Option 2');
|
|
24
|
+
const option3 = screen.getByText('Option 3');
|
|
25
|
+
|
|
26
|
+
expect(option1).toBeInTheDocument();
|
|
27
|
+
expect(option2).toBeInTheDocument();
|
|
28
|
+
expect(option3).toBeInTheDocument();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('selects options when clicked', async () => {
|
|
32
|
+
const initialOptions = [
|
|
33
|
+
{ content: 'Option 1', value: 'option1' },
|
|
34
|
+
{ content: 'Option 2', value: 'option2' },
|
|
35
|
+
{ content: 'Option 3', value: 'option3' }
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const user = userEvent.setup();
|
|
39
|
+
|
|
40
|
+
render(<TypeaheadSelect initialOptions={initialOptions} />);
|
|
41
|
+
|
|
42
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
43
|
+
|
|
44
|
+
await user.click(toggle);
|
|
45
|
+
|
|
46
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
47
|
+
|
|
48
|
+
expect(option1).not.toHaveClass(styles.modifiers.selected);
|
|
49
|
+
|
|
50
|
+
await user.click(option1);
|
|
51
|
+
|
|
52
|
+
expect(option1).toHaveClass(styles.modifiers.selected);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('calls the onSelect callback with the selected value when an option is selected', async () => {
|
|
56
|
+
const initialOptions = [
|
|
57
|
+
{ content: 'Option 1', value: 'option1' },
|
|
58
|
+
{ content: 'Option 2', value: 'option2' },
|
|
59
|
+
{ content: 'Option 3', value: 'option3' }
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const user = userEvent.setup();
|
|
63
|
+
const onSelectMock = jest.fn();
|
|
64
|
+
|
|
65
|
+
render(<TypeaheadSelect initialOptions={initialOptions} onSelect={onSelectMock} />);
|
|
66
|
+
|
|
67
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
68
|
+
|
|
69
|
+
await user.click(toggle);
|
|
70
|
+
|
|
71
|
+
expect(onSelectMock).not.toHaveBeenCalled();
|
|
72
|
+
|
|
73
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
74
|
+
|
|
75
|
+
await user.click(option1);
|
|
76
|
+
|
|
77
|
+
expect(onSelectMock).toHaveBeenCalledTimes(1);
|
|
78
|
+
expect(onSelectMock).toHaveBeenCalledWith(expect.anything(), 'option1');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('deselects options when clear button is clicked', async () => {
|
|
82
|
+
const initialOptions = [
|
|
83
|
+
{ content: 'Option 1', value: 'option1' },
|
|
84
|
+
{ content: 'Option 2', value: 'option2' },
|
|
85
|
+
{ content: 'Option 3', value: 'option3' }
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
const user = userEvent.setup();
|
|
89
|
+
|
|
90
|
+
render(<TypeaheadSelect initialOptions={initialOptions} />);
|
|
91
|
+
|
|
92
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
93
|
+
|
|
94
|
+
await user.click(toggle);
|
|
95
|
+
|
|
96
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
97
|
+
await user.click(option1);
|
|
98
|
+
expect(option1).toHaveClass(styles.modifiers.selected);
|
|
99
|
+
|
|
100
|
+
const input = screen.getByRole('combobox');
|
|
101
|
+
expect(input).toHaveValue('Option 1');
|
|
102
|
+
|
|
103
|
+
const clearButton = screen.getByRole('button', { name: 'Clear input value' });
|
|
104
|
+
await user.click(clearButton);
|
|
105
|
+
expect(input).toHaveValue('');
|
|
106
|
+
|
|
107
|
+
await user.click(toggle);
|
|
108
|
+
expect(screen.getByRole('option', { name: 'Option 1' })).not.toHaveClass(styles.modifiers.selected);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('toggles the select menu when the toggle button is clicked', async () => {
|
|
112
|
+
const initialOptions = [
|
|
113
|
+
{ content: 'Option 1', value: 'option1' },
|
|
114
|
+
{ content: 'Option 2', value: 'option2' },
|
|
115
|
+
{ content: 'Option 3', value: 'option3' }
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
const user = userEvent.setup();
|
|
119
|
+
|
|
120
|
+
render(<TypeaheadSelect initialOptions={initialOptions} />);
|
|
121
|
+
|
|
122
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
123
|
+
|
|
124
|
+
await user.click(toggle);
|
|
125
|
+
|
|
126
|
+
const menu = screen.getByRole('listbox');
|
|
127
|
+
expect(menu).toBeInTheDocument();
|
|
128
|
+
|
|
129
|
+
await user.click(toggle);
|
|
130
|
+
|
|
131
|
+
await waitForElementToBeRemoved(menu);
|
|
132
|
+
|
|
133
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('calls the onToggle callback when the toggle is clicked', async () => {
|
|
137
|
+
const initialOptions = [
|
|
138
|
+
{ content: 'Option 1', value: 'option1' },
|
|
139
|
+
{ content: 'Option 2', value: 'option2' },
|
|
140
|
+
{ content: 'Option 3', value: 'option3' }
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
const user = userEvent.setup();
|
|
144
|
+
const onToggleMock = jest.fn();
|
|
145
|
+
|
|
146
|
+
render(<TypeaheadSelect initialOptions={initialOptions} onToggle={onToggleMock} />);
|
|
147
|
+
|
|
148
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
149
|
+
|
|
150
|
+
expect(onToggleMock).not.toHaveBeenCalled();
|
|
151
|
+
|
|
152
|
+
await user.click(toggle);
|
|
153
|
+
|
|
154
|
+
expect(onToggleMock).toHaveBeenCalledTimes(1);
|
|
155
|
+
expect(onToggleMock).toHaveBeenCalledWith(true);
|
|
156
|
+
|
|
157
|
+
await user.click(toggle);
|
|
158
|
+
|
|
159
|
+
expect(onToggleMock).toHaveBeenCalledTimes(2);
|
|
160
|
+
expect(onToggleMock).toHaveBeenCalledWith(false);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('Passes toggleWidth', () => {
|
|
164
|
+
const initialOptions = [
|
|
165
|
+
{ content: 'Option 1', value: 'option1' },
|
|
166
|
+
{ content: 'Option 2', value: 'option2' },
|
|
167
|
+
{ content: 'Option 3', value: 'option3' }
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
render(<TypeaheadSelect initialOptions={initialOptions} toggleWidth="500px" />);
|
|
171
|
+
|
|
172
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
173
|
+
expect(toggle.parentElement).toHaveAttribute('style', 'width: 500px;');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('Passes additional toggleProps', () => {
|
|
177
|
+
const initialOptions = [
|
|
178
|
+
{ content: 'Option 1', value: 'option1' },
|
|
179
|
+
{ content: 'Option 2', value: 'option2' },
|
|
180
|
+
{ content: 'Option 3', value: 'option3' }
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
render(<TypeaheadSelect initialOptions={initialOptions} toggleProps={{ id: 'toggle' }} />);
|
|
184
|
+
|
|
185
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
186
|
+
expect(toggle.parentElement).toHaveAttribute('id', 'toggle');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('passes custom placeholder text', async () => {
|
|
190
|
+
const initialOptions = [
|
|
191
|
+
{ content: 'Option 1', value: 'option1' },
|
|
192
|
+
{ content: 'Option 2', value: 'option2' },
|
|
193
|
+
{ content: 'Option 3', value: 'option3' }
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
render(<TypeaheadSelect initialOptions={initialOptions} placeholder="custom" />);
|
|
197
|
+
|
|
198
|
+
const input = screen.getByRole('combobox');
|
|
199
|
+
|
|
200
|
+
expect(input).toHaveAttribute('placeholder', 'custom');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('displays noOptionsFoundMessage when filter returns no results', async () => {
|
|
204
|
+
const initialOptions = [
|
|
205
|
+
{ content: 'Option 1', value: 'option1' },
|
|
206
|
+
{ content: 'Option 2', value: 'option2' },
|
|
207
|
+
{ content: 'Option 3', value: 'option3' }
|
|
208
|
+
];
|
|
209
|
+
const user = userEvent.setup();
|
|
210
|
+
|
|
211
|
+
render(<TypeaheadSelect initialOptions={initialOptions} />);
|
|
212
|
+
|
|
213
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
214
|
+
const input = screen.getByRole('combobox');
|
|
215
|
+
|
|
216
|
+
expect(input).toHaveAttribute('placeholder', 'Select an option');
|
|
217
|
+
|
|
218
|
+
await user.click(toggle);
|
|
219
|
+
|
|
220
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
221
|
+
const option2 = screen.getByRole('option', { name: 'Option 2' });
|
|
222
|
+
const option3 = screen.getByRole('option', { name: 'Option 3' });
|
|
223
|
+
|
|
224
|
+
expect(option1).toBeInTheDocument();
|
|
225
|
+
expect(option2).toBeInTheDocument();
|
|
226
|
+
expect(option3).toBeInTheDocument();
|
|
227
|
+
|
|
228
|
+
await user.type(input, '9');
|
|
229
|
+
expect(input).toHaveValue('9');
|
|
230
|
+
|
|
231
|
+
expect(option1).not.toBeInTheDocument();
|
|
232
|
+
expect(option2).not.toBeInTheDocument();
|
|
233
|
+
expect(option3).not.toBeInTheDocument();
|
|
234
|
+
expect(screen.getByRole('option', { name: 'No results found for "9"' })).toBeInTheDocument();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('displays custom noOptionsFoundMessage', async () => {
|
|
238
|
+
const initialOptions = [
|
|
239
|
+
{ content: 'Option 1', value: 'option1' },
|
|
240
|
+
{ content: 'Option 2', value: 'option2' },
|
|
241
|
+
{ content: 'Option 3', value: 'option3' }
|
|
242
|
+
];
|
|
243
|
+
const user = userEvent.setup();
|
|
244
|
+
|
|
245
|
+
render(<TypeaheadSelect initialOptions={initialOptions} noOptionsFoundMessage="custom" />);
|
|
246
|
+
|
|
247
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
248
|
+
const input = screen.getByRole('combobox');
|
|
249
|
+
|
|
250
|
+
expect(input).toHaveAttribute('placeholder', 'Select an option');
|
|
251
|
+
|
|
252
|
+
await user.click(toggle);
|
|
253
|
+
|
|
254
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
255
|
+
const option2 = screen.getByRole('option', { name: 'Option 2' });
|
|
256
|
+
const option3 = screen.getByRole('option', { name: 'Option 3' });
|
|
257
|
+
|
|
258
|
+
expect(option1).toBeInTheDocument();
|
|
259
|
+
expect(option2).toBeInTheDocument();
|
|
260
|
+
expect(option3).toBeInTheDocument();
|
|
261
|
+
|
|
262
|
+
await user.type(input, '9');
|
|
263
|
+
expect(input).toHaveValue('9');
|
|
264
|
+
|
|
265
|
+
expect(option1).not.toBeInTheDocument();
|
|
266
|
+
expect(option2).not.toBeInTheDocument();
|
|
267
|
+
expect(option3).not.toBeInTheDocument();
|
|
268
|
+
expect(screen.getByRole('option', { name: 'custom' })).toBeInTheDocument();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('disables the select when isDisabled prop is true', async () => {
|
|
272
|
+
const initialOptions = [
|
|
273
|
+
{ content: 'Option 1', value: 'option1' },
|
|
274
|
+
{ content: 'Option 2', value: 'option2' },
|
|
275
|
+
{ content: 'Option 3', value: 'option3' }
|
|
276
|
+
];
|
|
277
|
+
|
|
278
|
+
const user = userEvent.setup();
|
|
279
|
+
|
|
280
|
+
render(<TypeaheadSelect initialOptions={initialOptions} isDisabled={true} />);
|
|
281
|
+
|
|
282
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
283
|
+
|
|
284
|
+
expect(toggle.parentElement).toHaveClass(styles.modifiers.disabled);
|
|
285
|
+
|
|
286
|
+
await user.click(toggle);
|
|
287
|
+
|
|
288
|
+
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test('passes other SelectOption props to the SelectOption component', async () => {
|
|
292
|
+
const initialOptions = [{ content: 'Option 1', value: 'option1', isDisabled: true }];
|
|
293
|
+
|
|
294
|
+
const user = userEvent.setup();
|
|
295
|
+
|
|
296
|
+
render(<TypeaheadSelect initialOptions={initialOptions} />);
|
|
297
|
+
|
|
298
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
299
|
+
|
|
300
|
+
await user.click(toggle);
|
|
301
|
+
|
|
302
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
303
|
+
expect(option1).toBeDisabled();
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test('displays the option in input when option is selected', async () => {
|
|
307
|
+
const initialOptions = [
|
|
308
|
+
{ content: 'Option 1', value: 'option1' },
|
|
309
|
+
{ content: 'Option 2', value: 'option2' },
|
|
310
|
+
{ content: 'Option 3', value: 'option3' }
|
|
311
|
+
];
|
|
312
|
+
|
|
313
|
+
const user = userEvent.setup();
|
|
314
|
+
|
|
315
|
+
render(<TypeaheadSelect initialOptions={initialOptions} />);
|
|
316
|
+
|
|
317
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
318
|
+
const input = screen.getByRole('combobox');
|
|
319
|
+
|
|
320
|
+
expect(input).toHaveAttribute('placeholder', 'Select an option');
|
|
321
|
+
|
|
322
|
+
await user.click(toggle);
|
|
323
|
+
|
|
324
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
325
|
+
|
|
326
|
+
await user.click(option1);
|
|
327
|
+
|
|
328
|
+
expect(input).toHaveValue('Option 1');
|
|
329
|
+
|
|
330
|
+
const clearButton = screen.getByRole('button', { name: 'Clear input value' });
|
|
331
|
+
await user.click(clearButton);
|
|
332
|
+
|
|
333
|
+
expect(input).toHaveValue('');
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test('typing in input filters options', async () => {
|
|
337
|
+
const initialOptions = [
|
|
338
|
+
{ content: 'Option 1', value: 'option1' },
|
|
339
|
+
{ content: 'Option 2', value: 'option2' },
|
|
340
|
+
{ content: 'Option 3', value: 'option3' }
|
|
341
|
+
];
|
|
342
|
+
|
|
343
|
+
const user = userEvent.setup();
|
|
344
|
+
|
|
345
|
+
render(<TypeaheadSelect initialOptions={initialOptions} />);
|
|
346
|
+
|
|
347
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
348
|
+
const input = screen.getByRole('combobox');
|
|
349
|
+
|
|
350
|
+
expect(input).toHaveAttribute('placeholder', 'Select an option');
|
|
351
|
+
|
|
352
|
+
await user.click(toggle);
|
|
353
|
+
|
|
354
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
355
|
+
const option2 = screen.getByRole('option', { name: 'Option 2' });
|
|
356
|
+
const option3 = screen.getByRole('option', { name: 'Option 3' });
|
|
357
|
+
|
|
358
|
+
expect(option1).toBeInTheDocument();
|
|
359
|
+
expect(option2).toBeInTheDocument();
|
|
360
|
+
expect(option3).toBeInTheDocument();
|
|
361
|
+
|
|
362
|
+
await user.type(input, '1');
|
|
363
|
+
expect(input).toHaveValue('1');
|
|
364
|
+
|
|
365
|
+
expect(option1).toBeInTheDocument();
|
|
366
|
+
expect(option2).not.toBeInTheDocument();
|
|
367
|
+
expect(option3).not.toBeInTheDocument();
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('typing in input triggers onInputChange callback', async () => {
|
|
371
|
+
const initialOptions = [
|
|
372
|
+
{ content: 'Option 1', value: 'option1' },
|
|
373
|
+
{ content: 'Option 2', value: 'option2' },
|
|
374
|
+
{ content: 'Option 3', value: 'option3' }
|
|
375
|
+
];
|
|
376
|
+
|
|
377
|
+
const user = userEvent.setup();
|
|
378
|
+
const onInputChangeMock = jest.fn();
|
|
379
|
+
|
|
380
|
+
render(<TypeaheadSelect initialOptions={initialOptions} onInputChange={onInputChangeMock} />);
|
|
381
|
+
|
|
382
|
+
const input = screen.getByRole('combobox');
|
|
383
|
+
|
|
384
|
+
expect(input).toHaveAttribute('placeholder', 'Select an option');
|
|
385
|
+
|
|
386
|
+
await user.type(input, '1');
|
|
387
|
+
|
|
388
|
+
expect(input).toHaveValue('1');
|
|
389
|
+
expect(onInputChangeMock).toHaveBeenCalledTimes(1);
|
|
390
|
+
expect(onInputChangeMock).toHaveBeenCalledWith('1');
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
test('Matches snapshot', async () => {
|
|
394
|
+
const initialOptions = [
|
|
395
|
+
{ content: 'Option 1', value: 'option1' },
|
|
396
|
+
{ content: 'Option 2', value: 'option2' },
|
|
397
|
+
{ content: 'Option 3', value: 'option3' }
|
|
398
|
+
];
|
|
399
|
+
|
|
400
|
+
const user = userEvent.setup();
|
|
401
|
+
|
|
402
|
+
const { asFragment } = render(<TypeaheadSelect initialOptions={initialOptions} />);
|
|
403
|
+
|
|
404
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
405
|
+
await user.click(toggle);
|
|
406
|
+
|
|
407
|
+
expect(asFragment()).toMatchSnapshot();
|
|
408
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`checkbox select with no props snapshot 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<button
|
|
6
|
+
aria-expanded="false"
|
|
7
|
+
class="pf-v6-c-menu-toggle"
|
|
8
|
+
data-ouia-component-id="OUIA-Generated-MenuToggle-1"
|
|
9
|
+
data-ouia-component-type="PF6/MenuToggle"
|
|
10
|
+
data-ouia-safe="true"
|
|
11
|
+
style="width: 200px;"
|
|
12
|
+
type="button"
|
|
13
|
+
>
|
|
14
|
+
<span
|
|
15
|
+
class="pf-v6-c-menu-toggle__text"
|
|
16
|
+
>
|
|
17
|
+
Filter by status
|
|
18
|
+
</span>
|
|
19
|
+
<span
|
|
20
|
+
class="pf-v6-c-menu-toggle__controls"
|
|
21
|
+
>
|
|
22
|
+
<span
|
|
23
|
+
class="pf-v6-c-menu-toggle__toggle-icon"
|
|
24
|
+
>
|
|
25
|
+
<svg
|
|
26
|
+
aria-hidden="true"
|
|
27
|
+
class="pf-v6-svg"
|
|
28
|
+
fill="currentColor"
|
|
29
|
+
height="1em"
|
|
30
|
+
role="img"
|
|
31
|
+
viewBox="0 0 320 512"
|
|
32
|
+
width="1em"
|
|
33
|
+
>
|
|
34
|
+
<path
|
|
35
|
+
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
|
|
36
|
+
/>
|
|
37
|
+
</svg>
|
|
38
|
+
</span>
|
|
39
|
+
</span>
|
|
40
|
+
</button>
|
|
41
|
+
</DocumentFragment>
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
exports[`opened checkbox select snapshot 1`] = `
|
|
45
|
+
<DocumentFragment>
|
|
46
|
+
<button
|
|
47
|
+
aria-expanded="true"
|
|
48
|
+
class="pf-v6-c-menu-toggle pf-m-expanded"
|
|
49
|
+
data-ouia-component-id="OUIA-Generated-MenuToggle-2"
|
|
50
|
+
data-ouia-component-type="PF6/MenuToggle"
|
|
51
|
+
data-ouia-safe="true"
|
|
52
|
+
style="width: 200px;"
|
|
53
|
+
type="button"
|
|
54
|
+
>
|
|
55
|
+
<span
|
|
56
|
+
class="pf-v6-c-menu-toggle__text"
|
|
57
|
+
>
|
|
58
|
+
Filter by status
|
|
59
|
+
</span>
|
|
60
|
+
<span
|
|
61
|
+
class="pf-v6-c-menu-toggle__controls"
|
|
62
|
+
>
|
|
63
|
+
<span
|
|
64
|
+
class="pf-v6-c-menu-toggle__toggle-icon"
|
|
65
|
+
>
|
|
66
|
+
<svg
|
|
67
|
+
aria-hidden="true"
|
|
68
|
+
class="pf-v6-svg"
|
|
69
|
+
fill="currentColor"
|
|
70
|
+
height="1em"
|
|
71
|
+
role="img"
|
|
72
|
+
viewBox="0 0 320 512"
|
|
73
|
+
width="1em"
|
|
74
|
+
>
|
|
75
|
+
<path
|
|
76
|
+
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
|
|
77
|
+
/>
|
|
78
|
+
</svg>
|
|
79
|
+
</span>
|
|
80
|
+
</span>
|
|
81
|
+
</button>
|
|
82
|
+
</DocumentFragment>
|
|
83
|
+
`;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Matches snapshot 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<button
|
|
6
|
+
aria-expanded="true"
|
|
7
|
+
class="pf-v6-c-menu-toggle pf-m-expanded"
|
|
8
|
+
data-ouia-component-id="OUIA-Generated-MenuToggle-13"
|
|
9
|
+
data-ouia-component-type="PF6/MenuToggle"
|
|
10
|
+
data-ouia-safe="true"
|
|
11
|
+
style="width: 200px;"
|
|
12
|
+
type="button"
|
|
13
|
+
>
|
|
14
|
+
<span
|
|
15
|
+
class="pf-v6-c-menu-toggle__text"
|
|
16
|
+
>
|
|
17
|
+
Select
|
|
18
|
+
</span>
|
|
19
|
+
<span
|
|
20
|
+
class="pf-v6-c-menu-toggle__controls"
|
|
21
|
+
>
|
|
22
|
+
<span
|
|
23
|
+
class="pf-v6-c-menu-toggle__toggle-icon"
|
|
24
|
+
>
|
|
25
|
+
<svg
|
|
26
|
+
aria-hidden="true"
|
|
27
|
+
class="pf-v6-svg"
|
|
28
|
+
fill="currentColor"
|
|
29
|
+
height="1em"
|
|
30
|
+
role="img"
|
|
31
|
+
viewBox="0 0 320 512"
|
|
32
|
+
width="1em"
|
|
33
|
+
>
|
|
34
|
+
<path
|
|
35
|
+
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
|
|
36
|
+
/>
|
|
37
|
+
</svg>
|
|
38
|
+
</span>
|
|
39
|
+
</span>
|
|
40
|
+
</button>
|
|
41
|
+
</DocumentFragment>
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
exports[`checkbox select with no props snapshot 1`] = `
|
|
45
|
+
<DocumentFragment>
|
|
46
|
+
<button
|
|
47
|
+
aria-expanded="false"
|
|
48
|
+
class="pf-v6-c-menu-toggle"
|
|
49
|
+
data-ouia-component-id="OUIA-Generated-MenuToggle-12"
|
|
50
|
+
data-ouia-component-type="PF6/MenuToggle"
|
|
51
|
+
data-ouia-safe="true"
|
|
52
|
+
style="width: 200px;"
|
|
53
|
+
type="button"
|
|
54
|
+
>
|
|
55
|
+
<span
|
|
56
|
+
class="pf-v6-c-menu-toggle__text"
|
|
57
|
+
>
|
|
58
|
+
Select a value
|
|
59
|
+
</span>
|
|
60
|
+
<span
|
|
61
|
+
class="pf-v6-c-menu-toggle__controls"
|
|
62
|
+
>
|
|
63
|
+
<span
|
|
64
|
+
class="pf-v6-c-menu-toggle__toggle-icon"
|
|
65
|
+
>
|
|
66
|
+
<svg
|
|
67
|
+
aria-hidden="true"
|
|
68
|
+
class="pf-v6-svg"
|
|
69
|
+
fill="currentColor"
|
|
70
|
+
height="1em"
|
|
71
|
+
role="img"
|
|
72
|
+
viewBox="0 0 320 512"
|
|
73
|
+
width="1em"
|
|
74
|
+
>
|
|
75
|
+
<path
|
|
76
|
+
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
|
|
77
|
+
/>
|
|
78
|
+
</svg>
|
|
79
|
+
</span>
|
|
80
|
+
</span>
|
|
81
|
+
</button>
|
|
82
|
+
</DocumentFragment>
|
|
83
|
+
`;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Matches snapshot 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="pf-v6-c-menu-toggle pf-m-expanded pf-m-full-width pf-m-typeahead"
|
|
7
|
+
>
|
|
8
|
+
<div
|
|
9
|
+
class="pf-v6-c-text-input-group pf-m-plain"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
autocomplete="off"
|
|
13
|
+
class="pf-v6-c-text-input-group__main"
|
|
14
|
+
>
|
|
15
|
+
<span
|
|
16
|
+
class="pf-v6-c-text-input-group__text"
|
|
17
|
+
>
|
|
18
|
+
<input
|
|
19
|
+
aria-controls="select-typeahead-listbox"
|
|
20
|
+
aria-expanded="true"
|
|
21
|
+
aria-label="Type to filter"
|
|
22
|
+
class="pf-v6-c-text-input-group__text-input"
|
|
23
|
+
placeholder="Select an option"
|
|
24
|
+
role="combobox"
|
|
25
|
+
type="text"
|
|
26
|
+
value=""
|
|
27
|
+
/>
|
|
28
|
+
</span>
|
|
29
|
+
</div>
|
|
30
|
+
<div
|
|
31
|
+
class="pf-v6-c-text-input-group__utilities"
|
|
32
|
+
style="display: none;"
|
|
33
|
+
>
|
|
34
|
+
<button
|
|
35
|
+
aria-disabled="false"
|
|
36
|
+
aria-label="Clear input value"
|
|
37
|
+
class="pf-v6-c-button pf-m-plain"
|
|
38
|
+
data-ouia-component-id="OUIA-Generated-Button-plain-17"
|
|
39
|
+
data-ouia-component-type="PF6/Button"
|
|
40
|
+
data-ouia-safe="true"
|
|
41
|
+
type="button"
|
|
42
|
+
>
|
|
43
|
+
<span
|
|
44
|
+
class="pf-v6-c-button__icon pf-m-start"
|
|
45
|
+
>
|
|
46
|
+
<svg
|
|
47
|
+
aria-hidden="true"
|
|
48
|
+
class="pf-v6-svg"
|
|
49
|
+
fill="currentColor"
|
|
50
|
+
height="1em"
|
|
51
|
+
role="img"
|
|
52
|
+
viewBox="0 0 352 512"
|
|
53
|
+
width="1em"
|
|
54
|
+
>
|
|
55
|
+
<path
|
|
56
|
+
d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
|
|
57
|
+
/>
|
|
58
|
+
</svg>
|
|
59
|
+
</span>
|
|
60
|
+
</button>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<button
|
|
64
|
+
aria-expanded="true"
|
|
65
|
+
aria-label="Typeahead menu toggle"
|
|
66
|
+
class="pf-v6-c-menu-toggle__button"
|
|
67
|
+
data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-17"
|
|
68
|
+
data-ouia-component-type="PF6/MenuToggle"
|
|
69
|
+
data-ouia-safe="true"
|
|
70
|
+
tabindex="-1"
|
|
71
|
+
type="button"
|
|
72
|
+
>
|
|
73
|
+
<span
|
|
74
|
+
class="pf-v6-c-menu-toggle__controls"
|
|
75
|
+
>
|
|
76
|
+
<span
|
|
77
|
+
class="pf-v6-c-menu-toggle__toggle-icon"
|
|
78
|
+
>
|
|
79
|
+
<svg
|
|
80
|
+
aria-hidden="true"
|
|
81
|
+
class="pf-v6-svg"
|
|
82
|
+
fill="currentColor"
|
|
83
|
+
height="1em"
|
|
84
|
+
role="img"
|
|
85
|
+
viewBox="0 0 320 512"
|
|
86
|
+
width="1em"
|
|
87
|
+
>
|
|
88
|
+
<path
|
|
89
|
+
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
|
|
90
|
+
/>
|
|
91
|
+
</svg>
|
|
92
|
+
</span>
|
|
93
|
+
</span>
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
</DocumentFragment>
|
|
97
|
+
`;
|
|
@@ -4,7 +4,7 @@ import { CheckboxSelect, CheckboxSelectOption } from '@patternfly/react-template
|
|
|
4
4
|
export const SelectBasic: React.FunctionComponent = () => {
|
|
5
5
|
const initialOptions: CheckboxSelectOption[] = [
|
|
6
6
|
{ content: 'Option 1', value: 'option-1' },
|
|
7
|
-
{ content: 'Option 2', value: 'option-2' },
|
|
7
|
+
{ content: 'Option 2', value: 'option-2', description: 'Option with description' },
|
|
8
8
|
{ content: 'Option 3', value: 'option-3', isDisabled: true },
|
|
9
9
|
{ content: 'Option 4', value: 'option-4' }
|
|
10
10
|
];
|