@dxc-technology/halstack-react 0.0.0-f44cd28 → 0.0.0-f77ec3a

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 (248) hide show
  1. package/README.md +2 -2
  2. package/babel.config.js +0 -1
  3. package/dist/BackgroundColorContext.js +46 -0
  4. package/dist/ThemeContext.js +213 -153
  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 +131 -46
  10. package/dist/accordion/index.d.ts +28 -0
  11. package/dist/accordion-group/AccordionGroup.js +34 -4
  12. package/dist/accordion-group/index.d.ts +16 -0
  13. package/dist/alert/Alert.js +180 -80
  14. package/dist/alert/index.d.ts +51 -0
  15. package/dist/badge/Badge.js +28 -7
  16. package/dist/box/Box.js +29 -18
  17. package/dist/box/index.d.ts +25 -0
  18. package/dist/button/Button.js +62 -23
  19. package/dist/button/index.d.ts +24 -0
  20. package/dist/card/Card.js +72 -35
  21. package/dist/card/index.d.ts +22 -0
  22. package/dist/checkbox/Checkbox.js +98 -28
  23. package/dist/checkbox/index.d.ts +24 -0
  24. package/dist/chip/Chip.js +92 -32
  25. package/dist/chip/index.d.ts +22 -0
  26. package/dist/common/utils.js +2 -22
  27. package/dist/common/variables.js +1404 -179
  28. package/dist/date/Date.js +65 -38
  29. package/dist/date/index.d.ts +27 -0
  30. package/dist/date-input/DateInput.js +400 -0
  31. package/dist/date-input/index.d.ts +95 -0
  32. package/dist/dialog/Dialog.js +54 -31
  33. package/dist/dialog/index.d.ts +18 -0
  34. package/dist/dropdown/Dropdown.js +173 -75
  35. package/dist/dropdown/index.d.ts +26 -0
  36. package/dist/file-input/FileInput.js +644 -0
  37. package/dist/file-input/FileItem.js +287 -0
  38. package/dist/file-input/index.d.ts +81 -0
  39. package/dist/footer/Footer.js +89 -34
  40. package/dist/footer/Icons.js +77 -0
  41. package/dist/footer/index.d.ts +25 -0
  42. package/dist/header/Header.js +190 -88
  43. package/dist/header/Icons.js +59 -0
  44. package/dist/header/index.d.ts +25 -0
  45. package/dist/heading/Heading.js +93 -16
  46. package/dist/heading/index.d.ts +17 -0
  47. package/dist/input-text/Icons.js +22 -0
  48. package/dist/input-text/InputText.js +247 -101
  49. package/dist/input-text/index.d.ts +36 -0
  50. package/dist/layout/ApplicationLayout.js +15 -18
  51. package/dist/layout/Icons.js +55 -0
  52. package/dist/link/Link.js +84 -34
  53. package/dist/link/index.d.ts +23 -0
  54. package/dist/main.d.ts +40 -0
  55. package/dist/main.js +72 -16
  56. package/dist/number-input/NumberInput.js +136 -0
  57. package/dist/number-input/NumberInputContext.js +16 -0
  58. package/dist/number-input/index.d.ts +113 -0
  59. package/dist/paginator/Icons.js +66 -0
  60. package/dist/paginator/Paginator.js +102 -44
  61. package/dist/paginator/index.d.ts +20 -0
  62. package/dist/password-input/PasswordInput.js +203 -0
  63. package/dist/password-input/index.d.ts +94 -0
  64. package/dist/progress-bar/ProgressBar.js +91 -33
  65. package/dist/progress-bar/index.d.ts +18 -0
  66. package/dist/radio/Radio.js +30 -11
  67. package/dist/radio/index.d.ts +23 -0
  68. package/dist/resultsetTable/ResultsetTable.js +79 -48
  69. package/dist/resultsetTable/index.d.ts +19 -0
  70. package/dist/select/Select.js +899 -278
  71. package/dist/select/index.d.ts +53 -0
  72. package/dist/sidenav/Sidenav.js +64 -8
  73. package/dist/sidenav/index.d.ts +13 -0
  74. package/dist/slider/Slider.js +212 -65
  75. package/dist/slider/index.d.ts +29 -0
  76. package/dist/spinner/Spinner.js +247 -56
  77. package/dist/spinner/index.d.ts +17 -0
  78. package/dist/stories/Button.js +71 -0
  79. package/dist/stories/Button.stories.js +55 -0
  80. package/dist/stories/Header.js +67 -0
  81. package/dist/stories/Header.stories.js +31 -0
  82. package/dist/stories/Introduction.stories.mdx +211 -0
  83. package/dist/stories/Page.js +68 -0
  84. package/dist/stories/Page.stories.js +39 -0
  85. package/dist/stories/assets/code-brackets.svg +1 -0
  86. package/dist/stories/assets/colors.svg +1 -0
  87. package/dist/stories/assets/comments.svg +1 -0
  88. package/dist/stories/assets/direction.svg +1 -0
  89. package/dist/stories/assets/flow.svg +1 -0
  90. package/dist/stories/assets/plugin.svg +1 -0
  91. package/dist/stories/assets/repo.svg +1 -0
  92. package/dist/stories/assets/stackalt.svg +1 -0
  93. package/dist/stories/button.css +30 -0
  94. package/dist/stories/header.css +26 -0
  95. package/dist/stories/page.css +69 -0
  96. package/dist/switch/Switch.js +51 -19
  97. package/dist/switch/index.d.ts +24 -0
  98. package/dist/table/Table.js +48 -18
  99. package/dist/table/index.d.ts +13 -0
  100. package/dist/tabs/Tabs.js +58 -17
  101. package/dist/tabs/index.d.ts +19 -0
  102. package/dist/tag/Tag.js +68 -35
  103. package/dist/tag/index.d.ts +24 -0
  104. package/dist/text-input/TextInput.js +974 -0
  105. package/dist/text-input/index.d.ts +135 -0
  106. package/dist/textarea/Textarea.js +246 -97
  107. package/dist/textarea/index.d.ts +117 -0
  108. package/dist/toggle/Toggle.js +16 -19
  109. package/dist/toggle/index.d.ts +21 -0
  110. package/dist/toggle-group/ToggleGroup.js +150 -32
  111. package/dist/toggle-group/index.d.ts +21 -0
  112. package/dist/upload/Upload.js +13 -8
  113. package/dist/upload/buttons-upload/ButtonsUpload.js +32 -19
  114. package/dist/upload/buttons-upload/Icons.js +40 -0
  115. package/dist/upload/dragAndDropArea/DragAndDropArea.js +84 -34
  116. package/dist/upload/dragAndDropArea/Icons.js +39 -0
  117. package/dist/upload/file-upload/FileToUpload.js +64 -33
  118. package/dist/upload/file-upload/Icons.js +66 -0
  119. package/dist/upload/files-upload/FilesToUpload.js +16 -16
  120. package/dist/upload/index.d.ts +15 -0
  121. package/dist/upload/transaction/Icons.js +160 -0
  122. package/dist/upload/transaction/Transaction.js +42 -49
  123. package/dist/upload/transactions/Transactions.js +38 -20
  124. package/dist/wizard/Icons.js +65 -0
  125. package/dist/wizard/Wizard.js +126 -47
  126. package/dist/wizard/index.d.ts +18 -0
  127. package/package.json +19 -13
  128. package/test/AccordionGroup.test.js +16 -0
  129. package/test/Date.test.js +15 -13
  130. package/test/DateInput.test.js +242 -0
  131. package/test/Dropdown.test.js +15 -0
  132. package/test/FileInput.test.js +201 -0
  133. package/test/Footer.test.js +2 -7
  134. package/test/Header.test.js +5 -10
  135. package/test/Heading.test.js +60 -12
  136. package/test/InputText.test.js +1 -2
  137. package/test/Link.test.js +3 -2
  138. package/test/NumberInput.test.js +259 -0
  139. package/test/Paginator.test.js +6 -2
  140. package/test/PasswordInput.test.js +83 -0
  141. package/test/ResultsetTable.test.js +6 -6
  142. package/test/Select.test.js +371 -148
  143. package/test/Slider.test.js +9 -17
  144. package/test/Spinner.test.js +5 -0
  145. package/test/TextInput.test.js +732 -0
  146. package/test/Textarea.test.js +193 -0
  147. package/test/ToggleGroup.test.js +5 -1
  148. package/test/Upload.test.js +1 -1
  149. package/test/V3Select.test.js +212 -0
  150. package/test/{TextArea.test.js → V3TextArea.test.js} +6 -7
  151. package/dist/accordion/Accordion.stories.js +0 -207
  152. package/dist/accordion/readme.md +0 -96
  153. package/dist/accordion-group/AccordionGroup.stories.js +0 -207
  154. package/dist/accordion-group/readme.md +0 -70
  155. package/dist/alert/Alert.stories.js +0 -158
  156. package/dist/alert/close.svg +0 -4
  157. package/dist/alert/error.svg +0 -4
  158. package/dist/alert/info.svg +0 -4
  159. package/dist/alert/readme.md +0 -43
  160. package/dist/alert/success.svg +0 -4
  161. package/dist/alert/warning.svg +0 -4
  162. package/dist/button/Button.stories.js +0 -224
  163. package/dist/button/readme.md +0 -93
  164. package/dist/checkbox/Checkbox.stories.js +0 -144
  165. package/dist/checkbox/readme.md +0 -116
  166. package/dist/common/services/example-service.js +0 -10
  167. package/dist/common/services/example-service.test.js +0 -12
  168. package/dist/date/Date.stories.js +0 -205
  169. package/dist/date/calendar.svg +0 -1
  170. package/dist/date/calendar_dark.svg +0 -1
  171. package/dist/date/readme.md +0 -73
  172. package/dist/dialog/Dialog.stories.js +0 -217
  173. package/dist/dialog/readme.md +0 -32
  174. package/dist/dropdown/Dropdown.stories.js +0 -249
  175. package/dist/dropdown/baseline-arrow_drop_down.svg +0 -1
  176. package/dist/dropdown/baseline-arrow_drop_down_wh.svg +0 -4
  177. package/dist/dropdown/baseline-arrow_drop_up.svg +0 -1
  178. package/dist/dropdown/baseline-arrow_drop_up_wh.svg +0 -4
  179. package/dist/dropdown/readme.md +0 -69
  180. package/dist/footer/Footer.stories.js +0 -94
  181. package/dist/footer/dxc_logo_wht.png +0 -0
  182. package/dist/footer/readme.md +0 -41
  183. package/dist/header/Header.stories.js +0 -176
  184. package/dist/header/close_icon.svg +0 -1
  185. package/dist/header/dxc_logo_black.png +0 -0
  186. package/dist/header/dxc_logo_blk_rgb.svg +0 -6
  187. package/dist/header/dxc_logo_white.png +0 -0
  188. package/dist/header/hamb_menu_black.svg +0 -1
  189. package/dist/header/hamb_menu_white.svg +0 -1
  190. package/dist/header/readme.md +0 -33
  191. package/dist/input-text/InputText.stories.js +0 -209
  192. package/dist/input-text/error.svg +0 -1
  193. package/dist/input-text/readme.md +0 -91
  194. package/dist/layout/facebook.svg +0 -45
  195. package/dist/layout/linkedin.svg +0 -50
  196. package/dist/layout/twitter.svg +0 -53
  197. package/dist/link/readme.md +0 -51
  198. package/dist/paginator/images/next.svg +0 -3
  199. package/dist/paginator/images/nextPage.svg +0 -3
  200. package/dist/paginator/images/previous.svg +0 -3
  201. package/dist/paginator/images/previousPage.svg +0 -3
  202. package/dist/paginator/readme.md +0 -50
  203. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  204. package/dist/progress-bar/readme.md +0 -63
  205. package/dist/radio/Radio.stories.js +0 -166
  206. package/dist/radio/readme.md +0 -70
  207. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  208. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  209. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  210. package/dist/select/Select.stories.js +0 -235
  211. package/dist/select/readme.md +0 -72
  212. package/dist/slider/Slider.stories.js +0 -241
  213. package/dist/slider/readme.md +0 -64
  214. package/dist/spinner/Spinner.stories.js +0 -183
  215. package/dist/spinner/readme.md +0 -65
  216. package/dist/switch/Switch.stories.js +0 -134
  217. package/dist/switch/readme.md +0 -133
  218. package/dist/tabs/Tabs.stories.js +0 -130
  219. package/dist/tabs/readme.md +0 -78
  220. package/dist/tabs-for-sections/TabsForSections.js +0 -92
  221. package/dist/tabs-for-sections/readme.md +0 -78
  222. package/dist/toggle/Toggle.stories.js +0 -297
  223. package/dist/toggle/readme.md +0 -80
  224. package/dist/toggle-group/readme.md +0 -82
  225. package/dist/upload/Upload.stories.js +0 -72
  226. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  227. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  228. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  229. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  230. package/dist/upload/file-upload/audio-icon.svg +0 -4
  231. package/dist/upload/file-upload/close.svg +0 -4
  232. package/dist/upload/file-upload/file-icon.svg +0 -4
  233. package/dist/upload/file-upload/video-icon.svg +0 -4
  234. package/dist/upload/readme.md +0 -37
  235. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  236. package/dist/upload/transaction/audio-icon.svg +0 -4
  237. package/dist/upload/transaction/error-icon.svg +0 -4
  238. package/dist/upload/transaction/file-icon-err.svg +0 -4
  239. package/dist/upload/transaction/file-icon.svg +0 -4
  240. package/dist/upload/transaction/image-icon-err.svg +0 -4
  241. package/dist/upload/transaction/image-icon.svg +0 -4
  242. package/dist/upload/transaction/success-icon.svg +0 -4
  243. package/dist/upload/transaction/video-icon-err.svg +0 -4
  244. package/dist/upload/transaction/video-icon.svg +0 -4
  245. package/dist/wizard/invalid_icon.svg +0 -6
  246. package/dist/wizard/valid_icon.svg +0 -6
  247. package/dist/wizard/validation-wrong.svg +0 -6
  248. package/test/TabsForSections.test.js +0 -34
