@dxc-technology/halstack-react 0.0.0-e792e0c → 0.0.0-e832ef8
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/babel.config.js +6 -2
- package/dist/BackgroundColorContext.js +46 -0
- package/dist/ThemeContext.js +235 -2
- package/dist/V3Textarea/V3Textarea.js +264 -0
- package/dist/accordion/Accordion.js +170 -81
- package/dist/accordion-group/AccordionGroup.js +186 -0
- package/dist/alert/Alert.js +184 -83
- package/dist/alert/index.d.ts +51 -0
- package/dist/badge/Badge.js +63 -0
- package/dist/box/Box.js +31 -23
- package/dist/button/Button.js +82 -27
- package/dist/card/Card.js +72 -35
- package/dist/checkbox/Checkbox.js +108 -32
- package/dist/chip/Chip.js +129 -35
- package/dist/common/RequiredComponent.js +2 -8
- package/dist/common/utils.js +2 -22
- package/dist/common/variables.js +1459 -197
- package/dist/date/Date.js +86 -64
- package/dist/date-input/DateInput.js +400 -0
- package/dist/date-input/index.d.ts +95 -0
- package/dist/dialog/Dialog.js +58 -37
- package/dist/dropdown/Dropdown.js +226 -94
- 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 +122 -47
- package/dist/footer/Icons.js +77 -0
- package/dist/header/Header.js +171 -91
- package/dist/header/Icons.js +59 -0
- package/dist/heading/Heading.js +81 -22
- package/dist/input-text/Icons.js +22 -0
- package/dist/input-text/InputText.js +293 -107
- package/dist/layout/ApplicationLayout.js +327 -0
- package/dist/layout/Icons.js +55 -0
- package/dist/link/Link.js +136 -35
- package/dist/main.d.ts +8 -0
- package/dist/main.js +111 -7
- package/dist/new-select/NewSelect.js +836 -0
- package/dist/new-select/index.d.ts +53 -0
- package/dist/number-input/NumberInput.js +136 -0
- package/dist/number-input/NumberInputContext.js +16 -0
- package/dist/number-input/index.d.ts +113 -0
- package/dist/paginator/Icons.js +66 -0
- package/dist/paginator/Paginator.js +162 -57
- package/dist/password-input/PasswordInput.js +198 -0
- package/dist/password-input/index.d.ts +94 -0
- package/dist/progress-bar/ProgressBar.js +97 -44
- package/dist/radio/Radio.js +39 -21
- package/dist/resultsetTable/ResultsetTable.js +93 -69
- package/dist/select/Select.js +250 -143
- package/dist/sidenav/Sidenav.js +85 -143
- package/dist/slider/Slider.js +219 -73
- package/dist/spinner/Spinner.js +249 -64
- package/dist/switch/Switch.js +51 -26
- package/dist/table/Table.js +63 -15
- package/dist/tabs/Tabs.js +208 -35
- package/dist/tabs-for-sections/TabsForSections.js +1 -16
- package/dist/tag/Tag.js +100 -35
- package/dist/text-input/TextInput.js +971 -0
- package/dist/text-input/index.d.ts +135 -0
- package/dist/textarea/Textarea.js +250 -107
- package/dist/textarea/index.d.ts +117 -0
- package/dist/toggle/Toggle.js +16 -19
- package/dist/toggle-group/ToggleGroup.js +327 -0
- package/dist/upload/Upload.js +16 -11
- package/dist/upload/buttons-upload/ButtonsUpload.js +35 -25
- package/dist/upload/buttons-upload/Icons.js +40 -0
- package/dist/upload/dragAndDropArea/DragAndDropArea.js +78 -31
- package/dist/upload/file-upload/FileToUpload.js +64 -33
- package/dist/upload/file-upload/Icons.js +66 -0
- package/dist/upload/files-upload/FilesToUpload.js +16 -16
- package/dist/upload/readme.md +2 -2
- package/dist/upload/transaction/Icons.js +160 -0
- package/dist/upload/transaction/Transaction.js +42 -49
- package/dist/upload/transactions/Transactions.js +38 -20
- package/dist/useTheme.js +22 -0
- package/dist/wizard/Icons.js +65 -0
- package/dist/wizard/Wizard.js +141 -56
- package/package.json +14 -6
- package/test/AccordionGroup.test.js +125 -0
- package/test/Date.test.js +49 -45
- package/test/DateInput.test.js +242 -0
- package/test/Dropdown.test.js +19 -4
- package/test/FileInput.test.js +201 -0
- package/test/Footer.test.js +2 -7
- package/test/Header.test.js +5 -10
- package/test/InputText.test.js +53 -41
- package/test/Link.test.js +25 -7
- package/test/NumberInput.test.js +259 -0
- package/test/Paginator.test.js +72 -60
- package/test/PasswordInput.test.js +83 -0
- package/test/ResultsetTable.test.js +66 -19
- package/test/Select.test.js +55 -34
- package/test/Sidenav.test.js +22 -64
- package/test/Slider.test.js +24 -15
- package/test/Spinner.test.js +5 -0
- package/test/Tabs.test.js +21 -0
- package/test/TextInput.test.js +732 -0
- package/test/Textarea.test.js +193 -0
- package/test/ToggleGroup.test.js +85 -0
- package/test/Upload.test.js +5 -5
- 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/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/common/services/example-service.js +0 -10
- package/dist/common/services/example-service.test.js +0 -12
- package/dist/date/calendar.svg +0 -1
- package/dist/date/calendar_dark.svg +0 -1
- 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_wht.png +0 -0
- 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.png +0 -0
- package/dist/header/dxc_logo_white.png +0 -0
- 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/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/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/sidenav/arrow_icon.svg +0 -3
- package/dist/slider/Slider.stories.js +0 -241
- package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
- package/dist/upload/buttons-upload/upload-button.svg +0 -1
- 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/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 -6
- package/dist/wizard/valid_icon.svg +0 -6
- package/dist/wizard/validation-wrong.svg +0 -6
- package/test/Toggle.test.js +0 -43
package/test/Date.test.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
-
import
|
|
3
|
+
import V3DxcDate from "../src/date/Date";
|
|
4
4
|
|
|
5
5
|
const defaultFormat = "DD-MM-YYYY";
|
|
6
6
|
|
|
7
7
|
describe("Date component general tests", () => {
|
|
8
8
|
test("Date renders correctly", () => {
|
|
9
|
-
const { getByPlaceholderText } = render(<
|
|
9
|
+
const { getByPlaceholderText } = render(<V3DxcDate label="Birthdate" placeholder />);
|
|
10
10
|
// const input = getByPlaceholderText('DD-MM-YYYY');
|
|
11
11
|
expect(getByPlaceholderText(defaultFormat)).toBeTruthy();
|
|
12
12
|
});
|
|
@@ -22,19 +22,19 @@ describe("Controlled Date Component", () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
const { getByRole, getByPlaceholderText, rerender } = render(
|
|
25
|
-
<
|
|
25
|
+
<V3DxcDate label="Birthdate" value="30-03-1981" onChange={onChange} placeholder />
|
|
26
26
|
);
|
|
27
27
|
const input = getByPlaceholderText(defaultFormat);
|
|
28
28
|
|
|
29
29
|
fireEvent.change(input, { target: { value: "something" } });
|
|
30
30
|
expect(onChange).toHaveBeenCalled();
|
|
31
31
|
fireEvent.blur(input);
|
|
32
|
-
rerender(<
|
|
32
|
+
rerender(<V3DxcDate label="Birthdate" value="" placeholder />);
|
|
33
33
|
// expect(getByRole("textbox").value).toBe('');
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test("The input´s value is the same as the one received as a parameter (Default format)", () => {
|
|
37
|
-
const { getByRole, getByPlaceholderText } = render(<
|
|
37
|
+
const { getByRole, getByPlaceholderText } = render(<V3DxcDate label="Birthdate" value="30/03/1981" placeholder />);
|
|
38
38
|
// const input = getByRole("textbox");
|
|
39
39
|
const input = getByPlaceholderText(defaultFormat);
|
|
40
40
|
expect(input.value).toBe("30/03/1981");
|
|
@@ -42,7 +42,7 @@ describe("Controlled Date Component", () => {
|
|
|
42
42
|
|
|
43
43
|
test("The input´s value is the same as the one received as a parameter (Custom format)", () => {
|
|
44
44
|
const { getByRole, getByPlaceholderText } = render(
|
|
45
|
-
<
|
|
45
|
+
<V3DxcDate label="Birthdate" format="dd/MM/yy" value="30/03/81" placeholder />
|
|
46
46
|
);
|
|
47
47
|
// const input = getByRole("textbox");
|
|
48
48
|
const input = getByPlaceholderText("DD/MM/YY");
|
|
@@ -50,21 +50,21 @@ describe("Controlled Date Component", () => {
|
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
test("Calendar´s value is the same as the input´s date if it´s right (Depending on the format)", () => {
|
|
53
|
-
const { getByRole, getByText } = render(<
|
|
54
|
-
fireEvent.click(
|
|
53
|
+
const { getByRole, getByText, getByTestId } = render(<V3DxcDate label="Birthdate" value="16-10-2020" />);
|
|
54
|
+
fireEvent.click(getByTestId("calendarIcon"));
|
|
55
55
|
expect(getByText("Fri, Oct 16")).toBeTruthy();
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
test("Calendar´s value is the same as the input´s date if it´s right after changing the input value", () => {
|
|
59
|
-
const { getByRole, getByText, rerender, getByPlaceholderText } = render(
|
|
60
|
-
<
|
|
59
|
+
const { getByRole, getByText, rerender, getByPlaceholderText, getByTestId } = render(
|
|
60
|
+
<V3DxcDate label="Birthdate" value="30-03-1981" placeholder />
|
|
61
61
|
);
|
|
62
62
|
// const input = getByRole("textbox");
|
|
63
63
|
const input = getByPlaceholderText(defaultFormat);
|
|
64
64
|
fireEvent.change(input, { target: { value: "10-02-2020" } });
|
|
65
65
|
|
|
66
|
-
rerender(<
|
|
67
|
-
const calendarButton =
|
|
66
|
+
rerender(<V3DxcDate label="Birthdate" value="10-02-2020" />);
|
|
67
|
+
const calendarButton = getByTestId("calendarIcon");
|
|
68
68
|
fireEvent.click(calendarButton);
|
|
69
69
|
expect(getByText("Mon, Feb 10")).toBeTruthy();
|
|
70
70
|
});
|
|
@@ -76,7 +76,7 @@ describe("Controlled Date Component", () => {
|
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
const { getByRole, getByPlaceholderText } = render(
|
|
79
|
-
<
|
|
79
|
+
<V3DxcDate label="Birthdate" value="30-03-1981" onChange={onChange} placeholder />
|
|
80
80
|
);
|
|
81
81
|
// const input = getByRole("textbox");
|
|
82
82
|
const input = getByPlaceholderText(defaultFormat);
|
|
@@ -92,7 +92,7 @@ describe("Controlled Date Component", () => {
|
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
const { getByRole, getByPlaceholderText } = render(
|
|
95
|
-
<
|
|
95
|
+
<V3DxcDate label="Birthdate" value="30-03-1981" onChange={onChange} placeholder />
|
|
96
96
|
);
|
|
97
97
|
// const input = getByRole("textbox");
|
|
98
98
|
const input = getByPlaceholderText(defaultFormat);
|
|
@@ -107,7 +107,7 @@ describe("Controlled Date Component", () => {
|
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
const { getByRole, getByPlaceholderText } = render(
|
|
110
|
-
<
|
|
110
|
+
<V3DxcDate label="Birthdate" format="dd-MM-yy" value="30-03-81" onChange={onChange} placeholder />
|
|
111
111
|
);
|
|
112
112
|
// const input = getByRole("textbox");
|
|
113
113
|
const input = getByPlaceholderText("DD-MM-YY");
|
|
@@ -123,7 +123,7 @@ describe("Controlled Date Component", () => {
|
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
const { getByRole, getByPlaceholderText } = render(
|
|
126
|
-
<
|
|
126
|
+
<V3DxcDate label="Birthdate" value="30-03-1981" onChange={onChange} placeholder />
|
|
127
127
|
);
|
|
128
128
|
// const input = getByRole("textbox");
|
|
129
129
|
const input = getByPlaceholderText(defaultFormat);
|
|
@@ -139,7 +139,7 @@ describe("Controlled Date Component", () => {
|
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
const { getByRole, getByPlaceholderText } = render(
|
|
142
|
-
<
|
|
142
|
+
<V3DxcDate label="Birthdate" value="03/30/1981" format="MM/dd/yyyy" onChange={onChange} placeholder />
|
|
143
143
|
);
|
|
144
144
|
// const input = getByRole("textbox");
|
|
145
145
|
const input = getByPlaceholderText("MM/DD/YYYY");
|
|
@@ -151,8 +151,8 @@ describe("Controlled Date Component", () => {
|
|
|
151
151
|
test("onChange function is called when the user selects from the calendar", () => {
|
|
152
152
|
const onChange = jest.fn();
|
|
153
153
|
|
|
154
|
-
const component = render(<
|
|
155
|
-
const calendarButton = component.
|
|
154
|
+
const component = render(<V3DxcDate label="Birthdate" value="01-02-2020" onChange={onChange} />);
|
|
155
|
+
const calendarButton = component.getByTestId("calendarIcon");
|
|
156
156
|
fireEvent.click(calendarButton);
|
|
157
157
|
const dayButton = component.getByRole("button", { name: "10" });
|
|
158
158
|
fireEvent.click(dayButton);
|
|
@@ -165,8 +165,8 @@ describe("Controlled Date Component", () => {
|
|
|
165
165
|
expect(returnedValue.dateValue.getTime()).toBe(date.getTime());
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
-
const component = render(<
|
|
169
|
-
const calendarButton = component.
|
|
168
|
+
const component = render(<V3DxcDate label="Birthdate" value="30-10-2020" onChange={onChange} />);
|
|
169
|
+
const calendarButton = component.getByTestId("calendarIcon");
|
|
170
170
|
fireEvent.click(calendarButton);
|
|
171
171
|
const dayButton = component.getByRole("button", { name: "16" });
|
|
172
172
|
fireEvent.click(dayButton);
|
|
@@ -178,8 +178,8 @@ describe("Controlled Date Component", () => {
|
|
|
178
178
|
expect(returnedValue.stringValue).toBe("16-10-2020");
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
const component = render(<
|
|
182
|
-
const calendarButton = component.
|
|
181
|
+
const component = render(<V3DxcDate label="Birthdate" value="01-10-2020" onChange={onChange} />);
|
|
182
|
+
const calendarButton = component.getByTestId("calendarIcon");
|
|
183
183
|
fireEvent.click(calendarButton);
|
|
184
184
|
const dayButton = component.getByRole("button", { name: "16" });
|
|
185
185
|
fireEvent.click(dayButton);
|
|
@@ -191,8 +191,10 @@ describe("Controlled Date Component", () => {
|
|
|
191
191
|
expect(returnedValue.stringValue).toBe("2020/10/16");
|
|
192
192
|
});
|
|
193
193
|
|
|
194
|
-
const component = render(
|
|
195
|
-
|
|
194
|
+
const component = render(
|
|
195
|
+
<V3DxcDate label="Birthdate" format="yyyy/MM/dd" value="2020/10/01" onChange={onChange} />
|
|
196
|
+
);
|
|
197
|
+
const calendarButton = component.getByTestId("calendarIcon");
|
|
196
198
|
fireEvent.click(calendarButton);
|
|
197
199
|
const dayButton = component.getByRole("button", { name: "16" });
|
|
198
200
|
fireEvent.click(dayButton);
|
|
@@ -200,8 +202,8 @@ describe("Controlled Date Component", () => {
|
|
|
200
202
|
});
|
|
201
203
|
|
|
202
204
|
test("Check selected date on calendar is the same date as the one on the input", () => {
|
|
203
|
-
const component = render(<
|
|
204
|
-
const calendarButton = component.
|
|
205
|
+
const component = render(<V3DxcDate label="Birthdate" value="01-10-2020" />);
|
|
206
|
+
const calendarButton = component.getByTestId("calendarIcon");
|
|
205
207
|
fireEvent.click(calendarButton);
|
|
206
208
|
const dayButton = component.getByRole("button", { name: "1" });
|
|
207
209
|
expect(dayButton.classList.contains("MuiPickersDay-daySelected")).toBe(true);
|
|
@@ -209,7 +211,7 @@ describe("Controlled Date Component", () => {
|
|
|
209
211
|
test("onBlur function is called", () => {
|
|
210
212
|
const onBlur = jest.fn();
|
|
211
213
|
const { getByRole, getByPlaceholderText } = render(
|
|
212
|
-
<
|
|
214
|
+
<V3DxcDate label="Birthdate" value="30-03-81" onBlur={onBlur} placeholder />
|
|
213
215
|
);
|
|
214
216
|
// const input = getByRole("textbox");
|
|
215
217
|
const input = getByPlaceholderText(defaultFormat);
|
|
@@ -222,7 +224,7 @@ describe("Controlled Date Component", () => {
|
|
|
222
224
|
expect(returnedValue).toBe("30-03-81");
|
|
223
225
|
});
|
|
224
226
|
const { getByRole, getByPlaceholderText } = render(
|
|
225
|
-
<
|
|
227
|
+
<V3DxcDate label="Birthdate" value="30-03-81" onBlur={onBlur} placeholder />
|
|
226
228
|
);
|
|
227
229
|
// const input = getByRole("textbox");
|
|
228
230
|
const input = getByPlaceholderText(defaultFormat);
|
|
@@ -235,7 +237,7 @@ describe("Controlled Date Component", () => {
|
|
|
235
237
|
expect(returnedValue).toBe("30/03/81");
|
|
236
238
|
});
|
|
237
239
|
const { getByRole, getByPlaceholderText } = render(
|
|
238
|
-
<
|
|
240
|
+
<V3DxcDate label="Birthdate" format="dd/MM/yy" value="30/03/81" onBlur={onBlur} placeholder />
|
|
239
241
|
);
|
|
240
242
|
// const input = getByRole("textbox");
|
|
241
243
|
const input = getByPlaceholderText("DD/MM/YY");
|
|
@@ -249,14 +251,16 @@ describe("Uncontrolled Date Component", () => {
|
|
|
249
251
|
const date = new Date("2020-10-16 00:00:00");
|
|
250
252
|
|
|
251
253
|
test("Calendar´s value is the same as the input´s date if it´s right after changing the input value", () => {
|
|
252
|
-
const { getByRole, getByText, rerender, getByPlaceholderText } = render(
|
|
254
|
+
const { getByRole, getByText, rerender, getByPlaceholderText, getByTestId } = render(
|
|
255
|
+
<V3DxcDate label="Birthdate" placeholder />
|
|
256
|
+
);
|
|
253
257
|
// const input = getByRole("textbox");
|
|
254
258
|
const input = getByPlaceholderText(defaultFormat);
|
|
255
259
|
|
|
256
260
|
fireEvent.change(input, { target: { value: "10-02-2020" } });
|
|
257
261
|
|
|
258
|
-
rerender(<
|
|
259
|
-
const calendarButton =
|
|
262
|
+
rerender(<V3DxcDate label="Birthdate" value="10-02-2020" />);
|
|
263
|
+
const calendarButton = getByTestId("calendarIcon");
|
|
260
264
|
fireEvent.click(calendarButton);
|
|
261
265
|
expect(getByText("Mon, Feb 10")).toBeTruthy();
|
|
262
266
|
});
|
|
@@ -267,7 +271,7 @@ describe("Uncontrolled Date Component", () => {
|
|
|
267
271
|
expect(returnedValue.stringValue).toBe("something");
|
|
268
272
|
});
|
|
269
273
|
|
|
270
|
-
const { getByRole, getByPlaceholderText } = render(<
|
|
274
|
+
const { getByRole, getByPlaceholderText } = render(<V3DxcDate label="Birthdate" onChange={onChange} placeholder />);
|
|
271
275
|
// const input = getByRole("textbox");
|
|
272
276
|
const input = getByPlaceholderText(defaultFormat);
|
|
273
277
|
|
|
@@ -280,7 +284,7 @@ describe("Uncontrolled Date Component", () => {
|
|
|
280
284
|
expect(returnedValue.stringValue).toBe("16-10-2020");
|
|
281
285
|
});
|
|
282
286
|
|
|
283
|
-
const { getByRole, getByPlaceholderText } = render(<
|
|
287
|
+
const { getByRole, getByPlaceholderText } = render(<V3DxcDate label="Birthdate" onChange={onChange} placeholder />);
|
|
284
288
|
// const input = getByRole("textbox");
|
|
285
289
|
const input = getByPlaceholderText(defaultFormat);
|
|
286
290
|
|
|
@@ -294,7 +298,7 @@ describe("Uncontrolled Date Component", () => {
|
|
|
294
298
|
});
|
|
295
299
|
|
|
296
300
|
const { getByRole, getByPlaceholderText } = render(
|
|
297
|
-
<
|
|
301
|
+
<V3DxcDate label="Birthdate" format="dd-MM-yy" onChange={onChange} placeholder />
|
|
298
302
|
);
|
|
299
303
|
// const input = getByRole("textbox");
|
|
300
304
|
const input = getByPlaceholderText("DD-MM-YY");
|
|
@@ -309,7 +313,7 @@ describe("Uncontrolled Date Component", () => {
|
|
|
309
313
|
expect(returnedValue.stringValue).toBe("11-15-2020");
|
|
310
314
|
});
|
|
311
315
|
|
|
312
|
-
const { getByRole, getByPlaceholderText } = render(<
|
|
316
|
+
const { getByRole, getByPlaceholderText } = render(<V3DxcDate label="Birthdate" onChange={onChange} placeholder />);
|
|
313
317
|
// const input = getByRole("textbox");
|
|
314
318
|
const input = getByPlaceholderText(defaultFormat);
|
|
315
319
|
|
|
@@ -324,7 +328,7 @@ describe("Uncontrolled Date Component", () => {
|
|
|
324
328
|
});
|
|
325
329
|
|
|
326
330
|
const { getByRole, getByPlaceholderText } = render(
|
|
327
|
-
<
|
|
331
|
+
<V3DxcDate label="Birthdate" format="MM/dd/yyyy" onChange={onChange} placeholder />
|
|
328
332
|
);
|
|
329
333
|
// const input = getByRole("textbox");
|
|
330
334
|
const input = getByPlaceholderText("MM/DD/YYYY");
|
|
@@ -335,8 +339,8 @@ describe("Uncontrolled Date Component", () => {
|
|
|
335
339
|
test("onChange function is called when the user selects from the calendar", () => {
|
|
336
340
|
const onChange = jest.fn();
|
|
337
341
|
|
|
338
|
-
const component = render(<
|
|
339
|
-
const calendarButton = component.
|
|
342
|
+
const component = render(<V3DxcDate label="Birthdate" onChange={onChange} />);
|
|
343
|
+
const calendarButton = component.getByTestId("calendarIcon");
|
|
340
344
|
fireEvent.click(calendarButton);
|
|
341
345
|
const dayButton = component.getByRole("button", { name: "10" });
|
|
342
346
|
fireEvent.click(dayButton);
|
|
@@ -345,19 +349,19 @@ describe("Uncontrolled Date Component", () => {
|
|
|
345
349
|
});
|
|
346
350
|
|
|
347
351
|
test("Check selected date on calendar is the same date as the one on the input", () => {
|
|
348
|
-
const component = render(<
|
|
352
|
+
const component = render(<V3DxcDate label="Birthdate" placeholder />);
|
|
349
353
|
// const input = component.getByRole("textbox");
|
|
350
354
|
const input = component.getByPlaceholderText(defaultFormat);
|
|
351
355
|
|
|
352
356
|
fireEvent.change(input, { target: { value: "10-02-2020" } });
|
|
353
|
-
const calendarButton = component.
|
|
357
|
+
const calendarButton = component.getByTestId("calendarIcon");
|
|
354
358
|
fireEvent.click(calendarButton);
|
|
355
359
|
const dayButton = component.getByRole("button", { name: "10" });
|
|
356
360
|
expect(dayButton.classList.contains("MuiPickersDay-daySelected")).toBe(true);
|
|
357
361
|
});
|
|
358
362
|
test("onBlur function is called", () => {
|
|
359
363
|
const onBlur = jest.fn();
|
|
360
|
-
const { getByRole, getByPlaceholderText } = render(<
|
|
364
|
+
const { getByRole, getByPlaceholderText } = render(<V3DxcDate label="Birthdate" onBlur={onBlur} placeholder />);
|
|
361
365
|
// const input = getByRole("textbox");
|
|
362
366
|
const input = getByPlaceholderText(defaultFormat);
|
|
363
367
|
|
|
@@ -368,7 +372,7 @@ describe("Uncontrolled Date Component", () => {
|
|
|
368
372
|
const onBlur = jest.fn((returnedValue) => {
|
|
369
373
|
expect(returnedValue).toBe("10-02-2020");
|
|
370
374
|
});
|
|
371
|
-
const { getByRole, getByPlaceholderText } = render(<
|
|
375
|
+
const { getByRole, getByPlaceholderText } = render(<V3DxcDate label="Birthdate" onBlur={onBlur} placeholder />);
|
|
372
376
|
// const input = getByRole("textbox");
|
|
373
377
|
const input = getByPlaceholderText("DD-MM-YYYY");
|
|
374
378
|
|
|
@@ -381,7 +385,7 @@ describe("Uncontrolled Date Component", () => {
|
|
|
381
385
|
expect(returnedValue).toBe("10/02/20");
|
|
382
386
|
});
|
|
383
387
|
const { getByRole, getByPlaceholderText } = render(
|
|
384
|
-
<
|
|
388
|
+
<V3DxcDate label="Birthdate" format="dd/MM/yy" onBlur={onBlur} placeholder />
|
|
385
389
|
);
|
|
386
390
|
// const input = getByRole("textbox");
|
|
387
391
|
const input = getByPlaceholderText("DD/MM/YY");
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import DxcDateInput from "../src/date-input/DateInput";
|
|
6
|
+
|
|
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
|
+
);
|
|
12
|
+
const input = getByRole("textbox");
|
|
13
|
+
expect(getByText("Example label")).toBeTruthy();
|
|
14
|
+
expect(getByText("Example of helper text")).toBeTruthy();
|
|
15
|
+
expect(getByText("(Optional)")).toBeTruthy();
|
|
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("");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("Renders with personalized error", () => {
|
|
24
|
+
const { getByText } = render(<DxcDateInput error="Personalized error." />);
|
|
25
|
+
expect(getByText("Personalized error.")).toBeTruthy();
|
|
26
|
+
});
|
|
27
|
+
|
|
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} />);
|
|
34
|
+
const input = getByRole("textbox");
|
|
35
|
+
|
|
36
|
+
userEvent.type(input, "10/90/2010");
|
|
37
|
+
fireEvent.blur(input);
|
|
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 });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("Calendar renders with correct date: today's date", () => {
|
|
53
|
+
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
54
|
+
const calendarAction = getByRole("button");
|
|
55
|
+
const d = new Date();
|
|
56
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
57
|
+
|
|
58
|
+
userEvent.click(calendarAction);
|
|
59
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("Calendar renders with correct date: value prop", () => {
|
|
63
|
+
const { getByText, getByRole } = render(<DxcDateInput value="20-10-2019" />);
|
|
64
|
+
const calendarAction = getByRole("button");
|
|
65
|
+
const d = new Date(2019, 9, 20);
|
|
66
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
67
|
+
|
|
68
|
+
userEvent.click(calendarAction);
|
|
69
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("Calendar renders with correct date: user typed value", () => {
|
|
73
|
+
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
74
|
+
const calendarAction = getByRole("button");
|
|
75
|
+
const d = new Date(2010, 0, 1);
|
|
76
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
77
|
+
const input = getByRole("textbox");
|
|
78
|
+
|
|
79
|
+
userEvent.type(input, "01-01-2010");
|
|
80
|
+
userEvent.click(calendarAction);
|
|
81
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("Calendar renders with correct date: invalid date, renders with today's date", () => {
|
|
85
|
+
const onBlur = jest.fn();
|
|
86
|
+
const { getByText, getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
87
|
+
const calendarAction = getByRole("button");
|
|
88
|
+
const d = new Date();
|
|
89
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
90
|
+
const input = getByRole("textbox");
|
|
91
|
+
|
|
92
|
+
userEvent.type(input, "01-01-xxxx");
|
|
93
|
+
fireEvent.blur(input);
|
|
94
|
+
expect(onBlur).toHaveBeenCalled();
|
|
95
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "01-01-xxxx", error: "Invalid date.", date: null });
|
|
96
|
+
userEvent.click(calendarAction);
|
|
97
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("Selecting a date from the calendar with an specific format", () => {
|
|
101
|
+
const { getByText, getByRole } = render(<DxcDateInput label="With format M-dd-yyyy" format="M-dd-yyyy" />);
|
|
102
|
+
const input = getByRole("textbox");
|
|
103
|
+
const calendarAction = getByRole("button");
|
|
104
|
+
userEvent.click(calendarAction);
|
|
105
|
+
const dayButton = getByText("10").closest("button");
|
|
106
|
+
fireEvent.click(dayButton);
|
|
107
|
+
const d = new Date();
|
|
108
|
+
d.setDate(10);
|
|
109
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
110
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
111
|
+
fireEvent.keyDown(document, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
112
|
+
expect(input.value).toBe(`${d.getMonth() + 1}-10-${d.getFullYear()}`);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("Selecting a date from the calendar (using keyboard presses)", () => {
|
|
116
|
+
const { getByRole } = render(<DxcDateInput />);
|
|
117
|
+
const calendarAction = getByRole("button");
|
|
118
|
+
const input = getByRole("textbox");
|
|
119
|
+
|
|
120
|
+
userEvent.type(input, "01-01-2010");
|
|
121
|
+
userEvent.click(calendarAction);
|
|
122
|
+
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
123
|
+
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
124
|
+
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
125
|
+
fireEvent.keyDown(document, { key: "ArrowLeft", code: "ArrowLeft", keyCode: 37, charCode: 37 });
|
|
126
|
+
fireEvent.keyDown(document, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
127
|
+
expect(input.value).toBe("03-01-2010");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("onChange & onBlur functions are called correctly", () => {
|
|
131
|
+
const onBlur = jest.fn();
|
|
132
|
+
const onChange = jest.fn();
|
|
133
|
+
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
134
|
+
const input = getByRole("textbox");
|
|
135
|
+
const d = new Date(2011, 9, 10);
|
|
136
|
+
|
|
137
|
+
userEvent.type(input, "10-10-2011");
|
|
138
|
+
expect(input.value).toBe("10-10-2011");
|
|
139
|
+
expect(onChange).toHaveBeenCalledTimes(10);
|
|
140
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
141
|
+
fireEvent.blur(input);
|
|
142
|
+
expect(onBlur).toHaveBeenCalled();
|
|
143
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("onChange & onBlur functions are called correctly, also with errors", () => {
|
|
147
|
+
const onBlur = jest.fn();
|
|
148
|
+
const onChange = jest.fn();
|
|
149
|
+
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
150
|
+
const input = getByRole("textbox");
|
|
151
|
+
|
|
152
|
+
userEvent.type(input, "10-10-");
|
|
153
|
+
expect(input.value).toBe("10-10-");
|
|
154
|
+
expect(onChange).toHaveBeenCalledTimes(6);
|
|
155
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
156
|
+
fireEvent.blur(input);
|
|
157
|
+
expect(onBlur).toHaveBeenCalled();
|
|
158
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("onBlur function removes the error when it is fixed", () => {
|
|
162
|
+
const onBlur = jest.fn();
|
|
163
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
164
|
+
const input = getByRole("textbox");
|
|
165
|
+
const d = new Date(2002, 1, 20);
|
|
166
|
+
|
|
167
|
+
userEvent.type(input, "test");
|
|
168
|
+
expect(input.value).toBe("test");
|
|
169
|
+
fireEvent.blur(input);
|
|
170
|
+
expect(onBlur).toHaveBeenCalled();
|
|
171
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Invalid date.", date: null });
|
|
172
|
+
userEvent.clear(input);
|
|
173
|
+
userEvent.type(input, "20-02-2002");
|
|
174
|
+
expect(input.value).toBe("20-02-2002");
|
|
175
|
+
fireEvent.blur(input);
|
|
176
|
+
expect(onBlur).toHaveBeenCalled();
|
|
177
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "20-02-2002", error: null, date: d });
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("onBlur function removes the error when the input is empty", () => {
|
|
181
|
+
const onBlur = jest.fn();
|
|
182
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} optional />);
|
|
183
|
+
const input = getByRole("textbox");
|
|
184
|
+
|
|
185
|
+
userEvent.type(input, "test");
|
|
186
|
+
expect(input.value).toBe("test");
|
|
187
|
+
fireEvent.blur(input);
|
|
188
|
+
expect(onBlur).toHaveBeenCalled();
|
|
189
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Invalid date.", date: null });
|
|
190
|
+
userEvent.clear(input);
|
|
191
|
+
fireEvent.blur(input);
|
|
192
|
+
expect(onBlur).toHaveBeenCalled();
|
|
193
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null, date: null });
|
|
194
|
+
});
|
|
195
|
+
|
|
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 />);
|
|
222
|
+
const calendarAction = getByRole("button");
|
|
223
|
+
const d = new Date();
|
|
224
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
225
|
+
|
|
226
|
+
expect(getByRole("textbox").disabled).toBeTruthy();
|
|
227
|
+
userEvent.click(calendarAction);
|
|
228
|
+
expect(queryByText(d.toLocaleString("en-US", options))).toBeFalsy();
|
|
229
|
+
});
|
|
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 = [
|
|
@@ -56,12 +71,12 @@ describe("Dropdown component tests", () => {
|
|
|
56
71
|
iconSrc: "/testIcon",
|
|
57
72
|
},
|
|
58
73
|
];
|
|
59
|
-
const { getByText,
|
|
74
|
+
const { getByText, getByRole } = render(<DxcDropdown options={options} label="dropdown-test"></DxcDropdown>);
|
|
60
75
|
const dropdown = getByText("dropdown-test");
|
|
61
76
|
act(() => {
|
|
62
77
|
fireEvent.click(dropdown);
|
|
63
78
|
});
|
|
64
|
-
expect(
|
|
79
|
+
expect(getByRole("img").getAttribute("src")).toEqual("/testIcon");
|
|
65
80
|
});
|
|
66
81
|
|
|
67
82
|
test("Dropdown renders with correct icon after option", () => {
|
|
@@ -72,14 +87,14 @@ describe("Dropdown component tests", () => {
|
|
|
72
87
|
iconSrc: "/testIcon",
|
|
73
88
|
},
|
|
74
89
|
];
|
|
75
|
-
const { getByText,
|
|
90
|
+
const { getByText, getByRole } = render(
|
|
76
91
|
<DxcDropdown options={options} optionsIconPosition="after" label="dropdown-test"></DxcDropdown>
|
|
77
92
|
);
|
|
78
93
|
const dropdown = getByText("dropdown-test");
|
|
79
94
|
act(() => {
|
|
80
95
|
fireEvent.click(dropdown);
|
|
81
96
|
});
|
|
82
|
-
expect(
|
|
97
|
+
expect(getByRole("img").getAttribute("src")).toEqual("/testIcon");
|
|
83
98
|
});
|
|
84
99
|
|
|
85
100
|
test("Dropdown renders with caret hidden", () => {
|