@dxc-technology/halstack-react 0.0.0-e904570 → 0.0.0-e961efe

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 (247) hide show
  1. package/README.md +2 -2
  2. package/babel.config.js +5 -2
  3. package/dist/BackgroundColorContext.js +46 -0
  4. package/dist/ThemeContext.js +237 -2
  5. package/dist/V3Select/V3Select.js +549 -0
  6. package/dist/V3Select/index.d.ts +27 -0
  7. package/dist/V3Textarea/V3Textarea.js +264 -0
  8. package/dist/V3Textarea/index.d.ts +27 -0
  9. package/dist/accordion/Accordion.js +170 -81
  10. package/dist/accordion/index.d.ts +28 -0
  11. package/dist/accordion-group/AccordionGroup.js +186 -0
  12. package/dist/accordion-group/index.d.ts +16 -0
  13. package/dist/alert/Alert.js +184 -83
  14. package/dist/alert/index.d.ts +51 -0
  15. package/dist/badge/Badge.js +63 -0
  16. package/dist/box/Box.js +39 -19
  17. package/dist/box/index.d.ts +25 -0
  18. package/dist/button/Button.js +84 -29
  19. package/dist/button/index.d.ts +24 -0
  20. package/dist/card/Card.js +64 -56
  21. package/dist/card/index.d.ts +22 -0
  22. package/dist/checkbox/Checkbox.js +107 -32
  23. package/dist/checkbox/index.d.ts +24 -0
  24. package/dist/chip/Chip.js +135 -40
  25. package/dist/chip/index.d.ts +22 -0
  26. package/dist/common/RequiredComponent.js +2 -8
  27. package/dist/common/utils.js +2 -22
  28. package/dist/common/variables.js +1482 -105
  29. package/dist/date/Date.js +110 -73
  30. package/dist/date/index.d.ts +27 -0
  31. package/dist/date-input/DateInput.js +400 -0
  32. package/dist/date-input/index.d.ts +95 -0
  33. package/dist/dialog/Dialog.js +61 -36
  34. package/dist/dialog/index.d.ts +18 -0
  35. package/dist/dropdown/Dropdown.js +226 -94
  36. package/dist/dropdown/index.d.ts +26 -0
  37. package/dist/file-input/FileInput.js +644 -0
  38. package/dist/file-input/FileItem.js +287 -0
  39. package/dist/file-input/index.d.ts +81 -0
  40. package/dist/footer/Footer.js +125 -45
  41. package/dist/footer/Icons.js +77 -0
  42. package/dist/footer/index.d.ts +25 -0
  43. package/dist/header/Header.js +211 -91
  44. package/dist/header/Icons.js +59 -0
  45. package/dist/header/index.d.ts +25 -0
  46. package/dist/heading/Heading.js +93 -22
  47. package/dist/heading/index.d.ts +17 -0
  48. package/dist/input-text/Icons.js +22 -0
  49. package/dist/input-text/InputText.js +292 -106
  50. package/dist/input-text/index.d.ts +36 -0
  51. package/dist/layout/ApplicationLayout.js +327 -0
  52. package/dist/layout/Icons.js +55 -0
  53. package/dist/link/Link.js +142 -34
  54. package/dist/link/index.d.ts +23 -0
  55. package/dist/main.d.ts +40 -0
  56. package/dist/main.js +112 -16
  57. package/dist/number-input/NumberInput.js +136 -0
  58. package/dist/number-input/NumberInputContext.js +16 -0
  59. package/dist/number-input/index.d.ts +113 -0
  60. package/dist/paginator/Icons.js +66 -0
  61. package/dist/paginator/Paginator.js +184 -57
  62. package/dist/paginator/index.d.ts +20 -0
  63. package/dist/password-input/PasswordInput.js +203 -0
  64. package/dist/password-input/index.d.ts +94 -0
  65. package/dist/progress-bar/ProgressBar.js +97 -44
  66. package/dist/progress-bar/index.d.ts +18 -0
  67. package/dist/radio/Radio.js +39 -21
  68. package/dist/radio/index.d.ts +23 -0
  69. package/dist/resultsetTable/ResultsetTable.js +93 -69
  70. package/dist/resultsetTable/index.d.ts +19 -0
  71. package/dist/select/Select.js +917 -263
  72. package/dist/select/index.d.ts +53 -0
  73. package/dist/sidenav/Sidenav.js +87 -125
  74. package/dist/sidenav/index.d.ts +13 -0
  75. package/dist/slider/Slider.js +219 -73
  76. package/dist/slider/index.d.ts +29 -0
  77. package/dist/spinner/Spinner.js +249 -64
  78. package/dist/spinner/index.d.ts +17 -0
  79. package/dist/stories/Button.js +71 -0
  80. package/dist/stories/Button.stories.js +55 -0
  81. package/dist/stories/Header.js +67 -0
  82. package/dist/stories/Header.stories.js +31 -0
  83. package/dist/stories/Introduction.stories.mdx +211 -0
  84. package/dist/stories/Page.js +68 -0
  85. package/dist/stories/Page.stories.js +39 -0
  86. package/dist/stories/assets/code-brackets.svg +1 -0
  87. package/dist/stories/assets/colors.svg +1 -0
  88. package/dist/stories/assets/comments.svg +1 -0
  89. package/dist/stories/assets/direction.svg +1 -0
  90. package/dist/stories/assets/flow.svg +1 -0
  91. package/dist/stories/assets/plugin.svg +1 -0
  92. package/dist/stories/assets/repo.svg +1 -0
  93. package/dist/stories/assets/stackalt.svg +1 -0
  94. package/dist/stories/button.css +30 -0
  95. package/dist/stories/header.css +26 -0
  96. package/dist/stories/page.css +69 -0
  97. package/dist/switch/Switch.js +52 -25
  98. package/dist/switch/index.d.ts +24 -0
  99. package/dist/table/Table.js +63 -15
  100. package/dist/table/index.d.ts +13 -0
  101. package/dist/tabs/Tabs.js +210 -50
  102. package/dist/tabs/index.d.ts +19 -0
  103. package/dist/tag/Tag.js +100 -35
  104. package/dist/tag/index.d.ts +24 -0
  105. package/dist/text-input/TextInput.js +974 -0
  106. package/dist/text-input/index.d.ts +135 -0
  107. package/dist/textarea/Textarea.js +250 -107
  108. package/dist/textarea/index.d.ts +117 -0
  109. package/dist/toggle/Toggle.js +16 -19
  110. package/dist/toggle/index.d.ts +21 -0
  111. package/dist/toggle-group/ToggleGroup.js +327 -0
  112. package/dist/toggle-group/index.d.ts +21 -0
  113. package/dist/upload/Upload.js +13 -8
  114. package/dist/upload/buttons-upload/ButtonsUpload.js +35 -25
  115. package/dist/upload/buttons-upload/Icons.js +40 -0
  116. package/dist/upload/dragAndDropArea/DragAndDropArea.js +84 -37
  117. package/dist/upload/dragAndDropArea/Icons.js +39 -0
  118. package/dist/upload/file-upload/FileToUpload.js +64 -33
  119. package/dist/upload/file-upload/Icons.js +66 -0
  120. package/dist/upload/files-upload/FilesToUpload.js +16 -16
  121. package/dist/upload/index.d.ts +15 -0
  122. package/dist/upload/transaction/Icons.js +160 -0
  123. package/dist/upload/transaction/Transaction.js +42 -49
  124. package/dist/upload/transactions/Transactions.js +38 -20
  125. package/dist/useTheme.js +22 -0
  126. package/dist/wizard/Icons.js +65 -0
  127. package/dist/wizard/Wizard.js +156 -61
  128. package/dist/wizard/index.d.ts +18 -0
  129. package/package.json +26 -14
  130. package/test/AccordionGroup.test.js +125 -0
  131. package/test/Date.test.js +15 -13
  132. package/test/DateInput.test.js +242 -0
  133. package/test/Dropdown.test.js +19 -4
  134. package/test/FileInput.test.js +201 -0
  135. package/test/Footer.test.js +2 -7
  136. package/test/Header.test.js +5 -10
  137. package/test/Heading.test.js +60 -12
  138. package/test/InputText.test.js +31 -28
  139. package/test/Link.test.js +25 -7
  140. package/test/NumberInput.test.js +259 -0
  141. package/test/Paginator.test.js +76 -60
  142. package/test/PasswordInput.test.js +83 -0
  143. package/test/ResultsetTable.test.js +65 -17
  144. package/test/Select.test.js +371 -147
  145. package/test/Sidenav.test.js +22 -64
  146. package/test/Slider.test.js +24 -15
  147. package/test/Spinner.test.js +5 -0
  148. package/test/Tabs.test.js +21 -0
  149. package/test/TextInput.test.js +732 -0
  150. package/test/Textarea.test.js +193 -0
  151. package/test/ToggleGroup.test.js +85 -0
  152. package/test/Upload.test.js +1 -1
  153. package/test/V3Select.test.js +212 -0
  154. package/test/{TextArea.test.js → V3TextArea.test.js} +6 -7
  155. package/dist/accordion/Accordion.stories.js +0 -207
  156. package/dist/accordion/readme.md +0 -96
  157. package/dist/alert/Alert.stories.js +0 -158
  158. package/dist/alert/close.svg +0 -4
  159. package/dist/alert/error.svg +0 -4
  160. package/dist/alert/info.svg +0 -4
  161. package/dist/alert/readme.md +0 -43
  162. package/dist/alert/success.svg +0 -4
  163. package/dist/alert/warning.svg +0 -4
  164. package/dist/button/Button.stories.js +0 -224
  165. package/dist/button/readme.md +0 -93
  166. package/dist/checkbox/Checkbox.stories.js +0 -144
  167. package/dist/checkbox/readme.md +0 -116
  168. package/dist/common/services/example-service.js +0 -10
  169. package/dist/common/services/example-service.test.js +0 -12
  170. package/dist/date/Date.stories.js +0 -205
  171. package/dist/date/calendar.svg +0 -1
  172. package/dist/date/calendar_dark.svg +0 -1
  173. package/dist/date/readme.md +0 -73
  174. package/dist/dialog/Dialog.stories.js +0 -217
  175. package/dist/dialog/readme.md +0 -32
  176. package/dist/dropdown/Dropdown.stories.js +0 -249
  177. package/dist/dropdown/baseline-arrow_drop_down.svg +0 -1
  178. package/dist/dropdown/baseline-arrow_drop_down_wh.svg +0 -4
  179. package/dist/dropdown/baseline-arrow_drop_up.svg +0 -1
  180. package/dist/dropdown/baseline-arrow_drop_up_wh.svg +0 -4
  181. package/dist/dropdown/readme.md +0 -69
  182. package/dist/footer/Footer.stories.js +0 -94
  183. package/dist/footer/dxc_logo_wht.png +0 -0
  184. package/dist/footer/readme.md +0 -41
  185. package/dist/header/Header.stories.js +0 -176
  186. package/dist/header/close_icon.svg +0 -1
  187. package/dist/header/dxc_logo_black.png +0 -0
  188. package/dist/header/dxc_logo_white.png +0 -0
  189. package/dist/header/hamb_menu_black.svg +0 -1
  190. package/dist/header/hamb_menu_white.svg +0 -1
  191. package/dist/header/readme.md +0 -33
  192. package/dist/input-text/InputText.stories.js +0 -209
  193. package/dist/input-text/error.svg +0 -1
  194. package/dist/input-text/readme.md +0 -91
  195. package/dist/link/readme.md +0 -51
  196. package/dist/paginator/images/next.svg +0 -3
  197. package/dist/paginator/images/nextPage.svg +0 -3
  198. package/dist/paginator/images/previous.svg +0 -3
  199. package/dist/paginator/images/previousPage.svg +0 -3
  200. package/dist/paginator/readme.md +0 -50
  201. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  202. package/dist/progress-bar/readme.md +0 -63
  203. package/dist/radio/Radio.stories.js +0 -166
  204. package/dist/radio/readme.md +0 -70
  205. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  206. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  207. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  208. package/dist/select/Select.stories.js +0 -235
  209. package/dist/select/readme.md +0 -72
  210. package/dist/sidenav/arrow_icon.svg +0 -3
  211. package/dist/slider/Slider.stories.js +0 -241
  212. package/dist/slider/readme.md +0 -64
  213. package/dist/spinner/Spinner.stories.js +0 -183
  214. package/dist/spinner/readme.md +0 -65
  215. package/dist/switch/Switch.stories.js +0 -134
  216. package/dist/switch/readme.md +0 -133
  217. package/dist/tabs/Tabs.stories.js +0 -130
  218. package/dist/tabs/readme.md +0 -78
  219. package/dist/tabs-for-sections/TabsForSections.js +0 -107
  220. package/dist/tabs-for-sections/readme.md +0 -78
  221. package/dist/toggle/Toggle.stories.js +0 -297
  222. package/dist/toggle/readme.md +0 -80
  223. package/dist/upload/Upload.stories.js +0 -72
  224. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  225. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  226. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  227. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  228. package/dist/upload/file-upload/audio-icon.svg +0 -4
  229. package/dist/upload/file-upload/close.svg +0 -4
  230. package/dist/upload/file-upload/file-icon.svg +0 -4
  231. package/dist/upload/file-upload/video-icon.svg +0 -4
  232. package/dist/upload/readme.md +0 -37
  233. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  234. package/dist/upload/transaction/audio-icon.svg +0 -4
  235. package/dist/upload/transaction/error-icon.svg +0 -4
  236. package/dist/upload/transaction/file-icon-err.svg +0 -4
  237. package/dist/upload/transaction/file-icon.svg +0 -4
  238. package/dist/upload/transaction/image-icon-err.svg +0 -4
  239. package/dist/upload/transaction/image-icon.svg +0 -4
  240. package/dist/upload/transaction/success-icon.svg +0 -4
  241. package/dist/upload/transaction/video-icon-err.svg +0 -4
  242. package/dist/upload/transaction/video-icon.svg +0 -4
  243. package/dist/wizard/invalid_icon.svg +0 -6
  244. package/dist/wizard/valid_icon.svg +0 -6
  245. package/dist/wizard/validation-wrong.svg +0 -6
  246. package/test/TabsForSections.test.js +0 -34
  247. package/test/Toggle.test.js +0 -43
