@dxc-technology/halstack-react 0.0.0-6091a5a → 0.0.0-618c6e0

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 (191) hide show
  1. package/README.md +27 -47
  2. package/dist/index.d.mts +6486 -0
  3. package/dist/index.d.ts +6486 -0
  4. package/dist/index.js +13510 -0
  5. package/dist/index.mjs +13453 -0
  6. package/package.json +76 -68
  7. package/babel.config.js +0 -8
  8. package/dist/BackgroundColorContext.js +0 -46
  9. package/dist/ThemeContext.js +0 -248
  10. package/dist/accordion/Accordion.js +0 -353
  11. package/dist/accordion-group/AccordionGroup.js +0 -186
  12. package/dist/alert/Alert.js +0 -403
  13. package/dist/alert/index.d.ts +0 -51
  14. package/dist/badge/Badge.js +0 -63
  15. package/dist/box/Box.js +0 -156
  16. package/dist/button/Button.js +0 -238
  17. package/dist/card/Card.js +0 -254
  18. package/dist/checkbox/Checkbox.js +0 -300
  19. package/dist/checkbox/Checkbox.stories.js +0 -144
  20. package/dist/checkbox/readme.md +0 -116
  21. package/dist/chip/Chip.js +0 -265
  22. package/dist/common/OpenSans.css +0 -81
  23. package/dist/common/RequiredComponent.js +0 -40
  24. package/dist/common/fonts/OpenSans-Bold.ttf +0 -0
  25. package/dist/common/fonts/OpenSans-BoldItalic.ttf +0 -0
  26. package/dist/common/fonts/OpenSans-ExtraBold.ttf +0 -0
  27. package/dist/common/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  28. package/dist/common/fonts/OpenSans-Italic.ttf +0 -0
  29. package/dist/common/fonts/OpenSans-Light.ttf +0 -0
  30. package/dist/common/fonts/OpenSans-LightItalic.ttf +0 -0
  31. package/dist/common/fonts/OpenSans-Regular.ttf +0 -0
  32. package/dist/common/fonts/OpenSans-SemiBold.ttf +0 -0
  33. package/dist/common/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
  34. package/dist/common/utils.js +0 -22
  35. package/dist/common/variables.js +0 -1441
  36. package/dist/date/Date.js +0 -379
  37. package/dist/date/Date.stories.js +0 -205
  38. package/dist/date/readme.md +0 -73
  39. package/dist/dialog/Dialog.js +0 -218
  40. package/dist/dropdown/Dropdown.js +0 -544
  41. package/dist/file-input/FileInput.js +0 -641
  42. package/dist/file-input/FileItem.js +0 -265
  43. package/dist/file-input/index.d.ts +0 -81
  44. package/dist/footer/Footer.js +0 -395
  45. package/dist/footer/Footer.stories.js +0 -94
  46. package/dist/footer/dxc_logo.svg +0 -15
  47. package/dist/footer/readme.md +0 -41
  48. package/dist/header/Header.js +0 -403
  49. package/dist/header/Header.stories.js +0 -176
  50. package/dist/header/close_icon.svg +0 -1
  51. package/dist/header/dxc_logo_black.svg +0 -8
  52. package/dist/header/hamb_menu_black.svg +0 -1
  53. package/dist/header/hamb_menu_white.svg +0 -1
  54. package/dist/header/readme.md +0 -33
  55. package/dist/heading/Heading.js +0 -218
  56. package/dist/input-text/InputText.js +0 -707
  57. package/dist/input-text/InputText.stories.js +0 -209
  58. package/dist/input-text/error.svg +0 -1
  59. package/dist/input-text/readme.md +0 -91
  60. package/dist/layout/ApplicationLayout.js +0 -331
  61. package/dist/layout/facebook.svg +0 -45
  62. package/dist/layout/linkedin.svg +0 -50
  63. package/dist/layout/twitter.svg +0 -53
  64. package/dist/link/Link.js +0 -237
  65. package/dist/link/readme.md +0 -51
  66. package/dist/main.d.ts +0 -7
  67. package/dist/main.js +0 -359
  68. package/dist/new-date/NewDate.js +0 -400
  69. package/dist/new-date/index.d.ts +0 -95
  70. package/dist/new-input-text/NewInputText.js +0 -987
  71. package/dist/new-input-text/index.d.ts +0 -135
  72. package/dist/new-textarea/NewTextarea.js +0 -362
  73. package/dist/new-textarea/index.d.ts +0 -117
  74. package/dist/number/Number.js +0 -138
  75. package/dist/number/NumberContext.js +0 -16
  76. package/dist/number/index.d.ts +0 -113
  77. package/dist/paginator/Paginator.js +0 -289
  78. package/dist/paginator/images/next.svg +0 -3
  79. package/dist/paginator/images/nextPage.svg +0 -3
  80. package/dist/paginator/images/previous.svg +0 -3
  81. package/dist/paginator/images/previousPage.svg +0 -3
  82. package/dist/paginator/readme.md +0 -50
  83. package/dist/password/Password.js +0 -200
  84. package/dist/password/index.d.ts +0 -94
  85. package/dist/password/styles.css +0 -3
  86. package/dist/progress-bar/ProgressBar.js +0 -242
  87. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  88. package/dist/progress-bar/readme.md +0 -63
  89. package/dist/radio/Radio.js +0 -209
  90. package/dist/radio/Radio.stories.js +0 -166
  91. package/dist/radio/readme.md +0 -70
  92. package/dist/resultsetTable/ResultsetTable.js +0 -358
  93. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  94. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  95. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  96. package/dist/select/Select.js +0 -549
  97. package/dist/sidenav/Sidenav.js +0 -179
  98. package/dist/slider/Slider.js +0 -319
  99. package/dist/slider/Slider.stories.js +0 -241
  100. package/dist/slider/readme.md +0 -64
  101. package/dist/spinner/Spinner.js +0 -381
  102. package/dist/spinner/Spinner.stories.js +0 -183
  103. package/dist/spinner/readme.md +0 -65
  104. package/dist/switch/Switch.js +0 -222
  105. package/dist/switch/Switch.stories.js +0 -134
  106. package/dist/switch/readme.md +0 -133
  107. package/dist/table/Table.js +0 -132
  108. package/dist/tabs/Tabs.js +0 -343
  109. package/dist/tabs/Tabs.stories.js +0 -130
  110. package/dist/tabs/readme.md +0 -78
  111. package/dist/tabs-for-sections/TabsForSections.js +0 -92
  112. package/dist/tabs-for-sections/readme.md +0 -78
  113. package/dist/tag/Tag.js +0 -282
  114. package/dist/textarea/Textarea.js +0 -264
  115. package/dist/toggle/Toggle.js +0 -220
  116. package/dist/toggle/Toggle.stories.js +0 -297
  117. package/dist/toggle/readme.md +0 -80
  118. package/dist/toggle-group/ToggleGroup.js +0 -223
  119. package/dist/upload/Upload.js +0 -205
  120. package/dist/upload/Upload.stories.js +0 -72
  121. package/dist/upload/buttons-upload/ButtonsUpload.js +0 -139
  122. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  123. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  124. package/dist/upload/dragAndDropArea/DragAndDropArea.js +0 -329
  125. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  126. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  127. package/dist/upload/file-upload/FileToUpload.js +0 -184
  128. package/dist/upload/file-upload/audio-icon.svg +0 -4
  129. package/dist/upload/file-upload/close.svg +0 -4
  130. package/dist/upload/file-upload/file-icon.svg +0 -4
  131. package/dist/upload/file-upload/video-icon.svg +0 -4
  132. package/dist/upload/files-upload/FilesToUpload.js +0 -123
  133. package/dist/upload/readme.md +0 -37
  134. package/dist/upload/transaction/Transaction.js +0 -175
  135. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  136. package/dist/upload/transaction/audio-icon.svg +0 -4
  137. package/dist/upload/transaction/error-icon.svg +0 -4
  138. package/dist/upload/transaction/file-icon-err.svg +0 -4
  139. package/dist/upload/transaction/file-icon.svg +0 -4
  140. package/dist/upload/transaction/image-icon-err.svg +0 -4
  141. package/dist/upload/transaction/image-icon.svg +0 -4
  142. package/dist/upload/transaction/success-icon.svg +0 -4
  143. package/dist/upload/transaction/video-icon-err.svg +0 -4
  144. package/dist/upload/transaction/video-icon.svg +0 -4
  145. package/dist/upload/transactions/Transactions.js +0 -138
  146. package/dist/useTheme.js +0 -22
  147. package/dist/wizard/Wizard.js +0 -411
  148. package/dist/wizard/invalid_icon.svg +0 -5
  149. package/dist/wizard/valid_icon.svg +0 -5
  150. package/dist/wizard/validation-wrong.svg +0 -6
  151. package/test/Accordion.test.js +0 -33
  152. package/test/AccordionGroup.test.js +0 -125
  153. package/test/Alert.test.js +0 -53
  154. package/test/Box.test.js +0 -10
  155. package/test/Button.test.js +0 -18
  156. package/test/Card.test.js +0 -30
  157. package/test/Checkbox.test.js +0 -45
  158. package/test/Chip.test.js +0 -25
  159. package/test/Date.test.js +0 -393
  160. package/test/Dialog.test.js +0 -23
  161. package/test/Dropdown.test.js +0 -145
  162. package/test/FileInput.test.js +0 -201
  163. package/test/Footer.test.js +0 -99
  164. package/test/Header.test.js +0 -39
  165. package/test/Heading.test.js +0 -35
  166. package/test/InputText.test.js +0 -240
  167. package/test/Link.test.js +0 -43
  168. package/test/NewDate.test.js +0 -232
  169. package/test/NewInputText.test.js +0 -734
  170. package/test/NewTextarea.test.js +0 -195
  171. package/test/Number.test.js +0 -257
  172. package/test/Paginator.test.js +0 -177
  173. package/test/Password.test.js +0 -83
  174. package/test/ProgressBar.test.js +0 -35
  175. package/test/Radio.test.js +0 -37
  176. package/test/ResultsetTable.test.js +0 -329
  177. package/test/Select.test.js +0 -212
  178. package/test/Sidenav.test.js +0 -45
  179. package/test/Slider.test.js +0 -82
  180. package/test/Spinner.test.js +0 -32
  181. package/test/Switch.test.js +0 -45
  182. package/test/Table.test.js +0 -36
  183. package/test/Tabs.test.js +0 -109
  184. package/test/TabsForSections.test.js +0 -34
  185. package/test/Tag.test.js +0 -32
  186. package/test/TextArea.test.js +0 -52
  187. package/test/ToggleGroup.test.js +0 -81
  188. package/test/Upload.test.js +0 -60
  189. package/test/Wizard.test.js +0 -130
  190. package/test/mocks/pngMock.js +0 -1
  191. 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
- });