@dxc-technology/halstack-react 0.0.0-4727df3 → 0.0.0-4970b2f

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 (252) 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/{dist/card → card}/Card.js +19 -73
  28. package/card/index.d.ts +22 -0
  29. package/checkbox/Checkbox.d.ts +4 -0
  30. package/{dist/checkbox → checkbox}/Checkbox.js +16 -63
  31. package/checkbox/types.d.ts +60 -0
  32. package/checkbox/types.js +5 -0
  33. package/{dist/chip → chip}/Chip.js +17 -61
  34. package/chip/index.d.ts +22 -0
  35. package/{dist/common → common}/OpenSans.css +0 -0
  36. package/{dist/common → common}/RequiredComponent.js +3 -11
  37. package/{dist/common → common}/fonts/OpenSans-Bold.ttf +0 -0
  38. package/{dist/common → common}/fonts/OpenSans-BoldItalic.ttf +0 -0
  39. package/{dist/common → common}/fonts/OpenSans-ExtraBold.ttf +0 -0
  40. package/{dist/common → common}/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  41. package/{dist/common → common}/fonts/OpenSans-Italic.ttf +0 -0
  42. package/{dist/common → common}/fonts/OpenSans-Light.ttf +0 -0
  43. package/{dist/common → common}/fonts/OpenSans-LightItalic.ttf +0 -0
  44. package/{dist/common → common}/fonts/OpenSans-Regular.ttf +0 -0
  45. package/{dist/common → common}/fonts/OpenSans-SemiBold.ttf +0 -0
  46. package/{dist/common → common}/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
  47. package/{dist/common → common}/utils.js +0 -0
  48. package/{dist/common → common}/variables.js +131 -131
  49. package/{dist/date → date}/Date.js +21 -27
  50. package/date/index.d.ts +27 -0
  51. package/date-input/DateInput.d.ts +4 -0
  52. package/{dist/date-input → date-input}/DateInput.js +22 -61
  53. package/date-input/types.d.ts +100 -0
  54. package/date-input/types.js +5 -0
  55. package/{dist/dialog → dialog}/Dialog.js +16 -50
  56. package/dialog/index.d.ts +18 -0
  57. package/{dist/dropdown → dropdown}/Dropdown.js +37 -131
  58. package/dropdown/index.d.ts +26 -0
  59. package/{dist/file-input → file-input}/FileInput.js +49 -161
  60. package/{dist/file-input → file-input}/FileItem.js +36 -123
  61. package/{dist/file-input → file-input}/index.d.ts +1 -1
  62. package/{dist/footer → footer}/Footer.js +34 -158
  63. package/{dist/footer → footer}/Icons.js +13 -13
  64. package/footer/index.d.ts +25 -0
  65. package/{dist/header → header}/Header.js +62 -170
  66. package/{dist/header → header}/Icons.js +11 -11
  67. package/header/index.d.ts +25 -0
  68. package/{dist/heading → heading}/Heading.js +30 -72
  69. package/heading/index.d.ts +17 -0
  70. package/{dist/input-text → input-text}/Icons.js +2 -2
  71. package/{dist/input-text → input-text}/InputText.js +36 -130
  72. package/input-text/index.d.ts +36 -0
  73. package/{dist/layout → layout}/ApplicationLayout.js +35 -131
  74. package/layout/Icons.js +55 -0
  75. package/{dist/link → link}/Link.js +18 -72
  76. package/link/index.d.ts +23 -0
  77. package/main.d.ts +44 -0
  78. package/{dist/main.js → main.js} +93 -97
  79. package/{dist/number-input → number-input}/NumberInput.js +5 -13
  80. package/{dist/number-input → number-input}/NumberInputContext.js +1 -1
  81. package/{dist/number-input → number-input}/index.d.ts +0 -0
  82. package/package.json +32 -25
  83. package/paginator/Icons.js +66 -0
  84. package/paginator/Paginator.d.ts +4 -0
  85. package/paginator/Paginator.js +198 -0
  86. package/paginator/types.d.ts +38 -0
  87. package/paginator/types.js +5 -0
  88. package/{dist/password-input → password-input}/PasswordInput.js +23 -22
  89. package/password-input/PasswordInput.stories.jsx +131 -0
  90. package/{dist/password-input → password-input}/index.d.ts +0 -0
  91. package/{dist/progress-bar → progress-bar}/ProgressBar.js +18 -72
  92. package/progress-bar/index.d.ts +18 -0
  93. package/radio/Radio.d.ts +4 -0
  94. package/{dist/radio → radio}/Radio.js +15 -50
  95. package/radio/types.d.ts +54 -0
  96. package/radio/types.js +5 -0
  97. package/{dist/resultsetTable → resultsetTable}/ResultsetTable.js +35 -119
  98. package/resultsetTable/index.d.ts +19 -0
  99. package/select/Select.js +865 -0
  100. package/select/index.d.ts +131 -0
  101. package/{dist/sidenav → sidenav}/Sidenav.js +15 -49
  102. package/sidenav/index.d.ts +13 -0
  103. package/{dist/slider → slider}/Slider.js +33 -87
  104. package/slider/index.d.ts +29 -0
  105. package/{dist/spinner → spinner}/Spinner.js +38 -152
  106. package/spinner/index.d.ts +17 -0
  107. package/switch/Switch.d.ts +4 -0
  108. package/{dist/switch → switch}/Switch.js +26 -69
  109. package/switch/types.d.ts +58 -0
  110. package/switch/types.js +5 -0
  111. package/{dist/table → table}/Table.js +10 -24
  112. package/table/index.d.ts +13 -0
  113. package/{dist/tabs → tabs}/Tabs.js +26 -110
  114. package/tabs/index.d.ts +19 -0
  115. package/{dist/tag → tag}/Tag.js +22 -96
  116. package/tag/index.d.ts +24 -0
  117. package/{dist/text-input → text-input}/TextInput.js +244 -390
  118. package/{dist/text-input → text-input}/index.d.ts +0 -0
  119. package/{dist/textarea → textarea}/Textarea.js +20 -72
  120. package/{dist/textarea → textarea}/index.d.ts +0 -0
  121. package/{dist/toggle → toggle}/Toggle.js +15 -49
  122. package/toggle/index.d.ts +21 -0
  123. package/{dist/toggle-group → toggle-group}/ToggleGroup.js +23 -107
  124. package/toggle-group/index.d.ts +21 -0
  125. package/{dist/upload → upload}/Upload.js +14 -18
  126. package/upload/buttons-upload/ButtonsUpload.js +111 -0
  127. package/upload/buttons-upload/Icons.js +40 -0
  128. package/upload/dragAndDropArea/DragAndDropArea.js +225 -0
  129. package/upload/dragAndDropArea/Icons.js +39 -0
  130. package/upload/file-upload/FileToUpload.js +115 -0
  131. package/upload/file-upload/Icons.js +66 -0
  132. package/{dist/upload → upload}/files-upload/FilesToUpload.js +12 -26
  133. package/upload/index.d.ts +15 -0
  134. package/upload/transaction/Icons.js +160 -0
  135. package/upload/transaction/Transaction.js +104 -0
  136. package/upload/transactions/Transactions.js +94 -0
  137. package/{dist/useTheme.js → useTheme.js} +0 -0
  138. package/wizard/Icons.js +65 -0
  139. package/{dist/wizard → wizard}/Wizard.js +32 -172
  140. package/wizard/index.d.ts +18 -0
  141. package/README.md +0 -66
  142. package/babel.config.js +0 -8
  143. package/dist/BackgroundColorContext.js +0 -46
  144. package/dist/ThemeContext.js +0 -248
  145. package/dist/accordion-group/AccordionGroup.js +0 -186
  146. package/dist/alert/index.d.ts +0 -51
  147. package/dist/badge/Badge.js +0 -63
  148. package/dist/checkbox/Checkbox.stories.js +0 -144
  149. package/dist/checkbox/readme.md +0 -116
  150. package/dist/date/Date.stories.js +0 -205
  151. package/dist/date/readme.md +0 -73
  152. package/dist/date-input/index.d.ts +0 -95
  153. package/dist/layout/facebook.svg +0 -45
  154. package/dist/layout/linkedin.svg +0 -50
  155. package/dist/layout/twitter.svg +0 -53
  156. package/dist/link/readme.md +0 -51
  157. package/dist/main.d.ts +0 -8
  158. package/dist/new-select/NewSelect.js +0 -836
  159. package/dist/new-select/index.d.ts +0 -53
  160. package/dist/paginator/Paginator.js +0 -289
  161. package/dist/paginator/images/next.svg +0 -3
  162. package/dist/paginator/images/nextPage.svg +0 -3
  163. package/dist/paginator/images/previous.svg +0 -3
  164. package/dist/paginator/images/previousPage.svg +0 -3
  165. package/dist/paginator/readme.md +0 -50
  166. package/dist/progress-bar/ProgressBar.stories.js +0 -280
  167. package/dist/progress-bar/readme.md +0 -63
  168. package/dist/radio/Radio.stories.js +0 -166
  169. package/dist/radio/readme.md +0 -70
  170. package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
  171. package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
  172. package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
  173. package/dist/slider/readme.md +0 -64
  174. package/dist/spinner/Spinner.stories.js +0 -183
  175. package/dist/spinner/readme.md +0 -65
  176. package/dist/switch/Switch.stories.js +0 -134
  177. package/dist/switch/readme.md +0 -133
  178. package/dist/tabs/Tabs.stories.js +0 -130
  179. package/dist/tabs/readme.md +0 -78
  180. package/dist/tabs-for-sections/TabsForSections.js +0 -92
  181. package/dist/tabs-for-sections/readme.md +0 -78
  182. package/dist/toggle/Toggle.stories.js +0 -297
  183. package/dist/toggle/readme.md +0 -80
  184. package/dist/upload/Upload.stories.js +0 -72
  185. package/dist/upload/buttons-upload/ButtonsUpload.js +0 -139
  186. package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
  187. package/dist/upload/buttons-upload/upload-button.svg +0 -1
  188. package/dist/upload/dragAndDropArea/DragAndDropArea.js +0 -329
  189. package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
  190. package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
  191. package/dist/upload/file-upload/FileToUpload.js +0 -184
  192. package/dist/upload/file-upload/audio-icon.svg +0 -4
  193. package/dist/upload/file-upload/close.svg +0 -4
  194. package/dist/upload/file-upload/file-icon.svg +0 -4
  195. package/dist/upload/file-upload/video-icon.svg +0 -4
  196. package/dist/upload/readme.md +0 -37
  197. package/dist/upload/transaction/Transaction.js +0 -175
  198. package/dist/upload/transaction/audio-icon-err.svg +0 -4
  199. package/dist/upload/transaction/audio-icon.svg +0 -4
  200. package/dist/upload/transaction/error-icon.svg +0 -4
  201. package/dist/upload/transaction/file-icon-err.svg +0 -4
  202. package/dist/upload/transaction/file-icon.svg +0 -4
  203. package/dist/upload/transaction/image-icon-err.svg +0 -4
  204. package/dist/upload/transaction/image-icon.svg +0 -4
  205. package/dist/upload/transaction/success-icon.svg +0 -4
  206. package/dist/upload/transaction/video-icon-err.svg +0 -4
  207. package/dist/upload/transaction/video-icon.svg +0 -4
  208. package/dist/upload/transactions/Transactions.js +0 -138
  209. package/dist/wizard/invalid_icon.svg +0 -5
  210. package/dist/wizard/valid_icon.svg +0 -5
  211. package/dist/wizard/validation-wrong.svg +0 -6
  212. package/test/Accordion.test.js +0 -33
  213. package/test/AccordionGroup.test.js +0 -125
  214. package/test/Alert.test.js +0 -53
  215. package/test/Box.test.js +0 -10
  216. package/test/Button.test.js +0 -18
  217. package/test/Card.test.js +0 -30
  218. package/test/Checkbox.test.js +0 -45
  219. package/test/Chip.test.js +0 -25
  220. package/test/Date.test.js +0 -397
  221. package/test/DateInput.test.js +0 -242
  222. package/test/Dialog.test.js +0 -23
  223. package/test/Dropdown.test.js +0 -145
  224. package/test/FileInput.test.js +0 -201
  225. package/test/Footer.test.js +0 -94
  226. package/test/Header.test.js +0 -34
  227. package/test/Heading.test.js +0 -35
  228. package/test/InputText.test.js +0 -248
  229. package/test/Link.test.js +0 -43
  230. package/test/NumberInput.test.js +0 -259
  231. package/test/Paginator.test.js +0 -177
  232. package/test/PasswordInput.test.js +0 -83
  233. package/test/ProgressBar.test.js +0 -35
  234. package/test/Radio.test.js +0 -37
  235. package/test/ResultsetTable.test.js +0 -329
  236. package/test/Select.test.js +0 -212
  237. package/test/Sidenav.test.js +0 -45
  238. package/test/Slider.test.js +0 -82
  239. package/test/Spinner.test.js +0 -32
  240. package/test/Switch.test.js +0 -45
  241. package/test/Table.test.js +0 -36
  242. package/test/Tabs.test.js +0 -109
  243. package/test/TabsForSections.test.js +0 -34
  244. package/test/Tag.test.js +0 -32
  245. package/test/TextInput.test.js +0 -732
  246. package/test/Textarea.test.js +0 -193
  247. package/test/ToggleGroup.test.js +0 -85
  248. package/test/Upload.test.js +0 -60
  249. package/test/V3TextArea.test.js +0 -51
  250. package/test/Wizard.test.js +0 -130
  251. package/test/mocks/pngMock.js +0 -1
  252. package/test/mocks/svgMock.js +0 -1