@@ -1,192 +1,415 @@
1
1
  import React from "react";
2
- import { render, act } from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
2
  import DxcSelect from "../src/select/Select";
3
+ import { render, fireEvent } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
5
+
6
+ const single_options = [
7
+ { label: "Option 01", value: "1" },
8
+ { label: "Option 02", value: "2" },
9
+ { label: "Option 03", value: "3" },
10
+ { label: "Option 04", value: "4" },
11
+ { label: "Option 05", value: "5" },
12
+ { label: "Option 06", value: "6" },
13
+ { label: "Option 07", value: "7" },
14
+ { label: "Option 08", value: "8" },
15
+ { label: "Option 09", value: "9" },
16
+ { label: "Option 10", value: "10" },
17
+ { label: "Option 11", value: "11" },
18
+ { label: "Option 12", value: "12" },
19
+ { label: "Option 13", value: "13" },
20
+ { label: "Option 14", value: "14" },
21
+ { label: "Option 15", value: "15" },
22
+ { label: "Option 16", value: "16" },
23
+ { label: "Option 17", value: "17" },
24
+ { label: "Option 18", value: "18" },
25
+ { label: "Option 19", value: "19" },
26
+ { label: "Option 20", value: "20" },
27
+ ];
5
28
 
6
- const optionsWithoutIcon = [
29
+ const group_options = [
7
30
  {
8
- value: 1,
9
- label: "Amazon",
31
+ label: "Group 1",
32
+ options: [
33
+ { label: "Option 001", value: "1" },
34
+ { label: "Option 002", value: "2" },
35
+ { label: "Option 003", value: "3" },
36
+ ],
10
37
  },
11
38
  {
12
- value: 2,
13
- label: "Ebay",
39
+ label: "Group 2",
40
+ options: [
41
+ { label: "Option 0004", value: "4" },
42
+ { label: "Option 05", value: "5" },
43
+ { label: "Option 006", value: "6" },
44
+ ],
14
45
  },
15
46
  {
16
- value: 3,
17
- label: "Apple",
47
+ label: "Group 3",
48
+ options: [
49
+ { label: "Option 0007", value: "7" },
50
+ { label: "Option 008", value: "8" },
51
+ { label: "Option 9", value: "9" },
52
+ ],
53
+ },
54
+ {
55
+ label: "Group 4",
56
+ options: [
57
+ { label: "Option 10", value: "10" },
58
+ { label: "Option 11", value: "11" },
59
+ { label: "Option 12", value: "12" },
60
+ ],
18
61
  },
19
- ];
20
-
21
- const optionsWithIcons = [
22
62
  {
23
- value: 1,
24
- label: "Facebook",
25
- iconSrc: "/testIconFacebook",
63
+ label: "Group 5",
64
+ options: [
65
+ { label: "Option x", value: "13" },
66
+ { label: "Option y", value: "14" },
67
+ { label: "Option z", value: "15" },
68
+ ],
26
69
  },
27
70
  {
28
- value: 2,
29
- label: "Twitter",
30
- iconSrc: "/testIconTwitter",
71
+ label: "Group 6",
72
+ options: [
73
+ { label: "Option 001", value: "16" },
74
+ { label: "Option 002", value: "17" },
75
+ { label: "Option 003", value: "18" },
76
+ ],
31
77
  },
32
78
  {
33
- value: 3,
34
- label: "Linkedin",
35
- iconSrc: "/testIconLinkedin",
79
+ label: "Group 7",
80
+ options: [
81
+ { label: "Option 001", value: "19" },
82
+ { label: "Option 002", value: "20" },
83
+ { label: "Option 003", value: "21" },
84
+ ],
36
85
  },
37
86
  ];
38
87
 
39
88
  describe("Select component tests", () => {
40
- test("Select renders with correct label", () => {
41
- const { getByText } = render(<DxcSelect label="test-select-label"></DxcSelect>);
89
+ test("Renders with correct label, helper text and placeholder", () => {
90
+ const { getByText } = render(
91
+ <DxcSelect label="test-select-label" helperText="test-select-helper-text" placeholder="Example text" />
92
+ );
93
+
42
94
  expect(getByText("test-select-label")).toBeTruthy();
95
+ expect(getByText("test-select-helper-text")).toBeTruthy();
96
+ expect(getByText("Example text")).toBeTruthy();
43
97
  });
98
+ test("Renders with correct optional label", () => {
99
+ const { getByText } = render(<DxcSelect label="test-select-label" optional />);
44
100
 
45
- test("Select renders options when select is clicked", () => {
46
- const { getByText, getByRole, queryByText } = render(
47
- <DxcSelect label="test-select-name" options={optionsWithoutIcon}></DxcSelect>
48
- );
49
- //Before are not shown
50
- expect(queryByText("Amazon")).toBeFalsy();
51
- expect(queryByText("Ebay")).toBeFalsy();
52
- expect(queryByText("Apple")).toBeFalsy();
53
- const select = getByRole("button");
54
- act(() => {
55
- userEvent.click(select);
56
- });
57
- expect(getByText("Amazon")).toBeTruthy();
58
- expect(getByText("Ebay")).toBeTruthy();
59
- expect(getByText("Apple")).toBeTruthy();
101
+ expect(getByText("test-select-label")).toBeTruthy();
102
+ expect(getByText("(Optional)")).toBeTruthy();
103
+ });
104
+ test("Renders with error message", () => {
105
+ const { getByText, getByRole } = render(<DxcSelect label="test-select-label" error="Error message." />);
106
+ const select = getByRole("combobox");
107
+
108
+ expect(getByText("Error message.")).toBeTruthy();
109
+ expect(select.getAttribute("aria-invalid")).toBe("true");
60
110
  });
111
+ test("Disabled select - Clear all options action must be shown but not clickable", () => {
112
+ const { getByRole, getByText, queryByRole } = render(
113
+ <DxcSelect label="test-select-label" value={["1", "2"]} options={single_options} disabled searchable multiple />
114
+ );
115
+ const select = getByRole("combobox");
61
116
 
62
- test("Select renders options with icons before", () => {
117
+ userEvent.click(select);
118
+ expect(queryByRole("listbox")).toBeFalsy();
119
+ userEvent.click(getByRole("button"));
120
+ expect(getByText("Option 01, Option 02")).toBeTruthy();
121
+ });
122
+ test("Focused select does not open the listbox", () => {
123
+ const { getByRole, queryByRole } = render(
124
+ <DxcSelect label="test-select-label" value={["1", "2"]} options={single_options} disabled searchable multiple />
125
+ );
126
+ const select = getByRole("combobox");
127
+
128
+ fireEvent.focus(select);
129
+ expect(queryByRole("listbox")).toBeFalsy();
130
+ });
131
+ test("Controlled - Not optional constraint", () => {
132
+ // scrollIntoView & scrollTo are not implemented in jsdom
133
+ window.HTMLElement.prototype.scrollIntoView = () => {};
134
+ window.HTMLElement.prototype.scrollTo = () => {};
135
+ const onChange = jest.fn();
136
+ const onBlur = jest.fn();
63
137
  const { getByRole, getAllByRole } = render(
64
- <DxcSelect label="test-select-name" options={optionsWithIcons}></DxcSelect>
138
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} onBlur={onBlur} />
65
139
  );
66
- const select = getByRole("button");
67
- act(() => {
68
- userEvent.click(select);
69
- });
70
- expect(getAllByRole("img")[0].getAttribute("src")).toEqual("/testIconFacebook");
71
- expect(getAllByRole("img")[1].getAttribute("src")).toEqual("/testIconTwitter");
72
- expect(getAllByRole("img")[2].getAttribute("src")).toEqual("/testIconLinkedin");
140
+ const select = getByRole("combobox");
141
+
142
+ expect(select.getAttribute("aria-required")).toBe("true");
143
+ fireEvent.focus(select);
144
+ fireEvent.blur(select);
145
+ expect(onBlur).toHaveBeenCalled();
146
+ expect(onBlur).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
147
+ userEvent.click(select);
148
+ userEvent.click(getAllByRole("option")[0]);
149
+ expect(onChange).toHaveBeenCalled();
150
+ expect(onChange).toHaveBeenCalledWith({ value: "1", error: null });
151
+ fireEvent.focus(select);
152
+ fireEvent.blur(select);
153
+ expect(onBlur).toHaveBeenCalled();
154
+ expect(onBlur).toHaveBeenCalledWith({ value: "1", error: null });
73
155
  });
156
+ test("Controlled - Optional constraint", () => {
157
+ window.HTMLElement.prototype.scrollIntoView = () => {};
158
+ window.HTMLElement.prototype.scrollTo = () => {};
159
+ const onChange = jest.fn();
160
+ const onBlur = jest.fn();
161
+ const { getByRole } = render(
162
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} onBlur={onBlur} optional />
163
+ );
164
+ const select = getByRole("combobox");
74
165
 
75
- test("Select renders options with icons after", () => {
76
- const { getByRole, getAllByRole } = render(
77
- <DxcSelect label="test-select-name" options={optionsWithIcons} iconPosition="after"></DxcSelect>
166
+ expect(select.getAttribute("aria-required")).toBe("false");
167
+ fireEvent.focus(select);
168
+ fireEvent.blur(select);
169
+ expect(onBlur).toHaveBeenCalled();
170
+ expect(onBlur).toHaveBeenCalledWith({ value: "", error: null });
171
+ expect(select.getAttribute("aria-invalid")).toBe("false");
172
+ });
173
+ test("Non-Grouped Options - Opens listbox or closes it with a click on select", () => {
174
+ window.HTMLElement.prototype.scrollIntoView = () => {};
175
+ window.HTMLElement.prototype.scrollTo = () => {};
176
+ const { getByText, getByRole, queryByRole } = render(
177
+ <DxcSelect label="test-select-label" options={single_options} />
78
178
  );
79
- const select = getByRole("button");
80
- act(() => {
81
- userEvent.click(select);
82
- });
83
- expect(getAllByRole("img")[0].getAttribute("src")).toEqual("/testIconFacebook");
84
- expect(getAllByRole("img")[1].getAttribute("src")).toEqual("/testIconTwitter");
85
- expect(getAllByRole("img")[2].getAttribute("src")).toEqual("/testIconLinkedin");
179
+ const select = getByRole("combobox");
180
+
181
+ userEvent.click(select);
182
+ expect(getByRole("listbox")).toBeTruthy();
183
+ expect(select.getAttribute("aria-expanded")).toBe("true");
184
+ expect(getByText("Option 01")).toBeTruthy();
185
+ expect(getByText("Option 02")).toBeTruthy();
186
+ expect(getByText("Option 08")).toBeTruthy();
187
+ expect(getByText("Option 09")).toBeTruthy();
188
+ userEvent.click(select);
189
+ expect(queryByRole("listbox")).toBeFalsy();
190
+ expect(select.getAttribute("aria-expanded")).toBe("false");
86
191
  });
192
+ test("Non-Grouped Options - If an empty list of options is passed, the select is rendered but doestn't open the listbox", () => {
193
+ window.HTMLElement.prototype.scrollIntoView = () => {};
194
+ window.HTMLElement.prototype.scrollTo = () => {};
195
+ const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={[]} />);
196
+ const select = getByRole("combobox");
87
197
 
88
- test("Select renders with a default value", () => {
89
- const { getByText } = render(
90
- <DxcSelect label="test-select-name" options={optionsWithoutIcon} value={1}></DxcSelect>
198
+ userEvent.click(select);
199
+ expect(queryByRole("listbox")).toBeFalsy();
200
+ expect(select.getAttribute("aria-expanded")).toBe("false");
201
+ });
202
+ test("Non-Grouped Options - Click in an option selects it and closes the listbox", () => {
203
+ window.HTMLElement.prototype.scrollIntoView = () => {};
204
+ window.HTMLElement.prototype.scrollTo = () => {};
205
+ const onChange = jest.fn();
206
+ const { getByText, getByRole, getAllByRole, queryByRole } = render(
207
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} />
91
208
  );
92
- expect(getByText("Amazon")).toBeTruthy();
209
+ const select = getByRole("combobox");
210
+
211
+ userEvent.click(select);
212
+ userEvent.click(getAllByRole("option")[2]);
213
+ expect(onChange).toHaveBeenCalledWith({ value: "3", error: null });
214
+ expect(queryByRole("listbox")).toBeFalsy();
215
+ expect(getByText("Option 03")).toBeTruthy();
216
+ userEvent.click(select);
217
+ expect(getAllByRole("option")[2].getAttribute("aria-selected")).toBe("true");
93
218
  });
219
+ test("Non-Grouped Options - Optional renders an empty first option with the placeholder as its label", () => {
220
+ window.HTMLElement.prototype.scrollIntoView = () => {};
221
+ window.HTMLElement.prototype.scrollTo = () => {};
222
+ const onChange = jest.fn();
223
+ const { getByRole, getAllByRole, getAllByText } = render(
224
+ <DxcSelect
225
+ label="test-select-label"
226
+ placeholder="Choose an option"
227
+ options={single_options}
228
+ onChange={onChange}
229
+ optional
230
+ />
231
+ );
232
+ const select = getByRole("combobox");
94
233
 
95
- test("Select renders with multiple default values", () => {
96
- const { getByText } = render(
97
- <DxcSelect label="test-select-name" options={optionsWithoutIcon} value={[1, 2]} multiple></DxcSelect>
234
+ userEvent.click(select);
235
+ expect(getAllByText("Choose an option").length).toBe(2);
236
+ expect(getAllByRole("option")[0].getAttribute("aria-selected")).toBe("true");
237
+ userEvent.click(getAllByRole("option")[0]);
238
+ expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
239
+ expect(getAllByText("Choose an option").length).toBe(1);
240
+ });
241
+ test("Non-Grouped Options: Arrow up key - Opens the listbox and visually focus the last option", () => {
242
+ window.HTMLElement.prototype.scrollIntoView = () => {};
243
+ window.HTMLElement.prototype.scrollTo = () => {};
244
+ const { getByRole, queryByRole } = render(
245
+ <DxcSelect label="test-select-label" options={single_options} />
246
+ );
247
+ const select = getByRole("combobox");
248
+
249
+ fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
250
+ expect(queryByRole("listbox")).toBeTruthy();
251
+ expect(select.getAttribute("aria-activedescendant")).toBe("option-19");
252
+ });
253
+ test("Non-Grouped Options: Arrow up key - Puts the focus in last option when the first one is visually focused", () => {
254
+ window.HTMLElement.prototype.scrollIntoView = () => {};
255
+ window.HTMLElement.prototype.scrollTo = () => {};
256
+ const { getByRole, queryByRole } = render(
257
+ <DxcSelect label="test-select-label" options={single_options} />
258
+ );
259
+ const select = getByRole("combobox");
260
+
261
+ fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
262
+ fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
263
+ expect(queryByRole("listbox")).toBeTruthy();
264
+ expect(select.getAttribute("aria-activedescendant")).toBe("option-19");
265
+ });
266
+ test("Non-Grouped Options: Arrow down key - Opens the listbox and visually focus the first option", () => {
267
+ window.HTMLElement.prototype.scrollIntoView = () => {};
268
+ window.HTMLElement.prototype.scrollTo = () => {};
269
+ const { getByRole, queryByRole } = render(
270
+ <DxcSelect label="test-select-label" options={single_options} />
98
271
  );
99
- expect(getByText("Amazon, Ebay")).toBeTruthy();
272
+ const select = getByRole("combobox");
273
+
274
+ fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
275
+ expect(queryByRole("listbox")).toBeTruthy();
276
+ expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
100
277
  });
278
+ test("Non-Grouped Options: Arrow down key - Puts the focus in the first option when the last one is visually focused", () => {
279
+ window.HTMLElement.prototype.scrollIntoView = () => {};
280
+ window.HTMLElement.prototype.scrollTo = () => {};
281
+ const { getByRole, queryByRole } = render(
282
+ <DxcSelect label="test-select-label" options={single_options} />
283
+ );
284
+ const select = getByRole("combobox");
285
+
286
+ fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
287
+ fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
288
+ expect(queryByRole("listbox")).toBeTruthy();
289
+ expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
290
+ });
291
+ test("Non-Grouped Options: Enter key - Selects the visually focused option and closes the listbox", () => {
292
+ window.HTMLElement.prototype.scrollIntoView = () => {};
293
+ window.HTMLElement.prototype.scrollTo = () => {};
294
+ const onChange = jest.fn();
295
+ const { getByText, getByRole, getAllByRole, queryByRole } = render(
296
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} />
297
+ );
298
+ const select = getByRole("combobox");
299
+
300
+ fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
301
+ fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
302
+ fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
303
+ fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
304
+ fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
305
+ expect(onChange).toHaveBeenCalledWith({ value: "19", error: null });
306
+ expect(queryByRole("listbox")).toBeFalsy();
307
+ expect(getByText("Option 19")).toBeTruthy();
308
+ userEvent.click(select);
309
+ expect(getAllByRole("option")[18].getAttribute("aria-selected")).toBe("true");
310
+ });
311
+ test("Non-Grouped Options: Searchable - Displays an input for filtering the list of options", () => {
312
+ window.HTMLElement.prototype.scrollIntoView = () => {};
313
+ window.HTMLElement.prototype.scrollTo = () => {};
314
+ const onChange = jest.fn();
315
+ const { container, getByText, getByRole, getAllByRole, queryByRole } = render(
316
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
317
+ );
318
+ const select = getByRole("combobox");
319
+ const searchInput = container.querySelectorAll("input")[1];
101
320
 
102
- test("Disabled select is not clickable", () => {
103
- const { getByText, queryByText } = render(
104
- <DxcSelect label="test-select-name" options={optionsWithoutIcon} disabled></DxcSelect>
321
+ userEvent.click(select);
322
+ expect(getByRole("listbox")).toBeTruthy();
323
+ userEvent.type(searchInput, "08");
324
+ userEvent.click(getByRole("option"));
325
+ expect(onChange).toHaveBeenCalledWith({ value: "8", error: null });
326
+ expect(queryByRole("listbox")).toBeFalsy();
327
+ expect(getByText("Option 08")).toBeTruthy();
328
+ expect(searchInput.value).toBe("");
329
+ userEvent.click(select);
330
+ expect(getAllByRole("option")[7].getAttribute("aria-selected")).toBe("true");
331
+ });
332
+ test("Non-Grouped Options: Searchable - Displays 'No matches found' when there are no filtering results", () => {
333
+ window.HTMLElement.prototype.scrollIntoView = () => {};
334
+ window.HTMLElement.prototype.scrollTo = () => {};
335
+ const onChange = jest.fn();
336
+ const { container, getByText, getByRole } = render(
337
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
105
338
  );
106
- expect(queryByText("Amazon")).toBeFalsy();
107
- expect(queryByText("Ebay")).toBeFalsy();
108
- expect(queryByText("Apple")).toBeFalsy();
109
- const select = getByText("test-select-name");
110
- act(() => {
111
- userEvent.click(select);
112
- });
113
- expect(queryByText("Amazon")).toBeFalsy();
114
- expect(queryByText("Ebay")).toBeFalsy();
115
- expect(queryByText("Apple")).toBeFalsy();
339
+ const select = getByRole("combobox");
340
+ const searchInput = container.querySelectorAll("input")[1];
341
+
342
+ userEvent.click(select);
343
+ expect(getByRole("listbox")).toBeTruthy();
344
+ userEvent.type(searchInput, "abc");
345
+ expect(getByText("No matches found")).toBeTruthy();
116
346
  });
347
+ test("Non-Grouped Options: Searchable - Clicking the select, when the list is open, clears the search value", () => {
348
+ window.HTMLElement.prototype.scrollIntoView = () => {};
349
+ window.HTMLElement.prototype.scrollTo = () => {};
350
+ const onChange = jest.fn();
351
+ const { container, getByText, getByRole, getAllByRole } = render(
352
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
353
+ );
354
+ const select = getByRole("combobox");
355
+ const searchInput = container.querySelectorAll("input")[1];
117
356
 
118
- test("Controlled select with unique value", () => {
357
+ userEvent.click(select);
358
+ expect(getByRole("listbox")).toBeTruthy();
359
+ userEvent.type(searchInput, "2");
360
+ expect(getByText("Option 02")).toBeTruthy();
361
+ expect(getByText("Option 12")).toBeTruthy();
362
+ expect(getByText("Option 20")).toBeTruthy();
363
+ expect(getAllByRole("option").length).toBe(3);
364
+ userEvent.click(select);
365
+ expect(searchInput.value).toBe("");
366
+ });
367
+ test("Non-Grouped Options: Searchable - Writing displays the listbox, if was not open", () => {
368
+ window.HTMLElement.prototype.scrollIntoView = () => {};
369
+ window.HTMLElement.prototype.scrollTo = () => {};
119
370
  const onChange = jest.fn();
120
- const { getByText, getAllByText } = render(
121
- <DxcSelect label="test-select-name" options={optionsWithoutIcon} value={1} onChange={onChange}></DxcSelect>
122
- );
123
- const select = getByText("Amazon");
124
- act(() => {
125
- userEvent.click(select);
126
- });
127
- const option2 = getByText("Ebay");
128
- act(() => {
129
- userEvent.click(option2);
130
- });
131
- expect(onChange).toHaveBeenCalledWith(2);
132
- //The value is not changed
133
- expect(getAllByText("Amazon").length).toBe(2);
134
- });
135
-
136
- test("Controlled select with multiple values", () => {
371
+ const { container, getByRole, queryByRole } = render(
372
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
373
+ );
374
+ const select = getByRole("combobox");
375
+ const searchInput = container.querySelectorAll("input")[1];
376
+
377
+ userEvent.click(select);
378
+ userEvent.click(select);
379
+ expect(queryByRole("listbox")).toBeFalsy();
380
+ userEvent.type(searchInput, "2");
381
+ expect(getByRole("listbox")).toBeTruthy();
382
+ });
383
+ test("Non-Grouped Options: Searchable - Key Esc cleans the search value and closes the options", () => {
384
+ window.HTMLElement.prototype.scrollIntoView = () => {};
385
+ window.HTMLElement.prototype.scrollTo = () => {};
137
386
  const onChange = jest.fn();
138
- const { getByText } = render(
139
- <DxcSelect
140
- label="test-select-name"
141
- options={optionsWithoutIcon}
142
- value={[1, 2]}
143
- multiple
144
- onChange={onChange}
145
- ></DxcSelect>
146
- );
147
- const select = getByText("Amazon, Ebay");
148
- act(() => {
149
- userEvent.click(select);
150
- });
151
- const option3 = getByText("Apple");
152
- act(() => {
153
- userEvent.click(option3);
154
- });
155
- expect(onChange).toHaveBeenCalledWith([1, 2, 3]);
156
- //The value is not changed
157
- expect(getByText("Amazon, Ebay")).toBeTruthy();
158
- });
159
-
160
- test("Uncontrolled select with multiple values", () => {
387
+ const { container, getByRole, queryByRole } = render(
388
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
389
+ );
390
+ const select = getByRole("combobox");
391
+ const searchInput = container.querySelectorAll("input")[1];
392
+
393
+ userEvent.type(searchInput, "Option 02");
394
+ fireEvent.keyDown(select, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
395
+ expect(searchInput.value).toBe("");
396
+ expect(queryByRole("listbox")).toBeFalsy();
397
+ });
398
+ test("Non-Grouped Options: Searchable - While user types, a clear action is displayed for cleaning the search value", () => {
399
+ window.HTMLElement.prototype.scrollIntoView = () => {};
400
+ window.HTMLElement.prototype.scrollTo = () => {};
161
401
  const onChange = jest.fn();
162
- const { getByText, getByRole } = render(
163
- <DxcSelect label="test-select-name" options={optionsWithoutIcon} multiple onChange={onChange}></DxcSelect>
164
- );
165
- const select = getByRole("button");
166
- act(() => {
167
- userEvent.click(select);
168
- });
169
- const option1 = getByText("Amazon");
170
- const option2 = getByText("Ebay");
171
- const option3 = getByText("Apple");
172
- act(() => {
173
- userEvent.click(option1);
174
- });
175
- expect(onChange).toHaveBeenCalledWith([1]);
176
- act(() => {
177
- userEvent.click(option2);
178
- });
179
- expect(onChange).toHaveBeenCalledWith([1, 2]);
180
- expect(getByText("Amazon, Ebay")).toBeTruthy();
181
- act(() => {
182
- userEvent.click(option3);
183
- });
184
- expect(onChange).toHaveBeenCalledWith([1, 2, 3]);
185
- expect(getByText("Amazon, Ebay, Apple")).toBeTruthy();
186
- act(() => {
187
- userEvent.click(option1);
188
- });
189
- expect(onChange).toHaveBeenCalledWith([2, 3]);
190
- expect(getByText("Ebay, Apple")).toBeTruthy();
402
+ const { container, getByRole, getAllByRole } = render(
403
+ <DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
404
+ );
405
+ const searchInput = container.querySelectorAll("input")[1];
406
+
407
+ userEvent.type(searchInput, "Option 02");
408
+ expect(getAllByRole("option").length).toBe(1);
409
+ const clearAction = getByRole("button");
410
+ expect(clearAction).toBeTruthy();
411
+ userEvent.click(clearAction);
412
+ expect(getByRole("listbox")).toBeTruthy();
413
+ expect(getAllByRole("option").length).toBe(20);
191
414
  });
192
415
  });
@@ -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
  });