@dxc-technology/halstack-react 0.0.0-c4ba791 → 0.0.0-c7ec4d1

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 (197) hide show
  1. package/README.md +1 -1
  2. package/babel.config.js +6 -2
  3. package/dist/BackgroundColorContext.js +46 -0
  4. package/dist/ThemeContext.js +218 -22
  5. package/dist/V3Select/V3Select.js +549 -0
  6. package/dist/V3Textarea/V3Textarea.js +264 -0
  7. package/dist/accordion/Accordion.js +134 -54
  8. package/dist/accordion-group/AccordionGroup.js +36 -9
  9. package/dist/alert/Alert.js +183 -84
  10. package/dist/alert/index.d.ts +51 -0
  11. package/dist/badge/Badge.js +23 -18
  12. package/dist/box/Box.js +31 -23
  13. package/dist/button/Button.js +63 -27
  14. package/dist/card/Card.js +72 -35
  15. package/dist/checkbox/Checkbox.js +98 -39
  16. package/dist/chip/Chip.js +97 -40
  17. package/dist/common/utils.js +2 -22
  18. package/dist/common/variables.js +1428 -282
  19. package/dist/date/Date.js +74 -52
  20. package/dist/date-input/DateInput.js +400 -0
  21. package/dist/date-input/index.d.ts +95 -0
  22. package/dist/dialog/Dialog.js +58 -37
  23. package/dist/dropdown/Dropdown.js +176 -81
  24. package/dist/file-input/FileInput.js +644 -0
  25. package/dist/file-input/FileItem.js +287 -0
  26. package/dist/file-input/index.d.ts +81 -0
  27. package/dist/footer/Footer.js +90 -40
  28. package/dist/footer/Icons.js +77 -0
  29. package/dist/header/Header.js +192 -95
  30. package/dist/header/Icons.js +59 -0
  31. package/dist/heading/Heading.js +93 -16
  32. package/dist/input-text/Icons.js +22 -0
  33. package/dist/input-text/InputText.js +251 -116
  34. package/dist/layout/ApplicationLayout.js +18 -26
  35. package/dist/layout/Icons.js +55 -0
  36. package/dist/link/Link.js +86 -41
  37. package/dist/main.d.ts +8 -0
  38. package/dist/main.js +74 -18
  39. package/dist/number-input/NumberInput.js +136 -0
  40. package/dist/number-input/NumberInputContext.js +16 -0
  41. package/dist/number-input/index.d.ts +113 -0
  42. package/dist/paginator/Icons.js +66 -0
  43. package/dist/paginator/Paginator.js +116 -65
  44. package/dist/password-input/PasswordInput.js +203 -0
  45. package/dist/password-input/index.d.ts +94 -0
  46. package/dist/progress-bar/ProgressBar.js +95 -38
  47. package/dist/radio/Radio.js +31 -17
  48. package/dist/resultsetTable/ResultsetTable.js +82 -65
  49. package/dist/select/Select.js +896 -284
  50. package/dist/select/index.d.ts +53 -0
  51. package/dist/sidenav/Sidenav.js +66 -15
  52. package/dist/slider/Slider.js +211 -73
  53. package/dist/spinner/Spinner.js +247 -59
  54. package/dist/switch/Switch.js +50 -27
  55. package/dist/table/Table.js +51 -24
  56. package/dist/tabs/Tabs.js +88 -37
  57. package/dist/tag/Tag.js +68 -35
  58. package/dist/text-input/TextInput.js +974 -0
  59. package/dist/text-input/index.d.ts +135 -0
  60. package/dist/textarea/Textarea.js +248 -106
  61. package/dist/textarea/index.d.ts +117 -0
  62. package/dist/toggle/Toggle.js +16 -19
  63. package/dist/toggle-group/ToggleGroup.js +142 -41
  64. package/dist/upload/Upload.js +16 -11
  65. package/dist/upload/buttons-upload/ButtonsUpload.js +32 -19
  66. package/dist/upload/buttons-upload/Icons.js +40 -0
  67. package/dist/upload/dragAndDropArea/DragAndDropArea.js +84 -34
  68. package/dist/upload/dragAndDropArea/Icons.js +39 -0
  69. package/dist/upload/file-upload/FileToUpload.js +64 -33
  70. package/dist/upload/file-upload/Icons.js +66 -0
  71. package/dist/upload/files-upload/FilesToUpload.js +16 -16
  72. package/dist/upload/transaction/Icons.js +160 -0
  73. package/dist/upload/transaction/Transaction.js +42 -49
  74. package/dist/upload/transactions/Transactions.js +38 -20
  75. package/dist/wizard/Icons.js +65 -0
  76. package/dist/wizard/Wizard.js +126 -52
  77. package/package.json +10 -9
  78. package/test/AccordionGroup.test.js +16 -0
  79. package/test/Date.test.js +49 -45
  80. package/test/DateInput.test.js +242 -0
  81. package/test/Dropdown.test.js +15 -0
  82. package/test/FileInput.test.js +201 -0
  83. package/test/Footer.test.js +2 -7
  84. package/test/Header.test.js +5 -10
  85. package/test/Heading.test.js +60 -12
  86. package/test/InputText.test.js +25 -17
  87. package/test/Link.test.js +3 -2
  88. package/test/NumberInput.test.js +259 -0
  89. package/test/Paginator.test.js +40 -57
  90. package/test/PasswordInput.test.js +83 -0
  91. package/test/ResultsetTable.test.js +33 -8
  92. package/test/Slider.test.js +9 -17
  93. package/test/Spinner.test.js +5 -0
  94. package/test/TextInput.test.js +732 -0
  95. package/test/Textarea.test.js +193 -0
  96. package/test/ToggleGroup.test.js +5 -1
  97. package/test/Upload.test.js +5 -5
  98. package/test/{Select.test.js → V3Select.test.js} +56 -36
  99. package/test/{TextArea.test.js → V3TextArea.test.js} +6 -7
  100. package/dist/accordion/Accordion.stories.js +0 -207
  101. package/dist/accordion/readme.md +0 -96
  102. package/dist/accordion-group/AccordionGroup.stories.js +0 -207
  103. package/dist/accordion-group/readme.md +0 -70
  104. package/dist/alert/Alert.stories.js +0 -158
  105. package/dist/alert/close.svg +0 -4
  106. package/dist/alert/error.svg +0 -4
  107. package/dist/alert/info.svg +0 -4
  108. package/dist/alert/readme.md +0 -43
  109. package/dist/alert/success.svg +0 -4
  110. package/dist/alert/warning.svg +0 -4
  111. package/dist/button/Button.stories.js +0 -224
  112. package/dist/button/readme.md +0 -93
  113. package/dist/checkbox/Checkbox.stories.js +0 -144
  114. package/dist/checkbox/readme.md +0 -116
  115. package/dist/common/services/example-service.js +0 -10
  116. package/dist/common/services/example-service.test.js +0 -12
  117. package/dist/date/Date.stories.js +0 -205
  118. package/dist/date/calendar.svg +0 -1
  119. package/dist/date/calendar_dark.svg +0 -1
  120. package/dist/date/readme.md +0 -73
  121. package/dist/dialog/Dialog.stories.js +0 -217
  122. package/dist/dialog/readme.md +0 -32
  123. package/dist/dropdown/Dropdown.stories.js +0 -249
  124. package/dist/dropdown/baseline-arrow_drop_down.svg +0 -1
  125. package/dist/dropdown/baseline-arrow_drop_down_wh.svg +0 -4
  126. package/dist/dropdown/baseline-arrow_drop_up.svg +0 -1
  127. package/dist/dropdown/baseline-arrow_drop_up_wh.svg +0 -4
  128. package/dist/dropdown/readme.md +0 -69
  129. package/dist/footer/Footer.stories.js +0 -94
  130. package/dist/footer/dxc_logo_wht.png +0 -0
  131. package/dist/footer/readme.md +0 -41
  132. package/dist/header/Header.stories.js +0 -176
  133. package/dist/header/close_icon.svg +0 -1
  134. package/dist/header/dxc_logo_black.png +0 -0
  135. package/dist/header/dxc_logo_blk_rgb.svg +0 -6
  136. package/dist/header/dxc_logo_white.png +0 -0
  137. package/dist/header/hamb_menu_black.svg +0 -1
  138. package/dist/header/hamb_menu_white.svg +0 -1
  139. package/dist/header/readme.md +0 -33
  140. package/dist/input-text/InputText.stories.js +0 -209
  141. package/dist/input-text/error.svg +0 -1
  142. package/dist/input-text/readme.md +0 -91
  143. package/dist/layout/facebook.svg +0 -45
  144. package/dist/layout/linkedin.svg +0 -50
  145. package/dist/layout/twitter.svg +0 -53
  146. package/dist/link/readme.md +0 -51
  147. package/dist/paginator/images/next.svg +0 -3
  148. package/dist/paginator/images/nextPage.svg +0 -3
  149. package/dist/paginator/images/previous.svg +0 -3
  150. package/dist/paginator/images/previousPage.svg +0 -3
  151. package/dist/paginator/readme.md +0 -50
  152. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  153. package/dist/progress-bar/readme.md +0 -63
  154. package/dist/radio/Radio.stories.js +0 -166
  155. package/dist/radio/readme.md +0 -70
  156. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  157. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  158. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  159. package/dist/select/Select.stories.js +0 -235
  160. package/dist/select/readme.md +0 -72
  161. package/dist/slider/Slider.stories.js +0 -241
  162. package/dist/slider/readme.md +0 -64
  163. package/dist/spinner/Spinner.stories.js +0 -183
  164. package/dist/spinner/readme.md +0 -65
  165. package/dist/switch/Switch.stories.js +0 -134
  166. package/dist/switch/readme.md +0 -133
  167. package/dist/tabs/Tabs.stories.js +0 -130
  168. package/dist/tabs/readme.md +0 -78
  169. package/dist/tabs-for-sections/TabsForSections.js +0 -92
  170. package/dist/tabs-for-sections/readme.md +0 -78
  171. package/dist/toggle/Toggle.stories.js +0 -297
  172. package/dist/toggle/readme.md +0 -80
  173. package/dist/toggle-group/readme.md +0 -82
  174. package/dist/upload/Upload.stories.js +0 -72
  175. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  176. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  177. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  178. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  179. package/dist/upload/file-upload/audio-icon.svg +0 -4
  180. package/dist/upload/file-upload/close.svg +0 -4
  181. package/dist/upload/file-upload/file-icon.svg +0 -4
  182. package/dist/upload/file-upload/video-icon.svg +0 -4
  183. package/dist/upload/readme.md +0 -37
  184. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  185. package/dist/upload/transaction/audio-icon.svg +0 -4
  186. package/dist/upload/transaction/error-icon.svg +0 -4
  187. package/dist/upload/transaction/file-icon-err.svg +0 -4
  188. package/dist/upload/transaction/file-icon.svg +0 -4
  189. package/dist/upload/transaction/image-icon-err.svg +0 -4
  190. package/dist/upload/transaction/image-icon.svg +0 -4
  191. package/dist/upload/transaction/success-icon.svg +0 -4
  192. package/dist/upload/transaction/video-icon-err.svg +0 -4
  193. package/dist/upload/transaction/video-icon.svg +0 -4
  194. package/dist/wizard/invalid_icon.svg +0 -6
  195. package/dist/wizard/valid_icon.svg +0 -6
  196. package/dist/wizard/validation-wrong.svg +0 -6
  197. package/test/TabsForSections.test.js +0 -34
