@dxc-technology/halstack-react 0.0.0-8d633bd → 0.0.0-8db6a95

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.
Files changed (185) hide show
  1. package/README.md +27 -47
  2. package/dist/index.d.mts +6669 -0
  3. package/dist/index.d.ts +6669 -0
  4. package/dist/index.js +14523 -0
  5. package/dist/index.mjs +14465 -0
  6. package/package.json +76 -68
  7. package/babel.config.js +0 -8
  8. package/dist/BackgroundColorContext.js +0 -46
  9. package/dist/ThemeContext.js +0 -240
  10. package/dist/accordion/Accordion.js +0 -353
  11. package/dist/accordion-group/AccordionGroup.js +0 -186
  12. package/dist/alert/Alert.js +0 -403
  13. package/dist/alert/index.d.ts +0 -26
  14. package/dist/badge/Badge.js +0 -63
  15. package/dist/box/Box.js +0 -156
  16. package/dist/button/Button.js +0 -238
  17. package/dist/card/Card.js +0 -254
  18. package/dist/checkbox/Checkbox.js +0 -300
  19. package/dist/checkbox/Checkbox.stories.js +0 -144
  20. package/dist/checkbox/readme.md +0 -116
  21. package/dist/chip/Chip.js +0 -265
  22. package/dist/common/OpenSans.css +0 -81
  23. package/dist/common/RequiredComponent.js +0 -40
  24. package/dist/common/fonts/OpenSans-Bold.ttf +0 -0
  25. package/dist/common/fonts/OpenSans-BoldItalic.ttf +0 -0
  26. package/dist/common/fonts/OpenSans-ExtraBold.ttf +0 -0
  27. package/dist/common/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  28. package/dist/common/fonts/OpenSans-Italic.ttf +0 -0
  29. package/dist/common/fonts/OpenSans-Light.ttf +0 -0
  30. package/dist/common/fonts/OpenSans-LightItalic.ttf +0 -0
  31. package/dist/common/fonts/OpenSans-Regular.ttf +0 -0
  32. package/dist/common/fonts/OpenSans-SemiBold.ttf +0 -0
  33. package/dist/common/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
  34. package/dist/common/utils.js +0 -22
  35. package/dist/common/variables.js +0 -1417
  36. package/dist/date/Date.js +0 -381
  37. package/dist/date/Date.stories.js +0 -205
  38. package/dist/date/readme.md +0 -73
  39. package/dist/dialog/Dialog.js +0 -218
  40. package/dist/dropdown/Dropdown.js +0 -544
  41. package/dist/file-input/FileInput.js +0 -641
  42. package/dist/file-input/FileItem.js +0 -263
  43. package/dist/footer/Footer.js +0 -395
  44. package/dist/footer/Footer.stories.js +0 -94
  45. package/dist/footer/dxc_logo.svg +0 -15
  46. package/dist/footer/readme.md +0 -41
  47. package/dist/header/Header.js +0 -403
  48. package/dist/header/Header.stories.js +0 -176
  49. package/dist/header/close_icon.svg +0 -1
  50. package/dist/header/dxc_logo_black.svg +0 -8
  51. package/dist/header/hamb_menu_black.svg +0 -1
  52. package/dist/header/hamb_menu_white.svg +0 -1
  53. package/dist/header/readme.md +0 -33
  54. package/dist/heading/Heading.js +0 -218
  55. package/dist/input-text/InputText.js +0 -707
  56. package/dist/input-text/InputText.stories.js +0 -209
  57. package/dist/input-text/error.svg +0 -1
  58. package/dist/input-text/readme.md +0 -91
  59. package/dist/layout/ApplicationLayout.js +0 -331
  60. package/dist/layout/facebook.svg +0 -45
  61. package/dist/layout/linkedin.svg +0 -50
  62. package/dist/layout/twitter.svg +0 -53
  63. package/dist/link/Link.js +0 -237
  64. package/dist/link/readme.md +0 -51
  65. package/dist/main.d.ts +0 -2
  66. package/dist/main.js +0 -359
  67. package/dist/new-date/NewDate.js +0 -403
  68. package/dist/new-input-text/NewInputText.js +0 -977
  69. package/dist/new-textarea/NewTextarea.js +0 -365
  70. package/dist/number/Number.js +0 -138
  71. package/dist/number/NumberContext.js +0 -16
  72. package/dist/paginator/Paginator.js +0 -289
  73. package/dist/paginator/images/next.svg +0 -3
  74. package/dist/paginator/images/nextPage.svg +0 -3
  75. package/dist/paginator/images/previous.svg +0 -3
  76. package/dist/paginator/images/previousPage.svg +0 -3
  77. package/dist/paginator/readme.md +0 -50
  78. package/dist/password/Password.js +0 -200
  79. package/dist/password/styles.css +0 -3
  80. package/dist/progress-bar/ProgressBar.js +0 -242
  81. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  82. package/dist/progress-bar/readme.md +0 -63
  83. package/dist/radio/Radio.js +0 -209
  84. package/dist/radio/Radio.stories.js +0 -166
  85. package/dist/radio/readme.md +0 -70
  86. package/dist/resultsetTable/ResultsetTable.js +0 -358
  87. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  88. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  89. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  90. package/dist/select/Select.js +0 -549
  91. package/dist/sidenav/Sidenav.js +0 -179
  92. package/dist/slider/Slider.js +0 -319
  93. package/dist/slider/Slider.stories.js +0 -241
  94. package/dist/slider/readme.md +0 -64
  95. package/dist/spinner/Spinner.js +0 -381
  96. package/dist/spinner/Spinner.stories.js +0 -183
  97. package/dist/spinner/readme.md +0 -65
  98. package/dist/switch/Switch.js +0 -222
  99. package/dist/switch/Switch.stories.js +0 -134
  100. package/dist/switch/readme.md +0 -133
  101. package/dist/table/Table.js +0 -132
  102. package/dist/tabs/Tabs.js +0 -343
  103. package/dist/tabs/Tabs.stories.js +0 -130
  104. package/dist/tabs/readme.md +0 -78
  105. package/dist/tabs-for-sections/TabsForSections.js +0 -92
  106. package/dist/tabs-for-sections/readme.md +0 -78
  107. package/dist/tag/Tag.js +0 -282
  108. package/dist/textarea/Textarea.js +0 -264
  109. package/dist/toggle/Toggle.js +0 -220
  110. package/dist/toggle/Toggle.stories.js +0 -297
  111. package/dist/toggle/readme.md +0 -80
  112. package/dist/toggle-group/ToggleGroup.js +0 -223
  113. package/dist/upload/Upload.js +0 -205
  114. package/dist/upload/Upload.stories.js +0 -72
  115. package/dist/upload/buttons-upload/ButtonsUpload.js +0 -139
  116. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  117. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  118. package/dist/upload/dragAndDropArea/DragAndDropArea.js +0 -329
  119. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  120. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  121. package/dist/upload/file-upload/FileToUpload.js +0 -184
  122. package/dist/upload/file-upload/audio-icon.svg +0 -4
  123. package/dist/upload/file-upload/close.svg +0 -4
  124. package/dist/upload/file-upload/file-icon.svg +0 -4
  125. package/dist/upload/file-upload/video-icon.svg +0 -4
  126. package/dist/upload/files-upload/FilesToUpload.js +0 -123
  127. package/dist/upload/readme.md +0 -37
  128. package/dist/upload/transaction/Transaction.js +0 -175
  129. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  130. package/dist/upload/transaction/audio-icon.svg +0 -4
  131. package/dist/upload/transaction/error-icon.svg +0 -4
  132. package/dist/upload/transaction/file-icon-err.svg +0 -4
  133. package/dist/upload/transaction/file-icon.svg +0 -4
  134. package/dist/upload/transaction/image-icon-err.svg +0 -4
  135. package/dist/upload/transaction/image-icon.svg +0 -4
  136. package/dist/upload/transaction/success-icon.svg +0 -4
  137. package/dist/upload/transaction/video-icon-err.svg +0 -4
  138. package/dist/upload/transaction/video-icon.svg +0 -4
  139. package/dist/upload/transactions/Transactions.js +0 -138
  140. package/dist/useTheme.js +0 -22
  141. package/dist/wizard/Wizard.js +0 -411
  142. package/dist/wizard/invalid_icon.svg +0 -5
  143. package/dist/wizard/valid_icon.svg +0 -5
  144. package/dist/wizard/validation-wrong.svg +0 -6
  145. package/test/Accordion.test.js +0 -33
  146. package/test/AccordionGroup.test.js +0 -125
  147. package/test/Alert.test.js +0 -53
  148. package/test/Box.test.js +0 -10
  149. package/test/Button.test.js +0 -18
  150. package/test/Card.test.js +0 -30
  151. package/test/Checkbox.test.js +0 -45
  152. package/test/Chip.test.js +0 -25
  153. package/test/Date.test.js +0 -393
  154. package/test/Dialog.test.js +0 -23
  155. package/test/Dropdown.test.js +0 -145
  156. package/test/FileInput.test.js +0 -39
  157. package/test/Footer.test.js +0 -99
  158. package/test/Header.test.js +0 -39
  159. package/test/Heading.test.js +0 -35
  160. package/test/InputText.test.js +0 -240
  161. package/test/Link.test.js +0 -43
  162. package/test/NewDate.test.js +0 -203
  163. package/test/NewInputText.test.js +0 -866
  164. package/test/NewTextarea.test.js +0 -252
  165. package/test/Number.test.js +0 -241
  166. package/test/Paginator.test.js +0 -177
  167. package/test/Password.test.js +0 -76
  168. package/test/ProgressBar.test.js +0 -35
  169. package/test/Radio.test.js +0 -37
  170. package/test/ResultsetTable.test.js +0 -329
  171. package/test/Select.test.js +0 -212
  172. package/test/Sidenav.test.js +0 -45
  173. package/test/Slider.test.js +0 -82
  174. package/test/Spinner.test.js +0 -32
  175. package/test/Switch.test.js +0 -45
  176. package/test/Table.test.js +0 -36
  177. package/test/Tabs.test.js +0 -109
  178. package/test/TabsForSections.test.js +0 -34
  179. package/test/Tag.test.js +0 -32
  180. package/test/TextArea.test.js +0 -52
  181. package/test/ToggleGroup.test.js +0 -81
  182. package/test/Upload.test.js +0 -60
  183. package/test/Wizard.test.js +0 -130
  184. package/test/mocks/pngMock.js +0 -1
  185. package/test/mocks/svgMock.js +0 -1