@@ -0,0 +1,259 @@
1
+ import React from "react";
2
+ import { render, fireEvent } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import DxcNumberInput from "../src/number-input/NumberInput";
5
+
6
+ describe("Number input component tests", () => {
7
+ test("Number input renders with label", () => {
8
+ const { getByText } = render(<DxcNumberInput label="Number input label" />);
9
+ expect(getByText("Number input label")).toBeTruthy();
10
+ });
11
+
12
+ test("Number input renders with helper text", () => {
13
+ const { getByText } = render(<DxcNumberInput helperText="Helper text" />);
14
+ expect(getByText("Helper text")).toBeTruthy();
15
+ });
16
+
17
+ test("Number input renders with placeholder", () => {
18
+ const { getByLabelText } = render(<DxcNumberInput label="Number label" placeholder="Placeholder" />);
19
+ const number = getByLabelText("Number label");
20
+ expect(number.getAttribute("placeholder")).toBe("Placeholder");
21
+ });
22
+
23
+ test("Number input renders increment and decrement buttons", () => {
24
+ const { queryAllByRole } = render(<DxcNumberInput label="Number label" />);
25
+ expect(queryAllByRole("button").length).toBe(2);
26
+ });
27
+
28
+ test("Number input is disabled", () => {
29
+ const { getByLabelText } = render(<DxcNumberInput label="Number label" disabled />);
30
+ const number = getByLabelText("Number label");
31
+ expect(number.disabled).toBeTruthy();
32
+ });
33
+
34
+ test("Number input is optional", () => {
35
+ const { getByText } = render(<DxcNumberInput label="Number label" optional />);
36
+ expect(getByText("(Optional)")).toBeTruthy();
37
+ });
38
+
39
+ test("Number input is not optional: required field, displays error if not filled in", () => {
40
+ const onBlur = jest.fn();
41
+ const onChange = jest.fn();
42
+ const { getByRole } = render(<DxcNumberInput onBlur={onBlur} onChange={onChange} />);
43
+ const input = getByRole("textbox");
44
+
45
+ userEvent.type(input, "1");
46
+ userEvent.clear(input);
47
+ fireEvent.blur(input);
48
+ expect(onBlur).toHaveBeenCalled();
49
+ expect(onBlur).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
50
+ expect(onChange).toHaveBeenCalled();
51
+ expect(onChange).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
52
+ });
53
+
54
+ test("Suffix and prefix must be shown)", () => {
55
+ const { getByText } = render(<DxcNumberInput label="Number input label" prefix="+34" suffix="USD" />);
56
+ expect(getByText("+34")).toBeTruthy();
57
+ expect(getByText("USD")).toBeTruthy();
58
+ });
59
+
60
+ test("Invalid number input renders error", () => {
61
+ const { getByText } = render(<DxcNumberInput error="Error message." />);
62
+ expect(getByText("Error message.")).toBeTruthy();
63
+ });
64
+
65
+ test("onChange function is called correctly", () => {
66
+ const onChange = jest.fn();
67
+ const { getByLabelText } = render(<DxcNumberInput label="Number input label" onChange={onChange} />);
68
+ const number = getByLabelText("Number input label");
69
+ userEvent.type(number, "t");
70
+ expect(onChange).not.toHaveBeenCalledWith({ value: "t", error: null });
71
+ expect(number.value).toBe("");
72
+ userEvent.type(number, "1");
73
+ expect(onChange).toHaveBeenCalledWith({ value: "1", error: null });
74
+ expect(number.value).toBe("1");
75
+ });
76
+
77
+ test("Error message is shown if the value is less than the min value", () => {
78
+ const onChange = jest.fn(({ value, error }) => {
79
+ expect(value).toBe("1");
80
+ expect(error).toBe("Value must be greater than or equal to 5.");
81
+ });
82
+ const onBlur = jest.fn(({ value, error }) => {
83
+ expect(value).toBe("1");
84
+ expect(error).toBe("Value must be greater than or equal to 5.");
85
+ });
86
+ const { getByLabelText } = render(
87
+ <DxcNumberInput label="Number input label" min={5} onBlur={onBlur} onChange={onChange} />
88
+ );
89
+ const number = getByLabelText("Number input label");
90
+
91
+ userEvent.type(number, "1");
92
+ fireEvent.blur(number);
93
+ });
94
+
95
+ test("Cannot decrement the value if it is less than the min value", () => {
96
+ const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" min={5} />);
97
+ const number = getByLabelText("Number input label");
98
+ userEvent.type(number, "1");
99
+ fireEvent.blur(number);
100
+ expect(number.value).toBe("1");
101
+ const decrement = getAllByRole("button")[0];
102
+ userEvent.click(decrement);
103
+ expect(number.value).toBe("1");
104
+ });
105
+
106
+ test("Increment the value when it is less than the min value", () => {
107
+ const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" min={5} />);
108
+ const number = getByLabelText("Number input label");
109
+ userEvent.type(number, "1");
110
+ fireEvent.blur(number);
111
+ expect(number.value).toBe("1");
112
+ const increment = getAllByRole("button")[1];
113
+ userEvent.click(increment);
114
+ expect(number.value).toBe("5");
115
+ });
116
+
117
+ test("Error message is shown if the value is greater than the max value", () => {
118
+ const onChange = jest.fn();
119
+ const onBlur = jest.fn();
120
+ const { getByLabelText } = render(
121
+ <DxcNumberInput label="Number input label" max={10} onBlur={onBlur} onChange={onChange} />
122
+ );
123
+ const number = getByLabelText("Number input label");
124
+
125
+ userEvent.type(number, "12");
126
+ expect(onChange).toHaveBeenCalledTimes(2);
127
+ expect(onChange).toHaveBeenCalledWith({ value: "12", error: "Value must be less than or equal to 10." });
128
+ fireEvent.blur(number);
129
+ expect(onBlur).toHaveBeenCalled();
130
+ expect(onBlur).toHaveBeenCalledWith({ value: "12", error: "Value must be less than or equal to 10." });
131
+ });
132
+
133
+ test("Cannot increment the value if it is greater than the max value", () => {
134
+ const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" max={10} />);
135
+ const number = getByLabelText("Number input label");
136
+ userEvent.type(number, "12");
137
+ fireEvent.blur(number);
138
+ expect(number.value).toBe("12");
139
+ const decrement = getAllByRole("button")[1];
140
+ userEvent.click(decrement);
141
+ expect(number.value).toBe("12");
142
+ });
143
+
144
+ test("Decrement the value when it is greater than the max value", () => {
145
+ const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" max={10} />);
146
+ const number = getByLabelText("Number input label");
147
+ userEvent.type(number, "12");
148
+ fireEvent.blur(number);
149
+ expect(number.value).toBe("12");
150
+ const decrement = getAllByRole("button")[0];
151
+ userEvent.click(decrement);
152
+ expect(number.value).toBe("10");
153
+ });
154
+
155
+ test("Increment and decrement the value with min and max values", () => {
156
+ const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" min={5} max={10} />);
157
+ const number = getByLabelText("Number input label");
158
+ userEvent.type(number, "1");
159
+ fireEvent.blur(number);
160
+ expect(number.value).toBe("1");
161
+ const decrement = getAllByRole("button")[0];
162
+ userEvent.click(decrement);
163
+ expect(number.value).toBe("1");
164
+ const increment = getAllByRole("button")[1];
165
+ userEvent.click(increment);
166
+ expect(number.value).toBe("5");
167
+ userEvent.click(increment);
168
+ userEvent.click(increment);
169
+ userEvent.click(increment);
170
+ userEvent.click(increment);
171
+ userEvent.click(increment);
172
+ expect(number.value).toBe("10");
173
+ userEvent.click(increment);
174
+ expect(number.value).toBe("10");
175
+ });
176
+
177
+ test("Increment and decrement the value with step", () => {
178
+ const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" step={5} />);
179
+ const number = getByLabelText("Number input label");
180
+ userEvent.type(number, "10");
181
+ fireEvent.blur(number);
182
+ expect(number.value).toBe("10");
183
+ const increment = getAllByRole("button")[1];
184
+ userEvent.click(increment);
185
+ expect(number.value).toBe("15");
186
+ userEvent.click(increment);
187
+ expect(number.value).toBe("20");
188
+ const decrement = getAllByRole("button")[0];
189
+ userEvent.click(decrement);
190
+ expect(number.value).toBe("15");
191
+ userEvent.click(decrement);
192
+ expect(number.value).toBe("10");
193
+ });
194
+
195
+ test("Increment and decrement the value with min, max and step", () => {
196
+ const onBlur = jest.fn(({ value, error }) => {
197
+ expect(value).toBe("1");
198
+ expect(error).toBe("Value must be greater than or equal to 5.");
199
+ });
200
+ const { getByLabelText, getAllByRole } = render(
201
+ <DxcNumberInput label="Number input label" min={5} max={20} step={8} onBlur={onBlur} />
202
+ );
203
+ const number = getByLabelText("Number input label");
204
+ userEvent.type(number, "1");
205
+ fireEvent.blur(number);
206
+ const increment = getAllByRole("button")[1];
207
+ userEvent.click(increment);
208
+ expect(number.value).toBe("5");
209
+ userEvent.click(increment);
210
+ expect(number.value).toBe("13");
211
+ userEvent.click(increment);
212
+ expect(number.value).toBe("20");
213
+ userEvent.click(increment);
214
+ expect(number.value).toBe("20");
215
+ const decrement = getAllByRole("button")[0];
216
+ userEvent.click(decrement);
217
+ expect(number.value).toBe("12");
218
+ userEvent.click(decrement);
219
+ expect(number.value).toBe("5");
220
+ userEvent.click(decrement);
221
+ expect(number.value).toBe("5");
222
+ });
223
+
224
+ test("Increment and decrement the value with min, max and step using the arrows in keyboard", () => {
225
+ const { getByLabelText } = render(<DxcNumberInput label="Number input label" min={5} max={20} step={5} />);
226
+ const number = getByLabelText("Number input label");
227
+ userEvent.type(number, "1");
228
+ fireEvent.keyDown(number, { keyCode: 38 });
229
+ expect(number.value).toBe("5");
230
+ fireEvent.keyDown(number, { keyCode: 38 });
231
+ expect(number.value).toBe("10");
232
+ fireEvent.keyDown(number, { keyCode: 38 });
233
+ expect(number.value).toBe("15");
234
+ fireEvent.keyDown(number, { keyCode: 38 });
235
+ expect(number.value).toBe("20");
236
+ fireEvent.keyDown(number, { keyCode: 38 });
237
+ expect(number.value).toBe("20");
238
+ fireEvent.keyDown(number, { keyCode: 40 });
239
+ expect(number.value).toBe("15");
240
+ fireEvent.keyDown(number, { keyCode: 40 });
241
+ expect(number.value).toBe("10");
242
+ fireEvent.keyDown(number, { keyCode: 40 });
243
+ expect(number.value).toBe("5");
244
+ fireEvent.keyDown(number, { keyCode: 40 });
245
+ expect(number.value).toBe("5");
246
+ });
247
+
248
+ test("Number has correct accesibility attributes", () => {
249
+ const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" />);
250
+ const number = getByLabelText("Number input label");
251
+ expect(number.getAttribute("aria-autocomplete")).toBeNull();
252
+ expect(number.getAttribute("aria-controls")).toBeNull();
253
+ expect(number.getAttribute("aria-expanded")).toBeNull();
254
+ const decrement = getAllByRole("button")[0];
255
+ expect(decrement.getAttribute("aria-label")).toBe("Decrement");
256
+ const increment = getAllByRole("button")[1];
257
+ expect(increment.getAttribute("aria-label")).toBe("Increment");
258
+ });
259
+ });
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
- import { render, fireEvent } from "@testing-library/react";
2
+ import { render, act } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
3
4
  import DxcPaginator from "../src/paginator/Paginator";
