@dxc-technology/halstack-react 0.0.0-e441916 → 0.0.0-e628009

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 (195) 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 +235 -2
  5. package/dist/V3Textarea/V3Textarea.js +264 -0
  6. package/dist/accordion/Accordion.js +170 -81
  7. package/dist/accordion-group/AccordionGroup.js +186 -0
  8. package/dist/alert/Alert.js +184 -83
  9. package/dist/alert/index.d.ts +51 -0
  10. package/dist/badge/Badge.js +63 -0
  11. package/dist/box/Box.js +39 -19
  12. package/dist/button/Button.js +84 -29
  13. package/dist/card/Card.js +64 -56
  14. package/dist/checkbox/Checkbox.js +108 -32
  15. package/dist/chip/Chip.js +135 -40
  16. package/dist/common/RequiredComponent.js +2 -8
  17. package/dist/common/utils.js +2 -22
  18. package/dist/common/variables.js +1486 -105
  19. package/dist/date/Date.js +115 -78
  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 +61 -36
  23. package/dist/dropdown/Dropdown.js +226 -94
  24. package/dist/file-input/FileInput.js +644 -0
  25. package/dist/file-input/FileItem.js +280 -0
  26. package/dist/file-input/index.d.ts +81 -0
  27. package/dist/footer/Footer.js +125 -45
  28. package/dist/footer/Icons.js +77 -0
  29. package/dist/header/Header.js +174 -90
  30. package/dist/header/Icons.js +59 -0
  31. package/dist/heading/Heading.js +93 -22
  32. package/dist/input-text/Icons.js +22 -0
  33. package/dist/input-text/InputText.js +298 -108
  34. package/dist/layout/ApplicationLayout.js +327 -0
  35. package/dist/layout/Icons.js +55 -0
  36. package/dist/link/Link.js +142 -34
  37. package/dist/main.d.ts +8 -0
  38. package/dist/main.js +111 -7
  39. package/dist/new-select/NewSelect.js +836 -0
  40. package/dist/new-select/index.d.ts +53 -0
  41. package/dist/number-input/NumberInput.js +136 -0
  42. package/dist/number-input/NumberInputContext.js +16 -0
  43. package/dist/number-input/index.d.ts +113 -0
  44. package/dist/paginator/Icons.js +66 -0
  45. package/dist/paginator/Paginator.js +162 -57
  46. package/dist/password-input/PasswordInput.js +198 -0
  47. package/dist/password-input/index.d.ts +94 -0
  48. package/dist/progress-bar/ProgressBar.js +97 -44
  49. package/dist/radio/Radio.js +39 -21
  50. package/dist/resultsetTable/ResultsetTable.js +93 -69
  51. package/dist/select/Select.js +253 -129
  52. package/dist/sidenav/Sidenav.js +87 -125
  53. package/dist/slider/Slider.js +219 -73
  54. package/dist/spinner/Spinner.js +249 -64
  55. package/dist/switch/Switch.js +52 -25
  56. package/dist/table/Table.js +63 -15
  57. package/dist/tabs/Tabs.js +210 -50
  58. package/dist/tabs-for-sections/TabsForSections.js +1 -16
  59. package/dist/tag/Tag.js +100 -35
  60. package/dist/text-input/TextInput.js +971 -0
  61. package/dist/text-input/index.d.ts +135 -0
  62. package/dist/textarea/Textarea.js +250 -107
  63. package/dist/textarea/index.d.ts +117 -0
  64. package/dist/toggle/Toggle.js +16 -19
  65. package/dist/toggle-group/ToggleGroup.js +327 -0
  66. package/dist/upload/Upload.js +16 -11
  67. package/dist/upload/buttons-upload/ButtonsUpload.js +35 -25
  68. package/dist/upload/buttons-upload/Icons.js +40 -0
  69. package/dist/upload/dragAndDropArea/DragAndDropArea.js +84 -37
  70. package/dist/upload/dragAndDropArea/Icons.js +39 -0
  71. package/dist/upload/file-upload/FileToUpload.js +64 -33
  72. package/dist/upload/file-upload/Icons.js +66 -0
  73. package/dist/upload/files-upload/FilesToUpload.js +16 -16
  74. package/dist/upload/transaction/Icons.js +160 -0
  75. package/dist/upload/transaction/Transaction.js +42 -49
  76. package/dist/upload/transactions/Transactions.js +38 -20
  77. package/dist/useTheme.js +22 -0
  78. package/dist/wizard/Icons.js +65 -0
  79. package/dist/wizard/Wizard.js +156 -61
  80. package/package.json +14 -6
  81. package/test/AccordionGroup.test.js +125 -0
  82. package/test/Date.test.js +49 -45
  83. package/test/DateInput.test.js +242 -0
  84. package/test/Dropdown.test.js +19 -4
  85. package/test/FileInput.test.js +201 -0
  86. package/test/Footer.test.js +2 -7
  87. package/test/Header.test.js +5 -10
  88. package/test/Heading.test.js +60 -12
  89. package/test/InputText.test.js +53 -41
  90. package/test/Link.test.js +25 -7
  91. package/test/NumberInput.test.js +259 -0
  92. package/test/Paginator.test.js +72 -60
  93. package/test/PasswordInput.test.js +83 -0
  94. package/test/ResultsetTable.test.js +66 -19
  95. package/test/Select.test.js +55 -34
  96. package/test/Sidenav.test.js +22 -64
  97. package/test/Slider.test.js +24 -15
  98. package/test/Spinner.test.js +5 -0
  99. package/test/Tabs.test.js +21 -0
  100. package/test/TextInput.test.js +732 -0
  101. package/test/Textarea.test.js +193 -0
  102. package/test/ToggleGroup.test.js +85 -0
  103. package/test/Upload.test.js +5 -5
  104. package/test/{TextArea.test.js → V3TextArea.test.js} +6 -7
  105. package/dist/accordion/Accordion.stories.js +0 -207
  106. package/dist/accordion/readme.md +0 -96
  107. package/dist/alert/Alert.stories.js +0 -158
  108. package/dist/alert/close.svg +0 -4
  109. package/dist/alert/error.svg +0 -4
  110. package/dist/alert/info.svg +0 -4
  111. package/dist/alert/readme.md +0 -43
  112. package/dist/alert/success.svg +0 -4
  113. package/dist/alert/warning.svg +0 -4
  114. package/dist/button/Button.stories.js +0 -224
  115. package/dist/button/readme.md +0 -93
  116. package/dist/checkbox/Checkbox.stories.js +0 -144
  117. package/dist/checkbox/readme.md +0 -116
  118. package/dist/common/services/example-service.js +0 -10
  119. package/dist/common/services/example-service.test.js +0 -12
  120. package/dist/date/Date.stories.js +0 -205
  121. package/dist/date/calendar.svg +0 -1
  122. package/dist/date/calendar_dark.svg +0 -1
  123. package/dist/date/readme.md +0 -73
  124. package/dist/dialog/Dialog.stories.js +0 -217
  125. package/dist/dialog/readme.md +0 -32
  126. package/dist/dropdown/Dropdown.stories.js +0 -249
  127. package/dist/dropdown/baseline-arrow_drop_down.svg +0 -1
  128. package/dist/dropdown/baseline-arrow_drop_down_wh.svg +0 -4
  129. package/dist/dropdown/baseline-arrow_drop_up.svg +0 -1
  130. package/dist/dropdown/baseline-arrow_drop_up_wh.svg +0 -4
  131. package/dist/dropdown/readme.md +0 -69
  132. package/dist/footer/Footer.stories.js +0 -94
  133. package/dist/footer/dxc_logo_wht.png +0 -0
  134. package/dist/footer/readme.md +0 -41
  135. package/dist/header/Header.stories.js +0 -176
  136. package/dist/header/close_icon.svg +0 -1
  137. package/dist/header/dxc_logo_black.png +0 -0
  138. package/dist/header/dxc_logo_white.png +0 -0
  139. package/dist/header/hamb_menu_black.svg +0 -1
  140. package/dist/header/hamb_menu_white.svg +0 -1
  141. package/dist/header/readme.md +0 -33
  142. package/dist/input-text/InputText.stories.js +0 -209
  143. package/dist/input-text/error.svg +0 -1
  144. package/dist/input-text/readme.md +0 -91
  145. package/dist/link/readme.md +0 -51
  146. package/dist/paginator/images/next.svg +0 -3
  147. package/dist/paginator/images/nextPage.svg +0 -3
  148. package/dist/paginator/images/previous.svg +0 -3
  149. package/dist/paginator/images/previousPage.svg +0 -3
  150. package/dist/paginator/readme.md +0 -50
  151. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  152. package/dist/progress-bar/readme.md +0 -63
  153. package/dist/radio/Radio.stories.js +0 -166
  154. package/dist/radio/readme.md +0 -70
  155. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  156. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  157. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  158. package/dist/select/Select.stories.js +0 -235
  159. package/dist/select/readme.md +0 -72
  160. package/dist/sidenav/arrow_icon.svg +0 -3
  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/readme.md +0 -78
  170. package/dist/toggle/Toggle.stories.js +0 -297
  171. package/dist/toggle/readme.md +0 -80
  172. package/dist/upload/Upload.stories.js +0 -72
  173. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  174. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  175. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  176. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  177. package/dist/upload/file-upload/audio-icon.svg +0 -4
  178. package/dist/upload/file-upload/close.svg +0 -4
  179. package/dist/upload/file-upload/file-icon.svg +0 -4
  180. package/dist/upload/file-upload/video-icon.svg +0 -4
  181. package/dist/upload/readme.md +0 -37
  182. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  183. package/dist/upload/transaction/audio-icon.svg +0 -4
  184. package/dist/upload/transaction/error-icon.svg +0 -4
  185. package/dist/upload/transaction/file-icon-err.svg +0 -4
  186. package/dist/upload/transaction/file-icon.svg +0 -4
  187. package/dist/upload/transaction/image-icon-err.svg +0 -4
  188. package/dist/upload/transaction/image-icon.svg +0 -4
  189. package/dist/upload/transaction/success-icon.svg +0 -4
  190. package/dist/upload/transaction/video-icon-err.svg +0 -4
  191. package/dist/upload/transaction/video-icon.svg +0 -4
  192. package/dist/wizard/invalid_icon.svg +0 -6
  193. package/dist/wizard/valid_icon.svg +0 -6
  194. package/dist/wizard/validation-wrong.svg +0 -6
  195. package/test/Toggle.test.js +0 -43
