@dxc-technology/halstack-react 0.0.0-e961efe → 0.0.0-ebb089f
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/dist/button/Button.stories.js +27 -0
- package/dist/select/Select.js +124 -83
- package/dist/select/index.d.ts +79 -1
- package/dist/text-input/TextInput.js +2 -2
- package/package.json +1 -1
- package/test/Select.test.js +606 -93
- package/test/TextInput.test.js +1 -2
- package/dist/stories/Button.js +0 -71
- package/dist/stories/Button.stories.js +0 -55
- package/dist/stories/Header.js +0 -67
- package/dist/stories/Header.stories.js +0 -31
- package/dist/stories/Introduction.stories.mdx +0 -211
- package/dist/stories/Page.js +0 -68
- package/dist/stories/Page.stories.js +0 -39
- package/dist/stories/assets/code-brackets.svg +0 -1
- package/dist/stories/assets/colors.svg +0 -1
- package/dist/stories/assets/comments.svg +0 -1
- package/dist/stories/assets/direction.svg +0 -1
- package/dist/stories/assets/flow.svg +0 -1
- package/dist/stories/assets/plugin.svg +0 -1
- package/dist/stories/assets/repo.svg +0 -1
- package/dist/stories/assets/stackalt.svg +0 -1
- package/dist/stories/button.css +0 -30
- package/dist/stories/header.css +0 -26
- package/dist/stories/page.css +0 -69
package/test/Select.test.js
CHANGED
|
@@ -26,72 +26,183 @@ const single_options = [
|
|
|
26
26
|
{ label: "Option 20", value: "20" },
|
|
27
27
|
];
|
|
28
28
|
|
|
29
|
-
const
|
|
29
|
+
const svg_icon_options = [
|
|
30
30
|
{
|
|
31
|
-
label: "
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
label: "3G Mobile",
|
|
32
|
+
value: "1",
|
|
33
|
+
icon: (
|
|
34
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
|
35
|
+
<g>
|
|
36
|
+
<path d="M0,0h24v24H0V0z" fill="none" />
|
|
37
|
+
</g>
|
|
38
|
+
<g>
|
|
39
|
+
<g>
|
|
40
|
+
<path d="M3,7v2h5v2H4v2h4v2H3v2h5c1.1,0,2-0.9,2-2v-1.5c0-0.83-0.67-1.5-1.5-1.5c0.83,0,1.5-0.67,1.5-1.5V9c0-1.1-0.9-2-2-2H3z M21,11v4c0,1.1-0.9,2-2,2h-5c-1.1,0-2-0.9-2-2V9c0-1.1,0.9-2,2-2h5c1.1,0,2,0.9,2,2h-7v6h5v-2h-2.5v-2H21z" />
|
|
41
|
+
</g>
|
|
42
|
+
</g>
|
|
43
|
+
</svg>
|
|
44
|
+
),
|
|
37
45
|
},
|
|
38
46
|
{
|
|
39
|
-
label: "
|
|
47
|
+
label: "Ethernet",
|
|
48
|
+
value: "2",
|
|
49
|
+
icon: (
|
|
50
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
|
51
|
+
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
52
|
+
<path d="M7.77 6.76L6.23 5.48.82 12l5.41 6.52 1.54-1.28L3.42 12l4.35-5.24zM7 13h2v-2H7v2zm10-2h-2v2h2v-2zm-6 2h2v-2h-2v2zm6.77-7.52l-1.54 1.28L20.58 12l-4.35 5.24 1.54 1.28L23.18 12l-5.41-6.52z" />
|
|
53
|
+
</svg>
|
|
54
|
+
),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
label: "Wi-fi",
|
|
58
|
+
value: "3",
|
|
59
|
+
icon: (
|
|
60
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
|
61
|
+
<path d="M0 0h24v24H0V0zm0 0h24v24H0V0z" fill="none" />
|
|
62
|
+
<path d="M1 9l2 2c4.97-4.97 13.03-4.97 18 0l2-2C16.93 2.93 7.08 2.93 1 9zm8 8l3 3 3-3c-1.65-1.66-4.34-1.66-6 0zm-4-4l2 2c2.76-2.76 7.24-2.76 10 0l2-2C15.14 9.14 8.87 9.14 5 13z" />
|
|
63
|
+
</svg>
|
|
64
|
+
),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
label: "Settings backup restore (just for previous configuration)",
|
|
68
|
+
value: "4",
|
|
69
|
+
icon: (
|
|
70
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
|
71
|
+
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
72
|
+
<path d="M14 12c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2zm-2-9c-4.97 0-9 4.03-9 9H0l4 4 4-4H5c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.51 0-2.91-.49-4.06-1.3l-1.42 1.44C8.04 20.3 9.94 21 12 21c4.97 0 9-4.03 9-9s-4.03-9-9-9z" />
|
|
73
|
+
</svg>
|
|
74
|
+
),
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
label: "Regular",
|
|
78
|
+
value: "Regular",
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const url_icon_options = [
|
|
83
|
+
{
|
|
84
|
+
label: "Instagram",
|
|
85
|
+
value: "1",
|
|
86
|
+
icon: "https://cdn.icon-icons.com/icons2/2518/PNG/512/brand_instagram_icon_151534.png",
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
label: "Twitter",
|
|
90
|
+
value: "2",
|
|
91
|
+
icon: "https://cdn-icons-png.flaticon.com/512/81/81609.png",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
label: "Snapchat",
|
|
95
|
+
value: "3",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
label: "Facebook",
|
|
99
|
+
value: "4",
|
|
100
|
+
icon: "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/2021_Facebook_icon.svg/2048px-2021_Facebook_icon.svg.png",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
label: "Pinterest",
|
|
104
|
+
value: "5",
|
|
105
|
+
icon: "https://cdn-icons-png.flaticon.com/512/145/145808.png",
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
const group_options = [
|
|
110
|
+
{
|
|
111
|
+
label: "Colores",
|
|
40
112
|
options: [
|
|
41
|
-
{ label: "
|
|
42
|
-
{ label: "
|
|
43
|
-
{ label: "
|
|
113
|
+
{ label: "Azul", value: "azul" },
|
|
114
|
+
{ label: "Rojo", value: "rojo" },
|
|
115
|
+
{ label: "Rosa", value: "rosa" },
|
|
116
|
+
{ label: "Verde", value: "verde" },
|
|
117
|
+
{ label: "Amarillo", value: "amarillo" },
|
|
118
|
+
{ label: "Blanco", value: "blanco" },
|
|
119
|
+
{ label: "Negro", value: "negro" },
|
|
44
120
|
],
|
|
45
121
|
},
|
|
46
122
|
{
|
|
47
|
-
label: "
|
|
123
|
+
label: "Ciudades españolas",
|
|
48
124
|
options: [
|
|
49
|
-
{ label: "
|
|
50
|
-
{ label: "
|
|
51
|
-
{ label: "
|
|
125
|
+
{ label: "Madrid", value: "madrid" },
|
|
126
|
+
{ label: "Oviedo", value: "oviedo" },
|
|
127
|
+
{ label: "Sevilla", value: "sevilla" },
|
|
128
|
+
{ label: "Bilbao", value: "bilbao" },
|
|
129
|
+
{ label: "Barcelona", value: "barcelona" },
|
|
52
130
|
],
|
|
53
131
|
},
|
|
54
132
|
{
|
|
55
|
-
label: "
|
|
133
|
+
label: "Ríos españoles",
|
|
56
134
|
options: [
|
|
57
|
-
{ label: "
|
|
58
|
-
{ label: "
|
|
59
|
-
{ label: "
|
|
135
|
+
{ label: "Miño", value: "miño" },
|
|
136
|
+
{ label: "Duero", value: "duero" },
|
|
137
|
+
{ label: "Tajo", value: "tajo" },
|
|
138
|
+
{ label: "Guadiana", value: "guadiana" },
|
|
139
|
+
{ label: "Guadalquivir", value: "guadalquivir" },
|
|
140
|
+
{ label: "Ebro", value: "ebro" },
|
|
60
141
|
],
|
|
61
142
|
},
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const grouped_icon_options = [
|
|
62
146
|
{
|
|
63
|
-
label: "
|
|
147
|
+
label: "Social Media",
|
|
64
148
|
options: [
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
149
|
+
{
|
|
150
|
+
label: "Instagram",
|
|
151
|
+
value: "1",
|
|
152
|
+
icon: "https://cdn.icon-icons.com/icons2/2518/PNG/512/brand_instagram_icon_151534.png",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
label: "Twitter",
|
|
156
|
+
value: "2",
|
|
157
|
+
icon: "https://cdn-icons-png.flaticon.com/512/81/81609.png",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
label: "Facebook",
|
|
161
|
+
value: "3",
|
|
162
|
+
icon: "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/2021_Facebook_icon.svg/2048px-2021_Facebook_icon.svg.png",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
label: "Pinterest",
|
|
166
|
+
value: "4",
|
|
167
|
+
icon: "https://cdn-icons-png.flaticon.com/512/145/145808.png",
|
|
168
|
+
},
|
|
68
169
|
],
|
|
69
170
|
},
|
|
70
171
|
{
|
|
71
|
-
label: "Group
|
|
172
|
+
label: "Group 2",
|
|
72
173
|
options: [
|
|
73
|
-
{ label: "Option
|
|
74
|
-
{ label: "Option
|
|
75
|
-
{ label: "Option
|
|
174
|
+
{ label: "Option 4", value: "5" },
|
|
175
|
+
{ label: "Option 5", value: "6" },
|
|
176
|
+
{ label: "Option 6", value: "7" },
|
|
76
177
|
],
|
|
77
178
|
},
|
|
78
179
|
{
|
|
79
|
-
label: "Group
|
|
180
|
+
label: "Group 3",
|
|
80
181
|
options: [
|
|
81
|
-
{ label: "Option
|
|
82
|
-
{ label: "Option
|
|
83
|
-
{ label: "Option
|
|
182
|
+
{ label: "Option 7", value: "8" },
|
|
183
|
+
{ label: "Option 8", value: "9" },
|
|
184
|
+
{ label: "Option 9", value: "10" },
|
|
84
185
|
],
|
|
85
186
|
},
|
|
86
187
|
];
|
|
87
188
|
|
|
88
189
|
describe("Select component tests", () => {
|
|
89
|
-
test("Renders with correct label
|
|
190
|
+
test("Renders with correct label", () => {
|
|
191
|
+
const { getByText, getByRole } = render(
|
|
192
|
+
<DxcSelect label="test-select-label" helperText="test-select-helper-text" placeholder="Example text" />
|
|
193
|
+
);
|
|
194
|
+
const select = getByRole("combobox");
|
|
195
|
+
const label = getByText("test-select-label");
|
|
196
|
+
|
|
197
|
+
expect(label).toBeTruthy();
|
|
198
|
+
userEvent.click(label);
|
|
199
|
+
expect(document.activeElement).toEqual(select);
|
|
200
|
+
});
|
|
201
|
+
test("Renders with correct helper text and placeholder", () => {
|
|
90
202
|
const { getByText } = render(
|
|
91
203
|
<DxcSelect label="test-select-label" helperText="test-select-helper-text" placeholder="Example text" />
|
|
92
204
|
);
|
|
93
205
|
|
|
94
|
-
expect(getByText("test-select-label")).toBeTruthy();
|
|
95
206
|
expect(getByText("test-select-helper-text")).toBeTruthy();
|
|
96
207
|
expect(getByText("Example text")).toBeTruthy();
|
|
97
208
|
});
|
|
@@ -124,14 +235,11 @@ describe("Select component tests", () => {
|
|
|
124
235
|
<DxcSelect label="test-select-label" value={["1", "2"]} options={single_options} disabled searchable multiple />
|
|
125
236
|
);
|
|
126
237
|
const select = getByRole("combobox");
|
|
127
|
-
|
|
238
|
+
|
|
128
239
|
fireEvent.focus(select);
|
|
129
240
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
130
241
|
});
|
|
131
242
|
test("Controlled - Not optional constraint", () => {
|
|
132
|
-
// scrollIntoView & scrollTo are not implemented in jsdom
|
|
133
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
134
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
135
243
|
const onChange = jest.fn();
|
|
136
244
|
const onBlur = jest.fn();
|
|
137
245
|
const { getByRole, getAllByRole } = render(
|
|
@@ -154,8 +262,6 @@ describe("Select component tests", () => {
|
|
|
154
262
|
expect(onBlur).toHaveBeenCalledWith({ value: "1", error: null });
|
|
155
263
|
});
|
|
156
264
|
test("Controlled - Optional constraint", () => {
|
|
157
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
158
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
159
265
|
const onChange = jest.fn();
|
|
160
266
|
const onBlur = jest.fn();
|
|
161
267
|
const { getByRole } = render(
|
|
@@ -170,10 +276,8 @@ describe("Select component tests", () => {
|
|
|
170
276
|
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null });
|
|
171
277
|
expect(select.getAttribute("aria-invalid")).toBe("false");
|
|
172
278
|
});
|
|
173
|
-
test("Non-Grouped Options - Opens listbox or closes it with a click on select", () => {
|
|
174
|
-
|
|
175
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
176
|
-
const { getByText, getByRole, queryByRole } = render(
|
|
279
|
+
test("Non-Grouped Options - Opens listbox and renders correctly or closes it with a click on select", () => {
|
|
280
|
+
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
177
281
|
<DxcSelect label="test-select-label" options={single_options} />
|
|
178
282
|
);
|
|
179
283
|
const select = getByRole("combobox");
|
|
@@ -185,13 +289,12 @@ describe("Select component tests", () => {
|
|
|
185
289
|
expect(getByText("Option 02")).toBeTruthy();
|
|
186
290
|
expect(getByText("Option 08")).toBeTruthy();
|
|
187
291
|
expect(getByText("Option 09")).toBeTruthy();
|
|
292
|
+
expect(getAllByRole("option").length).toBe(20);
|
|
188
293
|
userEvent.click(select);
|
|
189
294
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
190
295
|
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
191
296
|
});
|
|
192
297
|
test("Non-Grouped Options - If an empty list of options is passed, the select is rendered but doestn't open the listbox", () => {
|
|
193
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
194
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
195
298
|
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={[]} />);
|
|
196
299
|
const select = getByRole("combobox");
|
|
197
300
|
|
|
@@ -200,8 +303,6 @@ describe("Select component tests", () => {
|
|
|
200
303
|
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
201
304
|
});
|
|
202
305
|
test("Non-Grouped Options - Click in an option selects it and closes the listbox", () => {
|
|
203
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
204
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
205
306
|
const onChange = jest.fn();
|
|
206
307
|
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
207
308
|
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} />
|
|
@@ -217,8 +318,6 @@ describe("Select component tests", () => {
|
|
|
217
318
|
expect(getAllByRole("option")[2].getAttribute("aria-selected")).toBe("true");
|
|
218
319
|
});
|
|
219
320
|
test("Non-Grouped Options - Optional renders an empty first option with the placeholder as its label", () => {
|
|
220
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
221
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
222
321
|
const onChange = jest.fn();
|
|
223
322
|
const { getByRole, getAllByRole, getAllByText } = render(
|
|
224
323
|
<DxcSelect
|
|
@@ -237,80 +336,86 @@ describe("Select component tests", () => {
|
|
|
237
336
|
userEvent.click(getAllByRole("option")[0]);
|
|
238
337
|
expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
|
|
239
338
|
expect(getAllByText("Choose an option").length).toBe(1);
|
|
339
|
+
|
|
340
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
341
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
342
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
343
|
+
expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
|
|
344
|
+
expect(getAllByText("Choose an option").length).toBe(1);
|
|
345
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
346
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
240
347
|
});
|
|
241
|
-
test("Non-Grouped Options
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
348
|
+
test("Non-Grouped Options - Renders SVG icons correctly when passed with options", () => {
|
|
349
|
+
const { getByRole, getAllByRole } = render(<DxcSelect label="test-select-label" options={svg_icon_options} />);
|
|
350
|
+
const select = getByRole("combobox");
|
|
351
|
+
|
|
352
|
+
userEvent.click(select);
|
|
353
|
+
expect(getByRole("listbox").querySelectorAll("[role='img']").length).toBe(4);
|
|
354
|
+
expect(getAllByRole("option").length).toBe(5);
|
|
355
|
+
});
|
|
356
|
+
test("Non-Grouped Options - Renders string url icons correctly when passed with options", () => {
|
|
357
|
+
const { getByRole, getAllByRole } = render(
|
|
358
|
+
<DxcSelect label="test-select-label" options={url_icon_options} optional />
|
|
246
359
|
);
|
|
247
360
|
const select = getByRole("combobox");
|
|
248
|
-
|
|
361
|
+
|
|
362
|
+
userEvent.click(select);
|
|
363
|
+
expect(getByRole("listbox").querySelectorAll("img").length).toBe(4);
|
|
364
|
+
expect(getAllByRole("option").length).toBe(6);
|
|
365
|
+
});
|
|
366
|
+
test("Non-Grouped Options: Arrow up key - Opens the listbox and visually focus the last option", () => {
|
|
367
|
+
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={single_options} />);
|
|
368
|
+
const select = getByRole("combobox");
|
|
369
|
+
|
|
249
370
|
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
250
371
|
expect(queryByRole("listbox")).toBeTruthy();
|
|
251
372
|
expect(select.getAttribute("aria-activedescendant")).toBe("option-19");
|
|
252
373
|
});
|
|
253
374
|
test("Non-Grouped Options: Arrow up key - Puts the focus in last option when the first one is visually focused", () => {
|
|
254
|
-
|
|
255
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
256
|
-
const { getByRole, queryByRole } = render(
|
|
257
|
-
<DxcSelect label="test-select-label" options={single_options} />
|
|
258
|
-
);
|
|
375
|
+
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={single_options} />);
|
|
259
376
|
const select = getByRole("combobox");
|
|
260
|
-
|
|
377
|
+
|
|
261
378
|
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
262
379
|
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
263
380
|
expect(queryByRole("listbox")).toBeTruthy();
|
|
264
381
|
expect(select.getAttribute("aria-activedescendant")).toBe("option-19");
|
|
265
382
|
});
|
|
266
383
|
test("Non-Grouped Options: Arrow down key - Opens the listbox and visually focus the first option", () => {
|
|
267
|
-
|
|
268
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
269
|
-
const { getByRole, queryByRole } = render(
|
|
270
|
-
<DxcSelect label="test-select-label" options={single_options} />
|
|
271
|
-
);
|
|
384
|
+
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={single_options} />);
|
|
272
385
|
const select = getByRole("combobox");
|
|
273
|
-
|
|
386
|
+
|
|
274
387
|
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
275
388
|
expect(queryByRole("listbox")).toBeTruthy();
|
|
276
389
|
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
277
390
|
});
|
|
278
391
|
test("Non-Grouped Options: Arrow down key - Puts the focus in the first option when the last one is visually focused", () => {
|
|
279
|
-
|
|
280
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
281
|
-
const { getByRole, queryByRole } = render(
|
|
282
|
-
<DxcSelect label="test-select-label" options={single_options} />
|
|
283
|
-
);
|
|
392
|
+
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={single_options} />);
|
|
284
393
|
const select = getByRole("combobox");
|
|
285
|
-
|
|
394
|
+
|
|
286
395
|
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
287
396
|
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
288
397
|
expect(queryByRole("listbox")).toBeTruthy();
|
|
289
398
|
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
290
399
|
});
|
|
291
400
|
test("Non-Grouped Options: Enter key - Selects the visually focused option and closes the listbox", () => {
|
|
292
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
293
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
294
401
|
const onChange = jest.fn();
|
|
295
402
|
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
296
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} />
|
|
403
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} optional />
|
|
297
404
|
);
|
|
298
405
|
const select = getByRole("combobox");
|
|
299
|
-
|
|
406
|
+
|
|
300
407
|
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
301
408
|
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
302
409
|
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
303
410
|
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
304
411
|
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
305
|
-
expect(onChange).toHaveBeenCalledWith({ value: "
|
|
412
|
+
expect(onChange).toHaveBeenCalledWith({ value: "20", error: null });
|
|
306
413
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
307
|
-
expect(getByText("Option
|
|
414
|
+
expect(getByText("Option 20")).toBeTruthy();
|
|
308
415
|
userEvent.click(select);
|
|
309
|
-
expect(getAllByRole("option")[
|
|
416
|
+
expect(getAllByRole("option")[20].getAttribute("aria-selected")).toBe("true");
|
|
310
417
|
});
|
|
311
418
|
test("Non-Grouped Options: Searchable - Displays an input for filtering the list of options", () => {
|
|
312
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
313
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
314
419
|
const onChange = jest.fn();
|
|
315
420
|
const { container, getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
316
421
|
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
@@ -330,8 +435,6 @@ describe("Select component tests", () => {
|
|
|
330
435
|
expect(getAllByRole("option")[7].getAttribute("aria-selected")).toBe("true");
|
|
331
436
|
});
|
|
332
437
|
test("Non-Grouped Options: Searchable - Displays 'No matches found' when there are no filtering results", () => {
|
|
333
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
334
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
335
438
|
const onChange = jest.fn();
|
|
336
439
|
const { container, getByText, getByRole } = render(
|
|
337
440
|
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
@@ -345,8 +448,6 @@ describe("Select component tests", () => {
|
|
|
345
448
|
expect(getByText("No matches found")).toBeTruthy();
|
|
346
449
|
});
|
|
347
450
|
test("Non-Grouped Options: Searchable - Clicking the select, when the list is open, clears the search value", () => {
|
|
348
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
349
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
350
451
|
const onChange = jest.fn();
|
|
351
452
|
const { container, getByText, getByRole, getAllByRole } = render(
|
|
352
453
|
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
@@ -364,9 +465,7 @@ describe("Select component tests", () => {
|
|
|
364
465
|
userEvent.click(select);
|
|
365
466
|
expect(searchInput.value).toBe("");
|
|
366
467
|
});
|
|
367
|
-
test("Non-Grouped Options: Searchable - Writing displays the listbox, if was not open", () => {
|
|
368
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
369
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
468
|
+
test("Non-Grouped Options: Searchable - Writing displays the listbox, if it was not open", () => {
|
|
370
469
|
const onChange = jest.fn();
|
|
371
470
|
const { container, getByRole, queryByRole } = render(
|
|
372
471
|
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
@@ -381,8 +480,6 @@ describe("Select component tests", () => {
|
|
|
381
480
|
expect(getByRole("listbox")).toBeTruthy();
|
|
382
481
|
});
|
|
383
482
|
test("Non-Grouped Options: Searchable - Key Esc cleans the search value and closes the options", () => {
|
|
384
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
385
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
386
483
|
const onChange = jest.fn();
|
|
387
484
|
const { container, getByRole, queryByRole } = render(
|
|
388
485
|
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
@@ -396,8 +493,6 @@ describe("Select component tests", () => {
|
|
|
396
493
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
397
494
|
});
|
|
398
495
|
test("Non-Grouped Options: Searchable - While user types, a clear action is displayed for cleaning the search value", () => {
|
|
399
|
-
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
400
|
-
window.HTMLElement.prototype.scrollTo = () => {};
|
|
401
496
|
const onChange = jest.fn();
|
|
402
497
|
const { container, getByRole, getAllByRole } = render(
|
|
403
498
|
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
@@ -412,4 +507,422 @@ describe("Select component tests", () => {
|
|
|
412
507
|
expect(getByRole("listbox")).toBeTruthy();
|
|
413
508
|
expect(getAllByRole("option").length).toBe(20);
|
|
414
509
|
});
|
|
510
|
+
test("Non-Grouped Options: Multiple selection - Displays a checkbox per option and enables the multi-selection", () => {
|
|
511
|
+
const onChange = jest.fn();
|
|
512
|
+
const { getByText, getAllByText, getByRole, getAllByRole, queryByRole } = render(
|
|
513
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} multiple />
|
|
514
|
+
);
|
|
515
|
+
const select = getByRole("combobox");
|
|
516
|
+
|
|
517
|
+
userEvent.click(select);
|
|
518
|
+
expect(getByRole("listbox").getAttribute("aria-multiselectable")).toBe("true");
|
|
519
|
+
userEvent.click(getAllByRole("option")[10]);
|
|
520
|
+
// expect(onChange).toHaveBeenCalledWith({ value: ["11"], error: null });
|
|
521
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
522
|
+
expect(getAllByText("Option 11").length).toBe(2);
|
|
523
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
524
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
525
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
526
|
+
// expect(onChange).toHaveBeenCalledWith({ value: ["11", "19"], error: null });
|
|
527
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
528
|
+
expect(getByText("Option 11, Option 19")).toBeTruthy();
|
|
529
|
+
expect(getAllByRole("option")[10].getAttribute("aria-selected")).toBe("true");
|
|
530
|
+
expect(getAllByRole("option")[18].getAttribute("aria-selected")).toBe("true");
|
|
531
|
+
});
|
|
532
|
+
test("Non-Grouped Options: Multiple selection - Clear action and selection indicator", () => {
|
|
533
|
+
const onChange = jest.fn();
|
|
534
|
+
const { getByText, queryByText, getByRole, getAllByRole, queryByRole, getByTitle, queryByTitle } = render(
|
|
535
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} multiple />
|
|
536
|
+
);
|
|
537
|
+
const select = getByRole("combobox");
|
|
538
|
+
|
|
539
|
+
userEvent.click(select);
|
|
540
|
+
userEvent.click(getAllByRole("option")[5]);
|
|
541
|
+
userEvent.click(getAllByRole("option")[8]);
|
|
542
|
+
userEvent.click(getAllByRole("option")[13]);
|
|
543
|
+
// expect(onChange).toHaveBeenCalledWith({ value: ["6", "9", "14"], error: null });
|
|
544
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
545
|
+
expect(getByText("Option 06, Option 09, Option 14")).toBeTruthy();
|
|
546
|
+
expect(getByText("3", { exact: true })).toBeTruthy();
|
|
547
|
+
userEvent.click(getByTitle("Clear selected options"));
|
|
548
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
549
|
+
expect(queryByText("Option 06, Option 09, Option 14")).toBeFalsy();
|
|
550
|
+
expect(queryByText("3")).toBeFalsy();
|
|
551
|
+
expect(queryByTitle("Clear selected options")).toBeFalsy();
|
|
552
|
+
});
|
|
553
|
+
test("Non-Grouped Options: Multiple selection - Optional option should not be added when the select is marked as multiple", () => {
|
|
554
|
+
const onChange = jest.fn();
|
|
555
|
+
const { getByText, getAllByText, getByRole, getAllByRole } = render(
|
|
556
|
+
<DxcSelect
|
|
557
|
+
label="test-select-label"
|
|
558
|
+
placeholder="Choose an option"
|
|
559
|
+
options={single_options}
|
|
560
|
+
onChange={onChange}
|
|
561
|
+
multiple
|
|
562
|
+
optional
|
|
563
|
+
/>
|
|
564
|
+
);
|
|
565
|
+
const select = getByRole("combobox");
|
|
566
|
+
|
|
567
|
+
expect(getByText("(Optional)")).toBeTruthy();
|
|
568
|
+
userEvent.click(select);
|
|
569
|
+
expect(getAllByText("Choose an option").length).toBe(1);
|
|
570
|
+
expect(getAllByRole("option")[0].getAttribute("aria-selected")).toBe("false");
|
|
571
|
+
userEvent.click(getAllByRole("option")[0]);
|
|
572
|
+
// expect(onChange).toHaveBeenCalledWith({ value: ["1"], error: null });
|
|
573
|
+
expect(getAllByText("Option 01").length).toBe(2);
|
|
574
|
+
});
|
|
575
|
+
test("Non-Grouped Options - If an options was previously selected when its opened (by key press), the visual focus appears always in the selected option", () => {
|
|
576
|
+
const { getByText, getByRole, getAllByRole } = render(
|
|
577
|
+
<DxcSelect label="test-select-label" options={single_options} />
|
|
578
|
+
);
|
|
579
|
+
const select = getByRole("combobox");
|
|
580
|
+
|
|
581
|
+
userEvent.click(select);
|
|
582
|
+
userEvent.click(getAllByRole("option")[4]);
|
|
583
|
+
expect(getByText("Option 05")).toBeTruthy();
|
|
584
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
585
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-4");
|
|
586
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
587
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
588
|
+
expect(getByText("Option 04")).toBeTruthy();
|
|
589
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
590
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-3");
|
|
591
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
592
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
593
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
594
|
+
expect(getByText("Option 06")).toBeTruthy();
|
|
595
|
+
});
|
|
596
|
+
test("Non-Grouped Options - If an options was previously selected when its opened (by click and key press), the visual focus appears always in the selected option", () => {
|
|
597
|
+
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
598
|
+
<DxcSelect label="test-select-label" options={single_options} />
|
|
599
|
+
);
|
|
600
|
+
const select = getByRole("combobox");
|
|
601
|
+
|
|
602
|
+
userEvent.click(select);
|
|
603
|
+
userEvent.click(getAllByRole("option")[15]);
|
|
604
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
605
|
+
expect(getByText("Option 16")).toBeTruthy();
|
|
606
|
+
userEvent.click(select);
|
|
607
|
+
expect(select.getAttribute("aria-activedescendant")).toBeNull();
|
|
608
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
609
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-15");
|
|
610
|
+
userEvent.click(select);
|
|
611
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
612
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
613
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-15");
|
|
614
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
615
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
616
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
617
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
618
|
+
expect(getByText("Option 17")).toBeTruthy();
|
|
619
|
+
});
|
|
620
|
+
test("Grouped Options - Opens listbox and renders it correctly or closes it with a click on select", () => {
|
|
621
|
+
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
622
|
+
<DxcSelect label="test-select-label" options={group_options} />
|
|
623
|
+
);
|
|
624
|
+
const select = getByRole("combobox");
|
|
625
|
+
|
|
626
|
+
userEvent.click(select);
|
|
627
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
628
|
+
expect(select.getAttribute("aria-expanded")).toBe("true");
|
|
629
|
+
expect(getByText("Colores")).toBeTruthy();
|
|
630
|
+
expect(getByText("Azul")).toBeTruthy();
|
|
631
|
+
expect(getByText("Negro")).toBeTruthy();
|
|
632
|
+
expect(getByText("Ciudades españolas")).toBeTruthy();
|
|
633
|
+
expect(getByText("Madrid")).toBeTruthy();
|
|
634
|
+
expect(getAllByRole("group").length).toBe(3);
|
|
635
|
+
expect(getAllByRole("presentation").length).toBe(3);
|
|
636
|
+
expect(getAllByRole("option").length).toBe(18);
|
|
637
|
+
userEvent.click(select);
|
|
638
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
639
|
+
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
640
|
+
});
|
|
641
|
+
test("Grouped Options - If an empty list of options in a group is passed, the select is rendered but doestn't open the listbox", () => {
|
|
642
|
+
const { getByRole, queryByRole } = render(
|
|
643
|
+
<DxcSelect
|
|
644
|
+
label="test-select-label"
|
|
645
|
+
options={[
|
|
646
|
+
{
|
|
647
|
+
label: "Group 1",
|
|
648
|
+
options: [],
|
|
649
|
+
},
|
|
650
|
+
]}
|
|
651
|
+
/>
|
|
652
|
+
);
|
|
653
|
+
const select = getByRole("combobox");
|
|
654
|
+
|
|
655
|
+
userEvent.click(select);
|
|
656
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
657
|
+
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
658
|
+
});
|
|
659
|
+
test("Grouped Options - Click in an option selects it and closes the listbox", () => {
|
|
660
|
+
const onChange = jest.fn();
|
|
661
|
+
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
662
|
+
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} />
|
|
663
|
+
);
|
|
664
|
+
const select = getByRole("combobox");
|
|
665
|
+
|
|
666
|
+
userEvent.click(select);
|
|
667
|
+
userEvent.click(getAllByRole("option")[8]);
|
|
668
|
+
expect(onChange).toHaveBeenCalledWith({ value: "oviedo", error: null });
|
|
669
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
670
|
+
expect(getByText("Oviedo")).toBeTruthy();
|
|
671
|
+
userEvent.click(select);
|
|
672
|
+
expect(getAllByRole("option")[8].getAttribute("aria-selected")).toBe("true");
|
|
673
|
+
});
|
|
674
|
+
test("Grouped Options - Optional renders an empty first option (out of any group) with the placeholder as its label", () => {
|
|
675
|
+
const onChange = jest.fn();
|
|
676
|
+
const { getByRole, getAllByRole, getAllByText } = render(
|
|
677
|
+
<DxcSelect
|
|
678
|
+
label="test-select-label"
|
|
679
|
+
placeholder="Placeholder example"
|
|
680
|
+
options={group_options}
|
|
681
|
+
onChange={onChange}
|
|
682
|
+
optional
|
|
683
|
+
/>
|
|
684
|
+
);
|
|
685
|
+
const select = getByRole("combobox");
|
|
686
|
+
|
|
687
|
+
userEvent.click(select);
|
|
688
|
+
expect(getAllByText("Placeholder example").length).toBe(2);
|
|
689
|
+
expect(getAllByRole("option")[0].getAttribute("aria-selected")).toBe("true");
|
|
690
|
+
userEvent.click(getAllByRole("option")[0]);
|
|
691
|
+
expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
|
|
692
|
+
expect(getAllByText("Placeholder example").length).toBe(1);
|
|
693
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
694
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
695
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
696
|
+
expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
|
|
697
|
+
expect(getAllByText("Placeholder example").length).toBe(1);
|
|
698
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
699
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
700
|
+
});
|
|
701
|
+
test("Grouped Options - Renders icons correctly when passed with group options", () => {
|
|
702
|
+
const { getByRole, getAllByRole } = render(
|
|
703
|
+
<DxcSelect label="test-select-label" options={grouped_icon_options} optional />
|
|
704
|
+
);
|
|
705
|
+
const select = getByRole("combobox");
|
|
706
|
+
|
|
707
|
+
userEvent.click(select);
|
|
708
|
+
expect(getByRole("listbox").querySelectorAll("img").length).toBe(4);
|
|
709
|
+
expect(getAllByRole("option").length).toBe(11);
|
|
710
|
+
});
|
|
711
|
+
test("Grouped Options: Arrow up key - Opens the listbox and visually focus the last option", () => {
|
|
712
|
+
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={group_options} />);
|
|
713
|
+
const select = getByRole("combobox");
|
|
714
|
+
|
|
715
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
716
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
717
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-17");
|
|
718
|
+
});
|
|
719
|
+
test("Grouped Options: Arrow up key - Puts the focus in last option when the first one is visually focused", () => {
|
|
720
|
+
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={group_options} />);
|
|
721
|
+
const select = getByRole("combobox");
|
|
722
|
+
|
|
723
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
724
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
725
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
726
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-17");
|
|
727
|
+
});
|
|
728
|
+
test("Grouped Options: Arrow down key - Opens the listbox and visually focus the first option", () => {
|
|
729
|
+
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={group_options} />);
|
|
730
|
+
const select = getByRole("combobox");
|
|
731
|
+
|
|
732
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
733
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
734
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
735
|
+
});
|
|
736
|
+
test("Grouped Options: Arrow down key - Puts the focus in the first option when the last one is visually focused", () => {
|
|
737
|
+
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={group_options} />);
|
|
738
|
+
const select = getByRole("combobox");
|
|
739
|
+
|
|
740
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
741
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
742
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
743
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
744
|
+
});
|
|
745
|
+
test("Grouped Options: Enter key - Selects the visually focused option and closes the listbox", () => {
|
|
746
|
+
const onChange = jest.fn();
|
|
747
|
+
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
748
|
+
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} optional />
|
|
749
|
+
);
|
|
750
|
+
const select = getByRole("combobox");
|
|
751
|
+
|
|
752
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
753
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
754
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
755
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
756
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
757
|
+
expect(onChange).toHaveBeenCalledWith({ value: "ebro", error: null });
|
|
758
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
759
|
+
expect(getByText("Ebro")).toBeTruthy();
|
|
760
|
+
userEvent.click(select);
|
|
761
|
+
expect(getAllByRole("option")[18].getAttribute("aria-selected")).toBe("true");
|
|
762
|
+
});
|
|
763
|
+
test("Grouped Options: Searchable - Displays an input for filtering the list of options", () => {
|
|
764
|
+
const onChange = jest.fn();
|
|
765
|
+
const { container, getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
766
|
+
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} searchable />
|
|
767
|
+
);
|
|
768
|
+
const select = getByRole("combobox");
|
|
769
|
+
const searchInput = container.querySelectorAll("input")[1];
|
|
770
|
+
|
|
771
|
+
userEvent.click(select);
|
|
772
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
773
|
+
userEvent.type(searchInput, "ro");
|
|
774
|
+
expect(getAllByRole("group").length).toBe(2);
|
|
775
|
+
expect(getAllByRole("presentation").length).toBe(2);
|
|
776
|
+
expect(getAllByRole("option").length).toBe(5);
|
|
777
|
+
expect(getByText("Colores")).toBeTruthy();
|
|
778
|
+
expect(getByText("Ríos españoles")).toBeTruthy();
|
|
779
|
+
userEvent.click(getAllByRole("option")[4]);
|
|
780
|
+
expect(onChange).toHaveBeenCalledWith({ value: "ebro", error: null });
|
|
781
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
782
|
+
expect(getByText("Ebro")).toBeTruthy();
|
|
783
|
+
expect(searchInput.value).toBe("");
|
|
784
|
+
userEvent.click(select);
|
|
785
|
+
expect(getAllByRole("option")[17].getAttribute("aria-selected")).toBe("true");
|
|
786
|
+
});
|
|
787
|
+
test("Grouped Options: Searchable - Displays 'No matches found' when there are no filtering results", () => {
|
|
788
|
+
const onChange = jest.fn();
|
|
789
|
+
const { container, getByText, getByRole } = render(
|
|
790
|
+
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} searchable />
|
|
791
|
+
);
|
|
792
|
+
const select = getByRole("combobox");
|
|
793
|
+
const searchInput = container.querySelectorAll("input")[1];
|
|
794
|
+
|
|
795
|
+
userEvent.click(select);
|
|
796
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
797
|
+
userEvent.type(searchInput, "very long string");
|
|
798
|
+
expect(getByText("No matches found")).toBeTruthy();
|
|
799
|
+
});
|
|
800
|
+
test("Grouped Options: Multiple selection - Displays a checkbox per option and enables the multi-selection", () => {
|
|
801
|
+
const onChange = jest.fn();
|
|
802
|
+
const { getByText, getAllByText, getByRole, getAllByRole, queryByRole } = render(
|
|
803
|
+
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} multiple />
|
|
804
|
+
);
|
|
805
|
+
const select = getByRole("combobox");
|
|
806
|
+
|
|
807
|
+
userEvent.click(select);
|
|
808
|
+
expect(getByRole("listbox").getAttribute("aria-multiselectable")).toBe("true");
|
|
809
|
+
userEvent.click(getAllByRole("option")[10]);
|
|
810
|
+
// expect(onChange).toHaveBeenCalledWith({ value: ["bilbao"], error: null });
|
|
811
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
812
|
+
expect(getAllByText("Bilbao").length).toBe(2);
|
|
813
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
814
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
815
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
816
|
+
// expect(onChange).toHaveBeenCalledWith({ value: ["bilbao", "guadalquivir"], error: null });
|
|
817
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
818
|
+
expect(getByText("Bilbao, Guadalquivir")).toBeTruthy();
|
|
819
|
+
expect(getAllByRole("option")[10].getAttribute("aria-selected")).toBe("true");
|
|
820
|
+
expect(getAllByRole("option")[16].getAttribute("aria-selected")).toBe("true");
|
|
821
|
+
});
|
|
822
|
+
test("Grouped Options: Multiple selection - Clear action and selection indicator", () => {
|
|
823
|
+
const onChange = jest.fn();
|
|
824
|
+
const { getByText, queryByText, getByRole, getAllByRole, queryByRole, getByTitle, queryByTitle } = render(
|
|
825
|
+
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} multiple />
|
|
826
|
+
);
|
|
827
|
+
const select = getByRole("combobox");
|
|
828
|
+
|
|
829
|
+
userEvent.click(select);
|
|
830
|
+
userEvent.click(getAllByRole("option")[5]);
|
|
831
|
+
userEvent.click(getAllByRole("option")[8]);
|
|
832
|
+
userEvent.click(getAllByRole("option")[13]);
|
|
833
|
+
userEvent.click(getAllByRole("option")[17]);
|
|
834
|
+
// expect(onChange).toHaveBeenCalledWith({ value: ["blanco", "oviedo", "duero", "ebro"], error: null });
|
|
835
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
836
|
+
expect(getByText("Blanco, Oviedo, Duero, Ebro")).toBeTruthy();
|
|
837
|
+
expect(getByText("4", { exact: true })).toBeTruthy();
|
|
838
|
+
userEvent.click(getByTitle("Clear selected options"));
|
|
839
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
840
|
+
expect(queryByText("Blanco, Oviedo, Duero, Ebro")).toBeFalsy();
|
|
841
|
+
expect(queryByText("4")).toBeFalsy();
|
|
842
|
+
expect(queryByTitle("Clear selected options")).toBeFalsy();
|
|
843
|
+
});
|
|
844
|
+
test("Grouped Options: Multiple selection - Optional option should not be added when the select is marked as multiple", () => {
|
|
845
|
+
const onChange = jest.fn();
|
|
846
|
+
const { getByText, getAllByText, getByRole, getAllByRole } = render(
|
|
847
|
+
<DxcSelect
|
|
848
|
+
label="test-select-label"
|
|
849
|
+
placeholder="Choose an option"
|
|
850
|
+
options={group_options}
|
|
851
|
+
onChange={onChange}
|
|
852
|
+
multiple
|
|
853
|
+
optional
|
|
854
|
+
/>
|
|
855
|
+
);
|
|
856
|
+
const select = getByRole("combobox");
|
|
857
|
+
|
|
858
|
+
expect(getByText("(Optional)")).toBeTruthy();
|
|
859
|
+
userEvent.click(select);
|
|
860
|
+
expect(getAllByText("Choose an option").length).toBe(1);
|
|
861
|
+
expect(getAllByRole("option")[0].getAttribute("aria-selected")).toBe("false");
|
|
862
|
+
userEvent.click(getAllByRole("option")[0]);
|
|
863
|
+
// expect(onChange).toHaveBeenCalledWith({ value: ["azul"], error: null });
|
|
864
|
+
expect(getAllByText("Azul").length).toBe(2);
|
|
865
|
+
});
|
|
866
|
+
test("Grouped Options - If an options was previously selected when its opened (by key press), the visual focus appears always in the selected option", () => {
|
|
867
|
+
const { getByText, getByRole, getAllByRole } = render(
|
|
868
|
+
<DxcSelect label="test-select-label" options={group_options} />
|
|
869
|
+
);
|
|
870
|
+
const select = getByRole("combobox");
|
|
871
|
+
|
|
872
|
+
userEvent.click(select);
|
|
873
|
+
userEvent.click(getAllByRole("option")[2]);
|
|
874
|
+
expect(getByText("Rosa")).toBeTruthy();
|
|
875
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
876
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-2");
|
|
877
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
878
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
879
|
+
expect(getByText("Rojo")).toBeTruthy();
|
|
880
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
881
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-1");
|
|
882
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
883
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
884
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
885
|
+
expect(getByText("Verde")).toBeTruthy();
|
|
886
|
+
});
|
|
887
|
+
test("Grouped Options - If an options was previously selected when its opened (by click and key press), the visual focus appears always in the selected option", () => {
|
|
888
|
+
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
889
|
+
<DxcSelect label="test-select-label" options={group_options} />
|
|
890
|
+
);
|
|
891
|
+
const select = getByRole("combobox");
|
|
892
|
+
|
|
893
|
+
userEvent.click(select);
|
|
894
|
+
userEvent.click(getAllByRole("option")[17]);
|
|
895
|
+
expect(getByText("Ebro")).toBeTruthy();
|
|
896
|
+
userEvent.click(select);
|
|
897
|
+
expect(select.getAttribute("aria-activedescendant")).toBeNull();
|
|
898
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
899
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-17");
|
|
900
|
+
userEvent.click(select);
|
|
901
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
902
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-17");
|
|
903
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
904
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
905
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
906
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
907
|
+
expect(getByText("Azul")).toBeTruthy();
|
|
908
|
+
});
|
|
909
|
+
test("Renders with correct aria attributes", () => {
|
|
910
|
+
const { getByText, getByRole } = render(
|
|
911
|
+
<DxcSelect label="test-select-label" placeholder="Example" options={single_options} />
|
|
912
|
+
);
|
|
913
|
+
const select = getByRole("combobox");
|
|
914
|
+
const label = getByText("test-select-label");
|
|
915
|
+
|
|
916
|
+
expect(select.getAttribute("aria-haspopup")).toBe("listbox");
|
|
917
|
+
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
918
|
+
expect(select.getAttribute("aria-required")).toBe("true");
|
|
919
|
+
expect(select.getAttribute("aria-labelledby")).toBe(label.id);
|
|
920
|
+
expect(select.getAttribute("aria-activedescendant")).toBeNull();
|
|
921
|
+
expect(select.getAttribute("aria-invalid")).toBe("false");
|
|
922
|
+
userEvent.click(select);
|
|
923
|
+
const list = getByRole("listbox");
|
|
924
|
+
expect(select.getAttribute("aria-controls")).toBe(list.id);
|
|
925
|
+
expect(list.getAttribute("aria-multiselectable")).toBe("false");
|
|
926
|
+
expect(list.getAttribute("aria-labelledby")).toBe(label.id);
|
|
927
|
+
});
|
|
415
928
|
});
|