@dxc-technology/halstack-react 0.0.0-90f64ff → 0.0.0-9427b76
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 +66 -58
- package/dist/alert/Alert.js +1 -1
- package/dist/alert/index.d.ts +51 -0
- package/dist/common/variables.js +141 -58
- package/dist/date/Date.js +4 -6
- package/dist/file-input/FileInput.js +641 -0
- package/dist/file-input/FileItem.js +280 -0
- package/dist/file-input/index.d.ts +81 -0
- package/dist/layout/ApplicationLayout.js +1 -1
- package/dist/link/Link.js +4 -8
- package/dist/main.d.ts +7 -0
- package/dist/main.js +8 -0
- package/dist/new-date/NewDate.js +64 -67
- package/dist/new-date/index.d.ts +95 -0
- package/dist/new-input-text/NewInputText.js +160 -157
- package/dist/new-input-text/index.d.ts +135 -0
- package/dist/new-textarea/NewTextarea.js +53 -37
- package/dist/new-textarea/index.d.ts +117 -0
- package/dist/number/Number.js +1 -3
- package/dist/number/index.d.ts +113 -0
- package/dist/password/Password.js +3 -3
- package/dist/password/index.d.ts +94 -0
- package/dist/progress-bar/ProgressBar.js +1 -1
- package/dist/select/Select.js +122 -158
- package/dist/sidenav/Sidenav.js +6 -4
- package/dist/tag/Tag.js +26 -32
- package/package.json +2 -1
- package/test/FileInput.test.js +201 -0
- package/test/NewDate.test.js +41 -12
- package/test/NewInputText.test.js +104 -187
- package/test/NewTextarea.test.js +95 -101
- package/test/Number.test.js +44 -28
- package/test/Paginator.test.js +1 -1
- package/test/Password.test.js +15 -8
- package/test/ResultsetTable.test.js +1 -2
- package/test/Select.test.js +40 -17
- package/dist/select/Select.stories.js +0 -235
- package/dist/select/readme.md +0 -72
|
@@ -56,29 +56,38 @@ describe("NewInputText component tests", () => {
|
|
|
56
56
|
);
|
|
57
57
|
expect(getByText("Error message.")).toBeTruthy();
|
|
58
58
|
});
|
|
59
|
-
test("
|
|
59
|
+
test("Not optional constraint (onBlur)", () => {
|
|
60
60
|
const onChange = jest.fn();
|
|
61
61
|
const onBlur = jest.fn();
|
|
62
|
-
const { getByRole
|
|
63
|
-
<DxcNewInputText
|
|
64
|
-
label="Input label"
|
|
65
|
-
placeholder="Placeholder"
|
|
66
|
-
onChange={onChange}
|
|
67
|
-
onBlur={onBlur}
|
|
68
|
-
margin={{ left: "medium", right: "medium" }}
|
|
69
|
-
clearable
|
|
70
|
-
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
71
|
-
/>
|
|
62
|
+
const { getByRole } = render(
|
|
63
|
+
<DxcNewInputText label="Input label" placeholder="Placeholder" onChange={onChange} onBlur={onBlur} clearable />
|
|
72
64
|
);
|
|
73
65
|
const input = getByRole("textbox");
|
|
74
|
-
|
|
66
|
+
|
|
67
|
+
fireEvent.focus(input);
|
|
75
68
|
fireEvent.blur(input);
|
|
76
|
-
expect(
|
|
77
|
-
|
|
69
|
+
expect(onBlur).toHaveBeenCalled();
|
|
70
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
71
|
+
fireEvent.change(input, { target: { value: "Test" } });
|
|
78
72
|
fireEvent.blur(input);
|
|
79
|
-
expect(
|
|
73
|
+
expect(onBlur).toHaveBeenCalled();
|
|
74
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Test", error: null });
|
|
80
75
|
});
|
|
81
|
-
test("
|
|
76
|
+
test("Not optional constraint (onChange)", () => {
|
|
77
|
+
const onChange = jest.fn();
|
|
78
|
+
const { getByRole } = render(
|
|
79
|
+
<DxcNewInputText label="Input label" placeholder="Placeholder" onChange={onChange} clearable />
|
|
80
|
+
);
|
|
81
|
+
const input = getByRole("textbox");
|
|
82
|
+
|
|
83
|
+
fireEvent.change(input, { target: { value: "Test" } });
|
|
84
|
+
expect(onChange).toHaveBeenCalled();
|
|
85
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Test", error: null });
|
|
86
|
+
userEvent.clear(input);
|
|
87
|
+
expect(onChange).toHaveBeenCalled();
|
|
88
|
+
expect(onChange).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
89
|
+
});
|
|
90
|
+
test("Pattern constraint", () => {
|
|
82
91
|
const onChange = jest.fn();
|
|
83
92
|
const onBlur = jest.fn();
|
|
84
93
|
const { getByRole, getByText, queryByText } = render(
|
|
@@ -89,18 +98,26 @@ describe("NewInputText component tests", () => {
|
|
|
89
98
|
onBlur={onBlur}
|
|
90
99
|
margin={{ left: "medium", right: "medium" }}
|
|
91
100
|
clearable
|
|
92
|
-
|
|
101
|
+
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
93
102
|
/>
|
|
94
103
|
);
|
|
95
104
|
const input = getByRole("textbox");
|
|
96
|
-
|
|
105
|
+
|
|
106
|
+
fireEvent.change(input, { target: { value: "pattern test" } });
|
|
107
|
+
expect(onChange).toHaveBeenCalled();
|
|
108
|
+
expect(onChange).toHaveBeenCalledWith({ value: "pattern test", error: "Please match the format requested." });
|
|
97
109
|
fireEvent.blur(input);
|
|
98
|
-
expect(
|
|
99
|
-
|
|
110
|
+
expect(onBlur).toHaveBeenCalled();
|
|
111
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "pattern test", error: "Please match the format requested." });
|
|
112
|
+
userEvent.clear(input);
|
|
113
|
+
fireEvent.change(input, { target: { value: "pattern4&" } });
|
|
114
|
+
expect(onChange).toHaveBeenCalled();
|
|
115
|
+
expect(onChange).toHaveBeenCalledWith({ value: "pattern4&", error: null });
|
|
100
116
|
fireEvent.blur(input);
|
|
101
|
-
expect(
|
|
117
|
+
expect(onBlur).toHaveBeenCalled();
|
|
118
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "pattern4&", error: null });
|
|
102
119
|
});
|
|
103
|
-
test("
|
|
120
|
+
test("Length constraint", () => {
|
|
104
121
|
const onChange = jest.fn();
|
|
105
122
|
const onBlur = jest.fn();
|
|
106
123
|
const { getByRole, getByText, queryByText } = render(
|
|
@@ -111,30 +128,29 @@ describe("NewInputText component tests", () => {
|
|
|
111
128
|
onBlur={onBlur}
|
|
112
129
|
margin={{ left: "medium", right: "medium" }}
|
|
113
130
|
clearable
|
|
114
|
-
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
115
131
|
length={{ min: 5, max: 10 }}
|
|
116
132
|
/>
|
|
117
133
|
);
|
|
118
134
|
const input = getByRole("textbox");
|
|
119
|
-
|
|
120
|
-
fireEvent.
|
|
121
|
-
expect(
|
|
122
|
-
|
|
135
|
+
|
|
136
|
+
fireEvent.change(input, { target: { value: "test" } });
|
|
137
|
+
expect(onChange).toHaveBeenCalled();
|
|
138
|
+
expect(onChange).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
123
139
|
fireEvent.blur(input);
|
|
124
|
-
expect(
|
|
125
|
-
|
|
140
|
+
expect(onBlur).toHaveBeenCalled();
|
|
141
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
142
|
+
userEvent.clear(input);
|
|
143
|
+
fireEvent.change(input, { target: { value: "length" } });
|
|
144
|
+
expect(onChange).toHaveBeenCalled();
|
|
145
|
+
expect(onChange).toHaveBeenCalledWith({ value: "length", error: null });
|
|
126
146
|
fireEvent.blur(input);
|
|
127
|
-
expect(
|
|
147
|
+
expect(onBlur).toHaveBeenCalled();
|
|
148
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "length", error: null });
|
|
128
149
|
});
|
|
129
|
-
test("
|
|
130
|
-
const onChange = jest.fn(
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
134
|
-
expect(value).toBe("t");
|
|
135
|
-
expect(error).toBe("Please match the format requested.");
|
|
136
|
-
});
|
|
137
|
-
const { getByRole } = render(
|
|
150
|
+
test("Pattern and length constraints", () => {
|
|
151
|
+
const onChange = jest.fn();
|
|
152
|
+
const onBlur = jest.fn();
|
|
153
|
+
const { getByRole, getByText, queryByText } = render(
|
|
138
154
|
<DxcNewInputText
|
|
139
155
|
label="Input label"
|
|
140
156
|
placeholder="Placeholder"
|
|
@@ -143,57 +159,29 @@ describe("NewInputText component tests", () => {
|
|
|
143
159
|
margin={{ left: "medium", right: "medium" }}
|
|
144
160
|
clearable
|
|
145
161
|
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
146
|
-
/>
|
|
147
|
-
);
|
|
148
|
-
const input = getByRole("textbox");
|
|
149
|
-
userEvent.type(input, "t");
|
|
150
|
-
fireEvent.blur(input);
|
|
151
|
-
});
|
|
152
|
-
test("Input Non Strict - Length constraint", () => {
|
|
153
|
-
const onChange = jest.fn((value) => {
|
|
154
|
-
expect(value).toBe("t");
|
|
155
|
-
});
|
|
156
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
157
|
-
expect(value).toBe("t");
|
|
158
|
-
expect(error).toBe("Min length 5, max length 10.");
|
|
159
|
-
});
|
|
160
|
-
const { getByRole } = render(
|
|
161
|
-
<DxcNewInputText
|
|
162
|
-
label="Input label"
|
|
163
|
-
placeholder="Placeholder"
|
|
164
|
-
onChange={onChange}
|
|
165
|
-
onBlur={onBlur}
|
|
166
|
-
margin={{ left: "medium", right: "medium" }}
|
|
167
|
-
clearable
|
|
168
162
|
length={{ min: 5, max: 10 }}
|
|
169
163
|
/>
|
|
170
164
|
);
|
|
171
165
|
const input = getByRole("textbox");
|
|
172
|
-
|
|
166
|
+
|
|
167
|
+
fireEvent.change(input, { target: { value: "test" } });
|
|
168
|
+
expect(onChange).toHaveBeenCalled();
|
|
169
|
+
expect(onChange).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
173
170
|
fireEvent.blur(input);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
label="Input label"
|
|
186
|
-
placeholder="Placeholder"
|
|
187
|
-
onChange={onChange}
|
|
188
|
-
onBlur={onBlur}
|
|
189
|
-
margin={{ left: "medium", right: "medium" }}
|
|
190
|
-
clearable
|
|
191
|
-
length={{ min: 5, max: 10 }}
|
|
192
|
-
/>
|
|
193
|
-
);
|
|
194
|
-
const input = getByRole("textbox");
|
|
195
|
-
userEvent.type(input, "t");
|
|
171
|
+
expect(onBlur).toHaveBeenCalled();
|
|
172
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
173
|
+
fireEvent.change(input, { target: { value: "tests" } });
|
|
174
|
+
expect(onChange).toHaveBeenCalled();
|
|
175
|
+
expect(onChange).toHaveBeenCalledWith({ value: "tests", error: "Please match the format requested." });
|
|
176
|
+
fireEvent.blur(input);
|
|
177
|
+
expect(onBlur).toHaveBeenCalled();
|
|
178
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "tests", error: "Please match the format requested." });
|
|
179
|
+
fireEvent.change(input, { target: { value: "tests4&" } });
|
|
180
|
+
expect(onChange).toHaveBeenCalled();
|
|
181
|
+
expect(onChange).toHaveBeenCalledWith({ value: "tests4&", error: null });
|
|
196
182
|
fireEvent.blur(input);
|
|
183
|
+
expect(onBlur).toHaveBeenCalled();
|
|
184
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "tests4&", error: null });
|
|
197
185
|
});
|
|
198
186
|
test("onChange function is called correctly", () => {
|
|
199
187
|
const onChange = jest.fn();
|
|
@@ -202,40 +190,17 @@ describe("NewInputText component tests", () => {
|
|
|
202
190
|
userEvent.type(input, "onchange event test");
|
|
203
191
|
expect(input.value).toBe("onchange event test");
|
|
204
192
|
expect(onChange).toHaveBeenCalled();
|
|
205
|
-
expect(onChange).toHaveBeenCalledWith("onchange event test");
|
|
193
|
+
expect(onChange).toHaveBeenCalledWith({ value: "onchange event test", error: null });
|
|
206
194
|
});
|
|
207
195
|
test("onBlur function is called correctly", () => {
|
|
208
196
|
const onBlur = jest.fn();
|
|
209
197
|
const onChange = jest.fn();
|
|
210
198
|
const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} onBlur={onBlur} />);
|
|
211
199
|
const input = getByRole("textbox");
|
|
212
|
-
|
|
200
|
+
fireEvent.change(input, { target: { value: "Blur test" } });
|
|
213
201
|
fireEvent.blur(input);
|
|
214
202
|
expect(onBlur).toHaveBeenCalled();
|
|
215
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "
|
|
216
|
-
});
|
|
217
|
-
test("Uncontrolled input", () => {
|
|
218
|
-
const onChange = jest.fn();
|
|
219
|
-
const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} />);
|
|
220
|
-
const input = getByRole("textbox");
|
|
221
|
-
userEvent.type(input, "Uncontrolled test");
|
|
222
|
-
expect(onChange).toHaveBeenCalled();
|
|
223
|
-
expect(onChange).toHaveBeenCalledWith("Uncontrolled test");
|
|
224
|
-
expect(input.value).toBe("Uncontrolled test");
|
|
225
|
-
});
|
|
226
|
-
test("Controlled input", () => {
|
|
227
|
-
const onChange = jest.fn();
|
|
228
|
-
const onBlur = jest.fn();
|
|
229
|
-
const { getByRole } = render(
|
|
230
|
-
<DxcNewInputText label="Input label" value="Test value" onChange={onChange} onBlur={onBlur} />
|
|
231
|
-
);
|
|
232
|
-
const input = getByRole("textbox");
|
|
233
|
-
userEvent.type(input, "Example text");
|
|
234
|
-
expect(onChange).toHaveBeenCalled();
|
|
235
|
-
expect(input.value).toBe("Test value");
|
|
236
|
-
fireEvent.blur(input);
|
|
237
|
-
expect(onBlur).toHaveBeenCalled();
|
|
238
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "Test value", error: null });
|
|
203
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Blur test", error: null });
|
|
239
204
|
});
|
|
240
205
|
test("Clear action onClick cleans the input", () => {
|
|
241
206
|
const { getByRole } = render(<DxcNewInputText label="Input label" clearable />);
|
|
@@ -309,65 +274,11 @@ describe("NewInputText component tests", () => {
|
|
|
309
274
|
userEvent.click(getByRole("button"));
|
|
310
275
|
expect(onClick).toHaveBeenCalled();
|
|
311
276
|
});
|
|
312
|
-
test("Renders with correct prefix and suffix
|
|
277
|
+
test("Renders with correct prefix and suffix", () => {
|
|
313
278
|
const { getByText } = render(<DxcNewInputText label="Input label" prefix="+34" suffix="USD" />);
|
|
314
279
|
expect(getByText("+34")).toBeTruthy();
|
|
315
280
|
expect(getByText("USD")).toBeTruthy();
|
|
316
281
|
});
|
|
317
|
-
test("Renders with correct prefix (icon)", () => {
|
|
318
|
-
const { getByTestId } = render(
|
|
319
|
-
<DxcNewInputText
|
|
320
|
-
label="Input label"
|
|
321
|
-
prefix={
|
|
322
|
-
<svg
|
|
323
|
-
data-testid="image"
|
|
324
|
-
version="1.1"
|
|
325
|
-
x="0px"
|
|
326
|
-
y="0px"
|
|
327
|
-
width="24px"
|
|
328
|
-
height="24px"
|
|
329
|
-
viewBox="0 0 24 24"
|
|
330
|
-
enable-background="new 0 0 24 24"
|
|
331
|
-
>
|
|
332
|
-
<g id="Bounding_Box">
|
|
333
|
-
<rect fill="none" width="24" height="24" />
|
|
334
|
-
</g>
|
|
335
|
-
<g id="Master">
|
|
336
|
-
<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" />
|
|
337
|
-
</g>
|
|
338
|
-
</svg>
|
|
339
|
-
}
|
|
340
|
-
/>
|
|
341
|
-
);
|
|
342
|
-
expect(getByTestId("image")).toBeTruthy();
|
|
343
|
-
});
|
|
344
|
-
test("Renders with correct suffix (icon)", () => {
|
|
345
|
-
const { getByTestId } = render(
|
|
346
|
-
<DxcNewInputText
|
|
347
|
-
label="Input label"
|
|
348
|
-
suffix={
|
|
349
|
-
<svg
|
|
350
|
-
data-testid="image"
|
|
351
|
-
version="1.1"
|
|
352
|
-
x="0px"
|
|
353
|
-
y="0px"
|
|
354
|
-
width="24px"
|
|
355
|
-
height="24px"
|
|
356
|
-
viewBox="0 0 24 24"
|
|
357
|
-
enable-background="new 0 0 24 24"
|
|
358
|
-
>
|
|
359
|
-
<g id="Bounding_Box">
|
|
360
|
-
<rect fill="none" width="24" height="24" />
|
|
361
|
-
</g>
|
|
362
|
-
<g id="Master">
|
|
363
|
-
<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" />
|
|
364
|
-
</g>
|
|
365
|
-
</svg>
|
|
366
|
-
}
|
|
367
|
-
/>
|
|
368
|
-
);
|
|
369
|
-
expect(getByTestId("image")).toBeTruthy();
|
|
370
|
-
});
|
|
371
282
|
test("Input has correct accesibility attributes", () => {
|
|
372
283
|
const onClick = jest.fn();
|
|
373
284
|
const action = {
|
|
@@ -386,29 +297,32 @@ describe("NewInputText component tests", () => {
|
|
|
386
297
|
</svg>
|
|
387
298
|
),
|
|
388
299
|
};
|
|
389
|
-
const { getByRole, getAllByRole } = render(
|
|
390
|
-
<DxcNewInputText label="Example label" clearable action={action} error="Error message." />
|
|
391
|
-
);
|
|
300
|
+
const { getByRole, getAllByRole } = render(<DxcNewInputText label="Example label" clearable action={action} />);
|
|
392
301
|
const input = getByRole("textbox");
|
|
393
302
|
expect(input.getAttribute("aria-autocomplete")).toBeNull();
|
|
394
303
|
expect(input.getAttribute("aria-controls")).toBeNull();
|
|
395
304
|
expect(input.getAttribute("aria-expanded")).toBeNull();
|
|
396
|
-
expect(input.getAttribute("aria-
|
|
305
|
+
expect(input.getAttribute("aria-activedescendant")).toBeNull();
|
|
306
|
+
expect(input.getAttribute("aria-invalid")).toBe("false");
|
|
307
|
+
expect(input.getAttribute("aria-describedBy")).toBeNull();
|
|
308
|
+
expect(input.getAttribute("aria-required")).toBe("true");
|
|
397
309
|
userEvent.type(input, "Text");
|
|
398
310
|
const clear = getAllByRole("button")[0];
|
|
399
311
|
expect(clear.getAttribute("aria-label")).toBe("Clear");
|
|
400
312
|
});
|
|
401
313
|
test("Autosuggest has correct accesibility attributes", () => {
|
|
402
314
|
const { getByRole, getAllByRole } = render(
|
|
403
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} />
|
|
315
|
+
<DxcNewInputText label="Autocomplete Countries" optional suggestions={countries} />
|
|
404
316
|
);
|
|
405
317
|
const input = getByRole("combobox");
|
|
406
318
|
const inputId = input.id;
|
|
407
319
|
expect(input.getAttribute("aria-autocomplete")).toBe("list");
|
|
408
320
|
expect(input.getAttribute("aria-controls")).toBe(inputId);
|
|
409
321
|
expect(input.getAttribute("aria-expanded")).toBe("false");
|
|
322
|
+
expect(input.getAttribute("aria-required")).toBe("false");
|
|
410
323
|
fireEvent.focus(input);
|
|
411
324
|
const list = getByRole("listbox");
|
|
325
|
+
expect(input.getAttribute("aria-expanded")).toBe("true");
|
|
412
326
|
expect(list.getAttribute("aria-label")).toBe("Autocomplete Countries");
|
|
413
327
|
const options = getAllByRole("option");
|
|
414
328
|
expect(options[0].getAttribute("aria-selected")).toBe("false");
|
|
@@ -514,17 +428,18 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
514
428
|
expect(getByText("ra")).toBeTruthy();
|
|
515
429
|
fireEvent.mouseDown(getByRole("option"));
|
|
516
430
|
fireEvent.mouseUp(getByRole("option"));
|
|
517
|
-
expect(onChange).toHaveBeenCalledWith("Andorra");
|
|
431
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Andorra", error: null });
|
|
518
432
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
519
433
|
});
|
|
520
|
-
test("Autosuggest
|
|
434
|
+
test("Autosuggest - Pattern constraint", async () => {
|
|
521
435
|
const onChange = jest.fn();
|
|
522
|
-
const
|
|
436
|
+
const onBlur = jest.fn();
|
|
437
|
+
const { getByRole, getByText } = render(
|
|
523
438
|
<DxcNewInputText
|
|
524
439
|
label="Autocomplete Countries"
|
|
525
|
-
value="Andor"
|
|
526
440
|
suggestions={countries}
|
|
527
441
|
onChange={onChange}
|
|
442
|
+
onBlur={onBlur}
|
|
528
443
|
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
529
444
|
/>
|
|
530
445
|
);
|
|
@@ -535,30 +450,32 @@ describe("NewInputText component synchronous autosuggest tests", () => {
|
|
|
535
450
|
expect(getByText("ra")).toBeTruthy();
|
|
536
451
|
fireEvent.mouseDown(getByRole("option"));
|
|
537
452
|
fireEvent.mouseUp(getByRole("option"));
|
|
538
|
-
expect(onChange).toHaveBeenCalledWith("Andorra");
|
|
453
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Andorra", error: "Please match the format requested." });
|
|
539
454
|
fireEvent.blur(input);
|
|
540
|
-
expect(
|
|
455
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Andorra", error: "Please match the format requested." });
|
|
541
456
|
});
|
|
542
|
-
test("Autosuggest
|
|
457
|
+
test("Autosuggest - Length constraint", async () => {
|
|
543
458
|
const onChange = jest.fn();
|
|
544
|
-
const
|
|
459
|
+
const onBlur = jest.fn();
|
|
460
|
+
const { getByText, getByRole } = render(
|
|
545
461
|
<DxcNewInputText
|
|
546
462
|
label="Autocomplete Countries"
|
|
547
|
-
value="Cha"
|
|
548
463
|
suggestions={countries}
|
|
549
464
|
onChange={onChange}
|
|
465
|
+
onBlur={onBlur}
|
|
550
466
|
length={{ min: 5, max: 10 }}
|
|
551
467
|
/>
|
|
552
468
|
);
|
|
553
469
|
const input = getByRole("combobox");
|
|
554
470
|
fireEvent.focus(input);
|
|
555
|
-
userEvent.type(input, "
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
fireEvent.
|
|
559
|
-
|
|
471
|
+
userEvent.type(input, "Cha");
|
|
472
|
+
expect(getByText("Cha")).toBeTruthy();
|
|
473
|
+
expect(getByText("d")).toBeTruthy();
|
|
474
|
+
fireEvent.mouseDown(getByRole("option"));
|
|
475
|
+
fireEvent.mouseUp(getByRole("option"));
|
|
476
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Cha", error: "Min length 5, max length 10." });
|
|
560
477
|
fireEvent.blur(input);
|
|
561
|
-
expect(
|
|
478
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Chad", error: "Min length 5, max length 10." });
|
|
562
479
|
});
|
|
563
480
|
test("Autosuggest keys: arrow down key opens autosuggest, active first option is selected with Enter and closes the autosuggest", async () => {
|
|
564
481
|
Element.prototype.scrollTo = () => {};
|
|
@@ -747,7 +664,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
747
664
|
expect(getByText("Denmark")).toBeTruthy();
|
|
748
665
|
fireEvent.mouseDown(getByRole("option"));
|
|
749
666
|
fireEvent.mouseUp(getByRole("option"));
|
|
750
|
-
expect(onChange).toHaveBeenCalledWith("Denmark");
|
|
667
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Denmark", error: null });
|
|
751
668
|
expect(input.value).toBe("Denmark");
|
|
752
669
|
});
|
|
753
670
|
test("Asynchronous controlled autosuggest test", async () => {
|
|
@@ -772,7 +689,7 @@ describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
|
772
689
|
expect(getByText("Denmark")).toBeTruthy();
|
|
773
690
|
fireEvent.mouseDown(getByRole("option"));
|
|
774
691
|
fireEvent.mouseUp(getByRole("option"));
|
|
775
|
-
expect(onChange).toHaveBeenCalledWith("Denmark");
|
|
692
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Denmark", error: null });
|
|
776
693
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
777
694
|
});
|
|
778
695
|
test("Asynchronous autosuggest shows 'No results found' after finishing no matches search", async () => {
|