@dxc-technology/halstack-react 0.0.0-e1c85bf → 0.0.0-e3e5511

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 (233) hide show
  1. package/{dist/BackgroundColorContext.js → BackgroundColorContext.js} +0 -0
  2. package/{dist/ThemeContext.js → ThemeContext.js} +44 -42
  3. package/{dist/select/Select.js → V3Select/V3Select.js} +5 -5
  4. package/V3Select/index.d.ts +27 -0
  5. package/{dist/textarea/Textarea.js → V3Textarea/V3Textarea.js} +4 -4
  6. package/V3Textarea/index.d.ts +27 -0
  7. package/{dist/accordion → accordion}/Accordion.js +0 -0
  8. package/accordion/index.d.ts +28 -0
  9. package/{dist/accordion-group → accordion-group}/AccordionGroup.js +0 -0
  10. package/accordion-group/index.d.ts +16 -0
  11. package/{dist/alert → alert}/Alert.js +5 -5
  12. package/{dist/alert → alert}/index.d.ts +0 -0
  13. package/{dist/badge → badge}/Badge.js +0 -0
  14. package/{dist/box → box}/Box.js +0 -0
  15. package/box/index.d.ts +25 -0
  16. package/{dist/button → button}/Button.js +3 -3
  17. package/button/Button.stories.js +27 -0
  18. package/button/index.d.ts +24 -0
  19. package/{dist/card → card}/Card.js +0 -0
  20. package/card/index.d.ts +22 -0
  21. package/{dist/checkbox → checkbox}/Checkbox.js +4 -5
  22. package/checkbox/index.d.ts +24 -0
  23. package/{dist/chip → chip}/Chip.js +0 -0
  24. package/chip/index.d.ts +22 -0
  25. package/{dist/common → common}/OpenSans.css +0 -0
  26. package/{dist/common → common}/RequiredComponent.js +0 -0
  27. package/{dist/common → common}/fonts/OpenSans-Bold.ttf +0 -0
  28. package/{dist/common → common}/fonts/OpenSans-BoldItalic.ttf +0 -0
  29. package/{dist/common → common}/fonts/OpenSans-ExtraBold.ttf +0 -0
  30. package/{dist/common → common}/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  31. package/{dist/common → common}/fonts/OpenSans-Italic.ttf +0 -0
  32. package/{dist/common → common}/fonts/OpenSans-Light.ttf +0 -0
  33. package/{dist/common → common}/fonts/OpenSans-LightItalic.ttf +0 -0
  34. package/{dist/common → common}/fonts/OpenSans-Regular.ttf +0 -0
  35. package/{dist/common → common}/fonts/OpenSans-SemiBold.ttf +0 -0
  36. package/{dist/common → common}/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
  37. package/{dist/common → common}/utils.js +0 -0
  38. package/{dist/common → common}/variables.js +223 -90
  39. package/{dist/date → date}/Date.js +0 -0
  40. package/date/index.d.ts +27 -0
  41. package/{dist/new-date/NewDate.js → date-input/DateInput.js} +36 -36
  42. package/{dist/new-date → date-input}/index.d.ts +3 -3
  43. package/{dist/dialog → dialog}/Dialog.js +0 -0
  44. package/dialog/index.d.ts +18 -0
  45. package/{dist/dropdown → dropdown}/Dropdown.js +0 -0
  46. package/dropdown/index.d.ts +26 -0
  47. package/{dist/file-input → file-input}/FileInput.js +6 -3
  48. package/{dist/file-input → file-input}/FileItem.js +26 -4
  49. package/{dist/file-input → file-input}/index.d.ts +1 -1
  50. package/{dist/footer → footer}/Footer.js +44 -18
  51. package/footer/Icons.js +77 -0
  52. package/footer/index.d.ts +25 -0
  53. package/{dist/header → header}/Header.js +122 -55
  54. package/header/Icons.js +59 -0
  55. package/header/index.d.ts +25 -0
  56. package/{dist/heading → heading}/Heading.js +12 -0
  57. package/heading/index.d.ts +17 -0
  58. package/input-text/Icons.js +22 -0
  59. package/{dist/input-text → input-text}/InputText.js +4 -6
  60. package/input-text/index.d.ts +36 -0
  61. package/{dist/layout → layout}/ApplicationLayout.js +4 -8
  62. package/layout/Icons.js +55 -0
  63. package/{dist/link → link}/Link.js +0 -0
  64. package/link/index.d.ts +23 -0
  65. package/main.d.ts +40 -0
  66. package/{dist/main.js → main.js} +30 -30
  67. package/{dist/number/Number.js → number-input/NumberInput.js} +9 -11
  68. package/{dist/number/NumberContext.js → number-input/NumberInputContext.js} +2 -2
  69. package/{dist/number → number-input}/index.d.ts +3 -3
  70. package/package.json +21 -17
  71. package/paginator/Icons.js +66 -0
  72. package/{dist/paginator → paginator}/Paginator.js +53 -37
  73. package/paginator/index.d.ts +20 -0
  74. package/{dist/password/Password.js → password-input/PasswordInput.js} +14 -11
  75. package/{dist/password → password-input}/index.d.ts +5 -5
  76. package/{dist/progress-bar → progress-bar}/ProgressBar.js +0 -0
  77. package/progress-bar/index.d.ts +18 -0
  78. package/{dist/radio → radio}/Radio.js +0 -0
  79. package/radio/index.d.ts +23 -0
  80. package/{dist/resultsetTable → resultsetTable}/ResultsetTable.js +0 -0
  81. package/resultsetTable/index.d.ts +19 -0
  82. package/select/Select.js +1137 -0
  83. package/select/index.d.ts +131 -0
  84. package/{dist/sidenav → sidenav}/Sidenav.js +0 -0
  85. package/sidenav/index.d.ts +13 -0
  86. package/{dist/slider → slider}/Slider.js +104 -19
  87. package/slider/index.d.ts +29 -0
  88. package/{dist/spinner → spinner}/Spinner.js +0 -0
  89. package/spinner/index.d.ts +17 -0
  90. package/{dist/switch → switch}/Switch.js +0 -0
  91. package/switch/index.d.ts +24 -0
  92. package/{dist/table → table}/Table.js +0 -0
  93. package/table/index.d.ts +13 -0
  94. package/{dist/tabs → tabs}/Tabs.js +0 -0
  95. package/tabs/index.d.ts +19 -0
  96. package/{dist/tag → tag}/Tag.js +0 -0
  97. package/tag/index.d.ts +24 -0
  98. package/{dist/new-input-text/NewInputText.js → text-input/TextInput.js} +51 -59
  99. package/{dist/new-input-text → text-input}/index.d.ts +1 -1
  100. package/{dist/new-textarea/NewTextarea.js → textarea/Textarea.js} +16 -9
  101. package/{dist/new-textarea → textarea}/index.d.ts +1 -1
  102. package/{dist/toggle → toggle}/Toggle.js +0 -0
  103. package/toggle/index.d.ts +21 -0
  104. package/{dist/toggle-group → toggle-group}/ToggleGroup.js +132 -28
  105. package/toggle-group/index.d.ts +21 -0
  106. package/{dist/upload → upload}/Upload.js +0 -0
  107. package/{dist/upload → upload}/buttons-upload/ButtonsUpload.js +7 -11
  108. package/upload/buttons-upload/Icons.js +40 -0
  109. package/{dist/upload → upload}/dragAndDropArea/DragAndDropArea.js +14 -14
  110. package/upload/dragAndDropArea/Icons.js +39 -0
  111. package/{dist/upload → upload}/file-upload/FileToUpload.js +26 -21
  112. package/upload/file-upload/Icons.js +66 -0
  113. package/{dist/upload → upload}/files-upload/FilesToUpload.js +0 -0
  114. package/upload/index.d.ts +15 -0
  115. package/upload/transaction/Icons.js +160 -0
  116. package/{dist/upload → upload}/transaction/Transaction.js +11 -38
  117. package/{dist/upload → upload}/transactions/Transactions.js +0 -0
  118. package/{dist/useTheme.js → useTheme.js} +0 -0
  119. package/wizard/Icons.js +65 -0
  120. package/{dist/wizard → wizard}/Wizard.js +3 -9
  121. package/wizard/index.d.ts +18 -0
  122. package/README.md +0 -66
  123. package/babel.config.js +0 -8
  124. package/dist/checkbox/Checkbox.stories.js +0 -144
  125. package/dist/checkbox/readme.md +0 -116
  126. package/dist/date/Date.stories.js +0 -205
  127. package/dist/date/readme.md +0 -73
  128. package/dist/footer/Footer.stories.js +0 -94
  129. package/dist/footer/dxc_logo.svg +0 -15
  130. package/dist/footer/readme.md +0 -41
  131. package/dist/header/Header.stories.js +0 -176
  132. package/dist/header/close_icon.svg +0 -1
  133. package/dist/header/dxc_logo_black.svg +0 -8
  134. package/dist/header/hamb_menu_black.svg +0 -1
  135. package/dist/header/hamb_menu_white.svg +0 -1
  136. package/dist/header/readme.md +0 -33
  137. package/dist/input-text/InputText.stories.js +0 -209
  138. package/dist/input-text/error.svg +0 -1
  139. package/dist/input-text/readme.md +0 -91
  140. package/dist/layout/facebook.svg +0 -45
  141. package/dist/layout/linkedin.svg +0 -50
  142. package/dist/layout/twitter.svg +0 -53
  143. package/dist/link/readme.md +0 -51
  144. package/dist/main.d.ts +0 -7
  145. package/dist/paginator/images/next.svg +0 -3
  146. package/dist/paginator/images/nextPage.svg +0 -3
  147. package/dist/paginator/images/previous.svg +0 -3
  148. package/dist/paginator/images/previousPage.svg +0 -3
  149. package/dist/paginator/readme.md +0 -50
  150. package/dist/password/styles.css +0 -3
  151. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  152. package/dist/progress-bar/readme.md +0 -63
  153. package/dist/radio/Radio.stories.js +0 -166
  154. package/dist/radio/readme.md +0 -70
  155. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  156. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  157. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  158. package/dist/slider/Slider.stories.js +0 -241
  159. package/dist/slider/readme.md +0 -64
  160. package/dist/spinner/Spinner.stories.js +0 -183
  161. package/dist/spinner/readme.md +0 -65
  162. package/dist/switch/Switch.stories.js +0 -134
  163. package/dist/switch/readme.md +0 -133
  164. package/dist/tabs/Tabs.stories.js +0 -130
  165. package/dist/tabs/readme.md +0 -78
  166. package/dist/tabs-for-sections/TabsForSections.js +0 -92
  167. package/dist/tabs-for-sections/readme.md +0 -78
  168. package/dist/toggle/Toggle.stories.js +0 -297
  169. package/dist/toggle/readme.md +0 -80
  170. package/dist/upload/Upload.stories.js +0 -72
  171. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  172. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  173. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  174. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  175. package/dist/upload/file-upload/audio-icon.svg +0 -4
  176. package/dist/upload/file-upload/close.svg +0 -4
  177. package/dist/upload/file-upload/file-icon.svg +0 -4
  178. package/dist/upload/file-upload/video-icon.svg +0 -4
  179. package/dist/upload/readme.md +0 -37
  180. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  181. package/dist/upload/transaction/audio-icon.svg +0 -4
  182. package/dist/upload/transaction/error-icon.svg +0 -4
  183. package/dist/upload/transaction/file-icon-err.svg +0 -4
  184. package/dist/upload/transaction/file-icon.svg +0 -4
  185. package/dist/upload/transaction/image-icon-err.svg +0 -4
  186. package/dist/upload/transaction/image-icon.svg +0 -4
  187. package/dist/upload/transaction/success-icon.svg +0 -4
  188. package/dist/upload/transaction/video-icon-err.svg +0 -4
  189. package/dist/upload/transaction/video-icon.svg +0 -4
  190. package/dist/wizard/invalid_icon.svg +0 -5
  191. package/dist/wizard/valid_icon.svg +0 -5
  192. package/dist/wizard/validation-wrong.svg +0 -6
  193. package/test/Accordion.test.js +0 -33
  194. package/test/AccordionGroup.test.js +0 -125
  195. package/test/Alert.test.js +0 -53
  196. package/test/Box.test.js +0 -10
  197. package/test/Button.test.js +0 -18
  198. package/test/Card.test.js +0 -30
  199. package/test/Checkbox.test.js +0 -45
  200. package/test/Chip.test.js +0 -25
  201. package/test/Date.test.js +0 -393
  202. package/test/Dialog.test.js +0 -23
  203. package/test/Dropdown.test.js +0 -145
  204. package/test/FileInput.test.js +0 -201
  205. package/test/Footer.test.js +0 -99
  206. package/test/Header.test.js +0 -39
  207. package/test/Heading.test.js +0 -35
  208. package/test/InputText.test.js +0 -240
  209. package/test/Link.test.js +0 -43
  210. package/test/NewDate.test.js +0 -232
  211. package/test/NewInputText.test.js +0 -734
  212. package/test/NewTextarea.test.js +0 -195
  213. package/test/Number.test.js +0 -257
  214. package/test/Paginator.test.js +0 -177
  215. package/test/Password.test.js +0 -83
  216. package/test/ProgressBar.test.js +0 -35
  217. package/test/Radio.test.js +0 -37
  218. package/test/ResultsetTable.test.js +0 -329
  219. package/test/Select.test.js +0 -212
  220. package/test/Sidenav.test.js +0 -45
  221. package/test/Slider.test.js +0 -82
  222. package/test/Spinner.test.js +0 -32
  223. package/test/Switch.test.js +0 -45
  224. package/test/Table.test.js +0 -36
  225. package/test/Tabs.test.js +0 -109
  226. package/test/TabsForSections.test.js +0 -34
  227. package/test/Tag.test.js +0 -32
  228. package/test/TextArea.test.js +0 -52
  229. package/test/ToggleGroup.test.js +0 -81
  230. package/test/Upload.test.js +0 -60
  231. package/test/Wizard.test.js +0 -130
  232. package/test/mocks/pngMock.js +0 -1
  233. package/test/mocks/svgMock.js +0 -1
