@patternfly/react-templates 1.1.0-prerelease.9 → 1.1.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.
- package/CHANGELOG.md +150 -0
- package/components/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -1
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/dynamic-modules.json +14 -10
- package/dist/esm/components/Dropdown/{DropdownSimple.d.ts → SimpleDropdown.d.ts} +11 -6
- package/dist/esm/components/Dropdown/SimpleDropdown.d.ts.map +1 -0
- package/dist/esm/components/Dropdown/{DropdownSimple.js → SimpleDropdown.js} +13 -7
- package/dist/esm/components/Dropdown/SimpleDropdown.js.map +1 -0
- package/dist/esm/components/Dropdown/index.d.ts +1 -1
- package/dist/esm/components/Dropdown/index.js +1 -1
- 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 +14 -6
- package/dist/esm/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts +33 -0
- package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts.map +1 -0
- package/dist/esm/components/Select/{SelectTypeahead.js → MultiTypeaheadSelect.js} +52 -45
- package/dist/esm/components/Select/MultiTypeaheadSelect.js.map +1 -0
- package/dist/{js/components/Select/SelectSimple.d.ts → esm/components/Select/SimpleSelect.d.ts} +12 -7
- package/dist/esm/components/Select/SimpleSelect.d.ts.map +1 -0
- package/dist/esm/components/Select/SimpleSelect.js +39 -0
- package/dist/esm/components/Select/SimpleSelect.js.map +1 -0
- package/dist/esm/components/Select/TypeaheadSelect.d.ts +47 -0
- package/dist/esm/components/Select/TypeaheadSelect.d.ts.map +1 -0
- package/dist/esm/components/Select/TypeaheadSelect.js +228 -0
- package/dist/esm/components/Select/TypeaheadSelect.js.map +1 -0
- package/dist/esm/components/Select/index.d.ts +3 -2
- package/dist/esm/components/Select/index.d.ts.map +1 -1
- package/dist/esm/components/Select/index.js +3 -2
- package/dist/esm/components/Select/index.js.map +1 -1
- package/dist/js/components/Dropdown/{DropdownSimple.d.ts → SimpleDropdown.d.ts} +11 -6
- package/dist/js/components/Dropdown/SimpleDropdown.d.ts.map +1 -0
- package/dist/js/components/Dropdown/{DropdownSimple.js → SimpleDropdown.js} +14 -9
- package/dist/js/components/Dropdown/SimpleDropdown.js.map +1 -0
- package/dist/js/components/Dropdown/index.d.ts +1 -1
- package/dist/js/components/Dropdown/index.js +1 -1
- 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 +14 -6
- package/dist/js/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts +33 -0
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts.map +1 -0
- package/dist/js/components/Select/{SelectTypeahead.js → MultiTypeaheadSelect.js} +53 -46
- package/dist/js/components/Select/MultiTypeaheadSelect.js.map +1 -0
- package/dist/{esm/components/Select/SelectSimple.d.ts → js/components/Select/SimpleSelect.d.ts} +12 -7
- package/dist/js/components/Select/SimpleSelect.d.ts.map +1 -0
- package/dist/js/components/Select/SimpleSelect.js +42 -0
- package/dist/js/components/Select/SimpleSelect.js.map +1 -0
- package/dist/js/components/Select/TypeaheadSelect.d.ts +47 -0
- package/dist/js/components/Select/TypeaheadSelect.d.ts.map +1 -0
- package/dist/js/components/Select/TypeaheadSelect.js +232 -0
- package/dist/js/components/Select/TypeaheadSelect.js.map +1 -0
- package/dist/js/components/Select/index.d.ts +3 -2
- package/dist/js/components/Select/index.d.ts.map +1 -1
- package/dist/js/components/Select/index.js +3 -2
- package/dist/js/components/Select/index.js.map +1 -1
- package/dist/umd/assets/output-D8cue3c6.css +26066 -0
- package/dist/umd/react-templates.min.js +1 -1
- package/package.json +7 -10
- package/rollup.config.mjs +8 -0
- package/src/components/Dropdown/{DropdownSimple.tsx → SimpleDropdown.tsx} +28 -11
- package/src/components/Dropdown/__tests__/{DropdownSimple.test.tsx → SimpleDropdown.test.tsx} +35 -23
- package/src/components/Dropdown/__tests__/__snapshots__/{DropdownSimple.test.tsx.snap → SimpleDropdown.test.tsx.snap} +6 -0
- package/src/components/Dropdown/examples/DropdownTemplates.md +4 -16
- package/src/components/Dropdown/examples/{DropdownSimpleExample.tsx → SimpleDropdownExample.tsx} +7 -7
- package/src/components/Dropdown/index.ts +1 -1
- package/src/components/Select/CheckboxSelect.tsx +23 -7
- package/src/components/Select/{SelectTypeahead.tsx → MultiTypeaheadSelect.tsx} +91 -64
- package/src/components/Select/{SelectSimple.tsx → SimpleSelect.tsx} +39 -18
- package/src/components/Select/TypeaheadSelect.tsx +393 -0
- package/src/components/Select/{CheckboxSelect.test.tsx → __tests__/CheckboxSelect.test.tsx} +32 -3
- package/src/components/Select/{CheckboxSelectSnapshots.test.tsx → __tests__/CheckboxSelectSnapshots.test.tsx} +1 -1
- package/src/components/Select/__tests__/MultiTypeaheadSelect.test.tsx +412 -0
- package/src/components/Select/__tests__/SimpleSelect.test.tsx +242 -0
- package/src/components/Select/__tests__/TypeaheadSelect.test.tsx +372 -0
- package/src/components/Select/{__snapshots__ → __tests__/__snapshots__}/CheckboxSelectSnapshots.test.tsx.snap +7 -2
- package/src/components/Select/__tests__/__snapshots__/MultiTypeaheadSelect.test.tsx.snap +180 -0
- package/src/components/Select/__tests__/__snapshots__/SimpleSelect.test.tsx.snap +170 -0
- package/src/components/Select/__tests__/__snapshots__/TypeaheadSelect.test.tsx.snap +180 -0
- package/src/components/Select/examples/CheckboxSelectDemo.tsx +25 -8
- package/src/components/Select/examples/MultiTypeaheadSelectDemo.tsx +35 -0
- package/src/components/Select/examples/SelectTemplates.md +14 -5
- package/src/components/Select/examples/SimpleSelectDemo.tsx +36 -0
- package/src/components/Select/examples/TypeaheadSelectDemo.tsx +67 -0
- package/src/components/Select/index.ts +3 -2
- package/dist/esm/components/Dropdown/DropdownSimple.d.ts.map +0 -1
- package/dist/esm/components/Dropdown/DropdownSimple.js.map +0 -1
- package/dist/esm/components/Select/SelectSimple.d.ts.map +0 -1
- package/dist/esm/components/Select/SelectSimple.js +0 -31
- package/dist/esm/components/Select/SelectSimple.js.map +0 -1
- package/dist/esm/components/Select/SelectTypeahead.d.ts +0 -29
- package/dist/esm/components/Select/SelectTypeahead.d.ts.map +0 -1
- package/dist/esm/components/Select/SelectTypeahead.js.map +0 -1
- package/dist/js/components/Dropdown/DropdownSimple.d.ts.map +0 -1
- package/dist/js/components/Dropdown/DropdownSimple.js.map +0 -1
- package/dist/js/components/Select/SelectSimple.d.ts.map +0 -1
- package/dist/js/components/Select/SelectSimple.js +0 -34
- package/dist/js/components/Select/SelectSimple.js.map +0 -1
- package/dist/js/components/Select/SelectTypeahead.d.ts +0 -29
- package/dist/js/components/Select/SelectTypeahead.d.ts.map +0 -1
- package/dist/js/components/Select/SelectTypeahead.js.map +0 -1
- package/rollup.config.js +0 -7
- package/src/components/Select/examples/SelectSimpleDemo.tsx +0 -26
- package/src/components/Select/examples/SelectTypeaheadDemo.tsx +0 -21
|
@@ -0,0 +1,372 @@
|
|
|
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 selectOptions = [
|
|
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 selectOptions={selectOptions} />);
|
|
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('shows the selected item as selected', async () => {
|
|
32
|
+
const selectOptions = [
|
|
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 selectOptions={selectOptions} selected="option1" />);
|
|
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).toHaveClass(styles.modifiers.selected);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('calls the onSelect callback with the selected value when an option is selected', async () => {
|
|
52
|
+
const selectOptions = [
|
|
53
|
+
{ content: 'Option 1', value: 'option1' },
|
|
54
|
+
{ content: 'Option 2', value: 'option2' },
|
|
55
|
+
{ content: 'Option 3', value: 'option3' }
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const user = userEvent.setup();
|
|
59
|
+
const onSelectMock = jest.fn();
|
|
60
|
+
|
|
61
|
+
render(<TypeaheadSelect selectOptions={selectOptions} onSelect={onSelectMock} />);
|
|
62
|
+
|
|
63
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
64
|
+
|
|
65
|
+
await user.click(toggle);
|
|
66
|
+
|
|
67
|
+
expect(onSelectMock).not.toHaveBeenCalled();
|
|
68
|
+
|
|
69
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
70
|
+
|
|
71
|
+
await user.click(option1);
|
|
72
|
+
|
|
73
|
+
expect(onSelectMock).toHaveBeenCalledTimes(1);
|
|
74
|
+
expect(onSelectMock).toHaveBeenCalledWith(expect.anything(), 'option1');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('calls the onClearSelection callback when clear button is clicked', async () => {
|
|
78
|
+
const selectOptions = [
|
|
79
|
+
{ content: 'Option 1', value: 'option1' },
|
|
80
|
+
{ content: 'Option 2', value: 'option2' },
|
|
81
|
+
{ content: 'Option 3', value: 'option3' }
|
|
82
|
+
];
|
|
83
|
+
const onClearSelectionMock = jest.fn();
|
|
84
|
+
|
|
85
|
+
const user = userEvent.setup();
|
|
86
|
+
|
|
87
|
+
render(<TypeaheadSelect selectOptions={selectOptions} selected="option1" onClearSelection={onClearSelectionMock} />);
|
|
88
|
+
|
|
89
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
90
|
+
|
|
91
|
+
await user.click(toggle);
|
|
92
|
+
|
|
93
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
94
|
+
expect(option1).toHaveClass(styles.modifiers.selected);
|
|
95
|
+
|
|
96
|
+
const input = screen.getByRole('combobox');
|
|
97
|
+
expect(input).toHaveValue('Option 1');
|
|
98
|
+
|
|
99
|
+
const clearButton = screen.getByRole('button', { name: 'Clear input value' });
|
|
100
|
+
await user.click(clearButton);
|
|
101
|
+
|
|
102
|
+
expect(onClearSelectionMock).toHaveBeenCalledTimes(1);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('toggles the select menu when the toggle button is clicked', async () => {
|
|
106
|
+
const selectOptions = [
|
|
107
|
+
{ content: 'Option 1', value: 'option1' },
|
|
108
|
+
{ content: 'Option 2', value: 'option2' },
|
|
109
|
+
{ content: 'Option 3', value: 'option3' }
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
const user = userEvent.setup();
|
|
113
|
+
|
|
114
|
+
render(<TypeaheadSelect selectOptions={selectOptions} />);
|
|
115
|
+
|
|
116
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
117
|
+
|
|
118
|
+
await user.click(toggle);
|
|
119
|
+
|
|
120
|
+
const menu = screen.getByRole('listbox');
|
|
121
|
+
expect(menu).toBeInTheDocument();
|
|
122
|
+
|
|
123
|
+
await user.click(toggle);
|
|
124
|
+
|
|
125
|
+
await waitForElementToBeRemoved(menu);
|
|
126
|
+
|
|
127
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('calls the onToggle callback when the toggle is clicked', async () => {
|
|
131
|
+
const selectOptions = [
|
|
132
|
+
{ content: 'Option 1', value: 'option1' },
|
|
133
|
+
{ content: 'Option 2', value: 'option2' },
|
|
134
|
+
{ content: 'Option 3', value: 'option3' }
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
const user = userEvent.setup();
|
|
138
|
+
const onToggleMock = jest.fn();
|
|
139
|
+
|
|
140
|
+
render(<TypeaheadSelect selectOptions={selectOptions} onToggle={onToggleMock} />);
|
|
141
|
+
|
|
142
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
143
|
+
|
|
144
|
+
expect(onToggleMock).not.toHaveBeenCalled();
|
|
145
|
+
|
|
146
|
+
await user.click(toggle);
|
|
147
|
+
|
|
148
|
+
expect(onToggleMock).toHaveBeenCalledTimes(1);
|
|
149
|
+
expect(onToggleMock).toHaveBeenCalledWith(true);
|
|
150
|
+
|
|
151
|
+
await user.click(toggle);
|
|
152
|
+
|
|
153
|
+
expect(onToggleMock).toHaveBeenCalledTimes(2);
|
|
154
|
+
expect(onToggleMock).toHaveBeenCalledWith(false);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('Passes toggleWidth', () => {
|
|
158
|
+
const selectOptions = [
|
|
159
|
+
{ content: 'Option 1', value: 'option1' },
|
|
160
|
+
{ content: 'Option 2', value: 'option2' },
|
|
161
|
+
{ content: 'Option 3', value: 'option3' }
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
render(<TypeaheadSelect selectOptions={selectOptions} toggleWidth="500px" />);
|
|
165
|
+
|
|
166
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
167
|
+
expect(toggle.parentElement).toHaveAttribute('style', 'width: 500px;');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('Passes additional toggleProps', () => {
|
|
171
|
+
const selectOptions = [
|
|
172
|
+
{ content: 'Option 1', value: 'option1' },
|
|
173
|
+
{ content: 'Option 2', value: 'option2' },
|
|
174
|
+
{ content: 'Option 3', value: 'option3' }
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
render(<TypeaheadSelect selectOptions={selectOptions} toggleProps={{ id: 'toggle' }} />);
|
|
178
|
+
|
|
179
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
180
|
+
expect(toggle.parentElement).toHaveAttribute('id', 'toggle');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('passes custom placeholder text', async () => {
|
|
184
|
+
const selectOptions = [
|
|
185
|
+
{ content: 'Option 1', value: 'option1' },
|
|
186
|
+
{ content: 'Option 2', value: 'option2' },
|
|
187
|
+
{ content: 'Option 3', value: 'option3' }
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
render(<TypeaheadSelect selectOptions={selectOptions} placeholder="custom" />);
|
|
191
|
+
|
|
192
|
+
const input = screen.getByRole('combobox');
|
|
193
|
+
|
|
194
|
+
expect(input).toHaveAttribute('placeholder', 'custom');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('displays noOptionsFoundMessage when filter returns no results', async () => {
|
|
198
|
+
const selectOptions = [
|
|
199
|
+
{ content: 'Option 1', value: 'option1' },
|
|
200
|
+
{ content: 'Option 2', value: 'option2' },
|
|
201
|
+
{ content: 'Option 3', value: 'option3' }
|
|
202
|
+
];
|
|
203
|
+
const user = userEvent.setup();
|
|
204
|
+
|
|
205
|
+
render(<TypeaheadSelect selectOptions={selectOptions} />);
|
|
206
|
+
|
|
207
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
208
|
+
const input = screen.getByRole('combobox');
|
|
209
|
+
|
|
210
|
+
expect(input).toHaveAttribute('placeholder', 'Select an option');
|
|
211
|
+
|
|
212
|
+
await user.click(toggle);
|
|
213
|
+
|
|
214
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
215
|
+
const option2 = screen.getByRole('option', { name: 'Option 2' });
|
|
216
|
+
const option3 = screen.getByRole('option', { name: 'Option 3' });
|
|
217
|
+
|
|
218
|
+
expect(option1).toBeInTheDocument();
|
|
219
|
+
expect(option2).toBeInTheDocument();
|
|
220
|
+
expect(option3).toBeInTheDocument();
|
|
221
|
+
|
|
222
|
+
await user.type(input, '9');
|
|
223
|
+
expect(input).toHaveValue('9');
|
|
224
|
+
|
|
225
|
+
expect(option1).not.toBeInTheDocument();
|
|
226
|
+
expect(option2).not.toBeInTheDocument();
|
|
227
|
+
expect(option3).not.toBeInTheDocument();
|
|
228
|
+
expect(screen.getByRole('option', { name: 'No results found for "9"' })).toBeInTheDocument();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('displays custom noOptionsFoundMessage', async () => {
|
|
232
|
+
const selectOptions = [
|
|
233
|
+
{ content: 'Option 1', value: 'option1' },
|
|
234
|
+
{ content: 'Option 2', value: 'option2' },
|
|
235
|
+
{ content: 'Option 3', value: 'option3' }
|
|
236
|
+
];
|
|
237
|
+
const user = userEvent.setup();
|
|
238
|
+
|
|
239
|
+
render(<TypeaheadSelect selectOptions={selectOptions} noOptionsFoundMessage="custom" />);
|
|
240
|
+
|
|
241
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
242
|
+
const input = screen.getByRole('combobox');
|
|
243
|
+
|
|
244
|
+
expect(input).toHaveAttribute('placeholder', 'Select an option');
|
|
245
|
+
|
|
246
|
+
await user.click(toggle);
|
|
247
|
+
|
|
248
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
249
|
+
const option2 = screen.getByRole('option', { name: 'Option 2' });
|
|
250
|
+
const option3 = screen.getByRole('option', { name: 'Option 3' });
|
|
251
|
+
|
|
252
|
+
expect(option1).toBeInTheDocument();
|
|
253
|
+
expect(option2).toBeInTheDocument();
|
|
254
|
+
expect(option3).toBeInTheDocument();
|
|
255
|
+
|
|
256
|
+
await user.type(input, '9');
|
|
257
|
+
expect(input).toHaveValue('9');
|
|
258
|
+
|
|
259
|
+
expect(option1).not.toBeInTheDocument();
|
|
260
|
+
expect(option2).not.toBeInTheDocument();
|
|
261
|
+
expect(option3).not.toBeInTheDocument();
|
|
262
|
+
expect(screen.getByRole('option', { name: 'custom' })).toBeInTheDocument();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('disables the select when isDisabled prop is true', async () => {
|
|
266
|
+
const selectOptions = [
|
|
267
|
+
{ content: 'Option 1', value: 'option1' },
|
|
268
|
+
{ content: 'Option 2', value: 'option2' },
|
|
269
|
+
{ content: 'Option 3', value: 'option3' }
|
|
270
|
+
];
|
|
271
|
+
|
|
272
|
+
const user = userEvent.setup();
|
|
273
|
+
|
|
274
|
+
render(<TypeaheadSelect selectOptions={selectOptions} isDisabled={true} />);
|
|
275
|
+
|
|
276
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
277
|
+
|
|
278
|
+
expect(toggle.parentElement).toHaveClass(styles.modifiers.disabled);
|
|
279
|
+
|
|
280
|
+
await user.click(toggle);
|
|
281
|
+
|
|
282
|
+
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('passes other SelectOption props to the SelectOption component', async () => {
|
|
286
|
+
const selectOptions = [{ content: 'Option 1', value: 'option1', isDisabled: true }];
|
|
287
|
+
|
|
288
|
+
const user = userEvent.setup();
|
|
289
|
+
|
|
290
|
+
render(<TypeaheadSelect selectOptions={selectOptions} />);
|
|
291
|
+
|
|
292
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
293
|
+
|
|
294
|
+
await user.click(toggle);
|
|
295
|
+
|
|
296
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
297
|
+
expect(option1).toBeDisabled();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test('typing in input filters options', async () => {
|
|
301
|
+
const selectOptions = [
|
|
302
|
+
{ content: 'Option 1', value: 'option1' },
|
|
303
|
+
{ content: 'Option 2', value: 'option2' },
|
|
304
|
+
{ content: 'Option 3', value: 'option3' }
|
|
305
|
+
];
|
|
306
|
+
|
|
307
|
+
const user = userEvent.setup();
|
|
308
|
+
|
|
309
|
+
render(<TypeaheadSelect selectOptions={selectOptions} />);
|
|
310
|
+
|
|
311
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
312
|
+
const input = screen.getByRole('combobox');
|
|
313
|
+
|
|
314
|
+
expect(input).toHaveAttribute('placeholder', 'Select an option');
|
|
315
|
+
|
|
316
|
+
await user.click(toggle);
|
|
317
|
+
|
|
318
|
+
const option1 = screen.getByRole('option', { name: 'Option 1' });
|
|
319
|
+
const option2 = screen.getByRole('option', { name: 'Option 2' });
|
|
320
|
+
const option3 = screen.getByRole('option', { name: 'Option 3' });
|
|
321
|
+
|
|
322
|
+
expect(option1).toBeInTheDocument();
|
|
323
|
+
expect(option2).toBeInTheDocument();
|
|
324
|
+
expect(option3).toBeInTheDocument();
|
|
325
|
+
|
|
326
|
+
await user.type(input, '1');
|
|
327
|
+
expect(input).toHaveValue('1');
|
|
328
|
+
|
|
329
|
+
expect(option1).toBeInTheDocument();
|
|
330
|
+
expect(option2).not.toBeInTheDocument();
|
|
331
|
+
expect(option3).not.toBeInTheDocument();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test('typing in input triggers onInputChange callback', async () => {
|
|
335
|
+
const selectOptions = [
|
|
336
|
+
{ content: 'Option 1', value: 'option1' },
|
|
337
|
+
{ content: 'Option 2', value: 'option2' },
|
|
338
|
+
{ content: 'Option 3', value: 'option3' }
|
|
339
|
+
];
|
|
340
|
+
|
|
341
|
+
const user = userEvent.setup();
|
|
342
|
+
const onInputChangeMock = jest.fn();
|
|
343
|
+
|
|
344
|
+
render(<TypeaheadSelect selectOptions={selectOptions} onInputChange={onInputChangeMock} />);
|
|
345
|
+
|
|
346
|
+
const input = screen.getByRole('combobox');
|
|
347
|
+
|
|
348
|
+
expect(input).toHaveAttribute('placeholder', 'Select an option');
|
|
349
|
+
|
|
350
|
+
await user.type(input, '1');
|
|
351
|
+
|
|
352
|
+
expect(input).toHaveValue('1');
|
|
353
|
+
expect(onInputChangeMock).toHaveBeenCalledTimes(1);
|
|
354
|
+
expect(onInputChangeMock).toHaveBeenCalledWith('1');
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test('Matches snapshot', async () => {
|
|
358
|
+
const selectOptions = [
|
|
359
|
+
{ content: 'Option 1', value: 'option1' },
|
|
360
|
+
{ content: 'Option 2', value: 'option2' },
|
|
361
|
+
{ content: 'Option 3', value: 'option3' }
|
|
362
|
+
];
|
|
363
|
+
|
|
364
|
+
const user = userEvent.setup();
|
|
365
|
+
|
|
366
|
+
const { asFragment } = render(<TypeaheadSelect selectOptions={selectOptions} />);
|
|
367
|
+
|
|
368
|
+
const toggle = screen.getByRole('button', { name: 'Typeahead menu toggle' });
|
|
369
|
+
await user.click(toggle);
|
|
370
|
+
|
|
371
|
+
expect(asFragment()).toMatchSnapshot();
|
|
372
|
+
});
|
|
@@ -5,6 +5,9 @@ exports[`checkbox select with no props snapshot 1`] = `
|
|
|
5
5
|
<button
|
|
6
6
|
aria-expanded="false"
|
|
7
7
|
class="pf-v5-c-menu-toggle"
|
|
8
|
+
data-ouia-component-id="OUIA-Generated-MenuToggle-1"
|
|
9
|
+
data-ouia-component-type="PF5/MenuToggle"
|
|
10
|
+
data-ouia-safe="true"
|
|
8
11
|
style="width: 200px;"
|
|
9
12
|
type="button"
|
|
10
13
|
>
|
|
@@ -43,6 +46,9 @@ exports[`opened checkbox select snapshot 1`] = `
|
|
|
43
46
|
<button
|
|
44
47
|
aria-expanded="true"
|
|
45
48
|
class="pf-v5-c-menu-toggle pf-m-expanded"
|
|
49
|
+
data-ouia-component-id="OUIA-Generated-MenuToggle-2"
|
|
50
|
+
data-ouia-component-type="PF5/MenuToggle"
|
|
51
|
+
data-ouia-safe="true"
|
|
46
52
|
style="width: 200px;"
|
|
47
53
|
type="button"
|
|
48
54
|
>
|
|
@@ -75,13 +81,12 @@ exports[`opened checkbox select snapshot 1`] = `
|
|
|
75
81
|
</button>
|
|
76
82
|
<div
|
|
77
83
|
class="pf-v5-c-menu"
|
|
78
|
-
data-ouia-component-id="OUIA-Generated-Select-
|
|
84
|
+
data-ouia-component-id="OUIA-Generated-Select-5"
|
|
79
85
|
data-ouia-component-type="PF5/Select"
|
|
80
86
|
data-ouia-safe="true"
|
|
81
87
|
data-popper-escaped="true"
|
|
82
88
|
data-popper-placement="bottom-start"
|
|
83
89
|
data-popper-reference-hidden="true"
|
|
84
|
-
id="checkbox-select"
|
|
85
90
|
style="position: absolute; left: 0px; top: 0px; z-index: 9999; opacity: 1; transition: opacity 0ms cubic-bezier(.54, 1.5, .38, 1.11); min-width: 0px; transform: translate(0px, 0px);"
|
|
86
91
|
>
|
|
87
92
|
<div
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`MultiTypeaheadSelect Matches snapshot 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="pf-v5-c-menu-toggle pf-m-expanded pf-m-full-width pf-m-typeahead"
|
|
7
|
+
>
|
|
8
|
+
<div
|
|
9
|
+
class="pf-v5-c-text-input-group pf-m-plain"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
autocomplete="off"
|
|
13
|
+
class="pf-v5-c-text-input-group__main"
|
|
14
|
+
>
|
|
15
|
+
<span
|
|
16
|
+
class="pf-v5-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-v5-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-v5-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-v5-c-button pf-m-plain"
|
|
38
|
+
data-ouia-component-id="OUIA-Generated-Button-plain-20"
|
|
39
|
+
data-ouia-component-type="PF5/Button"
|
|
40
|
+
data-ouia-safe="true"
|
|
41
|
+
type="button"
|
|
42
|
+
>
|
|
43
|
+
<svg
|
|
44
|
+
aria-hidden="true"
|
|
45
|
+
class="pf-v5-svg"
|
|
46
|
+
fill="currentColor"
|
|
47
|
+
height="1em"
|
|
48
|
+
role="img"
|
|
49
|
+
viewBox="0 0 352 512"
|
|
50
|
+
width="1em"
|
|
51
|
+
>
|
|
52
|
+
<path
|
|
53
|
+
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"
|
|
54
|
+
/>
|
|
55
|
+
</svg>
|
|
56
|
+
</button>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
<button
|
|
60
|
+
aria-expanded="true"
|
|
61
|
+
aria-label="Multi select Typeahead menu toggle"
|
|
62
|
+
class="pf-v5-c-menu-toggle__button"
|
|
63
|
+
data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-17"
|
|
64
|
+
data-ouia-component-type="PF5/MenuToggle"
|
|
65
|
+
data-ouia-safe="true"
|
|
66
|
+
tabindex="-1"
|
|
67
|
+
type="button"
|
|
68
|
+
>
|
|
69
|
+
<span
|
|
70
|
+
class="pf-v5-c-menu-toggle__controls"
|
|
71
|
+
>
|
|
72
|
+
<span
|
|
73
|
+
class="pf-v5-c-menu-toggle__toggle-icon"
|
|
74
|
+
>
|
|
75
|
+
<svg
|
|
76
|
+
aria-hidden="true"
|
|
77
|
+
class="pf-v5-svg"
|
|
78
|
+
fill="currentColor"
|
|
79
|
+
height="1em"
|
|
80
|
+
role="img"
|
|
81
|
+
viewBox="0 0 320 512"
|
|
82
|
+
width="1em"
|
|
83
|
+
>
|
|
84
|
+
<path
|
|
85
|
+
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"
|
|
86
|
+
/>
|
|
87
|
+
</svg>
|
|
88
|
+
</span>
|
|
89
|
+
</span>
|
|
90
|
+
</button>
|
|
91
|
+
</div>
|
|
92
|
+
<div
|
|
93
|
+
class="pf-v5-c-menu"
|
|
94
|
+
data-ouia-component-id="OUIA-Generated-Select-67"
|
|
95
|
+
data-ouia-component-type="PF5/Select"
|
|
96
|
+
data-ouia-safe="true"
|
|
97
|
+
data-popper-escaped="true"
|
|
98
|
+
data-popper-placement="bottom-start"
|
|
99
|
+
data-popper-reference-hidden="true"
|
|
100
|
+
style="position: absolute; left: 0px; top: 0px; z-index: 9999; opacity: 1; transition: opacity 0ms cubic-bezier(.54, 1.5, .38, 1.11); min-width: 0px; transform: translate(0px, 0px);"
|
|
101
|
+
>
|
|
102
|
+
<div
|
|
103
|
+
class="pf-v5-c-menu__content"
|
|
104
|
+
>
|
|
105
|
+
<ul
|
|
106
|
+
aria-multiselectable="false"
|
|
107
|
+
class="pf-v5-c-menu__list"
|
|
108
|
+
role="listbox"
|
|
109
|
+
>
|
|
110
|
+
<li
|
|
111
|
+
class="pf-v5-c-menu__list-item"
|
|
112
|
+
role="none"
|
|
113
|
+
>
|
|
114
|
+
<button
|
|
115
|
+
aria-selected="false"
|
|
116
|
+
class="pf-v5-c-menu__item"
|
|
117
|
+
role="option"
|
|
118
|
+
tabindex="0"
|
|
119
|
+
type="button"
|
|
120
|
+
>
|
|
121
|
+
<span
|
|
122
|
+
class="pf-v5-c-menu__item-main"
|
|
123
|
+
>
|
|
124
|
+
<span
|
|
125
|
+
class="pf-v5-c-menu__item-text"
|
|
126
|
+
>
|
|
127
|
+
Option 1
|
|
128
|
+
</span>
|
|
129
|
+
</span>
|
|
130
|
+
</button>
|
|
131
|
+
</li>
|
|
132
|
+
<li
|
|
133
|
+
class="pf-v5-c-menu__list-item"
|
|
134
|
+
role="none"
|
|
135
|
+
>
|
|
136
|
+
<button
|
|
137
|
+
aria-selected="false"
|
|
138
|
+
class="pf-v5-c-menu__item"
|
|
139
|
+
role="option"
|
|
140
|
+
tabindex="-1"
|
|
141
|
+
type="button"
|
|
142
|
+
>
|
|
143
|
+
<span
|
|
144
|
+
class="pf-v5-c-menu__item-main"
|
|
145
|
+
>
|
|
146
|
+
<span
|
|
147
|
+
class="pf-v5-c-menu__item-text"
|
|
148
|
+
>
|
|
149
|
+
Option 2
|
|
150
|
+
</span>
|
|
151
|
+
</span>
|
|
152
|
+
</button>
|
|
153
|
+
</li>
|
|
154
|
+
<li
|
|
155
|
+
class="pf-v5-c-menu__list-item"
|
|
156
|
+
role="none"
|
|
157
|
+
>
|
|
158
|
+
<button
|
|
159
|
+
aria-selected="false"
|
|
160
|
+
class="pf-v5-c-menu__item"
|
|
161
|
+
role="option"
|
|
162
|
+
tabindex="-1"
|
|
163
|
+
type="button"
|
|
164
|
+
>
|
|
165
|
+
<span
|
|
166
|
+
class="pf-v5-c-menu__item-main"
|
|
167
|
+
>
|
|
168
|
+
<span
|
|
169
|
+
class="pf-v5-c-menu__item-text"
|
|
170
|
+
>
|
|
171
|
+
Option 3
|
|
172
|
+
</span>
|
|
173
|
+
</span>
|
|
174
|
+
</button>
|
|
175
|
+
</li>
|
|
176
|
+
</ul>
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
</DocumentFragment>
|
|
180
|
+
`;
|