@dxc-technology/halstack-react 0.0.0-8d633bd → 0.0.0-9196773
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/ThemeContext.js +69 -61
- package/dist/alert/Alert.js +4 -4
- package/dist/alert/index.d.ts +30 -5
- package/dist/common/variables.js +199 -47
- package/dist/date/Date.js +4 -6
- package/dist/{new-date/NewDate.js → date-input/DateInput.js} +69 -72
- package/dist/date-input/index.d.ts +95 -0
- package/dist/file-input/FileInput.js +11 -8
- package/dist/file-input/FileItem.js +25 -8
- package/dist/file-input/index.d.ts +81 -0
- package/dist/input-text/InputText.js +3 -3
- package/dist/main.d.ts +7 -1
- package/dist/main.js +22 -14
- package/dist/new-select/NewSelect.js +836 -0
- package/dist/new-select/index.d.ts +53 -0
- package/dist/new-textarea/NewTextarea.js +52 -48
- package/dist/new-textarea/index.d.ts +117 -0
- package/dist/{number/Number.js → number-input/NumberInput.js} +9 -11
- package/dist/{number/NumberContext.js → number-input/NumberInputContext.js} +2 -2
- package/dist/number-input/index.d.ts +113 -0
- package/dist/{password/Password.js → password-input/PasswordInput.js} +11 -13
- package/dist/password-input/index.d.ts +94 -0
- package/dist/slider/Slider.js +89 -14
- package/dist/{new-input-text/NewInputText.js → text-input/TextInput.js} +129 -135
- package/dist/text-input/index.d.ts +135 -0
- package/dist/toggle-group/ToggleGroup.js +132 -28
- package/dist/upload/Upload.js +3 -3
- package/dist/upload/readme.md +2 -2
- package/package.json +1 -1
- package/test/{NewDate.test.js → DateInput.test.js} +66 -27
- package/test/FileInput.test.js +164 -2
- package/test/InputText.test.js +24 -16
- package/test/NewTextarea.test.js +71 -128
- package/test/{Number.test.js → NumberInput.test.js} +84 -66
- package/test/PasswordInput.test.js +83 -0
- package/test/{NewInputText.test.js → TextInput.test.js} +134 -268
- package/test/ToggleGroup.test.js +5 -1
- package/test/Upload.test.js +5 -5
- package/dist/footer/Footer.stories.js +0 -94
- package/dist/input-text/InputText.stories.js +0 -209
- package/dist/password/styles.css +0 -3
- package/dist/slider/Slider.stories.js +0 -241
- package/test/Password.test.js +0 -76
|
@@ -2,7 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { render, fireEvent, waitForElementToBeRemoved } from "@testing-library/react";
|
|
3
3
|
import userEvent from "@testing-library/user-event";
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import DxcTextInput from "../src/text-input/TextInput";
|
|
6
6
|
|
|
7
7
|
const countries = [
|
|
8
8
|
"Afghanistan",
|
|
@@ -29,58 +29,67 @@ const countries = [
|
|
|
29
29
|
"Djibouti",
|
|
30
30
|
];
|
|
31
31
|
|
|
32
|
-
describe("
|
|
32
|
+
describe("TextInput component tests", () => {
|
|
33
33
|
test("Renders with correct label", () => {
|
|
34
|
-
const { getByText } = render(<
|
|
34
|
+
const { getByText } = render(<DxcTextInput label="Example label" />);
|
|
35
35
|
expect(getByText("Example label")).toBeTruthy();
|
|
36
36
|
});
|
|
37
37
|
test("Renders with correct label and helper text", () => {
|
|
38
|
-
const { getByText } = render(<
|
|
38
|
+
const { getByText } = render(<DxcTextInput label="Example label" helperText="Example helper text" />);
|
|
39
39
|
expect(getByText("Example label")).toBeTruthy();
|
|
40
40
|
expect(getByText("Example helper text")).toBeTruthy();
|
|
41
41
|
});
|
|
42
42
|
test("Renders with correct label and optional", () => {
|
|
43
|
-
const { getByText } = render(<
|
|
43
|
+
const { getByText } = render(<DxcTextInput label="Example label" helperText="Example helper text" optional />);
|
|
44
44
|
expect(getByText("Example label")).toBeTruthy();
|
|
45
45
|
expect(getByText("(Optional)")).toBeTruthy();
|
|
46
46
|
expect(getByText("Example helper text")).toBeTruthy();
|
|
47
47
|
});
|
|
48
48
|
test("Renders with correct placeholder", () => {
|
|
49
|
-
const { getByRole } = render(<
|
|
49
|
+
const { getByRole } = render(<DxcTextInput label="Example label" placeholder="Placeholder" />);
|
|
50
50
|
const input = getByRole("textbox");
|
|
51
51
|
expect(input.getAttribute("placeholder")).toBe("Placeholder");
|
|
52
52
|
});
|
|
53
53
|
test("Renders with error message", () => {
|
|
54
|
-
const { getByText } = render(
|
|
55
|
-
<DxcNewInputText label="Error label" placeholder="Placeholder" error="Error message." />
|
|
56
|
-
);
|
|
54
|
+
const { getByText } = render(<DxcTextInput label="Error label" placeholder="Placeholder" error="Error message." />);
|
|
57
55
|
expect(getByText("Error message.")).toBeTruthy();
|
|
58
56
|
});
|
|
59
|
-
test("
|
|
57
|
+
test("Not optional constraint (onBlur)", () => {
|
|
60
58
|
const onChange = jest.fn();
|
|
61
59
|
const onBlur = jest.fn();
|
|
62
|
-
const { getByRole
|
|
63
|
-
<
|
|
64
|
-
label="Input label"
|
|
65
|
-
placeholder="Placeholder"
|
|
66
|
-
onChange={onChange}
|
|
67
|
-
onBlur={onBlur}
|
|
68
|
-
clearable
|
|
69
|
-
/>
|
|
60
|
+
const { getByRole } = render(
|
|
61
|
+
<DxcTextInput label="Input label" placeholder="Placeholder" onChange={onChange} onBlur={onBlur} clearable />
|
|
70
62
|
);
|
|
71
63
|
const input = getByRole("textbox");
|
|
64
|
+
|
|
72
65
|
fireEvent.focus(input);
|
|
73
66
|
fireEvent.blur(input);
|
|
74
|
-
expect(
|
|
75
|
-
|
|
67
|
+
expect(onBlur).toHaveBeenCalled();
|
|
68
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
69
|
+
fireEvent.change(input, { target: { value: "Test" } });
|
|
76
70
|
fireEvent.blur(input);
|
|
77
|
-
expect(
|
|
71
|
+
expect(onBlur).toHaveBeenCalled();
|
|
72
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Test", error: null });
|
|
78
73
|
});
|
|
79
|
-
test("
|
|
74
|
+
test("Not optional constraint (onChange)", () => {
|
|
75
|
+
const onChange = jest.fn();
|
|
76
|
+
const { getByRole } = render(
|
|
77
|
+
<DxcTextInput label="Input label" placeholder="Placeholder" onChange={onChange} clearable />
|
|
78
|
+
);
|
|
79
|
+
const input = getByRole("textbox");
|
|
80
|
+
|
|
81
|
+
fireEvent.change(input, { target: { value: "Test" } });
|
|
82
|
+
expect(onChange).toHaveBeenCalled();
|
|
83
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Test", error: null });
|
|
84
|
+
userEvent.clear(input);
|
|
85
|
+
expect(onChange).toHaveBeenCalled();
|
|
86
|
+
expect(onChange).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
87
|
+
});
|
|
88
|
+
test("Pattern constraint", () => {
|
|
80
89
|
const onChange = jest.fn();
|
|
81
90
|
const onBlur = jest.fn();
|
|
82
91
|
const { getByRole, getByText, queryByText } = render(
|
|
83
|
-
<
|
|
92
|
+
<DxcTextInput
|
|
84
93
|
label="Input label"
|
|
85
94
|
placeholder="Placeholder"
|
|
86
95
|
onChange={onChange}
|
|
@@ -91,18 +100,26 @@ describe("NewInputText component tests", () => {
|
|
|
91
100
|
/>
|
|
92
101
|
);
|
|
93
102
|
const input = getByRole("textbox");
|
|
94
|
-
|
|
103
|
+
|
|
104
|
+
fireEvent.change(input, { target: { value: "pattern test" } });
|
|
105
|
+
expect(onChange).toHaveBeenCalled();
|
|
106
|
+
expect(onChange).toHaveBeenCalledWith({ value: "pattern test", error: "Please match the format requested." });
|
|
95
107
|
fireEvent.blur(input);
|
|
96
|
-
expect(
|
|
97
|
-
|
|
108
|
+
expect(onBlur).toHaveBeenCalled();
|
|
109
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "pattern test", error: "Please match the format requested." });
|
|
110
|
+
userEvent.clear(input);
|
|
111
|
+
fireEvent.change(input, { target: { value: "pattern4&" } });
|
|
112
|
+
expect(onChange).toHaveBeenCalled();
|
|
113
|
+
expect(onChange).toHaveBeenCalledWith({ value: "pattern4&", error: null });
|
|
98
114
|
fireEvent.blur(input);
|
|
99
|
-
expect(
|
|
115
|
+
expect(onBlur).toHaveBeenCalled();
|
|
116
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "pattern4&", error: null });
|
|
100
117
|
});
|
|
101
|
-
test("
|
|
118
|
+
test("Length constraint", () => {
|
|
102
119
|
const onChange = jest.fn();
|
|
103
120
|
const onBlur = jest.fn();
|
|
104
121
|
const { getByRole, getByText, queryByText } = render(
|
|
105
|
-
<
|
|
122
|
+
<DxcTextInput
|
|
106
123
|
label="Input label"
|
|
107
124
|
placeholder="Placeholder"
|
|
108
125
|
onChange={onChange}
|
|
@@ -113,18 +130,26 @@ describe("NewInputText component tests", () => {
|
|
|
113
130
|
/>
|
|
114
131
|
);
|
|
115
132
|
const input = getByRole("textbox");
|
|
116
|
-
|
|
133
|
+
|
|
134
|
+
fireEvent.change(input, { target: { value: "test" } });
|
|
135
|
+
expect(onChange).toHaveBeenCalled();
|
|
136
|
+
expect(onChange).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
117
137
|
fireEvent.blur(input);
|
|
118
|
-
expect(
|
|
119
|
-
|
|
138
|
+
expect(onBlur).toHaveBeenCalled();
|
|
139
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
140
|
+
userEvent.clear(input);
|
|
141
|
+
fireEvent.change(input, { target: { value: "length" } });
|
|
142
|
+
expect(onChange).toHaveBeenCalled();
|
|
143
|
+
expect(onChange).toHaveBeenCalledWith({ value: "length", error: null });
|
|
120
144
|
fireEvent.blur(input);
|
|
121
|
-
expect(
|
|
145
|
+
expect(onBlur).toHaveBeenCalled();
|
|
146
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "length", error: null });
|
|
122
147
|
});
|
|
123
|
-
test("
|
|
148
|
+
test("Pattern and length constraints", () => {
|
|
124
149
|
const onChange = jest.fn();
|
|
125
150
|
const onBlur = jest.fn();
|
|
126
151
|
const { getByRole, getByText, queryByText } = render(
|
|
127
|
-
<
|
|
152
|
+
<DxcTextInput
|
|
128
153
|
label="Input label"
|
|
129
154
|
placeholder="Placeholder"
|
|
130
155
|
onChange={onChange}
|
|
@@ -136,149 +161,47 @@ describe("NewInputText component tests", () => {
|
|
|
136
161
|
/>
|
|
137
162
|
);
|
|
138
163
|
const input = getByRole("textbox");
|
|
139
|
-
|
|
140
|
-
fireEvent.
|
|
141
|
-
expect(
|
|
142
|
-
|
|
143
|
-
fireEvent.blur(input);
|
|
144
|
-
expect(getByText("Please match the format requested.")).toBeTruthy();
|
|
145
|
-
userEvent.type(input, "test 4");
|
|
146
|
-
fireEvent.blur(input);
|
|
147
|
-
expect(queryByText("Please match the format requested.")).toBeFalsy();
|
|
148
|
-
});
|
|
149
|
-
test("Input Non Strict - Not optional constraint", () => {
|
|
150
|
-
const onChange = jest.fn((value) => {
|
|
151
|
-
expect(value).toBe("");
|
|
152
|
-
});
|
|
153
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
154
|
-
expect(value).toBe("");
|
|
155
|
-
expect(error).toBe("This field is required. Please, enter a value.");
|
|
156
|
-
});
|
|
157
|
-
const { getByRole } = render(
|
|
158
|
-
<DxcNewInputText
|
|
159
|
-
label="Input label"
|
|
160
|
-
placeholder="Placeholder"
|
|
161
|
-
onChange={onChange}
|
|
162
|
-
onBlur={onBlur}
|
|
163
|
-
/>
|
|
164
|
-
);
|
|
165
|
-
const input = getByRole("textbox");
|
|
166
|
-
fireEvent.focus(input);
|
|
167
|
-
fireEvent.blur(input);
|
|
168
|
-
});
|
|
169
|
-
test("Input Non Strict - Pattern constraint", () => {
|
|
170
|
-
const onChange = jest.fn((value) => {
|
|
171
|
-
expect(value).toBe("t");
|
|
172
|
-
});
|
|
173
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
174
|
-
expect(value).toBe("t");
|
|
175
|
-
expect(error).toBe("Please match the format requested.");
|
|
176
|
-
});
|
|
177
|
-
const { getByRole } = render(
|
|
178
|
-
<DxcNewInputText
|
|
179
|
-
label="Input label"
|
|
180
|
-
placeholder="Placeholder"
|
|
181
|
-
onChange={onChange}
|
|
182
|
-
onBlur={onBlur}
|
|
183
|
-
margin={{ left: "medium", right: "medium" }}
|
|
184
|
-
clearable
|
|
185
|
-
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
186
|
-
/>
|
|
187
|
-
);
|
|
188
|
-
const input = getByRole("textbox");
|
|
189
|
-
userEvent.type(input, "t");
|
|
164
|
+
|
|
165
|
+
fireEvent.change(input, { target: { value: "test" } });
|
|
166
|
+
expect(onChange).toHaveBeenCalled();
|
|
167
|
+
expect(onChange).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
190
168
|
fireEvent.blur(input);
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
});
|
|
196
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
197
|
-
expect(value).toBe("t");
|
|
198
|
-
expect(error).toBe("Min length 5, max length 10.");
|
|
199
|
-
});
|
|
200
|
-
const { getByRole } = render(
|
|
201
|
-
<DxcNewInputText
|
|
202
|
-
label="Input label"
|
|
203
|
-
placeholder="Placeholder"
|
|
204
|
-
onChange={onChange}
|
|
205
|
-
onBlur={onBlur}
|
|
206
|
-
margin={{ left: "medium", right: "medium" }}
|
|
207
|
-
clearable
|
|
208
|
-
length={{ min: 5, max: 10 }}
|
|
209
|
-
/>
|
|
210
|
-
);
|
|
211
|
-
const input = getByRole("textbox");
|
|
212
|
-
userEvent.type(input, "t");
|
|
169
|
+
expect(onBlur).toHaveBeenCalled();
|
|
170
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
171
|
+
fireEvent.change(input, { target: { value: "tests" } });
|
|
172
|
+
expect(onChange).toHaveBeenCalled();
|
|
173
|
+
expect(onChange).toHaveBeenCalledWith({ value: "tests", error: "Please match the format requested." });
|
|
213
174
|
fireEvent.blur(input);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
});
|
|
219
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
220
|
-
expect(value).toBe("t");
|
|
221
|
-
expect(error).toBe("Min length 5, max length 10.");
|
|
222
|
-
});
|
|
223
|
-
const { getByRole } = render(
|
|
224
|
-
<DxcNewInputText
|
|
225
|
-
label="Input label"
|
|
226
|
-
placeholder="Placeholder"
|
|
227
|
-
onChange={onChange}
|
|
228
|
-
onBlur={onBlur}
|
|
229
|
-
margin={{ left: "medium", right: "medium" }}
|
|
230
|
-
clearable
|
|
231
|
-
length={{ min: 5, max: 10 }}
|
|
232
|
-
/>
|
|
233
|
-
);
|
|
234
|
-
const input = getByRole("textbox");
|
|
235
|
-
userEvent.type(input, "t");
|
|
175
|
+
expect(onBlur).toHaveBeenCalled();
|
|
176
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "tests", error: "Please match the format requested." });
|
|
177
|
+
fireEvent.change(input, { target: { value: "tests4&" } });
|
|
178
|
+
expect(onChange).toHaveBeenCalled();
|
|
179
|
+
expect(onChange).toHaveBeenCalledWith({ value: "tests4&", error: null });
|
|
236
180
|
fireEvent.blur(input);
|
|
181
|
+
expect(onBlur).toHaveBeenCalled();
|
|
182
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "tests4&", error: null });
|
|
237
183
|
});
|
|
238
184
|
test("onChange function is called correctly", () => {
|
|
239
185
|
const onChange = jest.fn();
|
|
240
|
-
const { getByRole } = render(<
|
|
186
|
+
const { getByRole } = render(<DxcTextInput label="Input label" onChange={onChange} />);
|
|
241
187
|
const input = getByRole("textbox");
|
|
242
188
|
userEvent.type(input, "onchange event test");
|
|
243
189
|
expect(input.value).toBe("onchange event test");
|
|
244
190
|
expect(onChange).toHaveBeenCalled();
|
|
245
|
-
expect(onChange).toHaveBeenCalledWith("onchange event test");
|
|
191
|
+
expect(onChange).toHaveBeenCalledWith({ value: "onchange event test", error: null });
|
|
246
192
|
});
|
|
247
193
|
test("onBlur function is called correctly", () => {
|
|
248
194
|
const onBlur = jest.fn();
|
|
249
195
|
const onChange = jest.fn();
|
|
250
|
-
const { getByRole } = render(<
|
|
196
|
+
const { getByRole } = render(<DxcTextInput label="Input label" onChange={onChange} onBlur={onBlur} />);
|
|
251
197
|
const input = getByRole("textbox");
|
|
252
|
-
|
|
198
|
+
fireEvent.change(input, { target: { value: "Blur test" } });
|
|
253
199
|
fireEvent.blur(input);
|
|
254
200
|
expect(onBlur).toHaveBeenCalled();
|
|
255
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "
|
|
256
|
-
});
|
|
257
|
-
test("Uncontrolled input", () => {
|
|
258
|
-
const onChange = jest.fn();
|
|
259
|
-
const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} />);
|
|
260
|
-
const input = getByRole("textbox");
|
|
261
|
-
userEvent.type(input, "Uncontrolled test");
|
|
262
|
-
expect(onChange).toHaveBeenCalled();
|
|
263
|
-
expect(onChange).toHaveBeenCalledWith("Uncontrolled test");
|
|
264
|
-
expect(input.value).toBe("Uncontrolled test");
|
|
265
|
-
});
|
|
266
|
-
test("Controlled input", () => {
|
|
267
|
-
const onChange = jest.fn();
|
|
268
|
-
const onBlur = jest.fn();
|
|
269
|
-
const { getByRole } = render(
|
|
270
|
-
<DxcNewInputText label="Input label" value="Test value" onChange={onChange} onBlur={onBlur} />
|
|
271
|
-
);
|
|
272
|
-
const input = getByRole("textbox");
|
|
273
|
-
userEvent.type(input, "Example text");
|
|
274
|
-
expect(onChange).toHaveBeenCalled();
|
|
275
|
-
expect(input.value).toBe("Test value");
|
|
276
|
-
fireEvent.blur(input);
|
|
277
|
-
expect(onBlur).toHaveBeenCalled();
|
|
278
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "Test value", error: null });
|
|
201
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Blur test", error: null });
|
|
279
202
|
});
|
|
280
203
|
test("Clear action onClick cleans the input", () => {
|
|
281
|
-
const { getByRole } = render(<
|
|
204
|
+
const { getByRole } = render(<DxcTextInput label="Input label" clearable />);
|
|
282
205
|
const input = getByRole("textbox");
|
|
283
206
|
userEvent.type(input, "Test");
|
|
284
207
|
const closeAction = getByRole("button");
|
|
@@ -303,7 +226,7 @@ describe("NewInputText component tests", () => {
|
|
|
303
226
|
</svg>
|
|
304
227
|
),
|
|
305
228
|
};
|
|
306
|
-
const { getByRole } = render(<
|
|
229
|
+
const { getByRole } = render(<DxcTextInput label="Disabled input label" action={action} disabled />);
|
|
307
230
|
const input = getByRole("textbox");
|
|
308
231
|
expect(input.disabled).toBeTruthy();
|
|
309
232
|
userEvent.click(getByRole("button"));
|
|
@@ -311,7 +234,7 @@ describe("NewInputText component tests", () => {
|
|
|
311
234
|
});
|
|
312
235
|
test("Disabled input (clear default action should not be displayed, even with text written on the input)", () => {
|
|
313
236
|
const { getByRole, queryByRole } = render(
|
|
314
|
-
<
|
|
237
|
+
<DxcTextInput label="Disabled input label" value="Sample text" disabled clearable />
|
|
315
238
|
);
|
|
316
239
|
const input = getByRole("textbox");
|
|
317
240
|
expect(input.disabled).toBeTruthy();
|
|
@@ -319,7 +242,7 @@ describe("NewInputText component tests", () => {
|
|
|
319
242
|
});
|
|
320
243
|
test("Disabled input (suffix and preffix must be displayed)", () => {
|
|
321
244
|
const { getByRole, getByText } = render(
|
|
322
|
-
<
|
|
245
|
+
<DxcTextInput label="Disabled input label" value="Sample text" prefix="+34" suffix="USD" disabled />
|
|
323
246
|
);
|
|
324
247
|
const input = getByRole("textbox");
|
|
325
248
|
expect(input.disabled).toBeTruthy();
|
|
@@ -344,70 +267,16 @@ describe("NewInputText component tests", () => {
|
|
|
344
267
|
</svg>
|
|
345
268
|
),
|
|
346
269
|
};
|
|
347
|
-
const { getByRole, getByTestId } = render(<
|
|
270
|
+
const { getByRole, getByTestId } = render(<DxcTextInput label="Input label" action={action} />);
|
|
348
271
|
expect(getByTestId("image")).toBeTruthy();
|
|
349
272
|
userEvent.click(getByRole("button"));
|
|
350
273
|
expect(onClick).toHaveBeenCalled();
|
|
351
274
|
});
|
|
352
|
-
test("Renders with correct prefix and suffix
|
|
353
|
-
const { getByText } = render(<
|
|
275
|
+
test("Renders with correct prefix and suffix", () => {
|
|
276
|
+
const { getByText } = render(<DxcTextInput label="Input label" prefix="+34" suffix="USD" />);
|
|
354
277
|
expect(getByText("+34")).toBeTruthy();
|
|
355
278
|
expect(getByText("USD")).toBeTruthy();
|
|
356
279
|
});
|
|
357
|
-
test("Renders with correct prefix (icon)", () => {
|
|
358
|
-
const { getByTestId } = render(
|
|
359
|
-
<DxcNewInputText
|
|
360
|
-
label="Input label"
|
|
361
|
-
prefix={
|
|
362
|
-
<svg
|
|
363
|
-
data-testid="image"
|
|
364
|
-
version="1.1"
|
|
365
|
-
x="0px"
|
|
366
|
-
y="0px"
|
|
367
|
-
width="24px"
|
|
368
|
-
height="24px"
|
|
369
|
-
viewBox="0 0 24 24"
|
|
370
|
-
enable-background="new 0 0 24 24"
|
|
371
|
-
>
|
|
372
|
-
<g id="Bounding_Box">
|
|
373
|
-
<rect fill="none" width="24" height="24" />
|
|
374
|
-
</g>
|
|
375
|
-
<g id="Master">
|
|
376
|
-
<path d="M19,9.3V4h-3v2.6L12,3L2,12h3v8h5v-6h4v6h5v-8h3L19,9.3z M10,10c0-1.1,0.9-2,2-2s2,0.9,2,2H10z" />
|
|
377
|
-
</g>
|
|
378
|
-
</svg>
|
|
379
|
-
}
|
|
380
|
-
/>
|
|
381
|
-
);
|
|
382
|
-
expect(getByTestId("image")).toBeTruthy();
|
|
383
|
-
});
|
|
384
|
-
test("Renders with correct suffix (icon)", () => {
|
|
385
|
-
const { getByTestId } = render(
|
|
386
|
-
<DxcNewInputText
|
|
387
|
-
label="Input label"
|
|
388
|
-
suffix={
|
|
389
|
-
<svg
|
|
390
|
-
data-testid="image"
|
|
391
|
-
version="1.1"
|
|
392
|
-
x="0px"
|
|
393
|
-
y="0px"
|
|
394
|
-
width="24px"
|
|
395
|
-
height="24px"
|
|
396
|
-
viewBox="0 0 24 24"
|
|
397
|
-
enable-background="new 0 0 24 24"
|
|
398
|
-
>
|
|
399
|
-
<g id="Bounding_Box">
|
|
400
|
-
<rect fill="none" width="24" height="24" />
|
|
401
|
-
</g>
|
|
402
|
-
<g id="Master">
|
|
403
|
-
<path d="M19,9.3V4h-3v2.6L12,3L2,12h3v8h5v-6h4v6h5v-8h3L19,9.3z M10,10c0-1.1,0.9-2,2-2s2,0.9,2,2H10z" />
|
|
404
|
-
</g>
|
|
405
|
-
</svg>
|
|
406
|
-
}
|
|
407
|
-
/>
|
|
408
|
-
);
|
|
409
|
-
expect(getByTestId("image")).toBeTruthy();
|
|
410
|
-
});
|
|
411
280
|
test("Input has correct accesibility attributes", () => {
|
|
412
281
|
const onClick = jest.fn();
|
|
413
282
|
const action = {
|
|
@@ -426,9 +295,7 @@ describe("NewInputText component tests", () => {
|
|
|
426
295
|
</svg>
|
|
427
296
|
),
|
|
428
297
|
};
|
|
429
|
-
const { getByRole, getAllByRole } = render(
|
|
430
|
-
<DxcNewInputText label="Example label" clearable action={action} />
|
|
431
|
-
);
|
|
298
|
+
const { getByRole, getAllByRole } = render(<DxcTextInput label="Example label" clearable action={action} />);
|
|
432
299
|
const input = getByRole("textbox");
|
|
433
300
|
expect(input.getAttribute("aria-autocomplete")).toBeNull();
|
|
434
301
|
expect(input.getAttribute("aria-controls")).toBeNull();
|
|
@@ -440,14 +307,10 @@ describe("NewInputText component tests", () => {
|
|
|
440
307
|
userEvent.type(input, "Text");
|
|
441
308
|
const clear = getAllByRole("button")[0];
|
|
442
309
|
expect(clear.getAttribute("aria-label")).toBe("Clear");
|
|
443
|
-
userEvent.click(clear);
|
|
444
|
-
fireEvent.blur(input);
|
|
445
|
-
expect(input.getAttribute("aria-invalid")).toBe("true");
|
|
446
|
-
expect(input.getAttribute("aria-describedBy")).not.toBeNull();
|
|
447
310
|
});
|
|
448
311
|
test("Autosuggest has correct accesibility attributes", () => {
|
|
449
312
|
const { getByRole, getAllByRole } = render(
|
|
450
|
-
<
|
|
313
|
+
<DxcTextInput label="Autocomplete Countries" optional suggestions={countries} />
|
|
451
314
|
);
|
|
452
315
|
const input = getByRole("combobox");
|
|
453
316
|
const inputId = input.id;
|
|
@@ -464,11 +327,11 @@ describe("NewInputText component tests", () => {
|
|
|
464
327
|
});
|
|
465
328
|
});
|
|
466
329
|
|
|
467
|
-
describe("
|
|
330
|
+
describe("TextInput component synchronous autosuggest tests", () => {
|
|
468
331
|
test("Autosuggest is displayed when the input gains focus", async () => {
|
|
469
332
|
const onChange = jest.fn();
|
|
470
333
|
const { getByRole, getByText } = render(
|
|
471
|
-
<
|
|
334
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
472
335
|
);
|
|
473
336
|
const input = getByRole("combobox");
|
|
474
337
|
fireEvent.focus(input);
|
|
@@ -482,7 +345,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
482
345
|
test("Autosuggest is displayed when the user clicks the input", async () => {
|
|
483
346
|
const onChange = jest.fn();
|
|
484
347
|
const { getByRole, getByText } = render(
|
|
485
|
-
<
|
|
348
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
486
349
|
);
|
|
487
350
|
const input = getByRole("combobox");
|
|
488
351
|
userEvent.click(input);
|
|
@@ -496,7 +359,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
496
359
|
test("Autosuggest is displayed while the user is writing (if closed previously, if open stays open)", async () => {
|
|
497
360
|
const onChange = jest.fn();
|
|
498
361
|
const { getByRole, queryByRole, getByText, getAllByText } = render(
|
|
499
|
-
<
|
|
362
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
500
363
|
);
|
|
501
364
|
const input = getByRole("combobox");
|
|
502
365
|
fireEvent.focus(input);
|
|
@@ -515,7 +378,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
515
378
|
test("Autosuggest is not displayed when prop suggestions is an empty array", async () => {
|
|
516
379
|
const onChange = jest.fn();
|
|
517
380
|
const { queryByRole } = render(
|
|
518
|
-
<
|
|
381
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={[]} onChange={onChange} />
|
|
519
382
|
);
|
|
520
383
|
const input = queryByRole("textbox");
|
|
521
384
|
fireEvent.focus(input);
|
|
@@ -524,7 +387,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
524
387
|
test("Autosuggest shows 'No results found' message when there are no matches with the user's input", async () => {
|
|
525
388
|
const onChange = jest.fn();
|
|
526
389
|
const { getByRole, getByText } = render(
|
|
527
|
-
<
|
|
390
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
528
391
|
);
|
|
529
392
|
const input = getByRole("combobox");
|
|
530
393
|
fireEvent.focus(input);
|
|
@@ -538,7 +401,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
538
401
|
test("Autosuggest uncontrolled suggestion selected", async () => {
|
|
539
402
|
const onChange = jest.fn();
|
|
540
403
|
const { getByRole, getByText, queryByRole } = render(
|
|
541
|
-
<
|
|
404
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
542
405
|
);
|
|
543
406
|
const input = getByRole("combobox");
|
|
544
407
|
fireEvent.focus(input);
|
|
@@ -554,7 +417,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
554
417
|
test("Autosuggest controlled suggestions selected", async () => {
|
|
555
418
|
const onChange = jest.fn();
|
|
556
419
|
const { getByRole, getByText, queryByRole } = render(
|
|
557
|
-
<
|
|
420
|
+
<DxcTextInput label="Autocomplete Countries" value="Andor" suggestions={countries} onChange={onChange} />
|
|
558
421
|
);
|
|
559
422
|
const input = getByRole("combobox");
|
|
560
423
|
fireEvent.focus(input);
|
|
@@ -563,17 +426,18 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
563
426
|
expect(getByText("ra")).toBeTruthy();
|
|
564
427
|
fireEvent.mouseDown(getByRole("option"));
|
|
565
428
|
fireEvent.mouseUp(getByRole("option"));
|
|
566
|
-
expect(onChange).toHaveBeenCalledWith("Andorra");
|
|
429
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Andorra", error: null });
|
|
567
430
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
568
431
|
});
|
|
569
|
-
test("Autosuggest
|
|
432
|
+
test("Autosuggest - Pattern constraint", async () => {
|
|
570
433
|
const onChange = jest.fn();
|
|
571
|
-
const
|
|
572
|
-
|
|
434
|
+
const onBlur = jest.fn();
|
|
435
|
+
const { getByRole, getByText } = render(
|
|
436
|
+
<DxcTextInput
|
|
573
437
|
label="Autocomplete Countries"
|
|
574
|
-
value="Andor"
|
|
575
438
|
suggestions={countries}
|
|
576
439
|
onChange={onChange}
|
|
440
|
+
onBlur={onBlur}
|
|
577
441
|
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
578
442
|
/>
|
|
579
443
|
);
|
|
@@ -584,36 +448,38 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
584
448
|
expect(getByText("ra")).toBeTruthy();
|
|
585
449
|
fireEvent.mouseDown(getByRole("option"));
|
|
586
450
|
fireEvent.mouseUp(getByRole("option"));
|
|
587
|
-
expect(onChange).toHaveBeenCalledWith("Andorra");
|
|
451
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Andorra", error: "Please match the format requested." });
|
|
588
452
|
fireEvent.blur(input);
|
|
589
|
-
expect(
|
|
453
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Andorra", error: "Please match the format requested." });
|
|
590
454
|
});
|
|
591
|
-
test("Autosuggest
|
|
455
|
+
test("Autosuggest - Length constraint", async () => {
|
|
592
456
|
const onChange = jest.fn();
|
|
593
|
-
const
|
|
594
|
-
|
|
457
|
+
const onBlur = jest.fn();
|
|
458
|
+
const { getByText, getByRole } = render(
|
|
459
|
+
<DxcTextInput
|
|
595
460
|
label="Autocomplete Countries"
|
|
596
|
-
value="Cha"
|
|
597
461
|
suggestions={countries}
|
|
598
462
|
onChange={onChange}
|
|
463
|
+
onBlur={onBlur}
|
|
599
464
|
length={{ min: 5, max: 10 }}
|
|
600
465
|
/>
|
|
601
466
|
);
|
|
602
467
|
const input = getByRole("combobox");
|
|
603
468
|
fireEvent.focus(input);
|
|
604
|
-
userEvent.type(input, "
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
fireEvent.
|
|
608
|
-
|
|
469
|
+
userEvent.type(input, "Cha");
|
|
470
|
+
expect(getByText("Cha")).toBeTruthy();
|
|
471
|
+
expect(getByText("d")).toBeTruthy();
|
|
472
|
+
fireEvent.mouseDown(getByRole("option"));
|
|
473
|
+
fireEvent.mouseUp(getByRole("option"));
|
|
474
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Cha", error: "Min length 5, max length 10." });
|
|
609
475
|
fireEvent.blur(input);
|
|
610
|
-
expect(
|
|
476
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Chad", error: "Min length 5, max length 10." });
|
|
611
477
|
});
|
|
612
478
|
test("Autosuggest keys: arrow down key opens autosuggest, active first option is selected with Enter and closes the autosuggest", async () => {
|
|
613
479
|
Element.prototype.scrollTo = () => {};
|
|
614
480
|
const onChange = jest.fn();
|
|
615
481
|
const { getByRole, queryByRole } = render(
|
|
616
|
-
<
|
|
482
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
617
483
|
);
|
|
618
484
|
const input = getByRole("combobox");
|
|
619
485
|
fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
@@ -627,7 +493,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
627
493
|
Element.prototype.scrollTo = () => {};
|
|
628
494
|
const onChange = jest.fn();
|
|
629
495
|
const { getByRole, queryByRole } = render(
|
|
630
|
-
<
|
|
496
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
631
497
|
);
|
|
632
498
|
const input = getByRole("combobox");
|
|
633
499
|
fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
@@ -641,7 +507,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
641
507
|
Element.prototype.scrollTo = () => {};
|
|
642
508
|
const onChange = jest.fn();
|
|
643
509
|
const { getByRole, queryByRole } = render(
|
|
644
|
-
<
|
|
510
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
645
511
|
);
|
|
646
512
|
const input = getByRole("combobox");
|
|
647
513
|
fireEvent.focus(input);
|
|
@@ -656,7 +522,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
656
522
|
Element.prototype.scrollTo = () => {};
|
|
657
523
|
const onChange = jest.fn();
|
|
658
524
|
const { getByRole, queryByRole } = render(
|
|
659
|
-
<
|
|
525
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
660
526
|
);
|
|
661
527
|
const input = getByRole("combobox");
|
|
662
528
|
fireEvent.focus(input);
|
|
@@ -670,13 +536,13 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
670
536
|
Element.prototype.scrollTo = () => {};
|
|
671
537
|
const onChange = jest.fn();
|
|
672
538
|
const { getByRole, queryByRole } = render(
|
|
673
|
-
<
|
|
539
|
+
<DxcTextInput label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
674
540
|
);
|
|
675
541
|
const input = getByRole("combobox");
|
|
676
542
|
fireEvent.focus(input);
|
|
677
543
|
userEvent.type(input, "Ba");
|
|
678
544
|
fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
679
|
-
fireEvent.keyDown(input, { key: "ArrowUp", code: "
|
|
545
|
+
fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUpp", keyCode: 38, charCode: 38 });
|
|
680
546
|
fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
681
547
|
fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
682
548
|
expect(input.value).toBe("Barbados");
|
|
@@ -687,7 +553,7 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
687
553
|
});
|
|
688
554
|
});
|
|
689
555
|
|
|
690
|
-
describe("
|
|
556
|
+
describe("TextInput component asynchronous autosuggest tests", () => {
|
|
691
557
|
test("Autosuggest 'Searching...' message is shown", async () => {
|
|
692
558
|
const callbackFunc = jest.fn((newValue) => {
|
|
693
559
|
const result = new Promise((resolve) =>
|
|
@@ -701,7 +567,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
701
567
|
});
|
|
702
568
|
const onChange = jest.fn();
|
|
703
569
|
const { getByRole, getByText } = render(
|
|
704
|
-
<
|
|
570
|
+
<DxcTextInput label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
|
|
705
571
|
);
|
|
706
572
|
const input = getByRole("combobox");
|
|
707
573
|
fireEvent.focus(input);
|
|
@@ -731,7 +597,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
731
597
|
});
|
|
732
598
|
const onChange = jest.fn();
|
|
733
599
|
const { getByRole, queryByText, queryByRole } = render(
|
|
734
|
-
<
|
|
600
|
+
<DxcTextInput label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
|
|
735
601
|
);
|
|
736
602
|
const input = getByRole("combobox");
|
|
737
603
|
fireEvent.focus(input);
|
|
@@ -755,7 +621,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
755
621
|
});
|
|
756
622
|
const onChange = jest.fn();
|
|
757
623
|
const { getByRole, getByText, queryByText, queryByRole } = render(
|
|
758
|
-
<
|
|
624
|
+
<DxcTextInput label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
|
|
759
625
|
);
|
|
760
626
|
const input = getByRole("combobox");
|
|
761
627
|
fireEvent.focus(input);
|
|
@@ -787,7 +653,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
787
653
|
});
|
|
788
654
|
const onChange = jest.fn();
|
|
789
655
|
const { getByRole, getByText } = render(
|
|
790
|
-
<
|
|
656
|
+
<DxcTextInput label="Autosuggest Countries" onChange={onChange} suggestions={callbackFunc} />
|
|
791
657
|
);
|
|
792
658
|
const input = getByRole("combobox");
|
|
793
659
|
fireEvent.focus(input);
|
|
@@ -796,7 +662,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
796
662
|
expect(getByText("Denmark")).toBeTruthy();
|
|
797
663
|
fireEvent.mouseDown(getByRole("option"));
|
|
798
664
|
fireEvent.mouseUp(getByRole("option"));
|
|
799
|
-
expect(onChange).toHaveBeenCalledWith("Denmark");
|
|
665
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Denmark", error: null });
|
|
800
666
|
expect(input.value).toBe("Denmark");
|
|
801
667
|
});
|
|
802
668
|
test("Asynchronous controlled autosuggest test", async () => {
|
|
@@ -812,7 +678,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
812
678
|
});
|
|
813
679
|
const onChange = jest.fn();
|
|
814
680
|
const { getByRole, getByText, queryByRole } = render(
|
|
815
|
-
<
|
|
681
|
+
<DxcTextInput label="Autosuggest Countries" value="Denm" onChange={onChange} suggestions={callbackFunc} />
|
|
816
682
|
);
|
|
817
683
|
const input = getByRole("combobox");
|
|
818
684
|
fireEvent.focus(input);
|
|
@@ -821,7 +687,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
821
687
|
expect(getByText("Denmark")).toBeTruthy();
|
|
822
688
|
fireEvent.mouseDown(getByRole("option"));
|
|
823
689
|
fireEvent.mouseUp(getByRole("option"));
|
|
824
|
-
expect(onChange).toHaveBeenCalledWith("Denmark");
|
|
690
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Denmark", error: null });
|
|
825
691
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
826
692
|
});
|
|
827
693
|
test("Asynchronous autosuggest shows 'No results found' after finishing no matches search", async () => {
|
|
@@ -837,7 +703,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
837
703
|
});
|
|
838
704
|
const onChange = jest.fn();
|
|
839
705
|
const { getByRole, getByText } = render(
|
|
840
|
-
<
|
|
706
|
+
<DxcTextInput label="Autosuggest Countries" onChange={onChange} suggestions={callbackFunc} />
|
|
841
707
|
);
|
|
842
708
|
const input = getByRole("combobox");
|
|
843
709
|
fireEvent.focus(input);
|
|
@@ -856,7 +722,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
856
722
|
});
|
|
857
723
|
const onChange = jest.fn();
|
|
858
724
|
const { getByRole, getByText } = render(
|
|
859
|
-
<
|
|
725
|
+
<DxcTextInput label="Autosuggest Countries" onChange={onChange} suggestions={errorCallbackFunc} />
|
|
860
726
|
);
|
|
861
727
|
const input = getByRole("combobox");
|
|
862
728
|
fireEvent.focus(input);
|