@dxc-technology/halstack-react 0.0.0-51a5c42 → 0.0.0-522074c

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 (265) hide show
  1. package/BackgroundColorContext.js +50 -0
  2. package/ThemeContext.js +246 -0
  3. package/{dist/select/Select.js → V3Select/V3Select.js} +38 -132
  4. package/V3Select/index.d.ts +27 -0
  5. package/{dist/V3Textarea → V3Textarea}/V3Textarea.js +10 -14
  6. package/V3Textarea/index.d.ts +27 -0
  7. package/accordion/Accordion.d.ts +4 -0
  8. package/{dist/accordion → accordion}/Accordion.js +35 -130
  9. package/accordion/types.d.ts +68 -0
  10. package/accordion/types.js +5 -0
  11. package/accordion-group/AccordionGroup.d.ts +7 -0
  12. package/accordion-group/AccordionGroup.js +170 -0
  13. package/accordion-group/types.d.ts +72 -0
  14. package/accordion-group/types.js +5 -0
  15. package/alert/Alert.d.ts +4 -0
  16. package/{dist/alert → alert}/Alert.js +38 -151
  17. package/alert/types.d.ts +49 -0
  18. package/alert/types.js +5 -0
  19. package/badge/Badge.js +59 -0
  20. package/{dist/box → box}/Box.js +9 -13
  21. package/box/index.d.ts +25 -0
  22. package/button/Button.d.ts +4 -0
  23. package/{dist/button → button}/Button.js +16 -72
  24. package/button/Button.stories.tsx +293 -0
  25. package/button/types.d.ts +57 -0
  26. package/button/types.js +5 -0
  27. package/card/Card.d.ts +4 -0
  28. package/{dist/card → card}/Card.js +32 -121
  29. package/card/types.d.ts +69 -0
  30. package/card/types.js +5 -0
  31. package/checkbox/Checkbox.d.ts +4 -0
  32. package/{dist/checkbox → checkbox}/Checkbox.js +16 -63
  33. package/checkbox/types.d.ts +60 -0
  34. package/checkbox/types.js +5 -0
  35. package/{dist/chip → chip}/Chip.js +17 -61
  36. package/chip/index.d.ts +22 -0
  37. package/{dist/common → common}/OpenSans.css +0 -0
  38. package/{dist/common → common}/RequiredComponent.js +3 -11
  39. package/{dist/common → common}/fonts/OpenSans-Bold.ttf +0 -0
  40. package/{dist/common → common}/fonts/OpenSans-BoldItalic.ttf +0 -0
  41. package/{dist/common → common}/fonts/OpenSans-ExtraBold.ttf +0 -0
  42. package/{dist/common → common}/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  43. package/{dist/common → common}/fonts/OpenSans-Italic.ttf +0 -0
  44. package/{dist/common → common}/fonts/OpenSans-Light.ttf +0 -0
  45. package/{dist/common → common}/fonts/OpenSans-LightItalic.ttf +0 -0
  46. package/{dist/common → common}/fonts/OpenSans-Regular.ttf +0 -0
  47. package/{dist/common → common}/fonts/OpenSans-SemiBold.ttf +0 -0
  48. package/{dist/common → common}/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
  49. package/{dist/common → common}/utils.js +0 -0
  50. package/{dist/common → common}/variables.js +133 -133
  51. package/{dist/date → date}/Date.js +21 -27
  52. package/date/index.d.ts +27 -0
  53. package/date-input/DateInput.d.ts +4 -0
  54. package/{dist/date-input → date-input}/DateInput.js +22 -61
  55. package/date-input/types.d.ts +100 -0
  56. package/date-input/types.js +5 -0
  57. package/{dist/dialog → dialog}/Dialog.js +16 -50
  58. package/dialog/index.d.ts +18 -0
  59. package/dropdown/Dropdown.d.ts +4 -0
  60. package/{dist/dropdown → dropdown}/Dropdown.js +44 -171
  61. package/dropdown/types.d.ts +89 -0
  62. package/dropdown/types.js +5 -0
  63. package/{dist/file-input → file-input}/FileInput.js +49 -161
  64. package/{dist/file-input → file-input}/FileItem.js +36 -123
  65. package/{dist/file-input → file-input}/index.d.ts +1 -1
  66. package/{dist/footer → footer}/Footer.js +53 -151
  67. package/footer/Icons.js +77 -0
  68. package/footer/index.d.ts +25 -0
  69. package/{dist/header → header}/Header.js +62 -170
  70. package/{dist/header → header}/Icons.js +11 -11
  71. package/header/index.d.ts +25 -0
  72. package/{dist/heading → heading}/Heading.js +30 -72
  73. package/heading/index.d.ts +17 -0
  74. package/input-text/Icons.js +22 -0
  75. package/{dist/input-text → input-text}/InputText.js +37 -133
  76. package/input-text/index.d.ts +36 -0
  77. package/{dist/layout → layout}/ApplicationLayout.js +35 -131
  78. package/layout/Icons.js +55 -0
  79. package/{dist/link → link}/Link.js +18 -72
  80. package/link/index.d.ts +23 -0
  81. package/main.d.ts +44 -0
  82. package/{dist/main.js → main.js} +93 -97
  83. package/{dist/number-input → number-input}/NumberInput.js +5 -13
  84. package/{dist/number-input → number-input}/NumberInputContext.js +1 -1
  85. package/{dist/number-input → number-input}/index.d.ts +0 -0
  86. package/package.json +32 -25
  87. package/paginator/Icons.js +66 -0
  88. package/paginator/Paginator.d.ts +4 -0
  89. package/paginator/Paginator.js +198 -0
  90. package/paginator/types.d.ts +38 -0
  91. package/paginator/types.js +5 -0
  92. package/{dist/password-input → password-input}/PasswordInput.js +23 -22
  93. package/password-input/PasswordInput.stories.jsx +131 -0
  94. package/{dist/password-input → password-input}/index.d.ts +0 -0
  95. package/progress-bar/ProgressBar.d.ts +4 -0
  96. package/{dist/progress-bar → progress-bar}/ProgressBar.js +19 -91
  97. package/progress-bar/types.d.ts +37 -0
  98. package/progress-bar/types.js +5 -0
  99. package/radio/Radio.d.ts +4 -0
  100. package/{dist/radio → radio}/Radio.js +15 -50
  101. package/radio/types.d.ts +54 -0
  102. package/radio/types.js +5 -0
  103. package/{dist/resultsetTable → resultsetTable}/ResultsetTable.js +35 -119
  104. package/resultsetTable/index.d.ts +19 -0
  105. package/select/Select.js +865 -0
  106. package/select/index.d.ts +131 -0
  107. package/{dist/sidenav → sidenav}/Sidenav.js +15 -49
  108. package/sidenav/index.d.ts +13 -0
  109. package/slider/Slider.d.ts +4 -0
  110. package/{dist/slider → slider}/Slider.js +48 -136
  111. package/slider/types.d.ts +83 -0
  112. package/slider/types.js +5 -0
  113. package/{dist/spinner → spinner}/Spinner.js +38 -152
  114. package/spinner/index.d.ts +17 -0
  115. package/switch/Switch.d.ts +4 -0
  116. package/{dist/switch → switch}/Switch.js +26 -69
  117. package/switch/types.d.ts +58 -0
  118. package/switch/types.js +5 -0
  119. package/{dist/table → table}/Table.js +10 -24
  120. package/table/index.d.ts +13 -0
  121. package/{dist/tabs → tabs}/Tabs.js +26 -110
  122. package/tabs/index.d.ts +19 -0
  123. package/{dist/tag → tag}/Tag.js +22 -96
  124. package/tag/index.d.ts +24 -0
  125. package/{dist/text-input → text-input}/TextInput.js +244 -390
  126. package/{dist/text-input → text-input}/index.d.ts +0 -0
  127. package/{dist/textarea → textarea}/Textarea.js +20 -72
  128. package/textarea/Textarea.stories.jsx +135 -0
  129. package/{dist/textarea → textarea}/index.d.ts +0 -0
  130. package/{dist/toggle → toggle}/Toggle.js +15 -49
  131. package/toggle/index.d.ts +21 -0
  132. package/{dist/toggle-group → toggle-group}/ToggleGroup.js +23 -107
  133. package/toggle-group/index.d.ts +21 -0
  134. package/{dist/upload → upload}/Upload.js +14 -18
  135. package/upload/buttons-upload/ButtonsUpload.js +111 -0
  136. package/upload/buttons-upload/Icons.js +40 -0
  137. package/upload/dragAndDropArea/DragAndDropArea.js +225 -0
  138. package/upload/dragAndDropArea/Icons.js +39 -0
  139. package/upload/file-upload/FileToUpload.js +115 -0
  140. package/upload/file-upload/Icons.js +66 -0
  141. package/{dist/upload → upload}/files-upload/FilesToUpload.js +12 -26
  142. package/upload/index.d.ts +15 -0
  143. package/upload/transaction/Icons.js +160 -0
  144. package/upload/transaction/Transaction.js +104 -0
  145. package/upload/transactions/Transactions.js +94 -0
  146. package/{dist/useTheme.js → useTheme.js} +0 -0
  147. package/wizard/Icons.js +65 -0
  148. package/{dist/wizard → wizard}/Wizard.js +32 -172
  149. package/wizard/index.d.ts +18 -0
  150. package/README.md +0 -66
  151. package/babel.config.js +0 -8
  152. package/dist/BackgroundColorContext.js +0 -46
  153. package/dist/ThemeContext.js +0 -248
  154. package/dist/accordion-group/AccordionGroup.js +0 -186
  155. package/dist/alert/index.d.ts +0 -51
  156. package/dist/badge/Badge.js +0 -63
  157. package/dist/checkbox/Checkbox.stories.js +0 -144
  158. package/dist/checkbox/readme.md +0 -116
  159. package/dist/date/Date.stories.js +0 -205
  160. package/dist/date/readme.md +0 -73
  161. package/dist/date-input/index.d.ts +0 -95
  162. package/dist/footer/dxc_logo.svg +0 -15
  163. package/dist/footer/readme.md +0 -41
  164. package/dist/input-text/error.svg +0 -1
  165. package/dist/input-text/readme.md +0 -91
  166. package/dist/layout/facebook.svg +0 -45
  167. package/dist/layout/linkedin.svg +0 -50
  168. package/dist/layout/twitter.svg +0 -53
  169. package/dist/link/readme.md +0 -51
  170. package/dist/main.d.ts +0 -8
  171. package/dist/new-select/NewSelect.js +0 -836
  172. package/dist/new-select/index.d.ts +0 -53
  173. package/dist/paginator/Paginator.js +0 -289
  174. package/dist/paginator/images/next.svg +0 -3
  175. package/dist/paginator/images/nextPage.svg +0 -3
  176. package/dist/paginator/images/previous.svg +0 -3
  177. package/dist/paginator/images/previousPage.svg +0 -3
  178. package/dist/paginator/readme.md +0 -50
  179. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  180. package/dist/progress-bar/readme.md +0 -63
  181. package/dist/radio/Radio.stories.js +0 -166
  182. package/dist/radio/readme.md +0 -70
  183. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  184. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  185. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  186. package/dist/slider/readme.md +0 -64
  187. package/dist/spinner/Spinner.stories.js +0 -183
  188. package/dist/spinner/readme.md +0 -65
  189. package/dist/switch/Switch.stories.js +0 -134
  190. package/dist/switch/readme.md +0 -133
  191. package/dist/tabs/Tabs.stories.js +0 -130
  192. package/dist/tabs/readme.md +0 -78
  193. package/dist/tabs-for-sections/TabsForSections.js +0 -92
  194. package/dist/tabs-for-sections/readme.md +0 -78
  195. package/dist/toggle/Toggle.stories.js +0 -297
  196. package/dist/toggle/readme.md +0 -80
  197. package/dist/upload/Upload.stories.js +0 -72
  198. package/dist/upload/buttons-upload/ButtonsUpload.js +0 -139
  199. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  200. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  201. package/dist/upload/dragAndDropArea/DragAndDropArea.js +0 -329
  202. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  203. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  204. package/dist/upload/file-upload/FileToUpload.js +0 -184
  205. package/dist/upload/file-upload/audio-icon.svg +0 -4
  206. package/dist/upload/file-upload/close.svg +0 -4
  207. package/dist/upload/file-upload/file-icon.svg +0 -4
  208. package/dist/upload/file-upload/video-icon.svg +0 -4
  209. package/dist/upload/readme.md +0 -37
  210. package/dist/upload/transaction/Transaction.js +0 -175
  211. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  212. package/dist/upload/transaction/audio-icon.svg +0 -4
  213. package/dist/upload/transaction/error-icon.svg +0 -4
  214. package/dist/upload/transaction/file-icon-err.svg +0 -4
  215. package/dist/upload/transaction/file-icon.svg +0 -4
  216. package/dist/upload/transaction/image-icon-err.svg +0 -4
  217. package/dist/upload/transaction/image-icon.svg +0 -4
  218. package/dist/upload/transaction/success-icon.svg +0 -4
  219. package/dist/upload/transaction/video-icon-err.svg +0 -4
  220. package/dist/upload/transaction/video-icon.svg +0 -4
  221. package/dist/upload/transactions/Transactions.js +0 -138
  222. package/dist/wizard/invalid_icon.svg +0 -5
  223. package/dist/wizard/valid_icon.svg +0 -5
  224. package/dist/wizard/validation-wrong.svg +0 -6
  225. package/test/Accordion.test.js +0 -33
  226. package/test/AccordionGroup.test.js +0 -125
  227. package/test/Alert.test.js +0 -53
  228. package/test/Box.test.js +0 -10
  229. package/test/Button.test.js +0 -18
  230. package/test/Card.test.js +0 -30
  231. package/test/Checkbox.test.js +0 -45
  232. package/test/Chip.test.js +0 -25
  233. package/test/Date.test.js +0 -397
  234. package/test/DateInput.test.js +0 -242
  235. package/test/Dialog.test.js +0 -23
  236. package/test/Dropdown.test.js +0 -145
  237. package/test/FileInput.test.js +0 -201
  238. package/test/Footer.test.js +0 -99
  239. package/test/Header.test.js +0 -34
  240. package/test/Heading.test.js +0 -35
  241. package/test/InputText.test.js +0 -248
  242. package/test/Link.test.js +0 -43
  243. package/test/NumberInput.test.js +0 -259
  244. package/test/Paginator.test.js +0 -177
  245. package/test/PasswordInput.test.js +0 -83
  246. package/test/ProgressBar.test.js +0 -35
  247. package/test/Radio.test.js +0 -37
  248. package/test/ResultsetTable.test.js +0 -329
  249. package/test/Select.test.js +0 -212
  250. package/test/Sidenav.test.js +0 -45
  251. package/test/Slider.test.js +0 -82
  252. package/test/Spinner.test.js +0 -32
  253. package/test/Switch.test.js +0 -45
  254. package/test/Table.test.js +0 -36
  255. package/test/Tabs.test.js +0 -109
  256. package/test/TabsForSections.test.js +0 -34
  257. package/test/Tag.test.js +0 -32
  258. package/test/TextInput.test.js +0 -732
  259. package/test/Textarea.test.js +0 -193
  260. package/test/ToggleGroup.test.js +0 -85
  261. package/test/Upload.test.js +0 -60
  262. package/test/V3TextArea.test.js +0 -51
  263. package/test/Wizard.test.js +0 -130
  264. package/test/mocks/pngMock.js +0 -1
  265. package/test/mocks/svgMock.js +0 -1
