@dxc-technology/halstack-react 0.0.0-5908eb4 → 0.0.0-5b2ad05
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.
- package/dist/ThemeContext.js +134 -100
- package/dist/V3Select/V3Select.js +549 -0
- package/dist/V3Textarea/V3Textarea.js +264 -0
- package/dist/accordion/Accordion.js +66 -59
- package/dist/accordion-group/AccordionGroup.js +1 -3
- package/dist/alert/Alert.js +126 -111
- package/dist/alert/index.d.ts +51 -0
- package/dist/box/Box.js +1 -9
- package/dist/button/Button.js +33 -27
- package/dist/checkbox/Checkbox.js +26 -21
- package/dist/chip/Chip.js +21 -25
- package/dist/common/variables.js +808 -535
- package/dist/date/Date.js +13 -15
- package/dist/{new-date/NewDate.js → date-input/DateInput.js} +85 -76
- package/dist/date-input/index.d.ts +95 -0
- package/dist/dialog/Dialog.js +15 -32
- package/dist/dropdown/Dropdown.js +117 -66
- package/dist/file-input/FileInput.js +644 -0
- package/dist/file-input/FileItem.js +280 -0
- package/dist/file-input/index.d.ts +81 -0
- package/dist/footer/Footer.js +63 -49
- package/dist/footer/Icons.js +77 -0
- package/dist/header/Header.js +123 -84
- package/dist/header/Icons.js +59 -0
- package/dist/heading/Heading.js +13 -5
- package/dist/input-text/Icons.js +22 -0
- package/dist/input-text/InputText.js +96 -63
- package/dist/layout/ApplicationLayout.js +5 -9
- package/dist/layout/Icons.js +55 -0
- package/dist/link/Link.js +4 -8
- package/dist/main.d.ts +8 -0
- package/dist/main.js +45 -29
- package/dist/{number/Number.js → number-input/NumberInput.js} +28 -19
- package/dist/{number/NumberContext.js → number-input/NumberInputContext.js} +2 -2
- package/dist/number-input/index.d.ts +113 -0
- package/dist/paginator/Icons.js +66 -0
- package/dist/paginator/Paginator.js +17 -17
- package/dist/password-input/PasswordInput.js +198 -0
- package/dist/password-input/index.d.ts +94 -0
- package/dist/progress-bar/ProgressBar.js +63 -27
- package/dist/select/Select.js +869 -347
- package/dist/select/index.d.ts +53 -0
- package/dist/sidenav/Sidenav.js +11 -15
- package/dist/slider/Slider.js +155 -66
- package/dist/spinner/Spinner.js +225 -58
- package/dist/table/Table.js +5 -1
- package/dist/tag/Tag.js +37 -35
- package/dist/{new-input-text/NewInputText.js → text-input/TextInput.js} +241 -199
- package/dist/text-input/index.d.ts +135 -0
- package/dist/textarea/Textarea.js +233 -124
- package/dist/textarea/index.d.ts +117 -0
- package/dist/toggle-group/ToggleGroup.js +130 -44
- package/dist/upload/Upload.js +3 -3
- package/dist/upload/buttons-upload/ButtonsUpload.js +12 -12
- package/dist/upload/buttons-upload/Icons.js +40 -0
- package/dist/upload/dragAndDropArea/DragAndDropArea.js +23 -19
- package/dist/upload/dragAndDropArea/Icons.js +39 -0
- package/dist/upload/file-upload/FileToUpload.js +27 -22
- package/dist/upload/file-upload/Icons.js +66 -0
- package/dist/upload/transaction/Icons.js +160 -0
- package/dist/upload/transaction/Transaction.js +18 -41
- package/dist/upload/transactions/Transactions.js +11 -11
- package/dist/wizard/Icons.js +65 -0
- package/dist/wizard/Wizard.js +11 -17
- package/package.json +6 -9
- package/test/Date.test.js +48 -44
- package/test/{NewDate.test.js → DateInput.test.js} +86 -33
- package/test/Dropdown.test.js +15 -0
- package/test/FileInput.test.js +201 -0
- package/test/Footer.test.js +2 -7
- package/test/Header.test.js +5 -10
- package/test/Heading.test.js +60 -12
- package/test/InputText.test.js +24 -16
- package/test/NumberInput.test.js +259 -0
- package/test/Paginator.test.js +1 -1
- package/test/PasswordInput.test.js +83 -0
- package/test/ResultsetTable.test.js +1 -2
- package/test/Slider.test.js +9 -17
- package/test/Spinner.test.js +5 -0
- package/test/TextInput.test.js +732 -0
- package/test/Textarea.test.js +193 -0
- package/test/ToggleGroup.test.js +5 -1
- package/test/Upload.test.js +5 -5
- package/test/{Select.test.js → V3Select.test.js} +56 -36
- package/test/{TextArea.test.js → V3TextArea.test.js} +6 -7
- package/dist/accordion/Accordion.stories.js +0 -207
- package/dist/accordion/readme.md +0 -96
- package/dist/accordion-group/AccordionGroup.stories.js +0 -207
- package/dist/accordion-group/readme.md +0 -70
- package/dist/alert/Alert.stories.js +0 -158
- package/dist/alert/close.svg +0 -4
- package/dist/alert/error.svg +0 -4
- package/dist/alert/info.svg +0 -4
- package/dist/alert/readme.md +0 -43
- package/dist/alert/success.svg +0 -4
- package/dist/alert/warning.svg +0 -4
- package/dist/button/Button.stories.js +0 -224
- package/dist/button/readme.md +0 -93
- package/dist/checkbox/Checkbox.stories.js +0 -144
- package/dist/checkbox/readme.md +0 -116
- package/dist/date/Date.stories.js +0 -205
- package/dist/date/readme.md +0 -73
- package/dist/dialog/Dialog.stories.js +0 -217
- package/dist/dialog/readme.md +0 -32
- package/dist/dropdown/Dropdown.stories.js +0 -249
- package/dist/dropdown/baseline-arrow_drop_down.svg +0 -1
- package/dist/dropdown/baseline-arrow_drop_down_wh.svg +0 -4
- package/dist/dropdown/baseline-arrow_drop_up.svg +0 -1
- package/dist/dropdown/baseline-arrow_drop_up_wh.svg +0 -4
- package/dist/dropdown/readme.md +0 -69
- package/dist/footer/Footer.stories.js +0 -94
- package/dist/footer/dxc_logo.svg +0 -15
- package/dist/footer/readme.md +0 -41
- package/dist/header/Header.stories.js +0 -176
- package/dist/header/close_icon.svg +0 -1
- package/dist/header/dxc_logo_black.svg +0 -8
- package/dist/header/hamb_menu_black.svg +0 -1
- package/dist/header/hamb_menu_white.svg +0 -1
- package/dist/header/readme.md +0 -33
- package/dist/input-text/InputText.stories.js +0 -209
- package/dist/input-text/error.svg +0 -1
- package/dist/input-text/readme.md +0 -91
- package/dist/layout/facebook.svg +0 -45
- package/dist/layout/linkedin.svg +0 -50
- package/dist/layout/twitter.svg +0 -53
- package/dist/link/readme.md +0 -51
- package/dist/paginator/images/next.svg +0 -3
- package/dist/paginator/images/nextPage.svg +0 -3
- package/dist/paginator/images/previous.svg +0 -3
- package/dist/paginator/images/previousPage.svg +0 -3
- package/dist/paginator/readme.md +0 -50
- package/dist/password/Password.js +0 -139
- package/dist/password/styles.css +0 -3
- package/dist/progress-bar/ProgressBar.stories.js +0 -280
- package/dist/progress-bar/readme.md +0 -63
- package/dist/radio/Radio.stories.js +0 -166
- package/dist/radio/readme.md +0 -70
- package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
- package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
- package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
- package/dist/select/Select.stories.js +0 -235
- package/dist/select/readme.md +0 -72
- package/dist/slider/Slider.stories.js +0 -241
- package/dist/slider/readme.md +0 -64
- package/dist/spinner/Spinner.stories.js +0 -183
- package/dist/spinner/readme.md +0 -65
- package/dist/switch/Switch.stories.js +0 -134
- package/dist/switch/readme.md +0 -133
- package/dist/tabs/Tabs.stories.js +0 -130
- package/dist/tabs/readme.md +0 -78
- package/dist/tabs-for-sections/TabsForSections.js +0 -92
- package/dist/tabs-for-sections/readme.md +0 -78
- package/dist/toggle/Toggle.stories.js +0 -297
- package/dist/toggle/readme.md +0 -80
- package/dist/toggle-group/readme.md +0 -82
- package/dist/upload/Upload.stories.js +0 -72
- package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
- package/dist/upload/buttons-upload/upload-button.svg +0 -1
- package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
- package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
- package/dist/upload/file-upload/audio-icon.svg +0 -4
- package/dist/upload/file-upload/close.svg +0 -4
- package/dist/upload/file-upload/file-icon.svg +0 -4
- package/dist/upload/file-upload/video-icon.svg +0 -4
- package/dist/upload/readme.md +0 -37
- package/dist/upload/transaction/audio-icon-err.svg +0 -4
- package/dist/upload/transaction/audio-icon.svg +0 -4
- package/dist/upload/transaction/error-icon.svg +0 -4
- package/dist/upload/transaction/file-icon-err.svg +0 -4
- package/dist/upload/transaction/file-icon.svg +0 -4
- package/dist/upload/transaction/image-icon-err.svg +0 -4
- package/dist/upload/transaction/image-icon.svg +0 -4
- package/dist/upload/transaction/success-icon.svg +0 -4
- package/dist/upload/transaction/video-icon-err.svg +0 -4
- package/dist/upload/transaction/video-icon.svg +0 -4
- package/dist/wizard/invalid_icon.svg +0 -5
- package/dist/wizard/valid_icon.svg +0 -5
- package/dist/wizard/validation-wrong.svg +0 -6
- package/test/NewInputText.test.js +0 -663
- package/test/Number.test.js +0 -205
- package/test/Password.test.js +0 -63
- package/test/TabsForSections.test.js +0 -34
|
@@ -1,39 +1,56 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { render, fireEvent
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
3
|
import userEvent from "@testing-library/user-event";
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import DxcDateInput from "../src/date-input/DateInput";
|
|
6
6
|
|
|
7
|
-
describe("
|
|
8
|
-
test("Renders with correct label, helper text, optional and
|
|
9
|
-
const { getByText, getByRole } = render(
|
|
10
|
-
<
|
|
7
|
+
describe("DateInput component tests", () => {
|
|
8
|
+
test("Renders with correct label, helper text, optional, placeholder and clearable action", () => {
|
|
9
|
+
const { getByText, getByRole, getAllByRole } = render(
|
|
10
|
+
<DxcDateInput label="Example label" helperText="Example of helper text" placeholder optional clearable />
|
|
11
11
|
);
|
|
12
12
|
const input = getByRole("textbox");
|
|
13
|
-
|
|
14
13
|
expect(getByText("Example label")).toBeTruthy();
|
|
15
14
|
expect(getByText("Example of helper text")).toBeTruthy();
|
|
16
15
|
expect(getByText("(Optional)")).toBeTruthy();
|
|
17
16
|
expect(input.getAttribute("placeholder")).toBe("DD-MM-YYYY");
|
|
17
|
+
userEvent.type(input, "10/10/2010");
|
|
18
|
+
const closeAction = getAllByRole("button")[0];
|
|
19
|
+
userEvent.click(closeAction);
|
|
20
|
+
expect(input.value).toBe("");
|
|
18
21
|
});
|
|
19
22
|
|
|
20
23
|
test("Renders with personalized error", () => {
|
|
21
|
-
const { getByText } = render(<
|
|
22
|
-
|
|
24
|
+
const { getByText } = render(<DxcDateInput error="Personalized error." />);
|
|
23
25
|
expect(getByText("Personalized error.")).toBeTruthy();
|
|
24
26
|
});
|
|
25
27
|
|
|
26
|
-
test("Renders with correct format: user typed date but it's invalid", () => {
|
|
27
|
-
const
|
|
28
|
+
test("Renders with correct format: user typed date but it's invalid, onBlur error", () => {
|
|
29
|
+
const onBlur = jest.fn(({ value, error }) => {
|
|
30
|
+
expect(value).toBe("10/90/2010");
|
|
31
|
+
expect(error).toBe("Invalid date.");
|
|
32
|
+
});
|
|
33
|
+
const { getByRole } = render(<DxcDateInput label="With format MM/dd/yyyy" format="MM/dd/yyyy" onBlur={onBlur} />);
|
|
28
34
|
const input = getByRole("textbox");
|
|
29
35
|
|
|
30
36
|
userEvent.type(input, "10/90/2010");
|
|
31
37
|
fireEvent.blur(input);
|
|
32
|
-
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("Renders with correct format: user typed date but it's invalid, onChange error", () => {
|
|
41
|
+
const onChange = jest.fn();
|
|
42
|
+
const { getByRole } = render(
|
|
43
|
+
<DxcDateInput label="With format MM/dd/yyyy" format="MM/dd/yyyy" onChange={onChange} />
|
|
44
|
+
);
|
|
45
|
+
const input = getByRole("textbox");
|
|
46
|
+
|
|
47
|
+
userEvent.type(input, "10/90/2010");
|
|
48
|
+
expect(onChange).toHaveBeenCalledTimes(10);
|
|
49
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10/90/2010", error: "Invalid date.", date: null });
|
|
33
50
|
});
|
|
34
51
|
|
|
35
52
|
test("Calendar renders with correct date: today's date", () => {
|
|
36
|
-
const { getByText, getByRole } = render(<
|
|
53
|
+
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
37
54
|
const calendarAction = getByRole("button");
|
|
38
55
|
const d = new Date();
|
|
39
56
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -43,7 +60,7 @@ describe("NewDate component tests", () => {
|
|
|
43
60
|
});
|
|
44
61
|
|
|
45
62
|
test("Calendar renders with correct date: value prop", () => {
|
|
46
|
-
const { getByText, getByRole } = render(<
|
|
63
|
+
const { getByText, getByRole } = render(<DxcDateInput value="20-10-2019" />);
|
|
47
64
|
const calendarAction = getByRole("button");
|
|
48
65
|
const d = new Date(2019, 9, 20);
|
|
49
66
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -53,7 +70,7 @@ describe("NewDate component tests", () => {
|
|
|
53
70
|
});
|
|
54
71
|
|
|
55
72
|
test("Calendar renders with correct date: user typed value", () => {
|
|
56
|
-
const { getByText, getByRole } = render(<
|
|
73
|
+
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
57
74
|
const calendarAction = getByRole("button");
|
|
58
75
|
const d = new Date(2010, 0, 1);
|
|
59
76
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -65,7 +82,8 @@ describe("NewDate component tests", () => {
|
|
|
65
82
|
});
|
|
66
83
|
|
|
67
84
|
test("Calendar renders with correct date: invalid date, renders with today's date", () => {
|
|
68
|
-
const
|
|
85
|
+
const onBlur = jest.fn();
|
|
86
|
+
const { getByText, getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
69
87
|
const calendarAction = getByRole("button");
|
|
70
88
|
const d = new Date();
|
|
71
89
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -73,17 +91,18 @@ describe("NewDate component tests", () => {
|
|
|
73
91
|
|
|
74
92
|
userEvent.type(input, "01-01-xxxx");
|
|
75
93
|
fireEvent.blur(input);
|
|
76
|
-
expect(
|
|
94
|
+
expect(onBlur).toHaveBeenCalled();
|
|
95
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "01-01-xxxx", error: "Invalid date.", date: null });
|
|
77
96
|
userEvent.click(calendarAction);
|
|
78
97
|
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
79
98
|
});
|
|
80
99
|
|
|
81
100
|
test("Selecting a date from the calendar with an specific format", () => {
|
|
82
|
-
const { getByText, getByRole } = render(<
|
|
101
|
+
const { getByText, getByRole } = render(<DxcDateInput label="With format M-dd-yyyy" format="M-dd-yyyy" />);
|
|
83
102
|
const input = getByRole("textbox");
|
|
84
103
|
const calendarAction = getByRole("button");
|
|
85
104
|
userEvent.click(calendarAction);
|
|
86
|
-
const dayButton =
|
|
105
|
+
const dayButton = getByText("10").closest("button");
|
|
87
106
|
fireEvent.click(dayButton);
|
|
88
107
|
const d = new Date();
|
|
89
108
|
d.setDate(10);
|
|
@@ -94,10 +113,10 @@ describe("NewDate component tests", () => {
|
|
|
94
113
|
});
|
|
95
114
|
|
|
96
115
|
test("Selecting a date from the calendar (using keyboard presses)", () => {
|
|
97
|
-
const { getByRole } = render(<
|
|
116
|
+
const { getByRole } = render(<DxcDateInput />);
|
|
98
117
|
const calendarAction = getByRole("button");
|
|
99
118
|
const input = getByRole("textbox");
|
|
100
|
-
|
|
119
|
+
|
|
101
120
|
userEvent.type(input, "01-01-2010");
|
|
102
121
|
userEvent.click(calendarAction);
|
|
103
122
|
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
@@ -111,14 +130,14 @@ describe("NewDate component tests", () => {
|
|
|
111
130
|
test("onChange & onBlur functions are called correctly", () => {
|
|
112
131
|
const onBlur = jest.fn();
|
|
113
132
|
const onChange = jest.fn();
|
|
114
|
-
const { getByRole } = render(<
|
|
133
|
+
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
115
134
|
const input = getByRole("textbox");
|
|
116
|
-
const d = new Date(2011, 9, 10);
|
|
135
|
+
const d = new Date(2011, 9, 10);
|
|
117
136
|
|
|
118
137
|
userEvent.type(input, "10-10-2011");
|
|
119
138
|
expect(input.value).toBe("10-10-2011");
|
|
120
139
|
expect(onChange).toHaveBeenCalledTimes(10);
|
|
121
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", date: d });
|
|
140
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
122
141
|
fireEvent.blur(input);
|
|
123
142
|
expect(onBlur).toHaveBeenCalled();
|
|
124
143
|
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
@@ -127,14 +146,13 @@ describe("NewDate component tests", () => {
|
|
|
127
146
|
test("onChange & onBlur functions are called correctly, also with errors", () => {
|
|
128
147
|
const onBlur = jest.fn();
|
|
129
148
|
const onChange = jest.fn();
|
|
130
|
-
const { getByRole } = render(<
|
|
149
|
+
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
131
150
|
const input = getByRole("textbox");
|
|
132
|
-
const d = new Date(2011, 9, 10);
|
|
133
151
|
|
|
134
152
|
userEvent.type(input, "10-10-");
|
|
135
153
|
expect(input.value).toBe("10-10-");
|
|
136
154
|
expect(onChange).toHaveBeenCalledTimes(6);
|
|
137
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", date: null });
|
|
155
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
138
156
|
fireEvent.blur(input);
|
|
139
157
|
expect(onBlur).toHaveBeenCalled();
|
|
140
158
|
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
@@ -142,9 +160,9 @@ describe("NewDate component tests", () => {
|
|
|
142
160
|
|
|
143
161
|
test("onBlur function removes the error when it is fixed", () => {
|
|
144
162
|
const onBlur = jest.fn();
|
|
145
|
-
const { getByRole } = render(<
|
|
163
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
146
164
|
const input = getByRole("textbox");
|
|
147
|
-
const d = new Date(2002, 1, 20);
|
|
165
|
+
const d = new Date(2002, 1, 20);
|
|
148
166
|
|
|
149
167
|
userEvent.type(input, "test");
|
|
150
168
|
expect(input.value).toBe("test");
|
|
@@ -161,7 +179,7 @@ describe("NewDate component tests", () => {
|
|
|
161
179
|
|
|
162
180
|
test("onBlur function removes the error when the input is empty", () => {
|
|
163
181
|
const onBlur = jest.fn();
|
|
164
|
-
const { getByRole } = render(<
|
|
182
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} optional />);
|
|
165
183
|
const input = getByRole("textbox");
|
|
166
184
|
|
|
167
185
|
userEvent.type(input, "test");
|
|
@@ -175,8 +193,32 @@ describe("NewDate component tests", () => {
|
|
|
175
193
|
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null, date: null });
|
|
176
194
|
});
|
|
177
195
|
|
|
178
|
-
test("
|
|
179
|
-
const
|
|
196
|
+
test("onBlur & onChange functions error: required field (not optional)", () => {
|
|
197
|
+
const onBlur = jest.fn();
|
|
198
|
+
const onChange = jest.fn();
|
|
199
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} onChange={onChange} />);
|
|
200
|
+
const date = getByRole("textbox");
|
|
201
|
+
|
|
202
|
+
userEvent.type(date, "t");
|
|
203
|
+
expect(date.value).toBe("t");
|
|
204
|
+
userEvent.clear(date);
|
|
205
|
+
fireEvent.blur(date);
|
|
206
|
+
expect(onBlur).toHaveBeenCalled();
|
|
207
|
+
expect(onBlur).toHaveBeenCalledWith({
|
|
208
|
+
value: "",
|
|
209
|
+
error: "This field is required. Please, enter a value.",
|
|
210
|
+
date: null,
|
|
211
|
+
});
|
|
212
|
+
expect(onChange).toHaveBeenCalled();
|
|
213
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
214
|
+
value: "",
|
|
215
|
+
error: "This field is required. Please, enter a value.",
|
|
216
|
+
date: null,
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("Disabled date input (calendar action must be shown but not clickable)", () => {
|
|
221
|
+
const { getByRole, queryByText } = render(<DxcDateInput disabled />);
|
|
180
222
|
const calendarAction = getByRole("button");
|
|
181
223
|
const d = new Date();
|
|
182
224
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -185,5 +227,16 @@ describe("NewDate component tests", () => {
|
|
|
185
227
|
userEvent.click(calendarAction);
|
|
186
228
|
expect(queryByText(d.toLocaleString("en-US", options))).toBeFalsy();
|
|
187
229
|
});
|
|
188
|
-
});
|
|
189
230
|
|
|
231
|
+
test("Input has correct accesibility attributes", () => {
|
|
232
|
+
const { getByRole } = render(<DxcDateInput label="Date input label" />);
|
|
233
|
+
const input = getByRole("textbox");
|
|
234
|
+
expect(input.getAttribute("aria-autocomplete")).toBeNull();
|
|
235
|
+
expect(input.getAttribute("aria-controls")).toBeNull();
|
|
236
|
+
expect(input.getAttribute("aria-expanded")).toBeNull();
|
|
237
|
+
const calendarAction = getByRole("button");
|
|
238
|
+
userEvent.click(calendarAction);
|
|
239
|
+
const datePicker = getByRole("dialog");
|
|
240
|
+
expect(datePicker.getAttribute("aria-modal")).toBe("true");
|
|
241
|
+
});
|
|
242
|
+
});
|
package/test/Dropdown.test.js
CHANGED
|
@@ -47,6 +47,21 @@ describe("Dropdown component tests", () => {
|
|
|
47
47
|
});
|
|
48
48
|
expect(queryByText("option-test")).toBeTruthy();
|
|
49
49
|
});
|
|
50
|
+
test("Disabled dropdown is not clickable", () => {
|
|
51
|
+
const options = [
|
|
52
|
+
{
|
|
53
|
+
value: 1,
|
|
54
|
+
label: "option-test",
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
const { queryByText } = render(<DxcDropdown options={options} disabled label="dropdown-test"></DxcDropdown>);
|
|
58
|
+
const dropdown = queryByText("dropdown-test");
|
|
59
|
+
expect(queryByText("option-test")).toBeFalsy();
|
|
60
|
+
act(() => {
|
|
61
|
+
fireEvent.click(dropdown);
|
|
62
|
+
});
|
|
63
|
+
expect(queryByText("option-test")).toBeFalsy();
|
|
64
|
+
});
|
|
50
65
|
|
|
51
66
|
test("Dropdown renders with correct icon before option", () => {
|
|
52
67
|
const options = [
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent, waitFor } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import DxcFileInput from "../src/file-input/FileInput";
|
|
6
|
+
|
|
7
|
+
describe("FileInput component tests", () => {
|
|
8
|
+
const file1 = new File(["file1"], "file1.png", { type: "image/png" });
|
|
9
|
+
const file2 = new File(["file2"], "file2.txt", {
|
|
10
|
+
type: "text/plain",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const files = [
|
|
14
|
+
{
|
|
15
|
+
error: null,
|
|
16
|
+
preview: null,
|
|
17
|
+
file: file1,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
error: "Error message",
|
|
21
|
+
preview: null,
|
|
22
|
+
file: file2,
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
test("Renders with correct labels and helper text in file mode", () => {
|
|
27
|
+
const { getByText } = render(<DxcFileInput label="File input label" helperText="File input helper text" />);
|
|
28
|
+
expect(getByText("File input label")).toBeTruthy();
|
|
29
|
+
expect(getByText("File input helper text")).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
test("Renders with correct button label in file mode", () => {
|
|
32
|
+
const { getByText } = render(<DxcFileInput label="File input label" helperText="File input helper text" />);
|
|
33
|
+
expect(getByText("Select files")).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
test("Renders with correct labels in filedrop mode", () => {
|
|
36
|
+
const { getByText } = render(
|
|
37
|
+
<DxcFileInput label="File input label" helperText="File input helper text" mode="filedrop" />
|
|
38
|
+
);
|
|
39
|
+
expect(getByText("Select")).toBeTruthy();
|
|
40
|
+
expect(getByText("or drop files")).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
test("Renders with correct labels in dropzone mode", () => {
|
|
43
|
+
const { getByText } = render(
|
|
44
|
+
<DxcFileInput label="File input label" helperText="File input helper text" mode="dropzone" />
|
|
45
|
+
);
|
|
46
|
+
expect(getByText("Select")).toBeTruthy();
|
|
47
|
+
expect(getByText("or drop files")).toBeTruthy();
|
|
48
|
+
});
|
|
49
|
+
test("Disabled file input", () => {
|
|
50
|
+
const { getByText, getByRole } = render(
|
|
51
|
+
<DxcFileInput label="File input label" helperText="File input helper text" disabled />
|
|
52
|
+
);
|
|
53
|
+
expect(getByText("Select files")).toBeTruthy();
|
|
54
|
+
const button = getByRole("button");
|
|
55
|
+
expect(button.disabled).toBeTruthy();
|
|
56
|
+
});
|
|
57
|
+
test("Renders file items passed in value when multiple file input", () => {
|
|
58
|
+
const callbackFile = jest.fn();
|
|
59
|
+
const { getByText } = render(
|
|
60
|
+
<DxcFileInput
|
|
61
|
+
label="File input label"
|
|
62
|
+
helperText="File input helper text"
|
|
63
|
+
value={files}
|
|
64
|
+
callbackFile={callbackFile}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
expect(getByText("file1.png")).toBeTruthy();
|
|
68
|
+
expect(getByText("file2.txt")).toBeTruthy();
|
|
69
|
+
expect(getByText("Error message")).toBeTruthy();
|
|
70
|
+
});
|
|
71
|
+
test("Renders file items when single file input", () => {
|
|
72
|
+
const callbackFile = jest.fn();
|
|
73
|
+
const { getByText } = render(
|
|
74
|
+
<DxcFileInput
|
|
75
|
+
label="File input label"
|
|
76
|
+
helperText="File input helper text"
|
|
77
|
+
multiple={false}
|
|
78
|
+
value={files}
|
|
79
|
+
callbackFile={callbackFile}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
expect(getByText("file1.png")).toBeTruthy();
|
|
83
|
+
expect(getByText("file2.txt")).toBeTruthy();
|
|
84
|
+
expect(getByText("Error message")).toBeTruthy();
|
|
85
|
+
});
|
|
86
|
+
test("Add file item when single file input", async () => {
|
|
87
|
+
const newFile = new File(["newFile"], "newFile.pdf", { type: "pdf" });
|
|
88
|
+
const callbackFile = jest.fn();
|
|
89
|
+
const { getByText, getByLabelText } = render(
|
|
90
|
+
<DxcFileInput
|
|
91
|
+
label="File input label"
|
|
92
|
+
helperText="File input helper text"
|
|
93
|
+
value={files}
|
|
94
|
+
callbackFile={callbackFile}
|
|
95
|
+
multiple={false}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
expect(getByText("file1.png")).toBeTruthy();
|
|
99
|
+
expect(getByText("file2.txt")).toBeTruthy();
|
|
100
|
+
expect(getByText("Error message")).toBeTruthy();
|
|
101
|
+
const inputFile = getByLabelText("File input label", { hidden: true });
|
|
102
|
+
fireEvent.change(inputFile, { target: { files: [newFile] } });
|
|
103
|
+
await waitFor(() => {
|
|
104
|
+
expect(callbackFile).toHaveBeenCalledWith([
|
|
105
|
+
{
|
|
106
|
+
error: undefined,
|
|
107
|
+
file: newFile,
|
|
108
|
+
preview: (
|
|
109
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
|
110
|
+
<path fill="none" d="M0 0h24v24H0V0z" />
|
|
111
|
+
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
112
|
+
</svg>
|
|
113
|
+
),
|
|
114
|
+
},
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
test("Renders file items and delete one file", async () => {
|
|
119
|
+
const callbackFile = jest.fn();
|
|
120
|
+
const { getByText, getAllByRole } = render(
|
|
121
|
+
<DxcFileInput
|
|
122
|
+
label="File input label"
|
|
123
|
+
helperText="File input helper text"
|
|
124
|
+
value={files}
|
|
125
|
+
callbackFile={callbackFile}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
expect(getByText("file1.png")).toBeTruthy();
|
|
129
|
+
expect(getByText("file2.txt")).toBeTruthy();
|
|
130
|
+
expect(getByText("Error message")).toBeTruthy();
|
|
131
|
+
const removeBtn = getAllByRole("button")[1];
|
|
132
|
+
userEvent.click(removeBtn);
|
|
133
|
+
await waitFor(() => {
|
|
134
|
+
expect(callbackFile).toHaveBeenCalledWith([{ error: "Error message", file: file2, preview: null }]);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("CallbackFile is correctly called", async () => {
|
|
139
|
+
const newFile = new File(["newFile"], "newFile.pdf", { type: "pdf" });
|
|
140
|
+
const callbackFile = jest.fn();
|
|
141
|
+
const { getByLabelText } = render(
|
|
142
|
+
<DxcFileInput
|
|
143
|
+
label="File input label"
|
|
144
|
+
helperText="File input helper text"
|
|
145
|
+
value={files}
|
|
146
|
+
callbackFile={callbackFile}
|
|
147
|
+
/>
|
|
148
|
+
);
|
|
149
|
+
const inputFile = getByLabelText("File input label", { hidden: true });
|
|
150
|
+
fireEvent.change(inputFile, { target: { files: [newFile] } });
|
|
151
|
+
await waitFor(() => {
|
|
152
|
+
expect(callbackFile).toHaveBeenCalledWith([
|
|
153
|
+
{ error: null, preview: null, file: file1 },
|
|
154
|
+
{ error: "Error message", preview: null, file: file2 },
|
|
155
|
+
{
|
|
156
|
+
error: undefined,
|
|
157
|
+
file: newFile,
|
|
158
|
+
preview: (
|
|
159
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
|
160
|
+
<path fill="none" d="M0 0h24v24H0V0z" />
|
|
161
|
+
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
162
|
+
</svg>
|
|
163
|
+
),
|
|
164
|
+
},
|
|
165
|
+
]);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("Callback called correctly when a file size does not comply minSize or maxSize", async () => {
|
|
170
|
+
const newFile = new File(["newFile"], "newFile.pdf", { type: "pdf" });
|
|
171
|
+
const callbackFile = jest.fn();
|
|
172
|
+
const { getByLabelText } = render(
|
|
173
|
+
<DxcFileInput
|
|
174
|
+
label="File input label"
|
|
175
|
+
helperText="File input helper text"
|
|
176
|
+
minSize={1000}
|
|
177
|
+
maxSize={20000}
|
|
178
|
+
value={files}
|
|
179
|
+
callbackFile={callbackFile}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
const inputFile = getByLabelText("File input label", { hidden: true });
|
|
183
|
+
fireEvent.change(inputFile, { target: { files: [newFile] } });
|
|
184
|
+
await waitFor(() => {
|
|
185
|
+
expect(callbackFile).toHaveBeenCalledWith([
|
|
186
|
+
{ error: null, preview: null, file: file1 },
|
|
187
|
+
{ error: "Error message", preview: null, file: file2 },
|
|
188
|
+
{
|
|
189
|
+
error: "File size must be greater than min size.",
|
|
190
|
+
file: newFile,
|
|
191
|
+
preview: (
|
|
192
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
|
193
|
+
<path fill="none" d="M0 0h24v24H0V0z" />
|
|
194
|
+
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
195
|
+
</svg>
|
|
196
|
+
),
|
|
197
|
+
},
|
|
198
|
+
]);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
package/test/Footer.test.js
CHANGED
|
@@ -5,13 +5,8 @@ import icon from "../../app/src/images/linkedin.svg";
|
|
|
5
5
|
|
|
6
6
|
describe("Footer component tests", () => {
|
|
7
7
|
test("Footer renders with default logo", () => {
|
|
8
|
-
const {
|
|
9
|
-
expect(
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test("Footer renders with logo", () => {
|
|
13
|
-
const { getByRole } = render(<DxcFooter logoSrc={icon}></DxcFooter>);
|
|
14
|
-
expect(getByRole("img")).toBeTruthy();
|
|
8
|
+
const { getByTitle } = render(<DxcFooter></DxcFooter>);
|
|
9
|
+
expect(getByTitle("DXC Logo")).toBeTruthy();
|
|
15
10
|
});
|
|
16
11
|
|
|
17
12
|
test("Footer renders with social links", () => {
|
package/test/Header.test.js
CHANGED
|
@@ -5,25 +5,20 @@ import icon from "../../app/src/images/linkedin.svg";
|
|
|
5
5
|
|
|
6
6
|
describe("Header component tests", () => {
|
|
7
7
|
test("Header renders with default logo", () => {
|
|
8
|
-
const {
|
|
9
|
-
expect(
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test("Header renders with logo", () => {
|
|
13
|
-
const { getByRole } = render(<DxcHeader logoSrc={icon}></DxcHeader>);
|
|
14
|
-
expect(getByRole("img")).toBeTruthy();
|
|
8
|
+
const { getByTitle } = render(<DxcHeader></DxcHeader>);
|
|
9
|
+
expect(getByTitle("DXC Logo")).toBeTruthy();
|
|
15
10
|
});
|
|
16
11
|
|
|
17
12
|
test("Call correct function on logo click", () => {
|
|
18
13
|
const onClick = jest.fn();
|
|
19
|
-
const {
|
|
20
|
-
const logo =
|
|
14
|
+
const { getByTitle } = render(<DxcHeader onClick={onClick}></DxcHeader>);
|
|
15
|
+
const logo = getByTitle("DXC Logo");
|
|
21
16
|
fireEvent.click(logo);
|
|
22
17
|
expect(onClick).toHaveBeenCalled();
|
|
23
18
|
});
|
|
24
19
|
|
|
25
20
|
test("Header renders with correct children", () => {
|
|
26
|
-
//We need to force the offsetWidth value
|
|
21
|
+
// We need to force the offsetWidth value
|
|
27
22
|
Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, value: 1024 });
|
|
28
23
|
|
|
29
24
|
const { getByText } = render(<DxcHeader content={<p>header-child-text</p>}></DxcHeader>);
|
package/test/Heading.test.js
CHANGED
|
@@ -3,33 +3,81 @@ import { render } from "@testing-library/react";
|
|
|
3
3
|
import DxcHeading from "../src/heading/Heading";
|
|
4
4
|
|
|
5
5
|
describe("Heading component tests", () => {
|
|
6
|
-
test("
|
|
7
|
-
const { getByText } = render(<DxcHeading text="my-heading-test"></DxcHeading>);
|
|
6
|
+
test("Heading renders with default level", () => {
|
|
7
|
+
const { getByText, getByRole } = render(<DxcHeading text="my-heading-test"></DxcHeading>);
|
|
8
8
|
expect(getByText("my-heading-test")).toBeTruthy();
|
|
9
|
+
expect(getByRole("heading", { level: 1 })).toBeTruthy();
|
|
9
10
|
});
|
|
10
11
|
|
|
11
|
-
test("
|
|
12
|
-
const { getByText } = render(<DxcHeading text="my-heading-test" level={1}></DxcHeading>);
|
|
12
|
+
test("Heading renders with level 1", () => {
|
|
13
|
+
const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={1}></DxcHeading>);
|
|
13
14
|
expect(getByText("my-heading-test")).toBeTruthy();
|
|
15
|
+
expect(getByRole("heading", { level: 1 })).toBeTruthy();
|
|
14
16
|
});
|
|
15
17
|
|
|
16
|
-
test("
|
|
17
|
-
const { getByText } = render(<DxcHeading text="my-heading-test" level={2}></DxcHeading>);
|
|
18
|
+
test("Heading renders with level 2", () => {
|
|
19
|
+
const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={2}></DxcHeading>);
|
|
18
20
|
expect(getByText("my-heading-test")).toBeTruthy();
|
|
21
|
+
expect(getByRole("heading", { level: 2 })).toBeTruthy();
|
|
19
22
|
});
|
|
20
23
|
|
|
21
|
-
test("
|
|
22
|
-
const { getByText } = render(<DxcHeading text="my-heading-test" level={3}></DxcHeading>);
|
|
24
|
+
test("Heading renders with level 3", () => {
|
|
25
|
+
const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={3}></DxcHeading>);
|
|
23
26
|
expect(getByText("my-heading-test")).toBeTruthy();
|
|
27
|
+
expect(getByRole("heading", { level: 3 })).toBeTruthy();
|
|
24
28
|
});
|
|
25
29
|
|
|
26
|
-
test("
|
|
27
|
-
const { getByText } = render(<DxcHeading text="my-heading-test" level={4}></DxcHeading>);
|
|
30
|
+
test("Heading renders with level 4", () => {
|
|
31
|
+
const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={4}></DxcHeading>);
|
|
28
32
|
expect(getByText("my-heading-test")).toBeTruthy();
|
|
33
|
+
expect(getByRole("heading", { level: 4 })).toBeTruthy();
|
|
29
34
|
});
|
|
30
35
|
|
|
31
|
-
test("
|
|
32
|
-
const { getByText } = render(<DxcHeading text="my-heading-test" level={5}></DxcHeading>);
|
|
36
|
+
test("Heading renders with level 5", () => {
|
|
37
|
+
const { getByText, getByRole } = render(<DxcHeading text="my-heading-test" level={5}></DxcHeading>);
|
|
33
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();
|
|
34
82
|
});
|
|
35
83
|
});
|