4
- import DxcButton from "../src/button/Button";
5
5
 
6
6
  describe("Paginator component tests", () => {
7
7
  test("Paginator renders with default values", () => {
@@ -15,7 +15,14 @@ describe("Paginator component tests", () => {
15
15
  expect(getByText("Page: 2 of 1")).toBeTruthy();
16
16
  });
17
17
 
18
- test("Paginator renders with itemsPerPage", () => {
18
+ test("Paginator renders with itemsPerPageOptions", () => {
19
+ const { getByText } = render(
20
+ <DxcPaginator currentPage={1} itemsPerPage={10} itemsPerPageOptions={[10, 15]} totalItems={20}></DxcPaginator>
21
+ );
22
+ expect(getByText("Items per page")).toBeTruthy();
23
+ });
24
+
25
+ test("Paginator renders with itemsPerPageOptions", () => {
19
26
  const { getByText } = render(<DxcPaginator currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>);
20
27
  expect(getByText("1 to 10 of 20")).toBeTruthy();
21
28
  expect(getByText("Page: 1 of 2")).toBeTruthy();
@@ -33,102 +40,119 @@ describe("Paginator component tests", () => {
33
40
  expect(getByText("Page: 2 of 2")).toBeTruthy();
34
41
  });
35
42
 
36
- test("Call correct nextFunction", () => {
37
- const onClick = jest.fn();
38
- const { getByRole } = render(
39
- <DxcPaginator nextFunction={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
43
+ test("Paginator renders goToPage select", () => {
44
+ const { getByText } = render(
45
+ <DxcPaginator currentPage={2} showGoToPage={true} itemsPerPage={10} totalItems={20}></DxcPaginator>
40
46
  );
41
- const nextButton = getByRole("button");
42
- fireEvent.click(nextButton);
43
- expect(onClick).toHaveBeenCalled();
47
+ expect(getByText("Go to page:")).toBeTruthy();
44
48
  });
45
49
 
46
- test("Call correct lastFunction", () => {
50
+ test("Paginator goToPage call correct function", () => {
47
51
  const onClick = jest.fn();
48
- const { getByRole } = render(
49
- <DxcPaginator lastFunction={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
52
+ window.HTMLElement.prototype.scrollIntoView = () => {};
53
+ window.HTMLElement.prototype.scrollTo = () => {};
54
+ const { getByText, getAllByRole, getByRole } = render(
55
+ <DxcPaginator
56
+ currentPage={1}
57
+ itemsPerPage={10}
58
+ totalItems={27}
59
+ showGoToPage={true}
60
+ onPageChange={onClick}
61
+ ></DxcPaginator>
50
62
  );
51
- const lastButton = getByRole("button");
52
- fireEvent.click(lastButton);
63
+ const goToPageSelect = getAllByRole("combobox")[0];
64
+ act(() => {
65
+ userEvent.click(goToPageSelect);
66
+ });
67
+ const goToPageOption = getByText("2");
68
+ act(() => {
69
+ userEvent.click(goToPageOption);
70
+ });
53
71
  expect(onClick).toHaveBeenCalledWith(2);
54
72
  });
55
73
 
56
- test("Call correct prevFunction", () => {
74
+ test("Call correct goToPageFunction", () => {
57
75
  const onClick = jest.fn();
58
- const { getByRole } = render(
59
- <DxcPaginator prevFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
76
+ const { getAllByRole } = render(
77
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
60
78
  );
61
- const prevButton = getByRole("button");
62
- fireEvent.click(prevButton);
79
+ const nextButton = getAllByRole("button")[2];
80
+ userEvent.click(nextButton);
63
81
  expect(onClick).toHaveBeenCalled();
64
82
  });
65
83
 
66
- test("Call correct firstFunction", () => {
84
+ test("Call correct itemsPerPageFunction", () => {
67
85
  const onClick = jest.fn();
68
- const { getByRole } = render(
69
- <DxcPaginator firstFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={30}></DxcPaginator>
86
+ window.HTMLElement.prototype.scrollIntoView = () => {};
87
+ window.HTMLElement.prototype.scrollTo = () => {};
88
+ const { getAllByText, getByText } = render(
89
+ <DxcPaginator
90
+ currentPage={1}
91
+ itemsPerPage={10}
92
+ itemsPerPageOptions={[10, 15]}
93
+ itemsPerPageFunction={onClick}
94
+ totalItems={20}
95
+ ></DxcPaginator>
70
96
  );
71
- const firstButton = getByRole("button");
72
- fireEvent.click(firstButton);
73
- expect(onClick).toHaveBeenCalled();
97
+ const select = getAllByText("10")[0];
98
+ act(() => {
99
+ userEvent.click(select);
100
+ });
101
+ const itemPerPageOption = getByText("15");
102
+ act(() => {
103
+ userEvent.click(itemPerPageOption);
104
+ });
105
+ expect(onClick).toHaveBeenCalledWith(15);
74
106
  });
75
107
 
76
108
  test("Next button is disable in last page", () => {
77
109
  const onClick = jest.fn();
78
- const { getByRole } = render(
79
- <DxcPaginator nextFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
110
+ const { getAllByRole } = render(
111
+ <DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
80
112
  );
81
- const nextButton = getByRole("button");
113
+ const nextButton = getAllByRole("button")[2];
82
114
  expect(nextButton.hasAttribute("disabled")).toBeTruthy();
83
- fireEvent.click(nextButton);
115
+ userEvent.click(nextButton);
84
116
  expect(onClick).toHaveBeenCalledTimes(0);
85
117
  });
86
118
 
87
119
  test("Last button is disable in last page", () => {
88
120
  const onClick = jest.fn();
89
- const { getByRole } = render(
90
- <DxcPaginator lastFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
121
+ const { getAllByRole } = render(
122
+ <DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
91
123
  );
92
- const lastButton = getByRole("button");
124
+ const lastButton = getAllByRole("button")[3];
93
125
  expect(lastButton.hasAttribute("disabled")).toBeTruthy();
94
- fireEvent.click(lastButton);
126
+ userEvent.click(lastButton);
95
127
  expect(onClick).toHaveBeenCalledTimes(0);
96
128
  });
97
129
 
98
130
  test("First button is disable in first page", () => {
99
131
  const onClick = jest.fn();
100
- const { getByRole } = render(
101
- <DxcPaginator firstFunction={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
132
+ const { getAllByRole } = render(
133
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
102
134
  );
103
- const lastButton = getByRole("button");
135
+ const lastButton = getAllByRole("button")[0];
104
136
  expect(lastButton.hasAttribute("disabled")).toBeTruthy();
105
- fireEvent.click(lastButton);
137
+ userEvent.click(lastButton);
106
138
  expect(onClick).toHaveBeenCalledTimes(0);
107
139
  });
108
140
 
109
141
  test("Previous button is disable in first page", () => {
110
142
  const onClick = jest.fn();
111
- const { getByRole } = render(
112
- <DxcPaginator prevFunction={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
143
+ const { getAllByRole } = render(
144
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
113
145
  );
114
- const lastButton = getByRole("button");
146
+ const lastButton = getAllByRole("button")[1];
115
147
  expect(lastButton.hasAttribute("disabled")).toBeTruthy();
116
- fireEvent.click(lastButton);
148
+ userEvent.click(lastButton);
117
149
  expect(onClick).toHaveBeenCalledTimes(0);
118
150
  });
119
151
 
120
152
  test("Last and next buttons are disable in last page", () => {
121
153
  const onClick = jest.fn();
122
154
  const { getAllByRole } = render(
123
- <DxcPaginator
124
- prevFunction={onClick}
125
- firstFunction={onClick}
126
- nextFunction={onClick}
127
- lastFunction={onClick}
128
- currentPage={2}
129
- itemsPerPage={10}
130
- totalItems={20}
131
- ></DxcPaginator>
155
+ <DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
132
156
  );
133
157
  const firstButton = getAllByRole("button")[0];
134
158
  const prevButton = getAllByRole("button")[1];
@@ -143,15 +167,7 @@ describe("Paginator component tests", () => {
143
167
  test("First and previous buttons are disable in first page", () => {
144
168
  const onClick = jest.fn();
145
169
  const { getAllByRole } = render(
146
- <DxcPaginator
147
- prevFunction={onClick}
148
- firstFunction={onClick}
149
- nextFunction={onClick}
150
- lastFunction={onClick}
151
- currentPage={1}
152
- itemsPerPage={10}
153
- totalItems={20}
154
- ></DxcPaginator>
170
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
155
171
  );
156
172
  const firstButton = getAllByRole("button")[0];
157
173
  const prevButton = getAllByRole("button")[1];
@@ -0,0 +1,83 @@
1
+ import React from "react";
2
+ import { render, fireEvent } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import DxcPasswordInput from "../src/password-input/PasswordInput";
5
+
6
+ describe("Password input component tests", () => {
7
+ test("Password input renders with label", () => {
8
+ const { getByText } = render(<DxcPasswordInput label="Password input label" />);
9
+ expect(getByText("Password input label")).toBeTruthy();
10
+ });
11
+
12
+ test("Password input renders with helper text", () => {
13
+ const { getByText } = render(<DxcPasswordInput helperText="Helper text" />);
14
+ expect(getByText("Helper text")).toBeTruthy();
15
+ });
16
+
17
+ test("Password input renders error", () => {
18
+ const { getByText } = render(<DxcPasswordInput error="Error message." />);
19
+ expect(getByText("Error message.")).toBeTruthy();
20
+ });
21
+
22
+ test("onChange function is called correctly", () => {
23
+ const onChange = jest.fn();
24
+ const { getByRole } = render(<DxcPasswordInput label="Password input" onChange={onChange} />);
25
+ const passwordInput = getByRole("textbox");
26
+ userEvent.type(passwordInput, "Pa$$w0rd");
27
+ expect(onChange).toHaveBeenCalledWith({ value: "P", error: null });
28
+ expect(passwordInput.value).toBe("Pa$$w0rd");
29
+ });
30
+
31
+ test("onBlur function is called correctly", () => {
32
+ const onBlur = jest.fn();
33
+ const { getByRole } = render(<DxcPasswordInput label="Password input" onBlur={onBlur} />);
34
+ const passwordInput = getByRole("textbox");
35
+ userEvent.type(passwordInput, "Pa$$w0rd");
36
+ fireEvent.blur(passwordInput);
37
+ expect(onBlur).toHaveBeenCalledWith({ value: "Pa$$w0rd", error: null });
38
+ expect(passwordInput.value).toBe("Pa$$w0rd");
39
+ });
40
+
41
+ test("Clear password input value", () => {
42
+ const { getAllByRole, getByRole } = render(<DxcPasswordInput label="Password input" clearable />);
43
+ const passwordInput = getByRole("textbox");
44
+ userEvent.type(passwordInput, "Pa$$w0rd");
45
+ expect(passwordInput.value).toBe("Pa$$w0rd");
46
+ const clearButton = getAllByRole("button")[0];
47
+ userEvent.click(clearButton);
48
+ expect(passwordInput.value).toBe("");
49
+ });
50
+
51
+ test("Non clearable password input has no clear icon", () => {
52
+ const { getAllByRole, getByRole } = render(<DxcPasswordInput label="Password input" />);
53
+ const passwordInput = getByRole("textbox");
54
+ userEvent.type(passwordInput, "Pa$$w0rd");
55
+ expect(passwordInput.value).toBe("Pa$$w0rd");
56
+ const buttons = getAllByRole("button");
57
+ expect(buttons.length).toBe(1);
58
+ });
59
+
60
+ test("Show/hide password input button works correctly", () => {
61
+ const { getAllByRole, getByRole } = render(<DxcPasswordInput label="Password input" clearable />);
62
+ const passwordInput = getByRole("textbox");
63
+ userEvent.type(passwordInput, "Pa$$w0rd");
64
+ expect(passwordInput.value).toBe("Pa$$w0rd");
65
+ expect(passwordInput.type).toBe("password");
66
+ const showButton = getAllByRole("button")[1];
67
+ userEvent.click(showButton);
68
+ expect(passwordInput.type).toBe("text");
69
+ });
70
+
71
+ test("Password input has correct accesibility attributes", () => {
72
+ const { getByRole } = render(<DxcPasswordInput label="Password input" />);
73
+ const passwordInput = getByRole("textbox");
74
+ expect(passwordInput.getAttribute("aria-autocomplete")).toBeNull();
75
+ expect(passwordInput.getAttribute("aria-controls")).toBeNull();
76
+ const showButton = getByRole("button");
77
+ expect(showButton.getAttribute("aria-expanded")).toBe("false");
78
+ expect(showButton.getAttribute("aria-label")).toBe("Show");
79
+ userEvent.click(showButton);
80
+ expect(showButton.getAttribute("aria-expanded")).toBe("true");
81
+ expect(showButton.getAttribute("aria-label")).toBe("Hide");
82
+ });
83
+ });