@@ -1,734 +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("Not optional constraint (onBlur)", () => {
60
- const onChange = jest.fn();
61
- const onBlur = jest.fn();
62
- const { getByRole } = render(
63
- <DxcNewInputText label="Input label" placeholder="Placeholder" onChange={onChange} onBlur={onBlur} clearable />
64
- );
65
- const input = getByRole("textbox");
66
-
67
- fireEvent.focus(input);
68
- fireEvent.blur(input);
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" } });
72
- fireEvent.blur(input);
73
- expect(onBlur).toHaveBeenCalled();
74
- expect(onBlur).toHaveBeenCalledWith({ value: "Test", error: null });
75
- });
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", () => {
91
- const onChange = jest.fn();
92
- const onBlur = jest.fn();
93
- const { getByRole, getByText, queryByText } = render(
94
- <DxcNewInputText
95
- label="Input label"
96
- placeholder="Placeholder"
97
- onChange={onChange}
98
- onBlur={onBlur}
99
- margin={{ left: "medium", right: "medium" }}
100
- clearable
101
- pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
102
- />
103
- );
104
- const input = getByRole("textbox");
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." });
109
- fireEvent.blur(input);
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 });
116
- fireEvent.blur(input);
117
- expect(onBlur).toHaveBeenCalled();
118
- expect(onBlur).toHaveBeenCalledWith({ value: "pattern4&", error: null });
119
- });
120
- test("Length constraint", () => {
121
- const onChange = jest.fn();
122
- const onBlur = jest.fn();
123
- const { getByRole, getByText, queryByText } = render(
124
- <DxcNewInputText
125
- label="Input label"
126
- placeholder="Placeholder"
127
- onChange={onChange}
128
- onBlur={onBlur}
129
- margin={{ left: "medium", right: "medium" }}
130
- clearable
131
- length={{ min: 5, max: 10 }}
132
- />
133
- );
134
- const input = getByRole("textbox");
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." });
139
- fireEvent.blur(input);
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 });
146
- fireEvent.blur(input);
147
- expect(onBlur).toHaveBeenCalled();
148
- expect(onBlur).toHaveBeenCalledWith({ value: "length", error: null });
149
- });
150
- test("Pattern and length constraints", () => {
151
- const onChange = jest.fn();
152
- const onBlur = jest.fn();
153
- const { getByRole, getByText, queryByText } = render(
154
- <DxcNewInputText
155
- label="Input label"
156
- placeholder="Placeholder"
157
- onChange={onChange}
158
- onBlur={onBlur}
159
- margin={{ left: "medium", right: "medium" }}
160
- clearable
161
- pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
162
- length={{ min: 5, max: 10 }}
163
- />
164
- );
165
- const input = getByRole("textbox");
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." });
170
- fireEvent.blur(input);
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 });
182
- fireEvent.blur(input);
183
- expect(onBlur).toHaveBeenCalled();
184
- expect(onBlur).toHaveBeenCalledWith({ value: "tests4&", error: null });
185
- });
186
- test("onChange function is called correctly", () => {
187
- const onChange = jest.fn();
188
- const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} />);
189
- const input = getByRole("textbox");
190
- userEvent.type(input, "onchange event test");
191
- expect(input.value).toBe("onchange event test");
192
- expect(onChange).toHaveBeenCalled();
193
- expect(onChange).toHaveBeenCalledWith({ value: "onchange event test", error: null });
194
- });
195
- test("onBlur function is called correctly", () => {
196
- const onBlur = jest.fn();
197
- const onChange = jest.fn();
198
- const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} onBlur={onBlur} />);
199
- const input = getByRole("textbox");
200
- fireEvent.change(input, { target: { value: "Blur test" } });
201
- fireEvent.blur(input);
202
- expect(onBlur).toHaveBeenCalled();
203
- expect(onBlur).toHaveBeenCalledWith({ value: "Blur test", error: null });
204
- });
205
- test("Clear action onClick cleans the input", () => {
206
- const { getByRole } = render(<DxcNewInputText label="Input label" clearable />);
207
- const input = getByRole("textbox");
208
- userEvent.type(input, "Test");
209
- const closeAction = getByRole("button");
210
- userEvent.click(closeAction);
211
- expect(input.value).toBe("");
212
- });
213
- test("Disabled input (action must be shown but not clickable)", () => {
214
- const onClick = jest.fn();
215
- const action = {
216
- onClick: onClick,
217
- icon: (
218
- <svg
219
- data-testid="image"
220
- xmlns="http://www.w3.org/2000/svg"
221
- height="24px"
222
- viewBox="0 0 24 24"
223
- width="24px"
224
- fill="currentColor"
225
- >
226
- <path d="M0 0h24v24H0V0z" fill="none" />
227
- <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" />
228
- </svg>
229
- ),
230
- };
231
- const { getByRole } = render(<DxcNewInputText label="Disabled input label" action={action} disabled />);
232
- const input = getByRole("textbox");
233
- expect(input.disabled).toBeTruthy();
234
- userEvent.click(getByRole("button"));
235
- expect(onClick).not.toHaveBeenCalled();
236
- });
237
- test("Disabled input (clear default action should not be displayed, even with text written on the input)", () => {
238
- const { getByRole, queryByRole } = render(
239
- <DxcNewInputText label="Disabled input label" value="Sample text" disabled clearable />
240
- );
241
- const input = getByRole("textbox");
242
- expect(input.disabled).toBeTruthy();
243
- expect(queryByRole("button")).toBeFalsy();
244
- });
245
- test("Disabled input (suffix and preffix must be displayed)", () => {
246
- const { getByRole, getByText } = render(
247
- <DxcNewInputText label="Disabled input label" value="Sample text" prefix="+34" suffix="USD" disabled />
248
- );
249
- const input = getByRole("textbox");
250
- expect(input.disabled).toBeTruthy();
251
- expect(getByText("+34")).toBeTruthy();
252
- expect(getByText("USD")).toBeTruthy();
253
- });
254
- test("Action prop: image displayed and onClick event", () => {
255
- const onClick = jest.fn();
256
- const action = {
257
- onClick: onClick,
258
- icon: (
259
- <svg
260
- data-testid="image"
261
- xmlns="http://www.w3.org/2000/svg"
262
- height="24px"
263
- viewBox="0 0 24 24"
264
- width="24px"
265
- fill="currentColor"
266
- >
267
- <path d="M0 0h24v24H0V0z" fill="none" />
268
- <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" />
269
- </svg>
270
- ),
271
- };
272
- const { getByRole, getByTestId } = render(<DxcNewInputText label="Input label" action={action} />);
273
- expect(getByTestId("image")).toBeTruthy();
274
- userEvent.click(getByRole("button"));
275
- expect(onClick).toHaveBeenCalled();
276
- });
277
- test("Renders with correct prefix and suffix", () => {
278
- const { getByText } = render(<DxcNewInputText label="Input label" prefix="+34" suffix="USD" />);
279
- expect(getByText("+34")).toBeTruthy();
280
- expect(getByText("USD")).toBeTruthy();
281
- });
282
- test("Input has correct accesibility attributes", () => {
283
- const onClick = jest.fn();
284
- const action = {
285
- onClick: onClick,
286
- icon: (
287
- <svg
288
- data-testid="image"
289
- xmlns="http://www.w3.org/2000/svg"
290
- height="24px"
291
- viewBox="0 0 24 24"
292
- width="24px"
293
- fill="currentColor"
294
- >
295
- <path d="M0 0h24v24H0V0z" fill="none" />
296
- <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" />
297
- </svg>
298
- ),
299
- };
300
- const { getByRole, getAllByRole } = render(<DxcNewInputText label="Example label" clearable action={action} />);
301
- const input = getByRole("textbox");
302
- expect(input.getAttribute("aria-autocomplete")).toBeNull();
303
- expect(input.getAttribute("aria-controls")).toBeNull();
304
- expect(input.getAttribute("aria-expanded")).toBeNull();
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");
309
- userEvent.type(input, "Text");
310
- const clear = getAllByRole("button")[0];
311
- expect(clear.getAttribute("aria-label")).toBe("Clear");
312
- });
313
- test("Autosuggest has correct accesibility attributes", () => {
314
- const { getByRole, getAllByRole } = render(
315
- <DxcNewInputText label="Autocomplete Countries" optional suggestions={countries} />
316
- );
317
- const input = getByRole("combobox");
318
- const inputId = input.id;
319
- expect(input.getAttribute("aria-autocomplete")).toBe("list");
320
- expect(input.getAttribute("aria-controls")).toBe(inputId);
321
- expect(input.getAttribute("aria-expanded")).toBe("false");
322
- expect(input.getAttribute("aria-required")).toBe("false");
323
- fireEvent.focus(input);
324
- const list = getByRole("listbox");
325
- expect(input.getAttribute("aria-expanded")).toBe("true");
326
- expect(list.getAttribute("aria-label")).toBe("Autocomplete Countries");
327
- const options = getAllByRole("option");
328
- expect(options[0].getAttribute("aria-selected")).toBe("false");
329
- });
330
- });
331
-
332
- describe("NewInputText component synchronous autosuggest tests", () => {
333
- test("Autosuggest is displayed when the input gains focus", async () => {
334
- const onChange = jest.fn();
335
- const { getByRole, getByText } = render(
336
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
337
- );
338
- const input = getByRole("combobox");
339
- fireEvent.focus(input);
340
- const list = getByRole("listbox");
341
- expect(list).toBeTruthy();
342
- expect(getByText("Afghanistan")).toBeTruthy();
343
- expect(getByText("Albania")).toBeTruthy();
344
- expect(getByText("Algeria")).toBeTruthy();
345
- expect(getByText("Andorra")).toBeTruthy();
346
- });
347
- test("Autosuggest is displayed when the user clicks the input", async () => {
348
- const onChange = jest.fn();
349
- const { getByRole, getByText } = render(
350
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
351
- );
352
- const input = getByRole("combobox");
353
- userEvent.click(input);
354
- const list = getByRole("listbox");
355
- expect(list).toBeTruthy();
356
- expect(getByText("Afghanistan")).toBeTruthy();
357
- expect(getByText("Albania")).toBeTruthy();
358
- expect(getByText("Algeria")).toBeTruthy();
359
- expect(getByText("Andorra")).toBeTruthy();
360
- });
361
- test("Autosuggest is displayed while the user is writing (if closed previously, if open stays open)", async () => {
362
- const onChange = jest.fn();
363
- const { getByRole, queryByRole, getByText, getAllByText } = render(
364
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
365
- );
366
- const input = getByRole("combobox");
367
- fireEvent.focus(input);
368
- const list = getByRole("listbox");
369
- expect(list).toBeTruthy();
370
- fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
371
- expect(queryByRole("listbox")).toBeFalsy();
372
- userEvent.type(input, "B");
373
- expect(list).toBeTruthy();
374
- expect(getAllByText("B").length).toBe(4);
375
- expect(getByText("ahamas")).toBeTruthy();
376
- expect(getByText("ahrain")).toBeTruthy();
377
- expect(getByText("angladesh")).toBeTruthy();
378
- expect(getByText("arbados")).toBeTruthy();
379
- });
380
- test("Autosuggest is not displayed when prop suggestions is an empty array", async () => {
381
- const onChange = jest.fn();
382
- const { queryByRole } = render(
383
- <DxcNewInputText label="Autocomplete Countries" suggestions={[]} onChange={onChange} />
384
- );
385
- const input = queryByRole("textbox");
386
- fireEvent.focus(input);
387
- expect(queryByRole("listbox")).toBeFalsy();
388
- });
389
- test("Autosuggest shows 'No results found' message when there are no matches with the user's input", async () => {
390
- const onChange = jest.fn();
391
- const { getByRole, getByText } = render(
392
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
393
- );
394
- const input = getByRole("combobox");
395
- fireEvent.focus(input);
396
- const list = getByRole("listbox");
397
- expect(list).toBeTruthy();
398
- expect(getByText("Afghanistan")).toBeTruthy();
399
- userEvent.type(input, "x");
400
- expect(list).toBeTruthy();
401
- expect(getByText("No results found")).toBeTruthy();
402
- });
403
- test("Autosuggest uncontrolled suggestion selected", async () => {
404
- const onChange = jest.fn();
405
- const { getByRole, getByText, queryByRole } = render(
406
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
407
- );
408
- const input = getByRole("combobox");
409
- fireEvent.focus(input);
410
- userEvent.type(input, "Alba");
411
- expect(onChange).toHaveBeenCalled();
412
- expect(getByText("Alba")).toBeTruthy();
413
- expect(getByText("nia")).toBeTruthy();
414
- fireEvent.mouseDown(getByRole("option"));
415
- fireEvent.mouseUp(getByRole("option"));
416
- expect(input.value).toBe("Albania");
417
- expect(queryByRole("listbox")).toBeFalsy();
418
- });
419
- test("Autosuggest controlled suggestions selected", async () => {
420
- const onChange = jest.fn();
421
- const { getByRole, getByText, queryByRole } = render(
422
- <DxcNewInputText label="Autocomplete Countries" value="Andor" suggestions={countries} onChange={onChange} />
423
- );
424
- const input = getByRole("combobox");
425
- fireEvent.focus(input);
426
- expect(input.value).toBe("Andor");
427
- expect(getByText("Andor")).toBeTruthy();
428
- expect(getByText("ra")).toBeTruthy();
429
- fireEvent.mouseDown(getByRole("option"));
430
- fireEvent.mouseUp(getByRole("option"));
431
- expect(onChange).toHaveBeenCalledWith({ value: "Andorra", error: null });
432
- expect(queryByRole("listbox")).toBeFalsy();
433
- });
434
- test("Autosuggest - Pattern constraint", async () => {
435
- const onChange = jest.fn();
436
- const onBlur = jest.fn();
437
- const { getByRole, getByText } = render(
438
- <DxcNewInputText
439
- label="Autocomplete Countries"
440
- suggestions={countries}
441
- onChange={onChange}
442
- onBlur={onBlur}
443
- pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
444
- />
445
- );
446
- const input = getByRole("combobox");
447
- fireEvent.focus(input);
448
- userEvent.type(input, "Andor");
449
- expect(getByText("Andor")).toBeTruthy();
450
- expect(getByText("ra")).toBeTruthy();
451
- fireEvent.mouseDown(getByRole("option"));
452
- fireEvent.mouseUp(getByRole("option"));
453
- expect(onChange).toHaveBeenCalledWith({ value: "Andorra", error: "Please match the format requested." });
454
- fireEvent.blur(input);
455
- expect(onBlur).toHaveBeenCalledWith({ value: "Andorra", error: "Please match the format requested." });
456
- });
457
- test("Autosuggest - Length constraint", async () => {
458
- const onChange = jest.fn();
459
- const onBlur = jest.fn();
460
- const { getByText, getByRole } = render(
461
- <DxcNewInputText
462
- label="Autocomplete Countries"
463
- suggestions={countries}
464
- onChange={onChange}
465
- onBlur={onBlur}
466
- length={{ min: 5, max: 10 }}
467
- />
468
- );
469
- const input = getByRole("combobox");
470
- fireEvent.focus(input);
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." });
477
- fireEvent.blur(input);
478
- expect(onBlur).toHaveBeenCalledWith({ value: "Chad", error: "Min length 5, max length 10." });
479
- });
480
- test("Autosuggest keys: arrow down key opens autosuggest, active first option is selected with Enter and closes the autosuggest", async () => {
481
- Element.prototype.scrollTo = () => {};
482
- const onChange = jest.fn();
483
- const { getByRole, queryByRole } = render(
484
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
485
- );
486
- const input = getByRole("combobox");
487
- fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
488
- const list = getByRole("listbox");
489
- expect(list).toBeTruthy();
490
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
491
- expect(input.value).toBe("Afghanistan");
492
- expect(queryByRole("list")).toBeFalsy();
493
- });
494
- test("Autosuggest keys: arrow up key opens autosuggest, active last option is selected with Enter and closes the autosuggest", async () => {
495
- Element.prototype.scrollTo = () => {};
496
- const onChange = jest.fn();
497
- const { getByRole, queryByRole } = render(
498
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
499
- );
500
- const input = getByRole("combobox");
501
- fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
502
- const list = getByRole("listbox");
503
- expect(list).toBeTruthy();
504
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
505
- expect(input.value).toBe("Djibouti");
506
- expect(queryByRole("list")).toBeFalsy();
507
- });
508
- test("Autosuggest keys: Esc key closes the autosuggest and cleans the input", async () => {
509
- Element.prototype.scrollTo = () => {};
510
- const onChange = jest.fn();
511
- const { getByRole, queryByRole } = render(
512
- <DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
513
- );
514
- const input = getByRole("combobox");
515
- fireEvent.focus(input);
516
- userEvent.type(input, "Bangla");
517
- const list = getByRole("listbox");
518
- expect(list).toBeTruthy();
519
- fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
520
- expect(input.value).toBe("");
521
- expect(queryByRole("listbox")).toBeFalsy();
522
- });
523
- test("Autosuggest keys: Enter, if no active suggestion closes the autosuggest", async () => {
524
- Element.prototype.scrollTo = () => {};
525
- const onChange = jest.fn();
526
- const { getByRole, queryByRole } = 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
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 27, charCode: 27 });
534
- expect(input.value).toBe("");
535
- expect(queryByRole("list")).toBeFalsy();
536
- });
537
- test("Autosuggest complex key secuence: write, arrow up two times, arrow down and select with Enter. Then, clean with Esc.", async () => {
538
- Element.prototype.scrollTo = () => {};
539
- const onChange = jest.fn();
540
- const { getByRole, 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, "Ba");
546
- fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
547
- fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
548
- fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
549
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
550
- expect(input.value).toBe("Barbados");
551
- expect(queryByRole("listbox")).toBeFalsy();
552
- fireEvent.keyDown(input, { key: "Esc", code: "Esp", keyCode: 27, charCode: 27 });
553
- expect(input.value).toBe("");
554
- expect(queryByRole("listbox")).toBeFalsy();
555
- });
556
- });
557
-
558
- describe("NewInputText component asynchronous autosuggest tests", () => {
559
- test("Autosuggest 'Searching...' message is shown", async () => {
560
- const callbackFunc = jest.fn((newValue) => {
561
- const result = new Promise((resolve) =>
562
- setTimeout(() => {
563
- resolve(
564
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
565
- );
566
- }, 1000)
567
- );
568
- return result;
569
- });
570
- const onChange = jest.fn();
571
- const { getByRole, getByText } = render(
572
- <DxcNewInputText label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
573
- );
574
- const input = getByRole("combobox");
575
- fireEvent.focus(input);
576
- expect(getByRole("listbox")).toBeTruthy();
577
- await waitForElementToBeRemoved(() => getByText("Searching..."));
578
- expect(getByText("Afghanistan")).toBeTruthy();
579
- expect(getByText("Albania")).toBeTruthy();
580
- expect(getByText("Algeria")).toBeTruthy();
581
- expect(getByText("Andorra")).toBeTruthy();
582
- userEvent.type(input, "Ab");
583
- await waitForElementToBeRemoved(() => getByText("Searching..."));
584
- expect(getByText("Cabo Verde")).toBeTruthy();
585
- fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
586
- fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
587
- expect(input.value).toBe("Cabo Verde");
588
- });
589
- test("Autosuggest Esc key works while 'Searching...' message is shown", async () => {
590
- const callbackFunc = jest.fn((newValue) => {
591
- const result = new Promise((resolve) =>
592
- setTimeout(() => {
593
- resolve(
594
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
595
- );
596
- }, 1000)
597
- );
598
- return result;
599
- });
600
- const onChange = jest.fn();
601
- const { getByRole, queryByText, queryByRole } = render(
602
- <DxcNewInputText label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
603
- );
604
- const input = getByRole("combobox");
605
- fireEvent.focus(input);
606
- expect(getByRole("listbox")).toBeTruthy();
607
- userEvent.type(input, "Ab");
608
- fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
609
- expect(queryByRole("listbox")).toBeFalsy();
610
- expect(queryByText("Searching...")).toBeFalsy();
611
- expect(input.value).toBe("");
612
- });
613
- test("Autosuggest Esc + arrow down working while 'Searching...' message is shown", async () => {
614
- const callbackFunc = jest.fn((newValue) => {
615
- const result = new Promise((resolve) =>
616
- setTimeout(() => {
617
- resolve(
618
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
619
- );
620
- }, 1000)
621
- );
622
- return result;
623
- });
624
- const onChange = jest.fn();
625
- const { getByRole, getByText, queryByText, queryByRole } = render(
626
- <DxcNewInputText label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
627
- );
628
- const input = getByRole("combobox");
629
- fireEvent.focus(input);
630
- const list = getByRole("listbox");
631
- expect(list).toBeTruthy();
632
- userEvent.type(input, "Ab");
633
- fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
634
- expect(queryByRole("listbox")).toBeFalsy();
635
- expect(queryByText("Searching...")).toBeFalsy();
636
- expect(input.value).toBe("");
637
- fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
638
- expect(list).toBeTruthy();
639
- await waitForElementToBeRemoved(() => getByText("Searching..."));
640
- expect(getByText("Afghanistan")).toBeTruthy();
641
- expect(getByText("Albania")).toBeTruthy();
642
- expect(getByText("Algeria")).toBeTruthy();
643
- expect(getByText("Andorra")).toBeTruthy();
644
- });
645
- test("Asynchronous uncontrolled autosuggest test", async () => {
646
- const callbackFunc = jest.fn((newValue) => {
647
- const result = new Promise((resolve) =>
648
- setTimeout(() => {
649
- resolve(
650
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
651
- );
652
- }, 1000)
653
- );
654
- return result;
655
- });
656
- const onChange = jest.fn();
657
- const { getByRole, getByText } = render(
658
- <DxcNewInputText label="Autosuggest Countries" onChange={onChange} suggestions={callbackFunc} />
659
- );
660
- const input = getByRole("combobox");
661
- fireEvent.focus(input);
662
- userEvent.type(input, "Den");
663
- await waitForElementToBeRemoved(() => getByText("Searching..."));
664
- expect(getByText("Denmark")).toBeTruthy();
665
- fireEvent.mouseDown(getByRole("option"));
666
- fireEvent.mouseUp(getByRole("option"));
667
- expect(onChange).toHaveBeenCalledWith({ value: "Denmark", error: null });
668
- expect(input.value).toBe("Denmark");
669
- });
670
- test("Asynchronous controlled autosuggest test", async () => {
671
- const callbackFunc = jest.fn((newValue) => {
672
- const result = new Promise((resolve) =>
673
- setTimeout(() => {
674
- resolve(
675
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
676
- );
677
- }, 1000)
678
- );
679
- return result;
680
- });
681
- const onChange = jest.fn();
682
- const { getByRole, getByText, queryByRole } = render(
683
- <DxcNewInputText label="Autosuggest Countries" value="Denm" onChange={onChange} suggestions={callbackFunc} />
684
- );
685
- const input = getByRole("combobox");
686
- fireEvent.focus(input);
687
- await waitForElementToBeRemoved(() => getByText("Searching..."));
688
- expect(input.value).toBe("Denm");
689
- expect(getByText("Denmark")).toBeTruthy();
690
- fireEvent.mouseDown(getByRole("option"));
691
- fireEvent.mouseUp(getByRole("option"));
692
- expect(onChange).toHaveBeenCalledWith({ value: "Denmark", error: null });
693
- expect(queryByRole("listbox")).toBeFalsy();
694
- });
695
- test("Asynchronous autosuggest shows 'No results found' after finishing no matches search", async () => {
696
- const callbackFunc = jest.fn((newValue) => {
697
- const result = new Promise((resolve) =>
698
- setTimeout(() => {
699
- resolve(
700
- newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
701
- );
702
- }, 1000)
703
- );
704
- return result;
705
- });
706
- const onChange = jest.fn();
707
- const { getByRole, getByText } = render(
708
- <DxcNewInputText label="Autosuggest Countries" onChange={onChange} suggestions={callbackFunc} />
709
- );
710
- const input = getByRole("combobox");
711
- fireEvent.focus(input);
712
- userEvent.type(input, "Example text");
713
- await waitForElementToBeRemoved(() => getByText("Searching..."));
714
- expect(getByText("No results found")).toBeTruthy();
715
- });
716
- test("Asynchronous autosuggest request failed, shows 'Error fetching data' message", async () => {
717
- const errorCallbackFunc = jest.fn(() => {
718
- const result = new Promise((resolve, reject) =>
719
- setTimeout(() => {
720
- reject("err");
721
- }, 1000)
722
- );
723
- return result;
724
- });
725
- const onChange = jest.fn();
726
- const { getByRole, getByText } = render(
727
- <DxcNewInputText label="Autosuggest Countries" onChange={onChange} suggestions={errorCallbackFunc} />
728
- );
729
- const input = getByRole("combobox");
730
- fireEvent.focus(input);
731
- await waitForElementToBeRemoved(() => getByText("Searching..."));
732
- expect(getByText("Error fetching data")).toBeTruthy();
733
- });
734
- });