@@ -1,866 +0,0 @@
1
- import React from "react";
2
- import { render, fireEvent, waitForElementToBeRemoved } from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
-
5
- import DxcNewInputText from "../src/new-input-text/NewInputText";
6
-
7
- const countries = [
8
- "Afghanistan",
9
- "Albania",
10
- "Algeria",
11
- "Andorra",
12
- "Angola",
13
- "Antigua and Barbuda",
14
- "Bahamas",
15
- "Bahrain",
16
- "Bangladesh",
17
- "Barbados",
18
- "Cabo Verde",
19
- "Cambodia",
20
- "Cameroon",
21
- "Canada",
22
- "Cayman Islands, The",
23
- "Central African Republic",
24
- "Chad",
25
- "Democratic Republic of the Congo",
26
- "Dominican Republic",
27
- "Dominica",
28
- "Denmark",
29
- "Djibouti",
30
- ];
31
-
32
- describe("NewInputText component tests", () => {
33
- test("Renders with correct label", () => {
34
- const { getByText } = render(<DxcNewInputText label="Example label" />);
35
- expect(getByText("Example label")).toBeTruthy();
36
- });
37
- test("Renders with correct label and helper text", () => {
38
- const { getByText } = render(<DxcNewInputText label="Example label" helperText="Example helper text" />);
39
- expect(getByText("Example label")).toBeTruthy();
40
- expect(getByText("Example helper text")).toBeTruthy();
41
- });
42
- test("Renders with correct label and optional", () => {
43
- const { getByText } = render(<DxcNewInputText label="Example label" helperText="Example helper text" optional />);
44
- expect(getByText("Example label")).toBeTruthy();
45
- expect(getByText("(Optional)")).toBeTruthy();
46
- expect(getByText("Example helper text")).toBeTruthy();
47
- });
48
- test("Renders with correct placeholder", () => {
49
- const { getByRole } = render(<DxcNewInputText label="Example label" placeholder="Placeholder" />);
50
- const input = getByRole("textbox");
51
- expect(input.getAttribute("placeholder")).toBe("Placeholder");
52
- });
53
- test("Renders with error message", () => {
54
- const { getByText } = render(
55
- <DxcNewInputText label="Error label" placeholder="Placeholder" error="Error message." />
56
- );
57
- expect(getByText("Error message.")).toBeTruthy();
58
- });
59
- test("Input Strict - Not optional constraint", () => {
60
- const onChange = jest.fn();
61
- const onBlur = jest.fn();
62
- const { getByRole, getByText, queryByText } = render(
63
- <DxcNewInputText
64
- label="Input label"
65
- placeholder="Placeholder"
66
- onChange={onChange}
67
- onBlur={onBlur}
68
- clearable
69
- />
70
- );
71
- const input = getByRole("textbox");
72
- fireEvent.focus(input);
73
- fireEvent.blur(input);
74
- expect(getByText("This field is required. Please, enter a value.")).toBeTruthy();
75
- userEvent.type(input, "A");
76
- fireEvent.blur(input);
77
- expect(queryByText("This field is required. Please, enter a value.")).toBeFalsy();
78
- });
79
- test("Input Strict - Pattern constraint", () => {
80
- const onChange = jest.fn();
81
- const onBlur = jest.fn();
82
- const { getByRole, getByText, queryByText } = render(
83
- <DxcNewInputText
84
- label="Input label"
85
- placeholder="Placeholder"
86
- onChange={onChange}
87
- onBlur={onBlur}
88
- margin={{ left: "medium", right: "medium" }}
89
- clearable
90
- pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
91
- />
92
- );
93
- const input = getByRole("textbox");
94
- userEvent.type(input, "pattern test");
95
- fireEvent.blur(input);
96
- expect(getByText("Please match the format requested.")).toBeTruthy();
97
- userEvent.type(input, "pattern4&");
98
- fireEvent.blur(input);
99
- expect(queryByText("Please match the format requested.")).toBeFalsy();
100
- });
101
- test("Input Strict - Length constraint", () => {
102
- const onChange = jest.fn();
103
- const onBlur = jest.fn();
104
- const { getByRole, getByText, queryByText } = render(
105
- <DxcNewInputText
106
- label="Input label"
107
- placeholder="Placeholder"
108
- onChange={onChange}
109
- onBlur={onBlur}
110
- margin={{ left: "medium", right: "medium" }}
111
- clearable
112
- length={{ min: 5, max: 10 }}
113
- />
114
- );
115
- const input = getByRole("textbox");
116
- userEvent.type(input, "test");
117
- fireEvent.blur(input);
118
- expect(getByText("Min length 5, max length 10.")).toBeTruthy();
119
- userEvent.type(input, "test ");
120
- fireEvent.blur(input);
121
- expect(queryByText(/Min length /)).toBeFalsy();
122
- });
123
- test("Input Strict - Pattern and length constraints", () => {
124
- const onChange = jest.fn();
125
- const onBlur = jest.fn();
126
- const { getByRole, getByText, queryByText } = render(
127
- <DxcNewInputText
128
- label="Input label"
129
- placeholder="Placeholder"
130
- onChange={onChange}
131
- onBlur={onBlur}
132
- margin={{ left: "medium", right: "medium" }}
133
- clearable
134
- pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
135
- length={{ min: 5, max: 10 }}
136
- />
137
- );
138
- const input = getByRole("textbox");
139
- userEvent.type(input, "test");
140
- fireEvent.blur(input);
141
- expect(getByText("Min length 5, max length 10.")).toBeTruthy();
142
- userEvent.type(input, "test ");
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");
190
- fireEvent.blur(input);
191
- });
192
- test("Input Non Strict - Length constraint", () => {
193
- const onChange = jest.fn((value) => {
194
- expect(value).toBe("t");
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");
213
- fireEvent.blur(input);
214
- });
215
- test("Input Non Strict - Pattern and length constraints", () => {
216
- const onChange = jest.fn((value) => {
217
- expect(value).toBe("t");
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");
236
- fireEvent.blur(input);
237
- });
238
- test("onChange function is called correctly", () => {
239
- const onChange = jest.fn();
240
- const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} />);
241
- const input = getByRole("textbox");
242
- userEvent.type(input, "onchange event test");
243
- expect(input.value).toBe("onchange event test");
244
- expect(onChange).toHaveBeenCalled();
245
- expect(onChange).toHaveBeenCalledWith("onchange event test");
246
- });
247
- test("onBlur function is called correctly", () => {
248
- const onBlur = jest.fn();
249
- const onChange = jest.fn();
250
- const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} onBlur={onBlur} />);
251
- const input = getByRole("textbox");
252
- userEvent.type(input, "Test string");
253
- fireEvent.blur(input);
254
- expect(onBlur).toHaveBeenCalled();
255
- expect(onBlur).toHaveBeenCalledWith({ value: "Test string", error: null });
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 });
279
- });
280
- test("Clear action onClick cleans the input", () => {
281
- const { getByRole } = render(<DxcNewInputText label="Input label" clearable />);
282
- const input = getByRole("textbox");
283
- userEvent.type(input, "Test");
284
- const closeAction = getByRole("button");
285
- userEvent.click(closeAction);
286
- expect(input.value).toBe("");
287
- });
288
- test("Disabled input (action must be shown but not clickable)", () => {
289
- const onClick = jest.fn();
290
- const action = {
291
- onClick: onClick,
292
- icon: (
293
- <svg
294
- data-testid="image"
295
- xmlns="http://www.w3.org/2000/svg"
296
- height="24px"
297
- viewBox="0 0 24 24"
298
- width="24px"
299
- fill="currentColor"
300
- >
301
- <path d="M0 0h24v24H0V0z" fill="none" />
302
- <path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" />
303
- </svg>
304
- ),
305
- };
306
- const { getByRole } = render(<DxcNewInputText label="Disabled input label" action={action} disabled />);
307
- const input = getByRole("textbox");
308
- expect(input.disabled).toBeTruthy();
309
- userEvent.click(getByRole("button"));
310
- expect(onClick).not.toHaveBeenCalled();
311
- });
312
- test("Disabled input (clear default action should not be displayed, even with text written on the input)", () => {
313
- const { getByRole, queryByRole } = render(
314
- <DxcNewInputText label="Disabled input label" value="Sample text" disabled clearable />
315
- );
316
- const input = getByRole("textbox");
317
- expect(input.disabled).toBeTruthy();
318
- expect(queryByRole("button")).toBeFalsy();
319
- });
320
- test("Disabled input (suffix and preffix must be displayed)", () => {
321
- const { getByRole, getByText } = render(
322
- <DxcNewInputText label="Disabled input label" value="Sample text" prefix="+34" suffix="USD" disabled />
323
- );
324
- const input = getByRole("textbox");
325
- expect(input.disabled).toBeTruthy();
326
- expect(getByText("+34")).toBeTruthy();
327
- expect(getByText("USD")).toBeTruthy();
328
- });
329
- test("Action prop: image displayed and onClick event", () => {
330
- const onClick = jest.fn();
331
- const action = {
332
- onClick: onClick,
333
- icon: (
334
- <svg
335
- data-testid="image"
336
- xmlns="http://www.w3.org/2000/svg"
337
- height="24px"
338
- viewBox="0 0 24 24"
339
- width="24px"
340
- fill="currentColor"
341
- >
342
- <path d="M0 0h24v24H0V0z" fill="none" />
343
- <path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" />
344
- </svg>
345
- ),
346
- };
347
- const { getByRole, getByTestId } = render(<DxcNewInputText label="Input label" action={action} />);
348
- expect(getByTestId("image")).toBeTruthy();
349
- userEvent.click(getByRole("button"));
350
- expect(onClick).toHaveBeenCalled();
351
- });
352
- test("Renders with correct prefix and suffix (text)", () => {
353
- const { getByText } = render(<DxcNewInputText label="Input label" prefix="+34" suffix="USD" />);
354
- expect(getByText("+34")).toBeTruthy();
355
- expect(getByText("USD")).toBeTruthy();
356
- });
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
- test("Input has correct accesibility attributes", () => {
412
- const onClick = jest.fn();
413
- const action = {
414
- onClick: onClick,
415
- icon: (
416
- <svg
417
- data-testid="image"
418
- xmlns="http://www.w3.org/2000/svg"
419
- height="24px"
420
- viewBox="0 0 24 24"
421
- width="24px"
422
- fill="currentColor"
423
- >
424
- <path d="M0 0h24v24H0V0z" fill="none" />
425
- <path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" />
426
- </svg>
427
- ),
428
- };
429
- const { getByRole, getAllByRole } = render(
430
- <DxcNewInputText label="Example label" clearable action={action} />
431
- );
432
- const input = getByRole("textbox");
433
- expect(input.getAttribute("aria-autocomplete")).toBeNull();
434
- expect(input.getAttribute("aria-controls")).toBeNull();
435
- expect(input.getAttribute("aria-expanded")).toBeNull();
436
- expect(input.getAttribute("aria-activedescendant")).toBeNull();
437
- expect(input.getAttribute("aria-invalid")).toBe("false");
438
- expect(input.getAttribute("aria-describedBy")).toBeNull();
439
- expect(input.getAttribute("aria-required")).toBe("true");
440
- userEvent.type(input, "Text");
441
- const clear = getAllByRole("button")[0];
442
- 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
- });
448
- test("Autosuggest has correct accesibility attributes", () => {
449
- const { getByRole, getAllByRole } = render(
450
- <DxcNewInputText label="Autocomplete Countries" optional suggestions={countries} />
451
- );
452
- const input = getByRole("combobox");
453
- const inputId = input.id;
454
- expect(input.getAttribute("aria-autocomplete")).toBe("list");
455
- expect(input.getAttribute("aria-controls")).toBe(inputId);
456
- expect(input.getAttribute("aria-expanded")).toBe("false");
457
- expect(input.getAttribute("aria-required")).toBe("false");
458
- fireEvent.focus(input);
459
- const list = getByRole("listbox");
460
- expect(input.getAttribute("aria-expanded")).toBe("true");
461
- expect(list.getAttribute("aria-label")).toBe("Autocomplete Countries");
462
- const options = getAllByRole("option");
463
- expect(options[0].getAttribute("aria-selected")).toBe("false");
464
- });
465
- });
466
-
467
- describe("NewInputText component synchronous autosuggest tests", () => {
468
- test("Autosuggest is displayed when the input gains focus", async () => {
469
- const onChange = jest.fn();
470
- const { getByRole, getByText } = render(
471
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
472
- );
473
- const input = getByRole("combobox");
474
- fireEvent.focus(input);
475
- const list = getByRole("listbox");
476
- expect(list).toBeTruthy();
477
- expect(getByText("Afghanistan")).toBeTruthy();
478
- expect(getByText("Albania")).toBeTruthy();
479
- expect(getByText("Algeria")).toBeTruthy();
480
- expect(getByText("Andorra")).toBeTruthy();
481
- });
482
- test("Autosuggest is displayed when the user clicks the input", async () => {
483
- const onChange = jest.fn();
484
- const { getByRole, getByText } = render(
485
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
486
- );
487
- const input = getByRole("combobox");
488
- userEvent.click(input);
489
- const list = getByRole("listbox");
490
- expect(list).toBeTruthy();
491
- expect(getByText("Afghanistan")).toBeTruthy();
492
- expect(getByText("Albania")).toBeTruthy();
493
- expect(getByText("Algeria")).toBeTruthy();
494
- expect(getByText("Andorra")).toBeTruthy();
495
- });
496
- test("Autosuggest is displayed while the user is writing (if closed previously, if open stays open)", async () => {
497
- const onChange = jest.fn();
498
- const { getByRole, queryByRole, getByText, getAllByText } = render(
499
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
500
- );
501
- const input = getByRole("combobox");
502
- fireEvent.focus(input);
503
- const list = getByRole("listbox");
504
- expect(list).toBeTruthy();
505
- fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
506
- expect(queryByRole("listbox")).toBeFalsy();
507
- userEvent.type(input, "B");
508
- expect(list).toBeTruthy();
509
- expect(getAllByText("B").length).toBe(4);
510
- expect(getByText("ahamas")).toBeTruthy();
511
- expect(getByText("ahrain")).toBeTruthy();
512
- expect(getByText("angladesh")).toBeTruthy();
513
- expect(getByText("arbados")).toBeTruthy();
514
- });
515
- test("Autosuggest is not displayed when prop suggestions is an empty array", async () => {
516
- const onChange = jest.fn();
517
- const { queryByRole } = render(
518
- <DxcNewInputText label="Autocomplete Countries" suggestions={[]} onChange={onChange} />
519
- );
520
- const input = queryByRole("textbox");
521
- fireEvent.focus(input);
522
- expect(queryByRole("listbox")).toBeFalsy();
523
- });
524
- test("Autosuggest shows 'No results found' message when there are no matches with the user's input", async () => {
525
- const onChange = jest.fn();
526
- const { getByRole, getByText } = render(
527
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
528
- );
529
- const input = getByRole("combobox");
530
- fireEvent.focus(input);
531
- const list = getByRole("listbox");
532
- expect(list).toBeTruthy();
533
- expect(getByText("Afghanistan")).toBeTruthy();
534
- userEvent.type(input, "x");
535
- expect(list).toBeTruthy();
536
- expect(getByText("No results found")).toBeTruthy();
537
- });
538
- test("Autosuggest uncontrolled suggestion selected", async () => {
539
- const onChange = jest.fn();
540
- const { getByRole, getByText, queryByRole } = render(
541
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
542
- );
543
- const input = getByRole("combobox");
544
- fireEvent.focus(input);
545
- userEvent.type(input, "Alba");
546
- expect(onChange).toHaveBeenCalled();
547
- expect(getByText("Alba")).toBeTruthy();
548
- expect(getByText("nia")).toBeTruthy();
549
- fireEvent.mouseDown(getByRole("option"));
550
- fireEvent.mouseUp(getByRole("option"));
551
- expect(input.value).toBe("Albania");
552
- expect(queryByRole("listbox")).toBeFalsy();
553
- });
554
- test("Autosuggest controlled suggestions selected", async () => {
555
- const onChange = jest.fn();
556
- const { getByRole, getByText, queryByRole } = render(
557
- <DxcNewInputText label="Autocomplete Countries" value="Andor" suggestions={countries} onChange={onChange} />
558
- );
559
- const input = getByRole("combobox");
560
- fireEvent.focus(input);
561
- expect(input.value).toBe("Andor");
562
- expect(getByText("Andor")).toBeTruthy();
563
- expect(getByText("ra")).toBeTruthy();
564
- fireEvent.mouseDown(getByRole("option"));
565
- fireEvent.mouseUp(getByRole("option"));
566
- expect(onChange).toHaveBeenCalledWith("Andorra");
567
- expect(queryByRole("listbox")).toBeFalsy();
568
- });
569
- test("Autosuggest Strict - Pattern constraint", async () => {
570
- const onChange = jest.fn();
571
- const { getByRole, getByText, queryByText } = render(
572
- <DxcNewInputText
573
- label="Autocomplete Countries"
574
- value="Andor"
575
- suggestions={countries}
576
- onChange={onChange}
577
- pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
578
- />
579
- );
580
- const input = getByRole("combobox");
581
- fireEvent.focus(input);
582
- userEvent.type(input, "Andor");
583
- expect(getByText("Andor")).toBeTruthy();
584
- expect(getByText("ra")).toBeTruthy();
585
- fireEvent.mouseDown(getByRole("option"));
586
- fireEvent.mouseUp(getByRole("option"));
587
- expect(onChange).toHaveBeenCalledWith("Andorra");
588
- fireEvent.blur(input);
589
- expect(queryByText("Please match the format requested.")).toBeTruthy();
590
- });
591
- test("Autosuggest Strict - Length constraint", async () => {
592
- const onChange = jest.fn();
593
- const { getByRole, queryByText } = render(
594
- <DxcNewInputText
595
- label="Autocomplete Countries"
596
- value="Cha"
597
- suggestions={countries}
598
- onChange={onChange}
599
- length={{ min: 5, max: 10 }}
600
- />
601
- );
602
- const input = getByRole("combobox");
603
- fireEvent.focus(input);
604
- userEvent.type(input, "d");
605
- const option = getByRole("option");
606
- fireEvent.mouseDown(option);
607
- fireEvent.mouseUp(option);
608
- expect(onChange).toHaveBeenCalledWith("Chad");
609
- fireEvent.blur(input);
610
- expect(queryByText("Min length 5, max length 10.")).toBeTruthy();
611
- });
612
- test("Autosuggest keys: arrow down key opens autosuggest, active first option is selected with Enter and closes the autosuggest", async () => {
613
- Element.prototype.scrollTo = () => {};
614
- const onChange = jest.fn();
615
- const { getByRole, queryByRole } = render(
616
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
617
- );
618
- const input = getByRole("combobox");
619
- fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
620
- const list = getByRole("listbox");
621
- expect(list).toBeTruthy();
622
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
623
- expect(input.value).toBe("Afghanistan");
624
- expect(queryByRole("list")).toBeFalsy();
625
- });
626
- test("Autosuggest keys: arrow up key opens autosuggest, active last option is selected with Enter and closes the autosuggest", async () => {
627
- Element.prototype.scrollTo = () => {};
628
- const onChange = jest.fn();
629
- const { getByRole, queryByRole } = render(
630
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
631
- );
632
- const input = getByRole("combobox");
633
- fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
634
- const list = getByRole("listbox");
635
- expect(list).toBeTruthy();
636
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
637
- expect(input.value).toBe("Djibouti");
638
- expect(queryByRole("list")).toBeFalsy();
639
- });
640
- test("Autosuggest keys: Esc key closes the autosuggest and cleans the input", async () => {
641
- Element.prototype.scrollTo = () => {};
642
- const onChange = jest.fn();
643
- const { getByRole, queryByRole } = render(
644
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
645
- );
646
- const input = getByRole("combobox");
647
- fireEvent.focus(input);
648
- userEvent.type(input, "Bangla");
649
- const list = getByRole("listbox");
650
- expect(list).toBeTruthy();
651
- fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
652
- expect(input.value).toBe("");
653
- expect(queryByRole("listbox")).toBeFalsy();
654
- });
655
- test("Autosuggest keys: Enter, if no active suggestion closes the autosuggest", async () => {
656
- Element.prototype.scrollTo = () => {};
657
- const onChange = jest.fn();
658
- const { getByRole, queryByRole } = render(
659
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
660
- );
661
- const input = getByRole("combobox");
662
- fireEvent.focus(input);
663
- const list = getByRole("listbox");
664
- expect(list).toBeTruthy();
665
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 27, charCode: 27 });
666
- expect(input.value).toBe("");
667
- expect(queryByRole("list")).toBeFalsy();
668
- });
669
- test("Autosuggest complex key secuence: write, arrow up two times, arrow down and select with Enter. Then, clean with Esc.", async () => {
670
- Element.prototype.scrollTo = () => {};
671
- const onChange = jest.fn();
672
- const { getByRole, queryByRole } = render(
673
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
674
- );
675
- const input = getByRole("combobox");
676
- fireEvent.focus(input);
677
- userEvent.type(input, "Ba");
678
- fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
679
- fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
680
- fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
681
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
682
- expect(input.value).toBe("Barbados");
683
- expect(queryByRole("listbox")).toBeFalsy();
684
- fireEvent.keyDown(input, { key: "Esc", code: "Esp", keyCode: 27, charCode: 27 });
685
- expect(input.value).toBe("");
686
- expect(queryByRole("listbox")).toBeFalsy();
687
- });
688
- });
689
-
690
- describe("NewInputText component asynchronous autosuggest tests", () => {
691
- test("Autosuggest 'Searching...' message is shown", async () => {
692
- const callbackFunc = jest.fn((newValue) => {
693
- const result = new Promise((resolve) =>
694
- setTimeout(() => {
695
- resolve(
696
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
697
- );
698
- }, 1000)
699
- );
700
- return result;
701
- });
702
- const onChange = jest.fn();
703
- const { getByRole, getByText } = render(
704
- <DxcNewInputText label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
705
- );
706
- const input = getByRole("combobox");
707
- fireEvent.focus(input);
708
- expect(getByRole("listbox")).toBeTruthy();
709
- await waitForElementToBeRemoved(() => getByText("Searching..."));
710
- expect(getByText("Afghanistan")).toBeTruthy();
711
- expect(getByText("Albania")).toBeTruthy();
712
- expect(getByText("Algeria")).toBeTruthy();
713
- expect(getByText("Andorra")).toBeTruthy();
714
- userEvent.type(input, "Ab");
715
- await waitForElementToBeRemoved(() => getByText("Searching..."));
716
- expect(getByText("Cabo Verde")).toBeTruthy();
717
- fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
718
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
719
- expect(input.value).toBe("Cabo Verde");
720
- });
721
- test("Autosuggest Esc key works while 'Searching...' message is shown", async () => {
722
- const callbackFunc = jest.fn((newValue) => {
723
- const result = new Promise((resolve) =>
724
- setTimeout(() => {
725
- resolve(
726
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
727
- );
728
- }, 1000)
729
- );
730
- return result;
731
- });
732
- const onChange = jest.fn();
733
- const { getByRole, queryByText, queryByRole } = render(
734
- <DxcNewInputText label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
735
- );
736
- const input = getByRole("combobox");
737
- fireEvent.focus(input);
738
- expect(getByRole("listbox")).toBeTruthy();
739
- userEvent.type(input, "Ab");
740
- fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
741
- expect(queryByRole("listbox")).toBeFalsy();
742
- expect(queryByText("Searching...")).toBeFalsy();
743
- expect(input.value).toBe("");
744
- });
745
- test("Autosuggest Esc + arrow down working while 'Searching...' message is shown", async () => {
746
- const callbackFunc = jest.fn((newValue) => {
747
- const result = new Promise((resolve) =>
748
- setTimeout(() => {
749
- resolve(
750
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
751
- );
752
- }, 1000)
753
- );
754
- return result;
755
- });
756
- const onChange = jest.fn();
757
- const { getByRole, getByText, queryByText, queryByRole } = render(
758
- <DxcNewInputText label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
759
- );
760
- const input = getByRole("combobox");
761
- fireEvent.focus(input);
762
- const list = getByRole("listbox");
763
- expect(list).toBeTruthy();
764
- userEvent.type(input, "Ab");
765
- fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
766
- expect(queryByRole("listbox")).toBeFalsy();
767
- expect(queryByText("Searching...")).toBeFalsy();
768
- expect(input.value).toBe("");
769
- fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
770
- expect(list).toBeTruthy();
771
- await waitForElementToBeRemoved(() => getByText("Searching..."));
772
- expect(getByText("Afghanistan")).toBeTruthy();
773
- expect(getByText("Albania")).toBeTruthy();
774
- expect(getByText("Algeria")).toBeTruthy();
775
- expect(getByText("Andorra")).toBeTruthy();
776
- });
777
- test("Asynchronous uncontrolled autosuggest test", async () => {
778
- const callbackFunc = jest.fn((newValue) => {
779
- const result = new Promise((resolve) =>
780
- setTimeout(() => {
781
- resolve(
782
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
783
- );
784
- }, 1000)
785
- );
786
- return result;
787
- });
788
- const onChange = jest.fn();
789
- const { getByRole, getByText } = render(
790
- <DxcNewInputText label="Autosuggest Countries" onChange={onChange} suggestions={callbackFunc} />
791
- );
792
- const input = getByRole("combobox");
793
- fireEvent.focus(input);
794
- userEvent.type(input, "Den");
795
- await waitForElementToBeRemoved(() => getByText("Searching..."));
796
- expect(getByText("Denmark")).toBeTruthy();
797
- fireEvent.mouseDown(getByRole("option"));
798
- fireEvent.mouseUp(getByRole("option"));
799
- expect(onChange).toHaveBeenCalledWith("Denmark");
800
- expect(input.value).toBe("Denmark");
801
- });
802
- test("Asynchronous controlled autosuggest test", async () => {
803
- const callbackFunc = jest.fn((newValue) => {
804
- const result = new Promise((resolve) =>
805
- setTimeout(() => {
806
- resolve(
807
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
808
- );
809
- }, 1000)
810
- );
811
- return result;
812
- });
813
- const onChange = jest.fn();
814
- const { getByRole, getByText, queryByRole } = render(
815
- <DxcNewInputText label="Autosuggest Countries" value="Denm" onChange={onChange} suggestions={callbackFunc} />
816
- );
817
- const input = getByRole("combobox");
818
- fireEvent.focus(input);
819
- await waitForElementToBeRemoved(() => getByText("Searching..."));
820
- expect(input.value).toBe("Denm");
821
- expect(getByText("Denmark")).toBeTruthy();
822
- fireEvent.mouseDown(getByRole("option"));
823
- fireEvent.mouseUp(getByRole("option"));
824
- expect(onChange).toHaveBeenCalledWith("Denmark");
825
- expect(queryByRole("listbox")).toBeFalsy();
826
- });
827
- test("Asynchronous autosuggest shows 'No results found' after finishing no matches search", async () => {
828
- const callbackFunc = jest.fn((newValue) => {
829
- const result = new Promise((resolve) =>
830
- setTimeout(() => {
831
- resolve(
832
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
833
- );
834
- }, 1000)
835
- );
836
- return result;
837
- });
838
- const onChange = jest.fn();
839
- const { getByRole, getByText } = render(
840
- <DxcNewInputText label="Autosuggest Countries" onChange={onChange} suggestions={callbackFunc} />
841
- );
842
- const input = getByRole("combobox");
843
- fireEvent.focus(input);
844
- userEvent.type(input, "Example text");
845
- await waitForElementToBeRemoved(() => getByText("Searching..."));
846
- expect(getByText("No results found")).toBeTruthy();
847
- });
848
- test("Asynchronous autosuggest request failed, shows 'Error fetching data' message", async () => {
849
- const errorCallbackFunc = jest.fn(() => {
850
- const result = new Promise((resolve, reject) =>
851
- setTimeout(() => {
852
- reject("err");
853
- }, 1000)
854
- );
855
- return result;
856
- });
857
- const onChange = jest.fn();
858
- const { getByRole, getByText } = render(
859
- <DxcNewInputText label="Autosuggest Countries" onChange={onChange} suggestions={errorCallbackFunc} />
860
- );
861
- const input = getByRole("combobox");
862
- fireEvent.focus(input);
863
- await waitForElementToBeRemoved(() => getByText("Searching..."));
864
- expect(getByText("Error fetching data")).toBeTruthy();
865
- });
866
- });