@@ -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
+ });
@@ -40,43 +40,42 @@ describe("Paginator component tests", () => {
40
40
  expect(getByText("Page: 2 of 2")).toBeTruthy();
41
41
  });
42
42
 
43
- test("Call correct nextFunction", () => {
44
- const onClick = jest.fn();
45
- const { getByRole } = render(
46
- <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>
47
46
  );
48
- const nextButton = getByRole("button");
49
- userEvent.click(nextButton);
50
- expect(onClick).toHaveBeenCalled();
47
+ expect(getByText("Go to page:")).toBeTruthy();
51
48
  });
52
49
 
53
- test("Call correct lastFunction", () => {
50
+ test("Paginator goToPage call correct function", () => {
54
51
  const onClick = jest.fn();
55
- const { getByRole } = render(
56
- <DxcPaginator lastFunction={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
52
+ const { getByText, getAllByRole, getByRole } = render(
53
+ <DxcPaginator
54
+ currentPage={1}
55
+ itemsPerPage={10}
56
+ totalItems={27}
57
+ showGoToPage={true}
58
+ onPageChange={onClick}
59
+ ></DxcPaginator>
57
60
  );
58
- const lastButton = getByRole("button");
59
- userEvent.click(lastButton);
61
+ const goToPageSelect = getAllByRole("button")[2];
62
+ act(() => {
63
+ userEvent.click(goToPageSelect);
64
+ });
65
+ const goToPageOption = getByText("2");
66
+ act(() => {
67
+ userEvent.click(goToPageOption);
68
+ });
60
69
  expect(onClick).toHaveBeenCalledWith(2);
61
70
  });
62
71
 
63
- test("Call correct prevFunction", () => {
64
- const onClick = jest.fn();
65
- const { getByRole } = render(
66
- <DxcPaginator prevFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
67
- );
68
- const prevButton = getByRole("button");
69
- userEvent.click(prevButton);
70
- expect(onClick).toHaveBeenCalled();
71
- });
72
-
73
- test("Call correct firstFunction", () => {
72
+ test("Call correct goToPageFunction", () => {
74
73
  const onClick = jest.fn();
75
- const { getByRole } = render(
76
- <DxcPaginator firstFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={30}></DxcPaginator>
74
+ const { getAllByRole } = render(
75
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
77
76
  );
78
- const firstButton = getByRole("button");
79
- userEvent.click(firstButton);
77
+ const nextButton = getAllByRole("button")[2];
78
+ userEvent.click(nextButton);
80
79
  expect(onClick).toHaveBeenCalled();
81
80
  });
82
81
 
@@ -104,10 +103,10 @@ describe("Paginator component tests", () => {
104
103
 
105
104
  test("Next button is disable in last page", () => {
106
105
  const onClick = jest.fn();
107
- const { getByRole } = render(
108
- <DxcPaginator nextFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
106
+ const { getAllByRole } = render(
107
+ <DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
109
108
  );
110
- const nextButton = getByRole("button");
109
+ const nextButton = getAllByRole("button")[2];
111
110
  expect(nextButton.hasAttribute("disabled")).toBeTruthy();
112
111
  userEvent.click(nextButton);
113
112
  expect(onClick).toHaveBeenCalledTimes(0);
@@ -115,10 +114,10 @@ describe("Paginator component tests", () => {
115
114
 
116
115
  test("Last button is disable in last page", () => {
117
116
  const onClick = jest.fn();
118
- const { getByRole } = render(
119
- <DxcPaginator lastFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
117
+ const { getAllByRole } = render(
118
+ <DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
120
119
  );
121
- const lastButton = getByRole("button");
120
+ const lastButton = getAllByRole("button")[3];
122
121
  expect(lastButton.hasAttribute("disabled")).toBeTruthy();
123
122
  userEvent.click(lastButton);
124
123
  expect(onClick).toHaveBeenCalledTimes(0);
@@ -126,10 +125,10 @@ describe("Paginator component tests", () => {
126
125
 
127
126
  test("First button is disable in first page", () => {
128
127
  const onClick = jest.fn();
129
- const { getByRole } = render(
130
- <DxcPaginator firstFunction={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
128
+ const { getAllByRole } = render(
129
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
131
130
  );
132
- const lastButton = getByRole("button");
131
+ const lastButton = getAllByRole("button")[0];
133
132
  expect(lastButton.hasAttribute("disabled")).toBeTruthy();
134
133
  userEvent.click(lastButton);
135
134
  expect(onClick).toHaveBeenCalledTimes(0);
@@ -137,10 +136,10 @@ describe("Paginator component tests", () => {
137
136
 
138
137
  test("Previous button is disable in first page", () => {
139
138
  const onClick = jest.fn();
140
- const { getByRole } = render(
141
- <DxcPaginator prevFunction={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
139
+ const { getAllByRole } = render(
140
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
142
141
  );
143
- const lastButton = getByRole("button");
142
+ const lastButton = getAllByRole("button")[1];
144
143
  expect(lastButton.hasAttribute("disabled")).toBeTruthy();
145
144
  userEvent.click(lastButton);
146
145
  expect(onClick).toHaveBeenCalledTimes(0);
@@ -149,15 +148,7 @@ describe("Paginator component tests", () => {
149
148
  test("Last and next buttons are disable in last page", () => {
150
149
  const onClick = jest.fn();
151
150
  const { getAllByRole } = render(
152
- <DxcPaginator
153
- prevFunction={onClick}
154
- firstFunction={onClick}
155
- nextFunction={onClick}
156
- lastFunction={onClick}
157
- currentPage={2}
158
- itemsPerPage={10}
159
- totalItems={20}
160
- ></DxcPaginator>
151
+ <DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
161
152
  );
162
153
  const firstButton = getAllByRole("button")[0];
163
154
  const prevButton = getAllByRole("button")[1];
@@ -172,15 +163,7 @@ describe("Paginator component tests", () => {
172
163
  test("First and previous buttons are disable in first page", () => {
173
164
  const onClick = jest.fn();
174
165
  const { getAllByRole } = render(
175
- <DxcPaginator
176
- prevFunction={onClick}
177
- firstFunction={onClick}
178
- nextFunction={onClick}
179
- lastFunction={onClick}
180
- currentPage={1}
181
- itemsPerPage={10}
182
- totalItems={20}
183
- ></DxcPaginator>
166
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
184
167
  );
185
168
  const firstButton = getAllByRole("button")[0];
186
169
  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
+ });
@@ -1,5 +1,7 @@
1
1
  import React from "react";
2
- import { render, fireEvent } from "@testing-library/react";
2
+ import { render, fireEvent, act } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+
3
5
  import DxcResultsetTable from "../src/resultsetTable/ResultsetTable";
4
6
 
5
7
  const columns = [
@@ -242,10 +244,34 @@ describe("ResultsetTable component tests", () => {
242
244
  expect(getByText("Louis")).toBeTruthy();
243
245
  expect(getByText("Lana")).toBeTruthy();
244
246
  expect(getAllByRole("row").length - 1).toEqual(3);
245
- const nextButton = getAllByRole("button")[2];
247
+ const nextButton = getAllByRole("button")[3];
246
248
  fireEvent.click(nextButton);
247
249
  expect(getByText("4 to 6 of 10")).toBeTruthy();
248
- expect(getByText("Page: 2 of 4")).toBeTruthy();
250
+ // expect(getByText("Page: 2 of 4")).toBeTruthy();
251
+ expect(getByText("Rick")).toBeTruthy();
252
+ expect(getByText("Mark")).toBeTruthy();
253
+ expect(getByText("Cris")).toBeTruthy();
254
+ expect(getAllByRole("row").length - 1).toEqual(3);
255
+ });
256
+
257
+ test("Resultsettable goToPage works as expected", () => {
258
+ const { getByText, getAllByRole, getByRole } = render(
259
+ <DxcResultsetTable columns={columns} showGoToPage={true} rows={rows} itemsPerPage={3}></DxcResultsetTable>
260
+ );
261
+ expect(getByText("Peter")).toBeTruthy();
262
+ expect(getByText("Louis")).toBeTruthy();
263
+ expect(getByText("Lana")).toBeTruthy();
264
+ expect(getAllByRole("row").length - 1).toEqual(3);
265
+ const goToPageSelect = getAllByRole("button")[2];
266
+ act(() => {
267
+ userEvent.click(goToPageSelect);
268
+ });
269
+ const goToPageOption = getByText("2");
270
+ act(() => {
271
+ userEvent.click(goToPageOption);
272
+ });
273
+
274
+ expect(getByText("4 to 6 of 10")).toBeTruthy();
249
275
  expect(getByText("Rick")).toBeTruthy();
250
276
  expect(getByText("Mark")).toBeTruthy();
251
277
  expect(getByText("Cris")).toBeTruthy();
@@ -256,10 +282,10 @@ describe("ResultsetTable component tests", () => {
256
282
  const { getByText, getAllByRole } = render(
257
283
  <DxcResultsetTable columns={columns} rows={rows} itemsPerPage={3}></DxcResultsetTable>
258
284
  );
259
- const lastButton = getAllByRole("button")[3];
285
+ debugger;
286
+ const lastButton = getAllByRole("button")[4];
260
287
  fireEvent.click(lastButton);
261
288
  expect(getByText("10 to 10 of 10")).toBeTruthy();
262
- expect(getByText("Page: 4 of 4")).toBeTruthy();
263
289
  expect(getAllByRole("row")).toHaveLength(2);
264
290
  expect(getByText("Cosmin")).toBeTruthy();
265
291
  });
@@ -293,12 +319,11 @@ describe("ResultsetTable component tests", () => {
293
319
  itemsPerPageOptions={[2, 3]}
294
320
  ></DxcResultsetTable>
295
321
  );
296
- const lastButton = getAllByRole("button")[4];
322
+ const lastButton = getAllByRole("button")[5];
297
323
  fireEvent.click(lastButton);
298
324
  expect(getAllByRole("row").length - 1).toEqual(1);
299
- expect(queryByText("Page: 4 of 4")).toBeTruthy();
300
325
  rerender(<DxcResultsetTable columns={columns} rows={rows} itemsPerPage={6}></DxcResultsetTable>);
301
326
  expect(getAllByRole("row").length - 1).toEqual(6);
302
- expect(queryByText("Page: 1 of 2")).toBeTruthy();
327
+ expect(queryByText("Peter")).toBeTruthy();
303
328
  });
304
329
  });
@@ -4,7 +4,7 @@ import DxcSlider from "../src/slider/Slider";
4
4
 
5
5
  describe("Slider component tests", () => {
6
6
  test("Slider renders with correct text", () => {
7
- const { getByText } = render(<DxcSlider minValue={0} maxValue={100} showLimitsValues></DxcSlider>);
7
+ const { getByText } = render(<DxcSlider minValue={0} maxValue={100} showLimitsValues />);
8
8
  expect(getByText("0")).toBeTruthy();
9
9
  expect(getByText("100")).toBeTruthy();
10
10
  });
@@ -12,37 +12,29 @@ describe("Slider component tests", () => {
12
12
  test("Calls correct function onChange in controlled slider", () => {
13
13
  const onChange = jest.fn();
14
14
  const { getByRole } = render(
15
- <DxcSlider minValue={0} maxValue={100} onChange={onChange} showLimitsValues value={13} showInput></DxcSlider>
15
+ <DxcSlider minValue={0} maxValue={100} onChange={onChange} showLimitsValues value={13} showInput />
16
16
  );
17
17
  act(() => {
18
18
  fireEvent.change(getByRole("textbox"), { target: { value: 25 } });
19
19
  });
20
- expect(onChange).toHaveBeenCalledWith("25");
20
+ expect(onChange).toHaveBeenCalledWith(25);
21
21
  });
22
22
 
23
23
  test("Calls correct function onChange in uncontrolled slider", () => {
24
24
  const onChange = jest.fn();
25
25
  const { getByRole } = render(
26
- <DxcSlider minValue={0} maxValue={100} onChange={onChange} showLimitsValues showInput></DxcSlider>
26
+ <DxcSlider minValue={0} maxValue={100} onChange={onChange} showLimitsValues showInput />
27
27
  );
28
28
  act(() => {
29
29
  fireEvent.change(getByRole("textbox"), { target: { value: 25 } });
30
30
  });
31
- expect(onChange).toHaveBeenCalledWith("25");
31
+ expect(onChange).toHaveBeenCalledWith(25);
32
32
  });
33
33
 
34
34
  test("Disabled slider have disabled input", () => {
35
35
  const onChange = jest.fn();
36
36
  const { getByRole } = render(
37
- <DxcSlider
38
- minValue={0}
39
- maxValue={100}
40
- onChange={onChange}
41
- showLimitsValues
42
- disabled
43
- showInput
44
- value={13}
45
- ></DxcSlider>
37
+ <DxcSlider minValue={0} maxValue={100} onChange={onChange} showLimitsValues disabled showInput value={13} />
46
38
  );
47
39
  act(() => {
48
40
  fireEvent.change(getByRole("textbox"), { target: { value: 25 } });
@@ -54,7 +46,7 @@ describe("Slider component tests", () => {
54
46
  test("Calls correct function onDragEnd", () => {
55
47
  const onDragEnd = jest.fn();
56
48
  const { getByRole } = render(
57
- <DxcSlider minValue={0} maxValue={100} showLimitsValues showInput onDragEnd={onDragEnd} value={25}></DxcSlider>
49
+ <DxcSlider minValue={0} maxValue={100} showLimitsValues showInput onDragEnd={onDragEnd} value={25} />
58
50
  );
59
51
  act(() => {
60
52
  fireEvent.mouseDown(getByRole("slider"));
@@ -64,7 +56,7 @@ describe("Slider component tests", () => {
64
56
  });
65
57
 
66
58
  test("Calls correct function labelFormatCallback", () => {
67
- const labelFormatCallback = jest.fn(x => `${x}$`);
59
+ const labelFormatCallback = jest.fn((x) => `${x}$`);
68
60
  const { getByText } = render(
69
61
  <DxcSlider
70
62
  minValue={0}
@@ -73,7 +65,7 @@ describe("Slider component tests", () => {
73
65
  showInput
74
66
  value={25}
75
67
  labelFormatCallback={labelFormatCallback}
76
- ></DxcSlider>
68
+ />
77
69
  );
78
70
  expect(getByText("0$")).toBeTruthy();
79
71
  expect(getByText("100$")).toBeTruthy();
@@ -24,4 +24,9 @@ describe("Spinner component tests", () => {
24
24
  expect(getByText("test-loading")).toBeTruthy();
25
25
  expect(getByText("75%")).toBeTruthy();
26
26
  });
27
+
28
+ test("Get spinner by role", () => {
29
+ const { getByRole } = render(<DxcSpinner label="test-loading" value={75} showValue></DxcSpinner>);
30
+ expect(getByRole("progressbar")).toBeTruthy();
31
+ });
27
32
  });