@@ -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,115 @@ 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
+ const { getByText, getAllByRole, getByRole } = render(
53
+ <DxcPaginator
54
+ currentPage={1}
55
+ itemsPerPage={10}
56
+ totalItems={27}
57
+ showGoToPage={true}
58
+ onPageChange={onClick}
59
+ ></DxcPaginator>
50
60
  );
51
- const lastButton = getByRole("button");
52
- fireEvent.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
+ });
53
69
  expect(onClick).toHaveBeenCalledWith(2);
54
70
  });
55
71
 
56
- test("Call correct prevFunction", () => {
72
+ test("Call correct goToPageFunction", () => {
57
73
  const onClick = jest.fn();
58
- const { getByRole } = render(
59
- <DxcPaginator prevFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
74
+ const { getAllByRole } = render(
75
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
60
76
  );
61
- const prevButton = getByRole("button");
62
- fireEvent.click(prevButton);
77
+ const nextButton = getAllByRole("button")[2];
78
+ userEvent.click(nextButton);
63
79
  expect(onClick).toHaveBeenCalled();
64
80
  });
65
81
 
66
- test("Call correct firstFunction", () => {
82
+ test("Call correct itemsPerPageFunction", () => {
67
83
  const onClick = jest.fn();
68
- const { getByRole } = render(
69
- <DxcPaginator firstFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={30}></DxcPaginator>
84
+ const { getAllByText, getByText } = render(
85
+ <DxcPaginator
86
+ currentPage={1}
87
+ itemsPerPage={10}
88
+ itemsPerPageOptions={[10, 15]}
89
+ itemsPerPageFunction={onClick}
90
+ totalItems={20}
91
+ ></DxcPaginator>
70
92
  );
71
- const firstButton = getByRole("button");
72
- fireEvent.click(firstButton);
73
- expect(onClick).toHaveBeenCalled();
93
+ const select = getAllByText("10")[0];
94
+ act(() => {
95
+ userEvent.click(select);
96
+ });
97
+ const itemPerPageOption = getByText("15");
98
+ act(() => {
99
+ userEvent.click(itemPerPageOption);
100
+ });
101
+ expect(onClick).toHaveBeenCalledWith(15);
74
102
  });
75
103
 
76
104
  test("Next button is disable in last page", () => {
77
105
  const onClick = jest.fn();
78
- const { getByRole } = render(
79
- <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>
80
108
  );
81
- const nextButton = getByRole("button");
109
+ const nextButton = getAllByRole("button")[2];
82
110
  expect(nextButton.hasAttribute("disabled")).toBeTruthy();
83
- fireEvent.click(nextButton);
111
+ userEvent.click(nextButton);
84
112
  expect(onClick).toHaveBeenCalledTimes(0);
85
113
  });
86
114
 
87
115
  test("Last button is disable in last page", () => {
88
116
  const onClick = jest.fn();
89
- const { getByRole } = render(
90
- <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>
91
119
  );
92
- const lastButton = getByRole("button");
120
+ const lastButton = getAllByRole("button")[3];
93
121
  expect(lastButton.hasAttribute("disabled")).toBeTruthy();
94
- fireEvent.click(lastButton);
122
+ userEvent.click(lastButton);
95
123
  expect(onClick).toHaveBeenCalledTimes(0);
96
124
  });
97
125
 
98
126
  test("First button is disable in first page", () => {
99
127
  const onClick = jest.fn();
100
- const { getByRole } = render(
101
- <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>
102
130
  );
103
- const lastButton = getByRole("button");
131
+ const lastButton = getAllByRole("button")[0];
104
132
  expect(lastButton.hasAttribute("disabled")).toBeTruthy();
105
- fireEvent.click(lastButton);
133
+ userEvent.click(lastButton);
106
134
  expect(onClick).toHaveBeenCalledTimes(0);
107
135
  });
108
136
 
109
137
  test("Previous button is disable in first page", () => {
110
138
  const onClick = jest.fn();
111
- const { getByRole } = render(
112
- <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>
113
141
  );
114
- const lastButton = getByRole("button");
142
+ const lastButton = getAllByRole("button")[1];
115
143
  expect(lastButton.hasAttribute("disabled")).toBeTruthy();
116
- fireEvent.click(lastButton);
144
+ userEvent.click(lastButton);
117
145
  expect(onClick).toHaveBeenCalledTimes(0);
118
146
  });
119
147
 
120
148
  test("Last and next buttons are disable in last page", () => {
121
149
  const onClick = jest.fn();
122
150
  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>
151
+ <DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
132
152
  );
133
153
  const firstButton = getAllByRole("button")[0];
134
154
  const prevButton = getAllByRole("button")[1];
@@ -143,15 +163,7 @@ describe("Paginator component tests", () => {
143
163
  test("First and previous buttons are disable in first page", () => {
144
164
  const onClick = jest.fn();
145
165
  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>
166
+ <DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
155
167
  );
156
168
  const firstButton = getAllByRole("button")[0];
157
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 = [
@@ -14,7 +16,7 @@ const columns = [
14
16
  {
15
17
  displayValue: "City",
16
18
  isSortable: false,
17
- }
19
+ },
18
20
  ];
19
21
 
20
22
  const rows = [
@@ -30,7 +32,7 @@ const rows = [
30
32
  {
31
33
  displayValue: "Oviedo",
32
34
  sortValue: "Oviedo",
33
- }
35
+ },
34
36
  ],
35
37
  [
36
38
  {
@@ -61,7 +63,7 @@ const rows = [
61
63
  {
62
64
  displayValue: "Albacete",
63
65
  sortValue: "Albacete",
64
- }
66
+ },
65
67
  ],
66
68
  [
67
69
  {
@@ -75,7 +77,7 @@ const rows = [
75
77
  {
76
78
  displayValue: "Albacete",
77
79
  sortValue: "Albacete",
78
- }
80
+ },
79
81
  ],
80
82
  [
81
83
  {
@@ -89,7 +91,7 @@ const rows = [
89
91
  {
90
92
  displayValue: "Madrid",
91
93
  sortValue: "Madrid",
92
- }
94
+ },
93
95
  ],
94
96
  [
95
97
  {
@@ -120,7 +122,7 @@ const rows = [
120
122
  {
121
123
  displayValue: "Madrid",
122
124
  sortValue: "Madrid",
123
- }
125
+ },
124
126
  ],
125
127
  [
126
128
  {
@@ -134,7 +136,7 @@ const rows = [
134
136
  {
135
137
  displayValue: "Barcelona",
136
138
  sortValue: "Barcelona",
137
- }
139
+ },
138
140
  ],
139
141
  [
140
142
  {
@@ -185,7 +187,7 @@ const rows2 = [
185
187
  {
186
188
  displayValue: "OtherValue",
187
189
  sortValue: "OtherValue",
188
- }
190
+ },
189
191
  ],
190
192
  [
191
193
  {
@@ -216,21 +218,22 @@ const rows2 = [
216
218
  {
217
219
  displayValue: "OtherValue",
218
220
  sortValue: "OtherValue",
219
- }
221
+ },
220
222
  ],
221
223
  ];
222
224
 
223
225
  describe("ResultsetTable component tests", () => {
224
226
  test("ResultsetTable rendered correctly", () => {
225
- const { getByText } = render(<DxcResultsetTable columns={columns} rows={rows} itemsPerPage={3}></DxcResultsetTable>);
227
+ const { getByText } = render(
228
+ <DxcResultsetTable columns={columns} rows={rows} itemsPerPage={3}></DxcResultsetTable>
229
+ );
226
230
  expect(getByText("Peter")).toBeTruthy();
227
231
  });
228
232
  test("Resultsettable shows as many rows as itemsPerPage", () => {
229
- const { getByText, queryByText } = render(
233
+ const { getAllByRole } = render(
230
234
  <DxcResultsetTable columns={columns} rows={rows} itemsPerPage={3}></DxcResultsetTable>
231
235
  );
232
- expect(getByText("Peter")).toBeTruthy();
233
- expect(queryByText("Rick")).toBeFalsy();
236
+ expect(getAllByRole("row").length - 1).toEqual(3);
234
237
  });
235
238
 
236
239
  test("Resultsettable shows rows on second page", () => {
@@ -240,23 +243,49 @@ describe("ResultsetTable component tests", () => {
240
243
  expect(getByText("Peter")).toBeTruthy();
241
244
  expect(getByText("Louis")).toBeTruthy();
242
245
  expect(getByText("Lana")).toBeTruthy();
243
- const nextButton = getAllByRole("button")[2];
246
+ expect(getAllByRole("row").length - 1).toEqual(3);
247
+ const nextButton = getAllByRole("button")[3];
244
248
  fireEvent.click(nextButton);
245
249
  expect(getByText("4 to 6 of 10")).toBeTruthy();
246
- 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();
247
275
  expect(getByText("Rick")).toBeTruthy();
248
276
  expect(getByText("Mark")).toBeTruthy();
249
277
  expect(getByText("Cris")).toBeTruthy();
278
+ expect(getAllByRole("row").length - 1).toEqual(3);
250
279
  });
251
280
 
252
281
  test("Resultsettable going to the last page shows only one row", () => {
253
282
  const { getByText, getAllByRole } = render(
254
283
  <DxcResultsetTable columns={columns} rows={rows} itemsPerPage={3}></DxcResultsetTable>
255
284
  );
256
- const lastButton = getAllByRole("button")[3];
285
+ debugger;
286
+ const lastButton = getAllByRole("button")[4];
257
287
  fireEvent.click(lastButton);
258
288
  expect(getByText("10 to 10 of 10")).toBeTruthy();
259
- expect(getByText("Page: 4 of 4")).toBeTruthy();
260
289
  expect(getAllByRole("row")).toHaveLength(2);
261
290
  expect(getByText("Cosmin")).toBeTruthy();
262
291
  });
@@ -273,10 +302,28 @@ describe("ResultsetTable component tests", () => {
273
302
  expect(component.queryByText("Cosmin")).not.toBeTruthy();
274
303
  });
275
304
  test("Resultsettable change rows should go to first page", () => {
276
- const {queryByText, rerender} = render(<DxcResultsetTable columns={columns} rows={rows} itemsPerPage={3}></DxcResultsetTable>);
305
+ const { queryByText, rerender } = render(
306
+ <DxcResultsetTable columns={columns} rows={rows} itemsPerPage={3}></DxcResultsetTable>
307
+ );
277
308
  expect(queryByText("Peter")).toBeTruthy();
278
309
  rerender(<DxcResultsetTable columns={columns} rows={rows2} itemsPerPage={3}></DxcResultsetTable>);
279
310
  expect(queryByText("1 to 3 of 3")).toBeTruthy();
280
311
  });
281
312
 
313
+ test("Resultsettable change itemsPerPage should go to first page", () => {
314
+ const { getAllByRole, queryByText, rerender } = render(
315
+ <DxcResultsetTable
316
+ columns={columns}
317
+ rows={rows}
318
+ itemsPerPage={3}
319
+ itemsPerPageOptions={[2, 3]}
320
+ ></DxcResultsetTable>
321
+ );
322
+ const lastButton = getAllByRole("button")[5];
323
+ fireEvent.click(lastButton);
324
+ expect(getAllByRole("row").length - 1).toEqual(1);
325
+ rerender(<DxcResultsetTable columns={columns} rows={rows} itemsPerPage={6}></DxcResultsetTable>);
326
+ expect(getAllByRole("row").length - 1).toEqual(6);
327
+ expect(queryByText("Peter")).toBeTruthy();
328
+ });
282
329
  });
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
- import { render, fireEvent, act } from "@testing-library/react";
2
+ import { render, act } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
3
4
  import DxcSelect from "../src/select/Select";
4
5
 
5
6
  const optionsWithoutIcon = [
@@ -20,18 +21,43 @@ const optionsWithoutIcon = [
20
21
  const optionsWithIcons = [
21
22
  {
22
23
  value: 1,
23
- label: "Facebook",
24
- iconSrc: "/testIconFacebook",
24
+ label: "Image 1",
25
+ icon: (
26
+ <svg
27
+ data-testid="image-1"
28
+ xmlns="http://www.w3.org/2000/svg"
29
+ height="24px"
30
+ viewBox="0 0 24 24"
31
+ width="24px"
32
+ fill="currentColor"
33
+ >
34
+ <path d="M0 0h24v24H0V0z" fill="none" />
35
+ <path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" />
36
+ </svg>
37
+ ),
25
38
  },
26
39
  {
27
40
  value: 2,
28
- label: "Twitter",
29
- iconSrc: "/testIconTwitter",
30
- },
31
- {
32
- value: 3,
33
- label: "Linkedin",
34
- iconSrc: "/testIconLinkedin",
41
+ label: "Image 2",
42
+ icon: (
43
+ <svg
44
+ data-testid="image-2"
45
+ version="1.1"
46
+ x="0px"
47
+ y="0px"
48
+ width="24px"
49
+ height="24px"
50
+ viewBox="0 0 24 24"
51
+ enable-background="new 0 0 24 24"
52
+ >
53
+ <g id="Bounding_Box">
54
+ <rect fill="none" width="24" height="24" />
55
+ </g>
56
+ <g id="Master">
57
+ <path d="M19,9.3V4h-3v2.6L12,3L2,12h3v8h5v-6h4v6h5v-8h3L19,9.3z M10,10c0-1.1,0.9-2,2-2s2,0.9,2,2H10z" />
58
+ </g>
59
+ </svg>
60
+ ),
35
61
  },
36
62
  ];
37
63
 
@@ -51,7 +77,7 @@ describe("Select component tests", () => {
51
77
  expect(queryByText("Apple")).toBeFalsy();
52
78
  const select = getByRole("button");
53
79
  act(() => {
54
- fireEvent.click(select);
80
+ userEvent.click(select);
55
81
  });
56
82
  expect(getByText("Amazon")).toBeTruthy();
57
83
  expect(getByText("Ebay")).toBeTruthy();
@@ -59,29 +85,27 @@ describe("Select component tests", () => {
59
85
  });
60
86
 
61
87
  test("Select renders options with icons before", () => {
62
- const { getByRole, getAllByRole } = render(
88
+ const { getByRole, getByTestId } = render(
63
89
  <DxcSelect label="test-select-name" options={optionsWithIcons}></DxcSelect>
64
90
  );
65
91
  const select = getByRole("button");
66
92
  act(() => {
67
- fireEvent.click(select);
93
+ userEvent.click(select);
68
94
  });
69
- expect(getAllByRole("img")[0].getAttribute("src")).toEqual("/testIconFacebook");
70
- expect(getAllByRole("img")[1].getAttribute("src")).toEqual("/testIconTwitter");
71
- expect(getAllByRole("img")[2].getAttribute("src")).toEqual("/testIconLinkedin");
95
+ expect(getByTestId("image-1")).toBeTruthy();
96
+ expect(getByTestId("image-2")).toBeTruthy();
72
97
  });
73
98
 
74
99
  test("Select renders options with icons after", () => {
75
- const { getByRole, getAllByRole } = render(
100
+ const { getByRole, getByTestId } = render(
76
101
  <DxcSelect label="test-select-name" options={optionsWithIcons} iconPosition="after"></DxcSelect>
77
102
  );
78
103
  const select = getByRole("button");
79
104
  act(() => {
80
- fireEvent.click(select);
105
+ userEvent.click(select);
81
106
  });
82
- expect(getAllByRole("img")[0].getAttribute("src")).toEqual("/testIconFacebook");
83
- expect(getAllByRole("img")[1].getAttribute("src")).toEqual("/testIconTwitter");
84
- expect(getAllByRole("img")[2].getAttribute("src")).toEqual("/testIconLinkedin");
107
+ expect(getByTestId("image-1")).toBeTruthy();
108
+ expect(getByTestId("image-2")).toBeTruthy();
85
109
  });
86
110
 
87
111
  test("Select renders with a default value", () => {
@@ -107,7 +131,7 @@ describe("Select component tests", () => {
107
131
  expect(queryByText("Apple")).toBeFalsy();
108
132
  const select = getByText("test-select-name");
109
133
  act(() => {
110
- fireEvent.click(select);
134
+ userEvent.click(select);
111
135
  });
112
136
  expect(queryByText("Amazon")).toBeFalsy();
113
137
  expect(queryByText("Ebay")).toBeFalsy();
@@ -121,11 +145,11 @@ describe("Select component tests", () => {
121
145
  );
122
146
  const select = getByText("Amazon");
123
147
  act(() => {
124
- fireEvent.click(select);
148
+ userEvent.click(select);
125
149
  });
126
150
  const option2 = getByText("Ebay");
127
151
  act(() => {
128
- fireEvent.click(option2);
152
+ userEvent.click(option2);
129
153
  });
130
154
  expect(onChange).toHaveBeenCalledWith(2);
131
155
  //The value is not changed
@@ -145,11 +169,11 @@ describe("Select component tests", () => {
145
169
  );
146
170
  const select = getByText("Amazon, Ebay");
147
171
  act(() => {
148
- fireEvent.click(select);
172
+ userEvent.click(select);
149
173
  });
150
174
  const option3 = getByText("Apple");
151
175
  act(() => {
152
- fireEvent.click(option3);
176
+ userEvent.click(option3);
153
177
  });
154
178
  expect(onChange).toHaveBeenCalledWith([1, 2, 3]);
155
179
  //The value is not changed
@@ -163,27 +187,24 @@ describe("Select component tests", () => {
163
187
  );
164
188
  const select = getByRole("button");
165
189
  act(() => {
166
- fireEvent.click(select);
190
+ userEvent.click(select);
167
191
  });
168
- const option1 = getByText("Amazon");
169
- const option2 = getByText("Ebay");
170
- const option3 = getByText("Apple");
171
192
  act(() => {
172
- fireEvent.click(option1);
193
+ userEvent.click(getByText("Amazon"));
173
194
  });
174
195
  expect(onChange).toHaveBeenCalledWith([1]);
175
196
  act(() => {
176
- fireEvent.click(option2);
197
+ userEvent.click(getByText("Ebay"));
177
198
  });
178
199
  expect(onChange).toHaveBeenCalledWith([1, 2]);
179
200
  expect(getByText("Amazon, Ebay")).toBeTruthy();
180
201
  act(() => {
181
- fireEvent.click(option3);
202
+ userEvent.click(getByText("Apple"));
182
203
  });
183
204
  expect(onChange).toHaveBeenCalledWith([1, 2, 3]);
184
205
  expect(getByText("Amazon, Ebay, Apple")).toBeTruthy();
185
206
  act(() => {
186
- fireEvent.click(option1);
207
+ userEvent.click(getByText("Amazon"));
187
208
  });
188
209
  expect(onChange).toHaveBeenCalledWith([2, 3]);
189
210
  expect(getByText("Ebay, Apple")).toBeTruthy();