@@ -1,99 +0,0 @@
1
- import React from "react";
2
- import { render } from "@testing-library/react";
3
- import DxcFooter from "../src/footer/Footer";
4
- import icon from "../../app/src/images/linkedin.svg";
5
-
6
- describe("Footer component tests", () => {
7
- test("Footer renders with default logo", () => {
8
- const { getByRole } = render(<DxcFooter></DxcFooter>);
9
- expect(getByRole("img")).toBeTruthy();
10
- });
11
-
12
- test("Footer renders with logo", () => {
13
- const { getByRole } = render(<DxcFooter logoSrc={icon}></DxcFooter>);
14
- expect(getByRole("img")).toBeTruthy();
15
- });
16
-
17
- test("Footer renders with social links", () => {
18
- const social = [
19
- {
20
- href: "https://www.test.com/test",
21
- logoSrc: icon,
22
- },
23
- ];
24
- const { getByRole } = render(<DxcFooter socialLinks={social}></DxcFooter>);
25
- const socialIcon = getByRole("link");
26
- expect(socialIcon.getAttribute("href")).toBe("https://www.test.com/test");
27
- });
28
-
29
- test("Footer renders with bottom links", () => {
30
- const bottom = [
31
- {
32
- href: "https://www.test.com/test",
33
- text: "bottom-link-text",
34
- },
35
- ];
36
- const { getByText } = render(<DxcFooter bottomLinks={bottom}></DxcFooter>);
37
- const link = getByText("bottom-link-text");
38
- expect(link.getAttribute("href")).toBe("https://www.test.com/test");
39
- });
40
-
41
- test("Footer renders with copyright text", () => {
42
- const { getByText } = render(<DxcFooter copyright="test-copyright"></DxcFooter>);
43
- expect(getByText("test-copyright")).toBeTruthy();
44
- });
45
-
46
- test("Footer renders with correct children", () => {
47
- //We need to force the offsetWidth value
48
- Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, value: 1024 });
49
-
50
- const { getByText } = render(
51
- <DxcFooter>
52
- <p>footer-child-text</p>
53
- </DxcFooter>
54
- );
55
-
56
- expect(getByText("footer-child-text")).toBeTruthy();
57
- });
58
-
59
- test("Footer renders without children in mobile", () => {
60
- //425 is mobile width
61
- Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, value: 425 });
62
-
63
- const { queryByText } = render(
64
- <DxcFooter>
65
- <p>footer-child-text</p>
66
- </DxcFooter>
67
- );
68
-
69
- expect(queryByText("footer-child-text")).toBeFalsy();
70
- });
71
-
72
- test("Footer is fully rendered", () => {
73
- Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, value: 1024 });
74
-
75
- const social = [
76
- {
77
- href: "https://www.test.com/social",
78
- logoSrc: icon,
79
- },
80
- ];
81
- const bottom = [
82
- {
83
- href: "https://www.test.com/bottom",
84
- text: "bottom-link-text",
85
- },
86
- ];
87
- const { getAllByRole, getByText } = render(
88
- <DxcFooter socialLinks={social} bottomLinks={bottom} copyright="test-copyright">
89
- <p>footer-child-text</p>
90
- </DxcFooter>
91
- );
92
- const socialIcon = getAllByRole("link")[0];
93
- expect(socialIcon.getAttribute("href")).toBe("https://www.test.com/social");
94
- const bottomLink = getByText("bottom-link-text");
95
- expect(bottomLink.getAttribute("href")).toBe("https://www.test.com/bottom");
96
- expect(getByText("test-copyright")).toBeTruthy();
97
- expect(getByText("footer-child-text")).toBeTruthy();
98
- });
99
- });
@@ -1,34 +0,0 @@
1
- import React from "react";
2
- import { render, fireEvent } from "@testing-library/react";
3
- import DxcHeader from "../src/header/Header";
4
- import icon from "../../app/src/images/linkedin.svg";
5
-
6
- describe("Header component tests", () => {
7
- test("Header renders with default logo", () => {
8
- const { getByTitle } = render(<DxcHeader></DxcHeader>);
9
- expect(getByTitle("DXC Logo")).toBeTruthy();
10
- });
11
-
12
- test("Call correct function on logo click", () => {
13
- const onClick = jest.fn();
14
- const { getByTitle } = render(<DxcHeader onClick={onClick}></DxcHeader>);
15
- const logo = getByTitle("DXC Logo");
16
- fireEvent.click(logo);
17
- expect(onClick).toHaveBeenCalled();
18
- });
19
-
20
- test("Header renders with correct children", () => {
21
- // We need to force the offsetWidth value
22
- Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, value: 1024 });
23
-
24
- const { getByText } = render(<DxcHeader content={<p>header-child-text</p>}></DxcHeader>);
25
- expect(getByText("header-child-text")).toBeTruthy();
26
- });
27
-
28
- test("Header renders menu button in mobile", () => {
29
- Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, value: 425 });
30
-
31
- const { getByText } = render(<DxcHeader responsiveContent={(closeMenu) => <p>header-child-text</p>}></DxcHeader>);
32
- expect(getByText("Menu")).toBeTruthy();
33
- });
34
- });
@@ -1,35 +0,0 @@
1
- import React from "react";
2
- import { render } from "@testing-library/react";
3
- import DxcHeading from "../src/heading/Heading";
4
-
5
- describe("Heading component tests", () => {
6
- test("Footer renders with default level", () => {
7
- const { getByText } = render(<DxcHeading text="my-heading-test"></DxcHeading>);
8
- expect(getByText("my-heading-test")).toBeTruthy();
9
- });
10
-
11
- test("Footer renders with level 1", () => {
12
- const { getByText } = render(<DxcHeading text="my-heading-test" level={1}></DxcHeading>);
13
- expect(getByText("my-heading-test")).toBeTruthy();
14
- });
15
-
16
- test("Footer renders with level 2", () => {
17
- const { getByText } = render(<DxcHeading text="my-heading-test" level={2}></DxcHeading>);
18
- expect(getByText("my-heading-test")).toBeTruthy();
19
- });
20
-
21
- test("Footer renders with level 3", () => {
22
- const { getByText } = render(<DxcHeading text="my-heading-test" level={3}></DxcHeading>);
23
- expect(getByText("my-heading-test")).toBeTruthy();
24
- });
25
-
26
- test("Footer renders with level 4", () => {
27
- const { getByText } = render(<DxcHeading text="my-heading-test" level={4}></DxcHeading>);
28
- expect(getByText("my-heading-test")).toBeTruthy();
29
- });
30
-
31
- test("Footer renders with level 5", () => {
32
- const { getByText } = render(<DxcHeading text="my-heading-test" level={5}></DxcHeading>);
33
- expect(getByText("my-heading-test")).toBeTruthy();
34
- });
35
- });
@@ -1,248 +0,0 @@
1
- import React from "react";
2
- import { render, fireEvent, waitFor, screen, act, waitForElementToBeRemoved } from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
-
5
- import icon from "../../app/src/images/invision.svg";
6
-
7
- import V3DxcInputText from "../src/input-text/InputText";
8
-
9
- const countries = ["Albania", "Andorra", "Armenia", "Austria", "Azerbaijan"];
10
-
11
- //Mock of popper.js because of an issue with createRange function
12
- //(https://github.com/popperjs/popper-core/issues/478)
13
- jest.mock("popper.js", () => {
14
- const PopperJS = jest.requireActual("popper.js");
15
-
16
- return class {
17
- static placements = PopperJS.placements;
18
-
19
- constructor() {
20
- return {
21
- destroy: () => {},
22
- scheduleUpdate: () => {},
23
- update: () => {},
24
- };
25
- }
26
- };
27
- });
28
-
29
- describe("InputText component tests", () => {
30
- test("Input renders with correct label", () => {
31
- const { getByText } = render(<V3DxcInputText label="Input label" />);
32
- expect(getByText("Input label")).toBeTruthy();
33
- });
34
-
35
- test("onChange function is called correctly", () => {
36
- const onChange = jest.fn();
37
- const { getByRole } = render(<V3DxcInputText label="Input label" onChange={onChange} />);
38
- const input = getByRole("textbox");
39
- userEvent.type(input, "20000");
40
- expect(onChange).toHaveBeenCalled();
41
- expect(onChange).toHaveBeenCalledWith("20000");
42
- });
43
- test("onBlur function is called correctly", () => {
44
- const onBlur = jest.fn();
45
- const onChange = jest.fn();
46
-
47
- const { getByRole } = render(<V3DxcInputText label="Input label" onChange={onChange} onBlur={onBlur} />);
48
- const input = getByRole("textbox");
49
- userEvent.type(input, "Test value");
50
- fireEvent.blur(input);
51
- expect(onBlur).toHaveBeenCalled();
52
- expect(onBlur).toHaveBeenCalledWith("Test value");
53
- });
54
-
55
- test("Uncontrolled component", () => {
56
- const onChange = jest.fn();
57
- const { getByRole } = render(<V3DxcInputText label="Input label" onChange={onChange} />);
58
- const input = getByRole("textbox");
59
- userEvent.type(input, "20000");
60
- expect(onChange).toHaveBeenCalled();
61
- expect(onChange).toHaveBeenCalledWith("20000");
62
- expect(input.value).toBe("20000");
63
- });
64
-
65
- test("Controlled component", () => {
66
- const onChange = jest.fn();
67
- const onBlur = jest.fn();
68
- const { getByRole } = render(
69
- <V3DxcInputText label="Input label" value="Test value" onChange={onChange} onBlur={onBlur} />
70
- );
71
- const input = getByRole("textbox");
72
- userEvent.type(input, "20000");
73
- expect(onChange).toHaveBeenCalled();
74
- expect(input.value).toBe("Test value");
75
- fireEvent.blur(input);
76
- expect(onBlur).toHaveBeenCalled();
77
- expect(onBlur).toHaveBeenCalledWith("Test value");
78
- });
79
- test("Prefix icon onClick", () => {
80
- const onClick = jest.fn();
81
- const { getByRole } = render(<V3DxcInputText label="Input label" prefixIconSrc={icon} onClickPrefix={onClick} />);
82
- const prefixIcon = getByRole("img");
83
- userEvent.click(prefixIcon);
84
- expect(onClick).toHaveBeenCalled();
85
- });
86
- test("Suffix icon onClick", () => {
87
- const onClick = jest.fn();
88
- const { getByRole } = render(<V3DxcInputText label="Input label" suffixIconSrc={icon} onClickSuffix={onClick} />);
89
- const suffixIcon = getByRole("img");
90
- userEvent.click(suffixIcon);
91
- expect(onClick).toHaveBeenCalled();
92
- });
93
- });
94
-
95
- describe("Autocomplete component Synchronous tests", () => {
96
- test("Autocomplete no matches found is shown", async () => {
97
- const onChangeAtocomplete = jest.fn();
98
- render(
99
- <V3DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
100
- );
101
- const input = screen.getByRole("textbox");
102
- fireEvent.focus(input);
103
- expect(screen.getByText("Andorra")).toBeTruthy();
104
- userEvent.type(input, "X");
105
- expect(screen.getByText("No matches found.")).toBeTruthy();
106
- });
107
-
108
- test("Autocomplete suggestions are shown", async () => {
109
- const onChangeAtocomplete = jest.fn();
110
- render(
111
- <V3DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
112
- );
113
- const input = screen.getByRole("textbox");
114
- fireEvent.focus(input);
115
- expect(screen.getByText("Andorra")).toBeTruthy();
116
- });
117
-
118
- test("Autocomplete UNCONTROLLED suggestion selected", async () => {
119
- const onChangeAtocomplete = jest.fn();
120
- render(
121
- <V3DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
122
- );
123
- const input = screen.getByRole("textbox");
124
- fireEvent.focus(input);
125
- expect(screen.getByText("Andorra")).toBeTruthy();
126
- userEvent.type(screen.getByRole("textbox"), "Alb");
127
- expect(onChangeAtocomplete).toHaveBeenCalled();
128
- expect(screen.getByText("Albania")).toBeTruthy();
129
- const suggestion1 = screen.getByText("Albania");
130
- act(() => {
131
- userEvent.click(suggestion1);
132
- });
133
-
134
- // expect(onChangeAtocomplete).toHaveBeenCalledWith("Albania");
135
- expect(screen.getByRole("textbox").value).toBe("Albania");
136
- });
137
-
138
- test("Autocomplete CONTROLLED suggestions selected", async () => {
139
- const onChangeAtocomplete = jest.fn();
140
- render(
141
- <V3DxcInputText
142
- label="Autocomplete Countries"
143
- value="Andorra"
144
- autocompleteOptions={countries}
145
- onChange={onChangeAtocomplete}
146
- />
147
- );
148
- const input = screen.getByRole("textbox");
149
- fireEvent.focus(input);
150
- expect(screen.getByText("Andorra")).toBeTruthy();
151
-
152
- expect(screen.getByText("Andorra")).toBeTruthy();
153
- const suggestion1 = screen.getByText("Andorra");
154
- act(() => {
155
- userEvent.click(suggestion1);
156
- });
157
-
158
- expect(onChangeAtocomplete).toHaveBeenCalledWith("Andorra");
159
- });
160
- });
161
-
162
- describe("InputText component Asynchronous Autocomplete tests", () => {
163
- test("Autocomplete Searching is shown", async () => {
164
- const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 1000)));
165
-
166
- const onChangeAtocomplete = jest.fn();
167
- render(
168
- <V3DxcInputText
169
- label="Autocomplete Countries"
170
- autocompleteOptions={callbackFunc}
171
- onChange={onChangeAtocomplete}
172
- />
173
- );
174
- const input = screen.getByRole("textbox");
175
- fireEvent.focus(input);
176
- await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
177
- expect(screen.getByText("Italy")).toBeTruthy();
178
- expect(screen.getByText("Spain")).toBeTruthy();
179
- });
180
-
181
- test("Asynchronous UNCONTROLLED autocomplete tests", async () => {
182
- const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 1000)));
183
- const onChangeAtocomplete = jest.fn();
184
- render(
185
- <V3DxcInputText
186
- label="Autocomplete Countries"
187
- onChange={onChangeAtocomplete}
188
- autocompleteOptions={callbackFunc}
189
- />
190
- );
191
- const input = screen.getByRole("textbox");
192
- fireEvent.focus(input);
193
- userEvent.type(input, "And");
194
- await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
195
- expect(screen.getByText("Italy")).toBeTruthy();
196
- expect(screen.getByText("Spain")).toBeTruthy();
197
- const suggestion1 = screen.getByText("Spain");
198
- act(() => {
199
- userEvent.click(suggestion1);
200
- });
201
- expect(onChangeAtocomplete).toHaveBeenCalledWith("Spain");
202
- expect(screen.getByRole("textbox").value).toBe("Spain");
203
- });
204
-
205
- test("Asynchronous CONTROLLED autocomplete tests", async () => {
206
- const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 3000)));
207
- const onChangeAtocomplete = jest.fn();
208
- render(
209
- <V3DxcInputText
210
- label="Autocomplete Countries"
211
- value="test value"
212
- onChange={onChangeAtocomplete}
213
- autocompleteOptions={callbackFunc}
214
- />
215
- );
216
- const input = screen.getByRole("textbox");
217
- fireEvent.focus(input);
218
- userEvent.type(input, "And");
219
- await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
220
- expect(screen.getByText("Italy")).toBeTruthy();
221
- expect(screen.getByText("Spain")).toBeTruthy();
222
- const suggestion1 = screen.getByText("Spain");
223
- act(() => {
224
- userEvent.click(suggestion1);
225
- });
226
- expect(onChangeAtocomplete).toHaveBeenCalledWith("Spain");
227
- expect(screen.getByRole("textbox").value).toBe("test value");
228
- });
229
-
230
- test("Asynchronous autocomplete request failed", async () => {
231
- const errorCallbackFunc = jest.fn(() => new Promise((resolve, reject) => setTimeout(reject("E"), 3000)));
232
- const onChangeAtocomplete = jest.fn();
233
-
234
- render(
235
- <V3DxcInputText
236
- label="Autocomplete Countries"
237
- value="test value"
238
- onChange={onChangeAtocomplete}
239
- autocompleteOptions={errorCallbackFunc}
240
- />
241
- );
242
-
243
- const input = screen.getByRole("textbox");
244
- fireEvent.focus(input);
245
- await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
246
- expect(screen.getByText("Error fetching data")).toBeTruthy();
247
- });
248
- });
package/test/Link.test.js DELETED
@@ -1,43 +0,0 @@
1
- import React from "react";
2
- import { render, fireEvent } from "@testing-library/react";
3
- import DxcLink from "../src/link/Link";
4
-
5
- describe("Link component tests", () => {
6
- test("Link renders with correct text", () => {
7
- const { getByText } = render(<DxcLink text="Link" />);
8
- expect(getByText("Link")).toBeTruthy();
9
- });
10
-
11
- test("Link renders with correct href", () => {
12
- const { getByRole } = render(<DxcLink text="Link" href="/testPage" />);
13
- expect(getByRole("link").getAttribute("href")).toEqual("/testPage");
14
- });
15
-
16
- test("Link renders with correct disabled state", () => {
17
- const { getByText } = render(<DxcLink text="Link" href="/testPage" disabled={true} />);
18
- expect(getByText("Link").hasAttribute("href")).toBeFalsy();
19
- const { getByText: getByTextLinkButton } = render(<DxcLink text="LinkButton" onClick={() => console.log("Andorra")} disabled={true} />);
20
- expect(getByTextLinkButton("LinkButton").hasAttribute("onclick")).toBeFalsy();
21
- });
22
-
23
- test("Link open new tab", () => {
24
- const { getByRole } = render(<DxcLink text="Link" href="/testPage" newWindow={true} />);
25
- expect(getByRole("link").getAttribute("target")).toEqual("_blank");
26
- });
27
-
28
- test("Link onClick called", () => {
29
- const onClick = jest.fn();
30
- const { getByText } = render(<DxcLink text="Link" onClick={onClick} />);
31
- const link = getByText("Link");
32
- fireEvent.click(link);
33
- expect(onClick).toHaveBeenCalled();
34
- });
35
-
36
- test("Disabled link onClick not called", () => {
37
- const onClick = jest.fn();
38
- const { getByText } = render(<DxcLink text="Link" onClick={onClick} disabled={true} />);
39
- const link = getByText("Link");
40
- fireEvent.click(link);
41
- expect(onClick).toHaveBeenCalledTimes(0);
42
- });
43
- });