@dxc-technology/halstack-react 0.0.0-a105522 → 0.0.0-a33ff0e

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 (341) hide show
  1. package/BackgroundColorContext.js +50 -0
  2. package/ThemeContext.js +246 -0
  3. package/{dist/select/Select.js → V3Select/V3Select.js} +38 -132
  4. package/V3Select/index.d.ts +27 -0
  5. package/{dist/textarea/Textarea.js → V3Textarea/V3Textarea.js} +14 -18
  6. package/V3Textarea/index.d.ts +27 -0
  7. package/accordion/Accordion.d.ts +4 -0
  8. package/{dist/accordion → accordion}/Accordion.js +35 -130
  9. package/accordion/types.d.ts +68 -0
  10. package/accordion/types.js +5 -0
  11. package/accordion-group/AccordionGroup.d.ts +7 -0
  12. package/accordion-group/AccordionGroup.js +170 -0
  13. package/accordion-group/types.d.ts +72 -0
  14. package/accordion-group/types.js +5 -0
  15. package/alert/Alert.d.ts +4 -0
  16. package/{dist/alert → alert}/Alert.js +41 -154
  17. package/alert/Alert.stories.tsx +170 -0
  18. package/alert/types.d.ts +49 -0
  19. package/alert/types.js +5 -0
  20. package/badge/Badge.js +59 -0
  21. package/box/Box.d.ts +4 -0
  22. package/{dist/box → box}/Box.js +13 -43
  23. package/box/Box.stories.tsx +132 -0
  24. package/box/types.d.ts +43 -0
  25. package/box/types.js +5 -0
  26. package/button/Button.d.ts +4 -0
  27. package/{dist/button → button}/Button.js +23 -84
  28. package/button/Button.stories.tsx +276 -0
  29. package/button/types.d.ts +57 -0
  30. package/button/types.js +5 -0
  31. package/card/Card.d.ts +4 -0
  32. package/{dist/card → card}/Card.js +33 -123
  33. package/card/Card.stories.tsx +201 -0
  34. package/card/ice-cream.jpg +0 -0
  35. package/card/types.d.ts +67 -0
  36. package/card/types.js +5 -0
  37. package/checkbox/Checkbox.d.ts +4 -0
  38. package/{dist/checkbox → checkbox}/Checkbox.js +16 -63
  39. package/checkbox/Checkbox.stories.tsx +192 -0
  40. package/checkbox/types.d.ts +60 -0
  41. package/checkbox/types.js +5 -0
  42. package/{dist/chip → chip}/Chip.js +17 -61
  43. package/chip/Chip.stories.tsx +121 -0
  44. package/chip/index.d.ts +22 -0
  45. package/{dist/common → common}/OpenSans.css +0 -0
  46. package/{dist/common → common}/RequiredComponent.js +3 -11
  47. package/{dist/common → common}/fonts/OpenSans-Bold.ttf +0 -0
  48. package/{dist/common → common}/fonts/OpenSans-BoldItalic.ttf +0 -0
  49. package/{dist/common → common}/fonts/OpenSans-ExtraBold.ttf +0 -0
  50. package/{dist/common → common}/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  51. package/{dist/common → common}/fonts/OpenSans-Italic.ttf +0 -0
  52. package/{dist/common → common}/fonts/OpenSans-Light.ttf +0 -0
  53. package/{dist/common → common}/fonts/OpenSans-LightItalic.ttf +0 -0
  54. package/{dist/common → common}/fonts/OpenSans-Regular.ttf +0 -0
  55. package/{dist/common → common}/fonts/OpenSans-SemiBold.ttf +0 -0
  56. package/{dist/common → common}/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
  57. package/{dist/common → common}/utils.js +0 -0
  58. package/{dist/common → common}/variables.js +318 -111
  59. package/{dist/date → date}/Date.js +20 -28
  60. package/date/index.d.ts +27 -0
  61. package/date-input/DateInput.d.ts +4 -0
  62. package/{dist/new-date/NewDate.js → date-input/DateInput.js} +88 -130
  63. package/date-input/DateInput.stories.tsx +138 -0
  64. package/date-input/types.d.ts +100 -0
  65. package/date-input/types.js +5 -0
  66. package/dialog/Dialog.d.ts +4 -0
  67. package/{dist/dialog → dialog}/Dialog.js +20 -73
  68. package/dialog/Dialog.stories.tsx +212 -0
  69. package/dialog/types.d.ts +43 -0
  70. package/dialog/types.js +5 -0
  71. package/dropdown/Dropdown.d.ts +4 -0
  72. package/{dist/dropdown → dropdown}/Dropdown.js +44 -171
  73. package/dropdown/types.d.ts +89 -0
  74. package/dropdown/types.js +5 -0
  75. package/file-input/FileInput.d.ts +4 -0
  76. package/file-input/FileInput.js +511 -0
  77. package/file-input/FileItem.d.ts +14 -0
  78. package/file-input/FileItem.js +182 -0
  79. package/file-input/types.d.ts +87 -0
  80. package/file-input/types.js +5 -0
  81. package/footer/Footer.d.ts +4 -0
  82. package/footer/Footer.js +266 -0
  83. package/footer/Footer.stories.jsx +151 -0
  84. package/footer/Icons.js +77 -0
  85. package/footer/types.d.ts +61 -0
  86. package/footer/types.js +5 -0
  87. package/header/Header.d.ts +7 -0
  88. package/header/Header.js +324 -0
  89. package/header/Header.stories.tsx +162 -0
  90. package/header/Icons.js +34 -0
  91. package/header/types.d.ts +47 -0
  92. package/header/types.js +5 -0
  93. package/heading/Heading.d.ts +4 -0
  94. package/{dist/heading → heading}/Heading.js +30 -89
  95. package/heading/Heading.stories.tsx +53 -0
  96. package/heading/types.d.ts +33 -0
  97. package/heading/types.js +5 -0
  98. package/input-text/Icons.js +22 -0
  99. package/{dist/input-text → input-text}/InputText.js +37 -133
  100. package/input-text/index.d.ts +36 -0
  101. package/{dist/layout → layout}/ApplicationLayout.js +35 -131
  102. package/layout/Icons.js +55 -0
  103. package/link/Link.d.ts +3 -0
  104. package/{dist/link → link}/Link.js +18 -94
  105. package/link/Link.stories.tsx +146 -0
  106. package/link/types.d.ts +74 -0
  107. package/link/types.js +5 -0
  108. package/main.d.ts +44 -0
  109. package/{dist/main.js → main.js} +104 -92
  110. package/number-input/NumberInput.d.ts +4 -0
  111. package/number-input/NumberInput.js +86 -0
  112. package/number-input/NumberInput.stories.tsx +115 -0
  113. package/number-input/NumberInputContext.d.ts +4 -0
  114. package/{dist/number/NumberContext.js → number-input/NumberInputContext.js} +6 -3
  115. package/number-input/numberInputContextTypes.d.ts +19 -0
  116. package/number-input/numberInputContextTypes.js +5 -0
  117. package/number-input/types.d.ts +117 -0
  118. package/number-input/types.js +5 -0
  119. package/package.json +32 -25
  120. package/paginator/Icons.js +66 -0
  121. package/paginator/Paginator.d.ts +4 -0
  122. package/paginator/Paginator.js +198 -0
  123. package/paginator/Paginator.stories.tsx +63 -0
  124. package/paginator/types.d.ts +38 -0
  125. package/paginator/types.js +5 -0
  126. package/password-input/PasswordInput.d.ts +4 -0
  127. package/{dist/password/Password.js → password-input/PasswordInput.js} +29 -67
  128. package/password-input/PasswordInput.stories.tsx +131 -0
  129. package/password-input/types.d.ts +105 -0
  130. package/password-input/types.js +5 -0
  131. package/progress-bar/ProgressBar.d.ts +4 -0
  132. package/{dist/progress-bar → progress-bar}/ProgressBar.js +20 -92
  133. package/progress-bar/ProgressBar.stories.jsx +58 -0
  134. package/progress-bar/types.d.ts +37 -0
  135. package/progress-bar/types.js +5 -0
  136. package/radio/Radio.d.ts +4 -0
  137. package/{dist/radio → radio}/Radio.js +15 -50
  138. package/radio/Radio.stories.tsx +192 -0
  139. package/radio/types.d.ts +54 -0
  140. package/radio/types.js +5 -0
  141. package/{dist/resultsetTable → resultsetTable}/ResultsetTable.js +35 -119
  142. package/resultsetTable/index.d.ts +19 -0
  143. package/select/Select.js +865 -0
  144. package/select/Select.stories.tsx +572 -0
  145. package/select/index.d.ts +131 -0
  146. package/sidenav/Sidenav.d.ts +9 -0
  147. package/{dist/sidenav → sidenav}/Sidenav.js +19 -62
  148. package/sidenav/Sidenav.stories.tsx +165 -0
  149. package/sidenav/types.d.ts +50 -0
  150. package/sidenav/types.js +5 -0
  151. package/slider/Slider.d.ts +4 -0
  152. package/slider/Slider.js +317 -0
  153. package/slider/Slider.stories.tsx +177 -0
  154. package/slider/types.d.ts +78 -0
  155. package/slider/types.js +5 -0
  156. package/spinner/Spinner.d.ts +4 -0
  157. package/spinner/Spinner.js +250 -0
  158. package/spinner/Spinner.stories.jsx +102 -0
  159. package/spinner/types.d.ts +32 -0
  160. package/spinner/types.js +5 -0
  161. package/switch/Switch.d.ts +4 -0
  162. package/{dist/switch → switch}/Switch.js +26 -69
  163. package/switch/Switch.stories.tsx +160 -0
  164. package/switch/types.d.ts +58 -0
  165. package/switch/types.js +5 -0
  166. package/table/Table.d.ts +4 -0
  167. package/{dist/table → table}/Table.js +10 -24
  168. package/table/Table.stories.jsx +276 -0
  169. package/table/types.d.ts +21 -0
  170. package/table/types.js +5 -0
  171. package/tabs/Tabs.d.ts +4 -0
  172. package/tabs/Tabs.js +213 -0
  173. package/tabs/types.d.ts +70 -0
  174. package/tabs/types.js +5 -0
  175. package/tag/Tag.d.ts +4 -0
  176. package/tag/Tag.js +193 -0
  177. package/tag/Tag.stories.tsx +145 -0
  178. package/tag/types.d.ts +60 -0
  179. package/tag/types.js +5 -0
  180. package/text-input/TextInput.d.ts +4 -0
  181. package/text-input/TextInput.js +785 -0
  182. package/text-input/types.d.ts +157 -0
  183. package/text-input/types.js +5 -0
  184. package/{dist/new-textarea/NewTextarea.js → textarea/Textarea.js} +73 -121
  185. package/textarea/Textarea.stories.jsx +135 -0
  186. package/textarea/index.d.ts +117 -0
  187. package/{dist/toggle → toggle}/Toggle.js +15 -49
  188. package/toggle/index.d.ts +21 -0
  189. package/toggle-group/ToggleGroup.js +243 -0
  190. package/toggle-group/ToggleGroup.stories.tsx +178 -0
  191. package/toggle-group/index.d.ts +21 -0
  192. package/{dist/upload → upload}/Upload.js +11 -15
  193. package/upload/buttons-upload/ButtonsUpload.js +111 -0
  194. package/upload/buttons-upload/Icons.js +40 -0
  195. package/upload/dragAndDropArea/DragAndDropArea.js +225 -0
  196. package/upload/dragAndDropArea/Icons.js +39 -0
  197. package/upload/file-upload/FileToUpload.js +115 -0
  198. package/upload/file-upload/Icons.js +66 -0
  199. package/{dist/upload → upload}/files-upload/FilesToUpload.js +12 -26
  200. package/upload/index.d.ts +15 -0
  201. package/upload/transaction/Icons.js +160 -0
  202. package/upload/transaction/Transaction.js +104 -0
  203. package/upload/transactions/Transactions.js +94 -0
  204. package/{dist/useTheme.js → useTheme.js} +0 -0
  205. package/wizard/Icons.js +65 -0
  206. package/wizard/Wizard.d.ts +4 -0
  207. package/{dist/wizard → wizard}/Wizard.js +33 -213
  208. package/wizard/Wizard.stories.jsx +224 -0
  209. package/wizard/types.d.ts +64 -0
  210. package/wizard/types.js +5 -0
  211. package/README.md +0 -66
  212. package/babel.config.js +0 -8
  213. package/dist/BackgroundColorContext.js +0 -46
  214. package/dist/ThemeContext.js +0 -240
  215. package/dist/accordion-group/AccordionGroup.js +0 -186
  216. package/dist/alert/index.d.ts +0 -26
  217. package/dist/badge/Badge.js +0 -63
  218. package/dist/checkbox/Checkbox.stories.js +0 -144
  219. package/dist/checkbox/readme.md +0 -116
  220. package/dist/date/Date.stories.js +0 -205
  221. package/dist/date/readme.md +0 -73
  222. package/dist/footer/Footer.js +0 -395
  223. package/dist/footer/Footer.stories.js +0 -94
  224. package/dist/footer/dxc_logo.svg +0 -15
  225. package/dist/footer/readme.md +0 -41
  226. package/dist/header/Header.js +0 -403
  227. package/dist/header/Header.stories.js +0 -176
  228. package/dist/header/close_icon.svg +0 -1
  229. package/dist/header/dxc_logo_black.svg +0 -8
  230. package/dist/header/hamb_menu_black.svg +0 -1
  231. package/dist/header/hamb_menu_white.svg +0 -1
  232. package/dist/header/readme.md +0 -33
  233. package/dist/input-text/InputText.stories.js +0 -209
  234. package/dist/input-text/error.svg +0 -1
  235. package/dist/input-text/readme.md +0 -91
  236. package/dist/layout/facebook.svg +0 -45
  237. package/dist/layout/linkedin.svg +0 -50
  238. package/dist/layout/twitter.svg +0 -53
  239. package/dist/link/readme.md +0 -51
  240. package/dist/main.d.ts +0 -2
  241. package/dist/new-input-text/NewInputText.js +0 -977
  242. package/dist/number/Number.js +0 -138
  243. package/dist/paginator/Paginator.js +0 -289
  244. package/dist/paginator/images/next.svg +0 -3
  245. package/dist/paginator/images/nextPage.svg +0 -3
  246. package/dist/paginator/images/previous.svg +0 -3
  247. package/dist/paginator/images/previousPage.svg +0 -3
  248. package/dist/paginator/readme.md +0 -50
  249. package/dist/password/styles.css +0 -3
  250. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  251. package/dist/progress-bar/readme.md +0 -63
  252. package/dist/radio/Radio.stories.js +0 -166
  253. package/dist/radio/readme.md +0 -70
  254. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  255. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  256. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  257. package/dist/slider/Slider.js +0 -319
  258. package/dist/slider/Slider.stories.js +0 -241
  259. package/dist/slider/readme.md +0 -64
  260. package/dist/spinner/Spinner.js +0 -381
  261. package/dist/spinner/Spinner.stories.js +0 -183
  262. package/dist/spinner/readme.md +0 -65
  263. package/dist/switch/Switch.stories.js +0 -134
  264. package/dist/switch/readme.md +0 -133
  265. package/dist/tabs/Tabs.js +0 -343
  266. package/dist/tabs/Tabs.stories.js +0 -130
  267. package/dist/tabs/readme.md +0 -78
  268. package/dist/tabs-for-sections/TabsForSections.js +0 -92
  269. package/dist/tabs-for-sections/readme.md +0 -78
  270. package/dist/tag/Tag.js +0 -282
  271. package/dist/toggle/Toggle.stories.js +0 -297
  272. package/dist/toggle/readme.md +0 -80
  273. package/dist/toggle-group/ToggleGroup.js +0 -223
  274. package/dist/upload/Upload.stories.js +0 -72
  275. package/dist/upload/buttons-upload/ButtonsUpload.js +0 -139
  276. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  277. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  278. package/dist/upload/dragAndDropArea/DragAndDropArea.js +0 -329
  279. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  280. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  281. package/dist/upload/file-upload/FileToUpload.js +0 -184
  282. package/dist/upload/file-upload/audio-icon.svg +0 -4
  283. package/dist/upload/file-upload/close.svg +0 -4
  284. package/dist/upload/file-upload/file-icon.svg +0 -4
  285. package/dist/upload/file-upload/video-icon.svg +0 -4
  286. package/dist/upload/readme.md +0 -37
  287. package/dist/upload/transaction/Transaction.js +0 -175
  288. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  289. package/dist/upload/transaction/audio-icon.svg +0 -4
  290. package/dist/upload/transaction/error-icon.svg +0 -4
  291. package/dist/upload/transaction/file-icon-err.svg +0 -4
  292. package/dist/upload/transaction/file-icon.svg +0 -4
  293. package/dist/upload/transaction/image-icon-err.svg +0 -4
  294. package/dist/upload/transaction/image-icon.svg +0 -4
  295. package/dist/upload/transaction/success-icon.svg +0 -4
  296. package/dist/upload/transaction/video-icon-err.svg +0 -4
  297. package/dist/upload/transaction/video-icon.svg +0 -4
  298. package/dist/upload/transactions/Transactions.js +0 -138
  299. package/dist/wizard/invalid_icon.svg +0 -5
  300. package/dist/wizard/valid_icon.svg +0 -5
  301. package/dist/wizard/validation-wrong.svg +0 -6
  302. package/test/Accordion.test.js +0 -33
  303. package/test/AccordionGroup.test.js +0 -125
  304. package/test/Alert.test.js +0 -53
  305. package/test/Box.test.js +0 -10
  306. package/test/Button.test.js +0 -18
  307. package/test/Card.test.js +0 -30
  308. package/test/Checkbox.test.js +0 -45
  309. package/test/Chip.test.js +0 -25
  310. package/test/Date.test.js +0 -393
  311. package/test/Dialog.test.js +0 -23
  312. package/test/Dropdown.test.js +0 -145
  313. package/test/Footer.test.js +0 -99
  314. package/test/Header.test.js +0 -39
  315. package/test/Heading.test.js +0 -35
  316. package/test/InputText.test.js +0 -240
  317. package/test/Link.test.js +0 -43
  318. package/test/NewDate.test.js +0 -203
  319. package/test/NewInputText.test.js +0 -866
  320. package/test/NewTextarea.test.js +0 -252
  321. package/test/Number.test.js +0 -241
  322. package/test/Paginator.test.js +0 -177
  323. package/test/Password.test.js +0 -76
  324. package/test/ProgressBar.test.js +0 -35
  325. package/test/Radio.test.js +0 -37
  326. package/test/ResultsetTable.test.js +0 -329
  327. package/test/Select.test.js +0 -212
  328. package/test/Sidenav.test.js +0 -45
  329. package/test/Slider.test.js +0 -82
  330. package/test/Spinner.test.js +0 -32
  331. package/test/Switch.test.js +0 -45
  332. package/test/Table.test.js +0 -36
  333. package/test/Tabs.test.js +0 -109
  334. package/test/TabsForSections.test.js +0 -34
  335. package/test/Tag.test.js +0 -32
  336. package/test/TextArea.test.js +0 -52
  337. package/test/ToggleGroup.test.js +0 -81
  338. package/test/Upload.test.js +0 -60
  339. package/test/Wizard.test.js +0 -130
  340. package/test/mocks/pngMock.js +0 -1
  341. 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
- });