@dxc-technology/halstack-react 0.0.0-ebb089f → 0.0.0-ebf1ceb

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 (168) hide show
  1. package/README.md +27 -47
  2. package/dist/index.d.mts +6580 -0
  3. package/dist/index.d.ts +6580 -0
  4. package/dist/index.js +14244 -0
  5. package/dist/index.mjs +14187 -0
  6. package/package.json +75 -71
  7. package/babel.config.js +0 -7
  8. package/dist/BackgroundColorContext.js +0 -46
  9. package/dist/ThemeContext.js +0 -250
  10. package/dist/V3Select/V3Select.js +0 -549
  11. package/dist/V3Select/index.d.ts +0 -27
  12. package/dist/V3Textarea/V3Textarea.js +0 -264
  13. package/dist/V3Textarea/index.d.ts +0 -27
  14. package/dist/accordion/Accordion.js +0 -353
  15. package/dist/accordion/index.d.ts +0 -28
  16. package/dist/accordion-group/AccordionGroup.js +0 -186
  17. package/dist/accordion-group/index.d.ts +0 -16
  18. package/dist/alert/Alert.js +0 -403
  19. package/dist/alert/index.d.ts +0 -51
  20. package/dist/badge/Badge.js +0 -63
  21. package/dist/box/Box.js +0 -156
  22. package/dist/box/index.d.ts +0 -25
  23. package/dist/button/Button.js +0 -238
  24. package/dist/button/Button.stories.js +0 -27
  25. package/dist/button/index.d.ts +0 -24
  26. package/dist/card/Card.js +0 -254
  27. package/dist/card/index.d.ts +0 -22
  28. package/dist/checkbox/Checkbox.js +0 -299
  29. package/dist/checkbox/index.d.ts +0 -24
  30. package/dist/chip/Chip.js +0 -265
  31. package/dist/chip/index.d.ts +0 -22
  32. package/dist/common/OpenSans.css +0 -81
  33. package/dist/common/RequiredComponent.js +0 -40
  34. package/dist/common/fonts/OpenSans-Bold.ttf +0 -0
  35. package/dist/common/fonts/OpenSans-BoldItalic.ttf +0 -0
  36. package/dist/common/fonts/OpenSans-ExtraBold.ttf +0 -0
  37. package/dist/common/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  38. package/dist/common/fonts/OpenSans-Italic.ttf +0 -0
  39. package/dist/common/fonts/OpenSans-Light.ttf +0 -0
  40. package/dist/common/fonts/OpenSans-LightItalic.ttf +0 -0
  41. package/dist/common/fonts/OpenSans-Regular.ttf +0 -0
  42. package/dist/common/fonts/OpenSans-SemiBold.ttf +0 -0
  43. package/dist/common/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
  44. package/dist/common/utils.js +0 -22
  45. package/dist/common/variables.js +0 -1574
  46. package/dist/date/Date.js +0 -379
  47. package/dist/date/index.d.ts +0 -27
  48. package/dist/date-input/DateInput.js +0 -400
  49. package/dist/date-input/index.d.ts +0 -95
  50. package/dist/dialog/Dialog.js +0 -218
  51. package/dist/dialog/index.d.ts +0 -18
  52. package/dist/dropdown/Dropdown.js +0 -544
  53. package/dist/dropdown/index.d.ts +0 -26
  54. package/dist/file-input/FileInput.js +0 -644
  55. package/dist/file-input/FileItem.js +0 -287
  56. package/dist/file-input/index.d.ts +0 -81
  57. package/dist/footer/Footer.js +0 -421
  58. package/dist/footer/Icons.js +0 -77
  59. package/dist/footer/index.d.ts +0 -25
  60. package/dist/header/Header.js +0 -470
  61. package/dist/header/Icons.js +0 -59
  62. package/dist/header/index.d.ts +0 -25
  63. package/dist/heading/Heading.js +0 -230
  64. package/dist/heading/index.d.ts +0 -17
  65. package/dist/input-text/Icons.js +0 -22
  66. package/dist/input-text/InputText.js +0 -705
  67. package/dist/input-text/index.d.ts +0 -36
  68. package/dist/layout/ApplicationLayout.js +0 -327
  69. package/dist/layout/Icons.js +0 -55
  70. package/dist/link/Link.js +0 -237
  71. package/dist/link/index.d.ts +0 -23
  72. package/dist/main.d.ts +0 -40
  73. package/dist/main.js +0 -359
  74. package/dist/number-input/NumberInput.js +0 -136
  75. package/dist/number-input/NumberInputContext.js +0 -16
  76. package/dist/number-input/index.d.ts +0 -113
  77. package/dist/paginator/Icons.js +0 -66
  78. package/dist/paginator/Paginator.js +0 -305
  79. package/dist/paginator/index.d.ts +0 -20
  80. package/dist/password-input/PasswordInput.js +0 -203
  81. package/dist/password-input/index.d.ts +0 -94
  82. package/dist/progress-bar/ProgressBar.js +0 -242
  83. package/dist/progress-bar/index.d.ts +0 -18
  84. package/dist/radio/Radio.js +0 -209
  85. package/dist/radio/index.d.ts +0 -23
  86. package/dist/resultsetTable/ResultsetTable.js +0 -358
  87. package/dist/resultsetTable/index.d.ts +0 -19
  88. package/dist/select/Select.js +0 -1137
  89. package/dist/select/index.d.ts +0 -131
  90. package/dist/sidenav/Sidenav.js +0 -179
  91. package/dist/sidenav/index.d.ts +0 -13
  92. package/dist/slider/Slider.js +0 -404
  93. package/dist/slider/index.d.ts +0 -29
  94. package/dist/spinner/Spinner.js +0 -381
  95. package/dist/spinner/index.d.ts +0 -17
  96. package/dist/switch/Switch.js +0 -222
  97. package/dist/switch/index.d.ts +0 -24
  98. package/dist/table/Table.js +0 -132
  99. package/dist/table/index.d.ts +0 -13
  100. package/dist/tabs/Tabs.js +0 -343
  101. package/dist/tabs/index.d.ts +0 -19
  102. package/dist/tag/Tag.js +0 -282
  103. package/dist/tag/index.d.ts +0 -24
  104. package/dist/text-input/TextInput.js +0 -974
  105. package/dist/text-input/index.d.ts +0 -135
  106. package/dist/textarea/Textarea.js +0 -369
  107. package/dist/textarea/index.d.ts +0 -117
  108. package/dist/toggle/Toggle.js +0 -220
  109. package/dist/toggle/index.d.ts +0 -21
  110. package/dist/toggle-group/ToggleGroup.js +0 -327
  111. package/dist/toggle-group/index.d.ts +0 -21
  112. package/dist/upload/Upload.js +0 -205
  113. package/dist/upload/buttons-upload/ButtonsUpload.js +0 -135
  114. package/dist/upload/buttons-upload/Icons.js +0 -40
  115. package/dist/upload/dragAndDropArea/DragAndDropArea.js +0 -329
  116. package/dist/upload/dragAndDropArea/Icons.js +0 -39
  117. package/dist/upload/file-upload/FileToUpload.js +0 -189
  118. package/dist/upload/file-upload/Icons.js +0 -66
  119. package/dist/upload/files-upload/FilesToUpload.js +0 -123
  120. package/dist/upload/index.d.ts +0 -15
  121. package/dist/upload/transaction/Icons.js +0 -160
  122. package/dist/upload/transaction/Transaction.js +0 -148
  123. package/dist/upload/transactions/Transactions.js +0 -138
  124. package/dist/useTheme.js +0 -22
  125. package/dist/wizard/Icons.js +0 -65
  126. package/dist/wizard/Wizard.js +0 -405
  127. package/dist/wizard/index.d.ts +0 -18
  128. package/test/Accordion.test.js +0 -33
  129. package/test/AccordionGroup.test.js +0 -125
  130. package/test/Alert.test.js +0 -53
  131. package/test/Box.test.js +0 -10
  132. package/test/Button.test.js +0 -18
  133. package/test/Card.test.js +0 -30
  134. package/test/Checkbox.test.js +0 -45
  135. package/test/Chip.test.js +0 -25
  136. package/test/Date.test.js +0 -395
  137. package/test/DateInput.test.js +0 -242
  138. package/test/Dialog.test.js +0 -23
  139. package/test/Dropdown.test.js +0 -145
  140. package/test/FileInput.test.js +0 -201
  141. package/test/Footer.test.js +0 -94
  142. package/test/Header.test.js +0 -34
  143. package/test/Heading.test.js +0 -83
  144. package/test/InputText.test.js +0 -239
  145. package/test/Link.test.js +0 -43
  146. package/test/NumberInput.test.js +0 -259
  147. package/test/Paginator.test.js +0 -181
  148. package/test/PasswordInput.test.js +0 -83
  149. package/test/ProgressBar.test.js +0 -35
  150. package/test/Radio.test.js +0 -37
  151. package/test/ResultsetTable.test.js +0 -330
  152. package/test/Select.test.js +0 -928
  153. package/test/Sidenav.test.js +0 -45
  154. package/test/Slider.test.js +0 -74
  155. package/test/Spinner.test.js +0 -32
  156. package/test/Switch.test.js +0 -45
  157. package/test/Table.test.js +0 -36
  158. package/test/Tabs.test.js +0 -109
  159. package/test/Tag.test.js +0 -32
  160. package/test/TextInput.test.js +0 -731
  161. package/test/Textarea.test.js +0 -193
  162. package/test/ToggleGroup.test.js +0 -85
  163. package/test/Upload.test.js +0 -60
  164. package/test/V3Select.test.js +0 -212
  165. package/test/V3TextArea.test.js +0 -51
  166. package/test/Wizard.test.js +0 -130
  167. package/test/mocks/pngMock.js +0 -1
  168. 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,83 +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("Heading renders with default level", () => {
7
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test"></DxcHeading>);
8
- expect(getByText("my-heading-test")).toBeTruthy();
9
- expect(getByRole("heading", { level: 1 })).toBeTruthy();
10
- });
11
-
12
- test("Heading renders with level 1", () => {
13
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={1}></DxcHeading>);
14
- expect(getByText("my-heading-test")).toBeTruthy();
15
- expect(getByRole("heading", { level: 1 })).toBeTruthy();
16
- });
17
-
18
- test("Heading renders with level 2", () => {
19
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={2}></DxcHeading>);
20
- expect(getByText("my-heading-test")).toBeTruthy();
21
- expect(getByRole("heading", { level: 2 })).toBeTruthy();
22
- });
23
-
24
- test("Heading renders with level 3", () => {
25
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={3}></DxcHeading>);
26
- expect(getByText("my-heading-test")).toBeTruthy();
27
- expect(getByRole("heading", { level: 3 })).toBeTruthy();
28
- });
29
-
30
- test("Heading renders with level 4", () => {
31
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={4}></DxcHeading>);
32
- expect(getByText("my-heading-test")).toBeTruthy();
33
- expect(getByRole("heading", { level: 4 })).toBeTruthy();
34
- });
35
-
36
- test("Heading renders with level 5", () => {
37
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={5}></DxcHeading>);
38
- expect(getByText("my-heading-test")).toBeTruthy();
39
- expect(getByRole("heading", { level: 5 })).toBeTruthy();
40
- });
41
-
42
- test("Heading renders with default level and as h5", () => {
43
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" as="h5"></DxcHeading>);
44
- expect(getByText("my-heading-test")).toBeTruthy();
45
- expect(getByRole("heading", { level: 5 })).toBeTruthy();
46
- });
47
-
48
- test("Heading renders with level 1 and as h5", () => {
49
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={1} as="h5"></DxcHeading>);
50
- expect(getByText("my-heading-test")).toBeTruthy();
51
- expect(getByRole("heading", { level: 5 })).toBeTruthy();
52
- });
53
-
54
- test("Heading renders with level 2 and as h4", () => {
55
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={2} as="h4"></DxcHeading>);
56
- expect(getByText("my-heading-test")).toBeTruthy();
57
- expect(getByRole("heading", { level: 4 })).toBeTruthy();
58
- });
59
-
60
- test("Heading renders with level 3 and as h2", () => {
61
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={3} as="h2"></DxcHeading>);
62
- expect(getByText("my-heading-test")).toBeTruthy();
63
- expect(getByRole("heading", { level: 2 })).toBeTruthy();
64
- });
65
-
66
- test("Heading renders with level 4 and as h3", () => {
67
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={4} as="h3"></DxcHeading>);
68
- expect(getByText("my-heading-test")).toBeTruthy();
69
- expect(getByRole("heading", { level: 3 })).toBeTruthy();
70
- });
71
-
72
- test("Heading renders with level 5 as h4", () => {
73
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={5} as="h4"></DxcHeading>);
74
- expect(getByText("my-heading-test")).toBeTruthy();
75
- expect(getByRole("heading", { level: 4 })).toBeTruthy();
76
- });
77
-
78
- test("Heading renders with level 5 and invalid as", () => {
79
- const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={5} as="h4afdssf"></DxcHeading>);
80
- expect(getByText("my-heading-test")).toBeTruthy();
81
- expect(getByRole("heading", { level: 5 })).toBeTruthy();
82
- });
83
- });
@@ -1,239 +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 DxcInputText 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
- constructor() {
18
- this.placements = PopperJS.placements;
19
- return {
20
- destroy: () => {},
21
- scheduleUpdate: () => {},
22
- update: () => {},
23
- };
24
- }
25
- };
26
- });
27
-
28
- describe("InputText component tests", () => {
29
- test("Input renders with correct label", () => {
30
- const { getByText } = render(<DxcInputText label="Input label" />);
31
- expect(getByText("Input label")).toBeTruthy();
32
- });
33
-
34
- test("onChange function is called correctly", () => {
35
- const onChange = jest.fn();
36
- const { getByRole } = render(<DxcInputText label="Input label" onChange={onChange} />);
37
- const input = getByRole("textbox");
38
- userEvent.type(input, "20000");
39
- expect(onChange).toHaveBeenCalled();
40
- expect(onChange).toHaveBeenCalledWith("20000");
41
- });
42
- test("onBlur function is called correctly", () => {
43
- const onBlur = jest.fn();
44
- const onChange = jest.fn();
45
-
46
- const { getByRole } = render(<DxcInputText label="Input label" onChange={onChange} onBlur={onBlur} />);
47
- const input = getByRole("textbox");
48
- userEvent.type(input, "Test value");
49
- fireEvent.blur(input);
50
- expect(onBlur).toHaveBeenCalled();
51
- expect(onBlur).toHaveBeenCalledWith("Test value");
52
- });
53
-
54
- test("Uncontrolled component", () => {
55
- const onChange = jest.fn();
56
- const { getByRole } = render(<DxcInputText label="Input label" onChange={onChange} />);
57
- const input = getByRole("textbox");
58
- userEvent.type(input, "20000");
59
- expect(onChange).toHaveBeenCalled();
60
- expect(onChange).toHaveBeenCalledWith("20000");
61
- expect(input.value).toBe("20000");
62
- });
63
-
64
- test("Controlled component", () => {
65
- const onChange = jest.fn();
66
- const onBlur = jest.fn();
67
- const { getByRole } = render(
68
- <DxcInputText label="Input label" value="Test value" onChange={onChange} onBlur={onBlur} />
69
- );
70
- const input = getByRole("textbox");
71
- userEvent.type(input, "20000");
72
- expect(onChange).toHaveBeenCalled();
73
- expect(input.value).toBe("Test value");
74
- fireEvent.blur(input);
75
- expect(onBlur).toHaveBeenCalled();
76
- expect(onBlur).toHaveBeenCalledWith("Test value");
77
- });
78
- test("Prefix icon onClick", () => {
79
- const onClick = jest.fn();
80
- const { getByRole } = render(<DxcInputText label="Input label" prefixIconSrc={icon} onClickPrefix={onClick} />);
81
- const prefixIcon = getByRole("img");
82
- userEvent.click(prefixIcon);
83
- expect(onClick).toHaveBeenCalled();
84
- });
85
- test("Suffix icon onClick", () => {
86
- const onClick = jest.fn();
87
- const { getByRole } = render(<DxcInputText label="Input label" suffixIconSrc={icon} onClickSuffix={onClick} />);
88
- const suffixIcon = getByRole("img");
89
- userEvent.click(suffixIcon);
90
- expect(onClick).toHaveBeenCalled();
91
- });
92
- });
93
-
94
- describe("Autocomplete component Synchronous tests", () => {
95
- test("Autocomplete no matches found is shown", async () => {
96
- const onChangeAtocomplete = jest.fn();
97
- render(
98
- <DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
99
- );
100
- const input = screen.getByRole("textbox");
101
- fireEvent.focus(input);
102
- expect(screen.getByText("Andorra")).toBeTruthy();
103
- userEvent.type(input, "X");
104
- expect(screen.getByText("No matches found.")).toBeTruthy();
105
- });
106
-
107
- test("Autocomplete suggestions are shown", async () => {
108
- const onChangeAtocomplete = jest.fn();
109
- render(
110
- <DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
111
- );
112
- const input = screen.getByRole("textbox");
113
- fireEvent.focus(input);
114
- expect(screen.getByText("Andorra")).toBeTruthy();
115
- });
116
-
117
- test("Autocomplete UNCONTROLLED suggestion selected", async () => {
118
- const onChangeAtocomplete = jest.fn();
119
- render(
120
- <DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
121
- );
122
- const input = screen.getByRole("textbox");
123
- fireEvent.focus(input);
124
- expect(screen.getByText("Andorra")).toBeTruthy();
125
- userEvent.type(screen.getByRole("textbox"), "Alb");
126
- expect(onChangeAtocomplete).toHaveBeenCalled();
127
- expect(screen.getByText("Albania")).toBeTruthy();
128
- const suggestion1 = screen.getByText("Albania");
129
- act(() => {
130
- userEvent.click(suggestion1);
131
- });
132
-
133
- // expect(onChangeAtocomplete).toHaveBeenCalledWith("Albania");
134
- expect(screen.getByRole("textbox").value).toBe("Albania");
135
- });
136
-
137
- test("Autocomplete CONTROLLED suggestions selected", async () => {
138
- const onChangeAtocomplete = jest.fn();
139
- render(
140
- <DxcInputText
141
- label="Autocomplete Countries"
142
- value="Andorra"
143
- autocompleteOptions={countries}
144
- onChange={onChangeAtocomplete}
145
- />
146
- );
147
- const input = screen.getByRole("textbox");
148
- fireEvent.focus(input);
149
- expect(screen.getByText("Andorra")).toBeTruthy();
150
-
151
- expect(screen.getByText("Andorra")).toBeTruthy();
152
- const suggestion1 = screen.getByText("Andorra");
153
- act(() => {
154
- userEvent.click(suggestion1);
155
- });
156
-
157
- expect(onChangeAtocomplete).toHaveBeenCalledWith("Andorra");
158
- });
159
- });
160
-
161
- describe("InputText component Asynchronous Autocomplete tests", () => {
162
- test("Autocomplete Searching is shown", async () => {
163
- const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 1000)));
164
-
165
- const onChangeAtocomplete = jest.fn();
166
- render(
167
- <DxcInputText label="Autocomplete Countries" autocompleteOptions={callbackFunc} onChange={onChangeAtocomplete} />
168
- );
169
- const input = screen.getByRole("textbox");
170
- fireEvent.focus(input);
171
- await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
172
- expect(screen.getByText("Italy")).toBeTruthy();
173
- expect(screen.getByText("Spain")).toBeTruthy();
174
- });
175
-
176
- test("Asynchronous UNCONTROLLED autocomplete tests", async () => {
177
- const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 1000)));
178
- const onChangeAtocomplete = jest.fn();
179
- render(
180
- <DxcInputText label="Autocomplete Countries" onChange={onChangeAtocomplete} autocompleteOptions={callbackFunc} />
181
- );
182
- const input = screen.getByRole("textbox");
183
- fireEvent.focus(input);
184
- userEvent.type(input, "And");
185
- await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
186
- expect(screen.getByText("Italy")).toBeTruthy();
187
- expect(screen.getByText("Spain")).toBeTruthy();
188
- const suggestion1 = screen.getByText("Spain");
189
- act(() => {
190
- userEvent.click(suggestion1);
191
- });
192
- expect(onChangeAtocomplete).toHaveBeenCalledWith("Spain");
193
- expect(screen.getByRole("textbox").value).toBe("Spain");
194
- });
195
-
196
- test("Asynchronous CONTROLLED autocomplete tests", async () => {
197
- const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 3000)));
198
- const onChangeAtocomplete = jest.fn();
199
- render(
200
- <DxcInputText
201
- label="Autocomplete Countries"
202
- value="test value"
203
- onChange={onChangeAtocomplete}
204
- autocompleteOptions={callbackFunc}
205
- />
206
- );
207
- const input = screen.getByRole("textbox");
208
- fireEvent.focus(input);
209
- userEvent.type(input, "And");
210
- await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
211
- expect(screen.getByText("Italy")).toBeTruthy();
212
- expect(screen.getByText("Spain")).toBeTruthy();
213
- const suggestion1 = screen.getByText("Spain");
214
- act(() => {
215
- userEvent.click(suggestion1);
216
- });
217
- expect(onChangeAtocomplete).toHaveBeenCalledWith("Spain");
218
- expect(screen.getByRole("textbox").value).toBe("test value");
219
- });
220
-
221
- test("Asynchronous autocomplete request failed", async () => {
222
- const errorCallbackFunc = jest.fn(() => new Promise((resolve, reject) => setTimeout(reject("E"), 3000)));
223
- const onChangeAtocomplete = jest.fn();
224
-
225
- render(
226
- <DxcInputText
227
- label="Autocomplete Countries"
228
- value="test value"
229
- onChange={onChangeAtocomplete}
230
- autocompleteOptions={errorCallbackFunc}
231
- />
232
- );
233
-
234
- const input = screen.getByRole("textbox");
235
- fireEvent.focus(input);
236
- await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
237
- expect(screen.getByText("Error fetching data")).toBeTruthy();
238
- });
239
- });
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
- });