@dxc-technology/halstack-react 0.0.0-5b2ad05 → 0.0.0-5b6503c
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/README.md +1 -1
- package/dist/V3Select/index.d.ts +27 -0
- package/dist/V3Textarea/index.d.ts +27 -0
- package/dist/accordion/index.d.ts +28 -0
- package/dist/accordion-group/index.d.ts +16 -0
- package/dist/box/index.d.ts +25 -0
- package/dist/button/index.d.ts +24 -0
- package/dist/card/index.d.ts +22 -0
- package/dist/checkbox/index.d.ts +24 -0
- package/dist/chip/index.d.ts +22 -0
- package/dist/common/variables.js +60 -64
- package/dist/date/Date.js +6 -6
- package/dist/date/index.d.ts +27 -0
- package/dist/dialog/index.d.ts +18 -0
- package/dist/dropdown/index.d.ts +26 -0
- package/dist/file-input/FileItem.js +8 -1
- package/dist/file-input/index.d.ts +1 -1
- package/dist/footer/index.d.ts +25 -0
- package/dist/header/index.d.ts +25 -0
- package/dist/heading/index.d.ts +17 -0
- package/dist/input-text/InputText.js +4 -4
- package/dist/input-text/index.d.ts +36 -0
- package/dist/link/index.d.ts +23 -0
- package/dist/main.d.ts +36 -4
- package/dist/main.js +3 -3
- package/dist/paginator/Paginator.js +51 -29
- package/dist/paginator/index.d.ts +20 -0
- package/dist/password-input/PasswordInput.js +6 -1
- package/dist/progress-bar/index.d.ts +18 -0
- package/dist/radio/index.d.ts +23 -0
- package/dist/resultsetTable/index.d.ts +19 -0
- package/dist/select/Select.js +193 -182
- package/dist/sidenav/index.d.ts +13 -0
- package/dist/slider/index.d.ts +29 -0
- package/dist/spinner/index.d.ts +17 -0
- package/dist/switch/index.d.ts +24 -0
- package/dist/table/index.d.ts +13 -0
- package/dist/tabs/index.d.ts +19 -0
- package/dist/tag/index.d.ts +24 -0
- package/dist/text-input/TextInput.js +3 -0
- package/dist/toggle/index.d.ts +21 -0
- package/dist/toggle-group/index.d.ts +21 -0
- package/dist/upload/Upload.js +3 -3
- package/dist/upload/index.d.ts +15 -0
- package/dist/wizard/index.d.ts +18 -0
- package/package.json +1 -1
- package/test/Date.test.js +34 -36
- package/test/InputText.test.js +16 -24
- package/test/Paginator.test.js +5 -1
- package/test/ResultsetTable.test.js +5 -4
- package/test/Select.test.js +415 -0
- package/test/TextInput.test.js +5 -5
- package/test/Upload.test.js +4 -4
package/test/InputText.test.js
CHANGED
|
@@ -4,7 +4,7 @@ import userEvent from "@testing-library/user-event";
|
|
|
4
4
|
|
|
5
5
|
import icon from "../../app/src/images/invision.svg";
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import DxcInputText from "../src/input-text/InputText";
|
|
8
8
|
|
|
9
9
|
const countries = ["Albania", "Andorra", "Armenia", "Austria", "Azerbaijan"];
|
|
10
10
|
|
|
@@ -28,13 +28,13 @@ jest.mock("popper.js", () => {
|
|
|
28
28
|
|
|
29
29
|
describe("InputText component tests", () => {
|
|
30
30
|
test("Input renders with correct label", () => {
|
|
31
|
-
const { getByText } = render(<
|
|
31
|
+
const { getByText } = render(<DxcInputText label="Input label" />);
|
|
32
32
|
expect(getByText("Input label")).toBeTruthy();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test("onChange function is called correctly", () => {
|
|
36
36
|
const onChange = jest.fn();
|
|
37
|
-
const { getByRole } = render(<
|
|
37
|
+
const { getByRole } = render(<DxcInputText label="Input label" onChange={onChange} />);
|
|
38
38
|
const input = getByRole("textbox");
|
|
39
39
|
userEvent.type(input, "20000");
|
|
40
40
|
expect(onChange).toHaveBeenCalled();
|
|
@@ -44,7 +44,7 @@ describe("InputText component tests", () => {
|
|
|
44
44
|
const onBlur = jest.fn();
|
|
45
45
|
const onChange = jest.fn();
|
|
46
46
|
|
|
47
|
-
const { getByRole } = render(<
|
|
47
|
+
const { getByRole } = render(<DxcInputText label="Input label" onChange={onChange} onBlur={onBlur} />);
|
|
48
48
|
const input = getByRole("textbox");
|
|
49
49
|
userEvent.type(input, "Test value");
|
|
50
50
|
fireEvent.blur(input);
|
|
@@ -54,7 +54,7 @@ describe("InputText component tests", () => {
|
|
|
54
54
|
|
|
55
55
|
test("Uncontrolled component", () => {
|
|
56
56
|
const onChange = jest.fn();
|
|
57
|
-
const { getByRole } = render(<
|
|
57
|
+
const { getByRole } = render(<DxcInputText label="Input label" onChange={onChange} />);
|
|
58
58
|
const input = getByRole("textbox");
|
|
59
59
|
userEvent.type(input, "20000");
|
|
60
60
|
expect(onChange).toHaveBeenCalled();
|
|
@@ -66,7 +66,7 @@ describe("InputText component tests", () => {
|
|
|
66
66
|
const onChange = jest.fn();
|
|
67
67
|
const onBlur = jest.fn();
|
|
68
68
|
const { getByRole } = render(
|
|
69
|
-
<
|
|
69
|
+
<DxcInputText label="Input label" value="Test value" onChange={onChange} onBlur={onBlur} />
|
|
70
70
|
);
|
|
71
71
|
const input = getByRole("textbox");
|
|
72
72
|
userEvent.type(input, "20000");
|
|
@@ -78,14 +78,14 @@ describe("InputText component tests", () => {
|
|
|
78
78
|
});
|
|
79
79
|
test("Prefix icon onClick", () => {
|
|
80
80
|
const onClick = jest.fn();
|
|
81
|
-
const { getByRole } = render(<
|
|
81
|
+
const { getByRole } = render(<DxcInputText label="Input label" prefixIconSrc={icon} onClickPrefix={onClick} />);
|
|
82
82
|
const prefixIcon = getByRole("img");
|
|
83
83
|
userEvent.click(prefixIcon);
|
|
84
84
|
expect(onClick).toHaveBeenCalled();
|
|
85
85
|
});
|
|
86
86
|
test("Suffix icon onClick", () => {
|
|
87
87
|
const onClick = jest.fn();
|
|
88
|
-
const { getByRole } = render(<
|
|
88
|
+
const { getByRole } = render(<DxcInputText label="Input label" suffixIconSrc={icon} onClickSuffix={onClick} />);
|
|
89
89
|
const suffixIcon = getByRole("img");
|
|
90
90
|
userEvent.click(suffixIcon);
|
|
91
91
|
expect(onClick).toHaveBeenCalled();
|
|
@@ -96,7 +96,7 @@ describe("Autocomplete component Synchronous tests", () => {
|
|
|
96
96
|
test("Autocomplete no matches found is shown", async () => {
|
|
97
97
|
const onChangeAtocomplete = jest.fn();
|
|
98
98
|
render(
|
|
99
|
-
<
|
|
99
|
+
<DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
|
|
100
100
|
);
|
|
101
101
|
const input = screen.getByRole("textbox");
|
|
102
102
|
fireEvent.focus(input);
|
|
@@ -108,7 +108,7 @@ describe("Autocomplete component Synchronous tests", () => {
|
|
|
108
108
|
test("Autocomplete suggestions are shown", async () => {
|
|
109
109
|
const onChangeAtocomplete = jest.fn();
|
|
110
110
|
render(
|
|
111
|
-
<
|
|
111
|
+
<DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
|
|
112
112
|
);
|
|
113
113
|
const input = screen.getByRole("textbox");
|
|
114
114
|
fireEvent.focus(input);
|
|
@@ -118,7 +118,7 @@ describe("Autocomplete component Synchronous tests", () => {
|
|
|
118
118
|
test("Autocomplete UNCONTROLLED suggestion selected", async () => {
|
|
119
119
|
const onChangeAtocomplete = jest.fn();
|
|
120
120
|
render(
|
|
121
|
-
<
|
|
121
|
+
<DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
|
|
122
122
|
);
|
|
123
123
|
const input = screen.getByRole("textbox");
|
|
124
124
|
fireEvent.focus(input);
|
|
@@ -138,7 +138,7 @@ describe("Autocomplete component Synchronous tests", () => {
|
|
|
138
138
|
test("Autocomplete CONTROLLED suggestions selected", async () => {
|
|
139
139
|
const onChangeAtocomplete = jest.fn();
|
|
140
140
|
render(
|
|
141
|
-
<
|
|
141
|
+
<DxcInputText
|
|
142
142
|
label="Autocomplete Countries"
|
|
143
143
|
value="Andorra"
|
|
144
144
|
autocompleteOptions={countries}
|
|
@@ -165,11 +165,7 @@ describe("InputText component Asynchronous Autocomplete tests", () => {
|
|
|
165
165
|
|
|
166
166
|
const onChangeAtocomplete = jest.fn();
|
|
167
167
|
render(
|
|
168
|
-
<
|
|
169
|
-
label="Autocomplete Countries"
|
|
170
|
-
autocompleteOptions={callbackFunc}
|
|
171
|
-
onChange={onChangeAtocomplete}
|
|
172
|
-
/>
|
|
168
|
+
<DxcInputText label="Autocomplete Countries" autocompleteOptions={callbackFunc} onChange={onChangeAtocomplete} />
|
|
173
169
|
);
|
|
174
170
|
const input = screen.getByRole("textbox");
|
|
175
171
|
fireEvent.focus(input);
|
|
@@ -182,11 +178,7 @@ describe("InputText component Asynchronous Autocomplete tests", () => {
|
|
|
182
178
|
const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 1000)));
|
|
183
179
|
const onChangeAtocomplete = jest.fn();
|
|
184
180
|
render(
|
|
185
|
-
<
|
|
186
|
-
label="Autocomplete Countries"
|
|
187
|
-
onChange={onChangeAtocomplete}
|
|
188
|
-
autocompleteOptions={callbackFunc}
|
|
189
|
-
/>
|
|
181
|
+
<DxcInputText label="Autocomplete Countries" onChange={onChangeAtocomplete} autocompleteOptions={callbackFunc} />
|
|
190
182
|
);
|
|
191
183
|
const input = screen.getByRole("textbox");
|
|
192
184
|
fireEvent.focus(input);
|
|
@@ -206,7 +198,7 @@ describe("InputText component Asynchronous Autocomplete tests", () => {
|
|
|
206
198
|
const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 3000)));
|
|
207
199
|
const onChangeAtocomplete = jest.fn();
|
|
208
200
|
render(
|
|
209
|
-
<
|
|
201
|
+
<DxcInputText
|
|
210
202
|
label="Autocomplete Countries"
|
|
211
203
|
value="test value"
|
|
212
204
|
onChange={onChangeAtocomplete}
|
|
@@ -232,7 +224,7 @@ describe("InputText component Asynchronous Autocomplete tests", () => {
|
|
|
232
224
|
const onChangeAtocomplete = jest.fn();
|
|
233
225
|
|
|
234
226
|
render(
|
|
235
|
-
<
|
|
227
|
+
<DxcInputText
|
|
236
228
|
label="Autocomplete Countries"
|
|
237
229
|
value="test value"
|
|
238
230
|
onChange={onChangeAtocomplete}
|
package/test/Paginator.test.js
CHANGED
|
@@ -49,6 +49,8 @@ describe("Paginator component tests", () => {
|
|
|
49
49
|
|
|
50
50
|
test("Paginator goToPage call correct function", () => {
|
|
51
51
|
const onClick = jest.fn();
|
|
52
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
53
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
52
54
|
const { getByText, getAllByRole, getByRole } = render(
|
|
53
55
|
<DxcPaginator
|
|
54
56
|
currentPage={1}
|
|
@@ -58,7 +60,7 @@ describe("Paginator component tests", () => {
|
|
|
58
60
|
onPageChange={onClick}
|
|
59
61
|
></DxcPaginator>
|
|
60
62
|
);
|
|
61
|
-
const goToPageSelect = getAllByRole("
|
|
63
|
+
const goToPageSelect = getAllByRole("combobox")[0];
|
|
62
64
|
act(() => {
|
|
63
65
|
userEvent.click(goToPageSelect);
|
|
64
66
|
});
|
|
@@ -81,6 +83,8 @@ describe("Paginator component tests", () => {
|
|
|
81
83
|
|
|
82
84
|
test("Call correct itemsPerPageFunction", () => {
|
|
83
85
|
const onClick = jest.fn();
|
|
86
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
87
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
84
88
|
const { getAllByText, getByText } = render(
|
|
85
89
|
<DxcPaginator
|
|
86
90
|
currentPage={1}
|
|
@@ -244,7 +244,7 @@ describe("ResultsetTable component tests", () => {
|
|
|
244
244
|
expect(getByText("Louis")).toBeTruthy();
|
|
245
245
|
expect(getByText("Lana")).toBeTruthy();
|
|
246
246
|
expect(getAllByRole("row").length - 1).toEqual(3);
|
|
247
|
-
const nextButton = getAllByRole("button")[
|
|
247
|
+
const nextButton = getAllByRole("button")[2];
|
|
248
248
|
fireEvent.click(nextButton);
|
|
249
249
|
expect(getByText("4 to 6 of 10")).toBeTruthy();
|
|
250
250
|
// expect(getByText("Page: 2 of 4")).toBeTruthy();
|
|
@@ -255,6 +255,8 @@ describe("ResultsetTable component tests", () => {
|
|
|
255
255
|
});
|
|
256
256
|
|
|
257
257
|
test("Resultsettable goToPage works as expected", () => {
|
|
258
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
259
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
258
260
|
const { getByText, getAllByRole, getByRole } = render(
|
|
259
261
|
<DxcResultsetTable columns={columns} showGoToPage={true} rows={rows} itemsPerPage={3}></DxcResultsetTable>
|
|
260
262
|
);
|
|
@@ -282,8 +284,7 @@ describe("ResultsetTable component tests", () => {
|
|
|
282
284
|
const { getByText, getAllByRole } = render(
|
|
283
285
|
<DxcResultsetTable columns={columns} rows={rows} itemsPerPage={3}></DxcResultsetTable>
|
|
284
286
|
);
|
|
285
|
-
|
|
286
|
-
const lastButton = getAllByRole("button")[4];
|
|
287
|
+
const lastButton = getAllByRole("button")[3];
|
|
287
288
|
fireEvent.click(lastButton);
|
|
288
289
|
expect(getByText("10 to 10 of 10")).toBeTruthy();
|
|
289
290
|
expect(getAllByRole("row")).toHaveLength(2);
|
|
@@ -319,7 +320,7 @@ describe("ResultsetTable component tests", () => {
|
|
|
319
320
|
itemsPerPageOptions={[2, 3]}
|
|
320
321
|
></DxcResultsetTable>
|
|
321
322
|
);
|
|
322
|
-
const lastButton = getAllByRole("button")[
|
|
323
|
+
const lastButton = getAllByRole("button")[3];
|
|
323
324
|
fireEvent.click(lastButton);
|
|
324
325
|
expect(getAllByRole("row").length - 1).toEqual(1);
|
|
325
326
|
rerender(<DxcResultsetTable columns={columns} rows={rows} itemsPerPage={6}></DxcResultsetTable>);
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import DxcSelect from "../src/select/Select";
|
|
3
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
const single_options = [
|
|
7
|
+
{ label: "Option 01", value: "1" },
|
|
8
|
+
{ label: "Option 02", value: "2" },
|
|
9
|
+
{ label: "Option 03", value: "3" },
|
|
10
|
+
{ label: "Option 04", value: "4" },
|
|
11
|
+
{ label: "Option 05", value: "5" },
|
|
12
|
+
{ label: "Option 06", value: "6" },
|
|
13
|
+
{ label: "Option 07", value: "7" },
|
|
14
|
+
{ label: "Option 08", value: "8" },
|
|
15
|
+
{ label: "Option 09", value: "9" },
|
|
16
|
+
{ label: "Option 10", value: "10" },
|
|
17
|
+
{ label: "Option 11", value: "11" },
|
|
18
|
+
{ label: "Option 12", value: "12" },
|
|
19
|
+
{ label: "Option 13", value: "13" },
|
|
20
|
+
{ label: "Option 14", value: "14" },
|
|
21
|
+
{ label: "Option 15", value: "15" },
|
|
22
|
+
{ label: "Option 16", value: "16" },
|
|
23
|
+
{ label: "Option 17", value: "17" },
|
|
24
|
+
{ label: "Option 18", value: "18" },
|
|
25
|
+
{ label: "Option 19", value: "19" },
|
|
26
|
+
{ label: "Option 20", value: "20" },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const group_options = [
|
|
30
|
+
{
|
|
31
|
+
label: "Group 1",
|
|
32
|
+
options: [
|
|
33
|
+
{ label: "Option 001", value: "1" },
|
|
34
|
+
{ label: "Option 002", value: "2" },
|
|
35
|
+
{ label: "Option 003", value: "3" },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
label: "Group 2",
|
|
40
|
+
options: [
|
|
41
|
+
{ label: "Option 0004", value: "4" },
|
|
42
|
+
{ label: "Option 05", value: "5" },
|
|
43
|
+
{ label: "Option 006", value: "6" },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
label: "Group 3",
|
|
48
|
+
options: [
|
|
49
|
+
{ label: "Option 0007", value: "7" },
|
|
50
|
+
{ label: "Option 008", value: "8" },
|
|
51
|
+
{ label: "Option 9", value: "9" },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
label: "Group 4",
|
|
56
|
+
options: [
|
|
57
|
+
{ label: "Option 10", value: "10" },
|
|
58
|
+
{ label: "Option 11", value: "11" },
|
|
59
|
+
{ label: "Option 12", value: "12" },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
label: "Group 5",
|
|
64
|
+
options: [
|
|
65
|
+
{ label: "Option x", value: "13" },
|
|
66
|
+
{ label: "Option y", value: "14" },
|
|
67
|
+
{ label: "Option z", value: "15" },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
label: "Group 6",
|
|
72
|
+
options: [
|
|
73
|
+
{ label: "Option 001", value: "16" },
|
|
74
|
+
{ label: "Option 002", value: "17" },
|
|
75
|
+
{ label: "Option 003", value: "18" },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
label: "Group 7",
|
|
80
|
+
options: [
|
|
81
|
+
{ label: "Option 001", value: "19" },
|
|
82
|
+
{ label: "Option 002", value: "20" },
|
|
83
|
+
{ label: "Option 003", value: "21" },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
describe("Select component tests", () => {
|
|
89
|
+
test("Renders with correct label, helper text and placeholder", () => {
|
|
90
|
+
const { getByText } = render(
|
|
91
|
+
<DxcSelect label="test-select-label" helperText="test-select-helper-text" placeholder="Example text" />
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
expect(getByText("test-select-label")).toBeTruthy();
|
|
95
|
+
expect(getByText("test-select-helper-text")).toBeTruthy();
|
|
96
|
+
expect(getByText("Example text")).toBeTruthy();
|
|
97
|
+
});
|
|
98
|
+
test("Renders with correct optional label", () => {
|
|
99
|
+
const { getByText } = render(<DxcSelect label="test-select-label" optional />);
|
|
100
|
+
|
|
101
|
+
expect(getByText("test-select-label")).toBeTruthy();
|
|
102
|
+
expect(getByText("(Optional)")).toBeTruthy();
|
|
103
|
+
});
|
|
104
|
+
test("Renders with error message", () => {
|
|
105
|
+
const { getByText, getByRole } = render(<DxcSelect label="test-select-label" error="Error message." />);
|
|
106
|
+
const select = getByRole("combobox");
|
|
107
|
+
|
|
108
|
+
expect(getByText("Error message.")).toBeTruthy();
|
|
109
|
+
expect(select.getAttribute("aria-invalid")).toBe("true");
|
|
110
|
+
});
|
|
111
|
+
test("Disabled select - Clear all options action must be shown but not clickable", () => {
|
|
112
|
+
const { getByRole, getByText, queryByRole } = render(
|
|
113
|
+
<DxcSelect label="test-select-label" value={["1", "2"]} options={single_options} disabled searchable multiple />
|
|
114
|
+
);
|
|
115
|
+
const select = getByRole("combobox");
|
|
116
|
+
|
|
117
|
+
userEvent.click(select);
|
|
118
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
119
|
+
userEvent.click(getByRole("button"));
|
|
120
|
+
expect(getByText("Option 01, Option 02")).toBeTruthy();
|
|
121
|
+
});
|
|
122
|
+
test("Focused select does not open the listbox", () => {
|
|
123
|
+
const { getByRole, queryByRole } = render(
|
|
124
|
+
<DxcSelect label="test-select-label" value={["1", "2"]} options={single_options} disabled searchable multiple />
|
|
125
|
+
);
|
|
126
|
+
const select = getByRole("combobox");
|
|
127
|
+
|
|
128
|
+
fireEvent.focus(select);
|
|
129
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
130
|
+
});
|
|
131
|
+
test("Controlled - Not optional constraint", () => {
|
|
132
|
+
// scrollIntoView & scrollTo are not implemented in jsdom
|
|
133
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
134
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
135
|
+
const onChange = jest.fn();
|
|
136
|
+
const onBlur = jest.fn();
|
|
137
|
+
const { getByRole, getAllByRole } = render(
|
|
138
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} onBlur={onBlur} />
|
|
139
|
+
);
|
|
140
|
+
const select = getByRole("combobox");
|
|
141
|
+
|
|
142
|
+
expect(select.getAttribute("aria-required")).toBe("true");
|
|
143
|
+
fireEvent.focus(select);
|
|
144
|
+
fireEvent.blur(select);
|
|
145
|
+
expect(onBlur).toHaveBeenCalled();
|
|
146
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
147
|
+
userEvent.click(select);
|
|
148
|
+
userEvent.click(getAllByRole("option")[0]);
|
|
149
|
+
expect(onChange).toHaveBeenCalled();
|
|
150
|
+
expect(onChange).toHaveBeenCalledWith({ value: "1", error: null });
|
|
151
|
+
fireEvent.focus(select);
|
|
152
|
+
fireEvent.blur(select);
|
|
153
|
+
expect(onBlur).toHaveBeenCalled();
|
|
154
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "1", error: null });
|
|
155
|
+
});
|
|
156
|
+
test("Controlled - Optional constraint", () => {
|
|
157
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
158
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
159
|
+
const onChange = jest.fn();
|
|
160
|
+
const onBlur = jest.fn();
|
|
161
|
+
const { getByRole } = render(
|
|
162
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} onBlur={onBlur} optional />
|
|
163
|
+
);
|
|
164
|
+
const select = getByRole("combobox");
|
|
165
|
+
|
|
166
|
+
expect(select.getAttribute("aria-required")).toBe("false");
|
|
167
|
+
fireEvent.focus(select);
|
|
168
|
+
fireEvent.blur(select);
|
|
169
|
+
expect(onBlur).toHaveBeenCalled();
|
|
170
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null });
|
|
171
|
+
expect(select.getAttribute("aria-invalid")).toBe("false");
|
|
172
|
+
});
|
|
173
|
+
test("Non-Grouped Options - Opens listbox or closes it with a click on select", () => {
|
|
174
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
175
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
176
|
+
const { getByText, getByRole, queryByRole } = render(
|
|
177
|
+
<DxcSelect label="test-select-label" options={single_options} />
|
|
178
|
+
);
|
|
179
|
+
const select = getByRole("combobox");
|
|
180
|
+
|
|
181
|
+
userEvent.click(select);
|
|
182
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
183
|
+
expect(select.getAttribute("aria-expanded")).toBe("true");
|
|
184
|
+
expect(getByText("Option 01")).toBeTruthy();
|
|
185
|
+
expect(getByText("Option 02")).toBeTruthy();
|
|
186
|
+
expect(getByText("Option 08")).toBeTruthy();
|
|
187
|
+
expect(getByText("Option 09")).toBeTruthy();
|
|
188
|
+
userEvent.click(select);
|
|
189
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
190
|
+
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
191
|
+
});
|
|
192
|
+
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
|
+
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={[]} />);
|
|
196
|
+
const select = getByRole("combobox");
|
|
197
|
+
|
|
198
|
+
userEvent.click(select);
|
|
199
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
200
|
+
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
201
|
+
});
|
|
202
|
+
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
|
+
const onChange = jest.fn();
|
|
206
|
+
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
207
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} />
|
|
208
|
+
);
|
|
209
|
+
const select = getByRole("combobox");
|
|
210
|
+
|
|
211
|
+
userEvent.click(select);
|
|
212
|
+
userEvent.click(getAllByRole("option")[2]);
|
|
213
|
+
expect(onChange).toHaveBeenCalledWith({ value: "3", error: null });
|
|
214
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
215
|
+
expect(getByText("Option 03")).toBeTruthy();
|
|
216
|
+
userEvent.click(select);
|
|
217
|
+
expect(getAllByRole("option")[2].getAttribute("aria-selected")).toBe("true");
|
|
218
|
+
});
|
|
219
|
+
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
|
+
const onChange = jest.fn();
|
|
223
|
+
const { getByRole, getAllByRole, getAllByText } = render(
|
|
224
|
+
<DxcSelect
|
|
225
|
+
label="test-select-label"
|
|
226
|
+
placeholder="Choose an option"
|
|
227
|
+
options={single_options}
|
|
228
|
+
onChange={onChange}
|
|
229
|
+
optional
|
|
230
|
+
/>
|
|
231
|
+
);
|
|
232
|
+
const select = getByRole("combobox");
|
|
233
|
+
|
|
234
|
+
userEvent.click(select);
|
|
235
|
+
expect(getAllByText("Choose an option").length).toBe(2);
|
|
236
|
+
expect(getAllByRole("option")[0].getAttribute("aria-selected")).toBe("true");
|
|
237
|
+
userEvent.click(getAllByRole("option")[0]);
|
|
238
|
+
expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
|
|
239
|
+
expect(getAllByText("Choose an option").length).toBe(1);
|
|
240
|
+
});
|
|
241
|
+
test("Non-Grouped Options: Arrow up key - Opens the listbox and visually focus the last option", () => {
|
|
242
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
243
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
244
|
+
const { getByRole, queryByRole } = render(
|
|
245
|
+
<DxcSelect label="test-select-label" options={single_options} />
|
|
246
|
+
);
|
|
247
|
+
const select = getByRole("combobox");
|
|
248
|
+
|
|
249
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
250
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
251
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-19");
|
|
252
|
+
});
|
|
253
|
+
test("Non-Grouped Options: Arrow up key - Puts the focus in last option when the first one is visually focused", () => {
|
|
254
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
255
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
256
|
+
const { getByRole, queryByRole } = render(
|
|
257
|
+
<DxcSelect label="test-select-label" options={single_options} />
|
|
258
|
+
);
|
|
259
|
+
const select = getByRole("combobox");
|
|
260
|
+
|
|
261
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
262
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
263
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
264
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-19");
|
|
265
|
+
});
|
|
266
|
+
test("Non-Grouped Options: Arrow down key - Opens the listbox and visually focus the first option", () => {
|
|
267
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
268
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
269
|
+
const { getByRole, queryByRole } = render(
|
|
270
|
+
<DxcSelect label="test-select-label" options={single_options} />
|
|
271
|
+
);
|
|
272
|
+
const select = getByRole("combobox");
|
|
273
|
+
|
|
274
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
275
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
276
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
277
|
+
});
|
|
278
|
+
test("Non-Grouped Options: Arrow down key - Puts the focus in the first option when the last one is visually focused", () => {
|
|
279
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
280
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
281
|
+
const { getByRole, queryByRole } = render(
|
|
282
|
+
<DxcSelect label="test-select-label" options={single_options} />
|
|
283
|
+
);
|
|
284
|
+
const select = getByRole("combobox");
|
|
285
|
+
|
|
286
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
287
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
288
|
+
expect(queryByRole("listbox")).toBeTruthy();
|
|
289
|
+
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
290
|
+
});
|
|
291
|
+
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
|
+
const onChange = jest.fn();
|
|
295
|
+
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
296
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} />
|
|
297
|
+
);
|
|
298
|
+
const select = getByRole("combobox");
|
|
299
|
+
|
|
300
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
301
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
302
|
+
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
303
|
+
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
304
|
+
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
305
|
+
expect(onChange).toHaveBeenCalledWith({ value: "19", error: null });
|
|
306
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
307
|
+
expect(getByText("Option 19")).toBeTruthy();
|
|
308
|
+
userEvent.click(select);
|
|
309
|
+
expect(getAllByRole("option")[18].getAttribute("aria-selected")).toBe("true");
|
|
310
|
+
});
|
|
311
|
+
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
|
+
const onChange = jest.fn();
|
|
315
|
+
const { container, getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
316
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
317
|
+
);
|
|
318
|
+
const select = getByRole("combobox");
|
|
319
|
+
const searchInput = container.querySelectorAll("input")[1];
|
|
320
|
+
|
|
321
|
+
userEvent.click(select);
|
|
322
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
323
|
+
userEvent.type(searchInput, "08");
|
|
324
|
+
userEvent.click(getByRole("option"));
|
|
325
|
+
expect(onChange).toHaveBeenCalledWith({ value: "8", error: null });
|
|
326
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
327
|
+
expect(getByText("Option 08")).toBeTruthy();
|
|
328
|
+
expect(searchInput.value).toBe("");
|
|
329
|
+
userEvent.click(select);
|
|
330
|
+
expect(getAllByRole("option")[7].getAttribute("aria-selected")).toBe("true");
|
|
331
|
+
});
|
|
332
|
+
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
|
+
const onChange = jest.fn();
|
|
336
|
+
const { container, getByText, getByRole } = render(
|
|
337
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
338
|
+
);
|
|
339
|
+
const select = getByRole("combobox");
|
|
340
|
+
const searchInput = container.querySelectorAll("input")[1];
|
|
341
|
+
|
|
342
|
+
userEvent.click(select);
|
|
343
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
344
|
+
userEvent.type(searchInput, "abc");
|
|
345
|
+
expect(getByText("No matches found")).toBeTruthy();
|
|
346
|
+
});
|
|
347
|
+
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
|
+
const onChange = jest.fn();
|
|
351
|
+
const { container, getByText, getByRole, getAllByRole } = render(
|
|
352
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
353
|
+
);
|
|
354
|
+
const select = getByRole("combobox");
|
|
355
|
+
const searchInput = container.querySelectorAll("input")[1];
|
|
356
|
+
|
|
357
|
+
userEvent.click(select);
|
|
358
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
359
|
+
userEvent.type(searchInput, "2");
|
|
360
|
+
expect(getByText("Option 02")).toBeTruthy();
|
|
361
|
+
expect(getByText("Option 12")).toBeTruthy();
|
|
362
|
+
expect(getByText("Option 20")).toBeTruthy();
|
|
363
|
+
expect(getAllByRole("option").length).toBe(3);
|
|
364
|
+
userEvent.click(select);
|
|
365
|
+
expect(searchInput.value).toBe("");
|
|
366
|
+
});
|
|
367
|
+
test("Non-Grouped Options: Searchable - Writing displays the listbox, if was not open", () => {
|
|
368
|
+
window.HTMLElement.prototype.scrollIntoView = () => {};
|
|
369
|
+
window.HTMLElement.prototype.scrollTo = () => {};
|
|
370
|
+
const onChange = jest.fn();
|
|
371
|
+
const { container, getByRole, queryByRole } = render(
|
|
372
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
373
|
+
);
|
|
374
|
+
const select = getByRole("combobox");
|
|
375
|
+
const searchInput = container.querySelectorAll("input")[1];
|
|
376
|
+
|
|
377
|
+
userEvent.click(select);
|
|
378
|
+
userEvent.click(select);
|
|
379
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
380
|
+
userEvent.type(searchInput, "2");
|
|
381
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
382
|
+
});
|
|
383
|
+
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
|
+
const onChange = jest.fn();
|
|
387
|
+
const { container, getByRole, queryByRole } = render(
|
|
388
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
389
|
+
);
|
|
390
|
+
const select = getByRole("combobox");
|
|
391
|
+
const searchInput = container.querySelectorAll("input")[1];
|
|
392
|
+
|
|
393
|
+
userEvent.type(searchInput, "Option 02");
|
|
394
|
+
fireEvent.keyDown(select, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
395
|
+
expect(searchInput.value).toBe("");
|
|
396
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
397
|
+
});
|
|
398
|
+
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
|
+
const onChange = jest.fn();
|
|
402
|
+
const { container, getByRole, getAllByRole } = render(
|
|
403
|
+
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
404
|
+
);
|
|
405
|
+
const searchInput = container.querySelectorAll("input")[1];
|
|
406
|
+
|
|
407
|
+
userEvent.type(searchInput, "Option 02");
|
|
408
|
+
expect(getAllByRole("option").length).toBe(1);
|
|
409
|
+
const clearAction = getByRole("button");
|
|
410
|
+
expect(clearAction).toBeTruthy();
|
|
411
|
+
userEvent.click(clearAction);
|
|
412
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
413
|
+
expect(getAllByRole("option").length).toBe(20);
|
|
414
|
+
});
|
|
415
|
+
});
|
package/test/TextInput.test.js
CHANGED
|
@@ -88,7 +88,7 @@ describe("TextInput component tests", () => {
|
|
|
88
88
|
test("Pattern constraint", () => {
|
|
89
89
|
const onChange = jest.fn();
|
|
90
90
|
const onBlur = jest.fn();
|
|
91
|
-
const { getByRole
|
|
91
|
+
const { getByRole } = render(
|
|
92
92
|
<DxcTextInput
|
|
93
93
|
label="Input label"
|
|
94
94
|
placeholder="Placeholder"
|
|
@@ -118,7 +118,7 @@ describe("TextInput component tests", () => {
|
|
|
118
118
|
test("Length constraint", () => {
|
|
119
119
|
const onChange = jest.fn();
|
|
120
120
|
const onBlur = jest.fn();
|
|
121
|
-
const { getByRole
|
|
121
|
+
const { getByRole } = render(
|
|
122
122
|
<DxcTextInput
|
|
123
123
|
label="Input label"
|
|
124
124
|
placeholder="Placeholder"
|
|
@@ -148,7 +148,7 @@ describe("TextInput component tests", () => {
|
|
|
148
148
|
test("Pattern and length constraints", () => {
|
|
149
149
|
const onChange = jest.fn();
|
|
150
150
|
const onBlur = jest.fn();
|
|
151
|
-
const { getByRole
|
|
151
|
+
const { getByRole } = render(
|
|
152
152
|
<DxcTextInput
|
|
153
153
|
label="Input label"
|
|
154
154
|
placeholder="Placeholder"
|
|
@@ -398,7 +398,7 @@ describe("TextInput component synchronous autosuggest tests", () => {
|
|
|
398
398
|
expect(list).toBeTruthy();
|
|
399
399
|
expect(getByText("No results found")).toBeTruthy();
|
|
400
400
|
});
|
|
401
|
-
test("Autosuggest uncontrolled
|
|
401
|
+
test("Autosuggest uncontrolled - Suggestion selected by click", async () => {
|
|
402
402
|
const onChange = jest.fn();
|
|
403
403
|
const { getByRole, getByText, queryByRole } = render(
|
|
404
404
|
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
@@ -414,7 +414,7 @@ describe("TextInput component synchronous autosuggest tests", () => {
|
|
|
414
414
|
expect(input.value).toBe("Albania");
|
|
415
415
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
416
416
|
});
|
|
417
|
-
test("Autosuggest controlled
|
|
417
|
+
test("Autosuggest controlled - Suggestion selected by click", async () => {
|
|
418
418
|
const onChange = jest.fn();
|
|
419
419
|
const { getByRole, getByText, queryByRole } = render(
|
|
420
420
|
<DxcTextInput label="Autocomplete Countries" value="Andor" suggestions={countries} onChange={onChange} />
|