@@ -1,94 +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 { getByTitle } = render(<DxcFooter></DxcFooter>);
9
- expect(getByTitle("DXC Logo")).toBeTruthy();
10
- });
11
-
12
- test("Footer renders with social links", () => {
13
- const social = [
14
- {
15
- href: "https://www.test.com/test",
16
- logoSrc: icon,
17
- },
18
- ];
19
- const { getByRole } = render(<DxcFooter socialLinks={social}></DxcFooter>);
20
- const socialIcon = getByRole("link");
21
- expect(socialIcon.getAttribute("href")).toBe("https://www.test.com/test");
22
- });
23
-
24
- test("Footer renders with bottom links", () => {
25
- const bottom = [
26
- {
27
- href: "https://www.test.com/test",
28
- text: "bottom-link-text",
29
- },
30
- ];
31
- const { getByText } = render(<DxcFooter bottomLinks={bottom}></DxcFooter>);
32
- const link = getByText("bottom-link-text");
33
- expect(link.getAttribute("href")).toBe("https://www.test.com/test");
34
- });
35
-
36
- test("Footer renders with copyright text", () => {
37
- const { getByText } = render(<DxcFooter copyright="test-copyright"></DxcFooter>);
38
- expect(getByText("test-copyright")).toBeTruthy();
39
- });
40
-
41
- test("Footer renders with correct children", () => {
42
- //We need to force the offsetWidth value
43
- Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, value: 1024 });
44
-
45
- const { getByText } = render(
46
- <DxcFooter>
47
- <p>footer-child-text</p>
48
- </DxcFooter>
49
- );
50
-
51
- expect(getByText("footer-child-text")).toBeTruthy();
52
- });
53
-
54
- test("Footer renders without children in mobile", () => {
55
- //425 is mobile width
56
- Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, value: 425 });
57
-
58
- const { queryByText } = render(
59
- <DxcFooter>
60
- <p>footer-child-text</p>
61
- </DxcFooter>
62
- );
63
-
64
- expect(queryByText("footer-child-text")).toBeFalsy();
65
- });
66
-
67
- test("Footer is fully rendered", () => {
68
- Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, value: 1024 });
69
-
70
- const social = [
71
- {
72
- href: "https://www.test.com/social",
73
- logoSrc: icon,
74
- },
75
- ];
76
- const bottom = [
77
- {
78
- href: "https://www.test.com/bottom",
79
- text: "bottom-link-text",
80
- },
81
- ];
82
- const { getAllByRole, getByText } = render(
83
- <DxcFooter socialLinks={social} bottomLinks={bottom} copyright="test-copyright">
84
- <p>footer-child-text</p>
85
- </DxcFooter>
86
- );
87
- const socialIcon = getAllByRole("link")[0];
88
- expect(socialIcon.getAttribute("href")).toBe("https://www.test.com/social");
89
- const bottomLink = getByText("bottom-link-text");
90
- expect(bottomLink.getAttribute("href")).toBe("https://www.test.com/bottom");
91
- expect(getByText("test-copyright")).toBeTruthy();
92
- expect(getByText("footer-child-text")).toBeTruthy();
93
- });
94
- });
@@ -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
- });