@dxc-technology/halstack-react 0.0.0-e2d44ba → 0.0.0-e628009
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 +69 -61
- package/dist/V3Textarea/V3Textarea.js +264 -0
- package/dist/alert/Alert.js +4 -4
- package/dist/alert/index.d.ts +51 -0
- package/dist/button/Button.js +3 -3
- package/dist/common/variables.js +302 -98
- package/dist/date/Date.js +10 -12
- package/dist/{new-date/NewDate.js → date-input/DateInput.js} +69 -72
- package/dist/date-input/index.d.ts +95 -0
- 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 +44 -18
- package/dist/footer/Icons.js +77 -0
- package/dist/header/Header.js +82 -51
- package/dist/header/Icons.js +59 -0
- package/dist/heading/Heading.js +12 -0
- package/dist/input-text/Icons.js +22 -0
- package/dist/input-text/InputText.js +7 -9
- 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 +37 -21
- package/dist/new-select/NewSelect.js +836 -0
- package/dist/new-select/index.d.ts +53 -0
- package/dist/{number/Number.js → number-input/NumberInput.js} +9 -11
- 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 +5 -11
- package/dist/{password/Password.js → password-input/PasswordInput.js} +11 -13
- package/dist/password-input/index.d.ts +94 -0
- package/dist/sidenav/Sidenav.js +6 -4
- package/dist/slider/Slider.js +104 -19
- package/dist/tag/Tag.js +26 -32
- package/dist/{new-input-text/NewInputText.js → text-input/TextInput.js} +180 -170
- package/dist/text-input/index.d.ts +135 -0
- package/dist/textarea/Textarea.js +227 -122
- package/dist/textarea/index.d.ts +117 -0
- package/dist/toggle-group/ToggleGroup.js +132 -28
- package/dist/upload/Upload.js +3 -3
- package/dist/upload/buttons-upload/ButtonsUpload.js +7 -11
- package/dist/upload/buttons-upload/Icons.js +40 -0
- package/dist/upload/dragAndDropArea/DragAndDropArea.js +14 -14
- package/dist/upload/dragAndDropArea/Icons.js +39 -0
- package/dist/upload/file-upload/FileToUpload.js +26 -21
- package/dist/upload/file-upload/Icons.js +66 -0
- package/dist/upload/transaction/Icons.js +160 -0
- package/dist/upload/transaction/Transaction.js +11 -38
- package/dist/wizard/Icons.js +65 -0
- package/dist/wizard/Wizard.js +3 -9
- package/package.json +2 -1
- package/test/Date.test.js +48 -44
- package/test/{NewDate.test.js → DateInput.test.js} +66 -27
- 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/{Number.test.js → NumberInput.test.js} +84 -66
- package/test/PasswordInput.test.js +83 -0
- package/test/Slider.test.js +9 -17
- package/test/{NewInputText.test.js → TextInput.test.js} +146 -231
- package/test/Textarea.test.js +193 -0
- package/test/ToggleGroup.test.js +5 -1
- package/test/Upload.test.js +5 -5
- package/test/{TextArea.test.js → V3TextArea.test.js} +6 -7
- 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/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/new-textarea/NewTextarea.js +0 -346
- 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/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/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/readme.md +0 -78
- package/dist/toggle/Toggle.stories.js +0 -297
- package/dist/toggle/readme.md +0 -80
- 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/NewTextarea.test.js +0 -201
- package/test/Password.test.js +0 -76
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, getByTestId } = render(<
|
|
54
|
-
fireEvent.click(getByTestId(
|
|
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
59
|
const { getByRole, getByText, rerender, getByPlaceholderText, getByTestId } = render(
|
|
60
|
-
<
|
|
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 = getByTestId(
|
|
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.getByTestId(
|
|
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.getByTestId(
|
|
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.getByTestId(
|
|
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.getByTestId(
|
|
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, getByTestId } = 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 = getByTestId(
|
|
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.getByTestId(
|
|
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.getByTestId(
|
|
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");
|
|
@@ -2,41 +2,55 @@ import React from "react";
|
|
|
2
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("
|
|
7
|
+
describe("DateInput component tests", () => {
|
|
8
8
|
test("Renders with correct label, helper text, optional, placeholder and clearable action", () => {
|
|
9
9
|
const { getByText, getByRole, getAllByRole } = render(
|
|
10
|
-
<
|
|
10
|
+
<DxcDateInput label="Example label" helperText="Example of helper text" placeholder optional clearable />
|
|
11
11
|
);
|
|
12
12
|
const input = getByRole("textbox");
|
|
13
13
|
expect(getByText("Example label")).toBeTruthy();
|
|
14
14
|
expect(getByText("Example of helper text")).toBeTruthy();
|
|
15
15
|
expect(getByText("(Optional)")).toBeTruthy();
|
|
16
16
|
expect(input.getAttribute("placeholder")).toBe("DD-MM-YYYY");
|
|
17
|
-
userEvent.type(input, "10/
|
|
17
|
+
userEvent.type(input, "10/10/2010");
|
|
18
18
|
const closeAction = getAllByRole("button")[0];
|
|
19
19
|
userEvent.click(closeAction);
|
|
20
20
|
expect(input.value).toBe("");
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
test("Renders with personalized error", () => {
|
|
24
|
-
const { getByText } = render(<
|
|
25
|
-
|
|
24
|
+
const { getByText } = render(<DxcDateInput error="Personalized error." />);
|
|
26
25
|
expect(getByText("Personalized error.")).toBeTruthy();
|
|
27
26
|
});
|
|
28
27
|
|
|
29
|
-
test("Renders with correct format: user typed date but it's invalid", () => {
|
|
30
|
-
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} />);
|
|
31
34
|
const input = getByRole("textbox");
|
|
32
35
|
|
|
33
36
|
userEvent.type(input, "10/90/2010");
|
|
34
37
|
fireEvent.blur(input);
|
|
35
|
-
|
|
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 });
|
|
36
50
|
});
|
|
37
51
|
|
|
38
52
|
test("Calendar renders with correct date: today's date", () => {
|
|
39
|
-
const { getByText, getByRole } = render(<
|
|
53
|
+
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
40
54
|
const calendarAction = getByRole("button");
|
|
41
55
|
const d = new Date();
|
|
42
56
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -46,7 +60,7 @@ describe("NewDate component tests", () => {
|
|
|
46
60
|
});
|
|
47
61
|
|
|
48
62
|
test("Calendar renders with correct date: value prop", () => {
|
|
49
|
-
const { getByText, getByRole } = render(<
|
|
63
|
+
const { getByText, getByRole } = render(<DxcDateInput value="20-10-2019" />);
|
|
50
64
|
const calendarAction = getByRole("button");
|
|
51
65
|
const d = new Date(2019, 9, 20);
|
|
52
66
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -56,7 +70,7 @@ describe("NewDate component tests", () => {
|
|
|
56
70
|
});
|
|
57
71
|
|
|
58
72
|
test("Calendar renders with correct date: user typed value", () => {
|
|
59
|
-
const { getByText, getByRole } = render(<
|
|
73
|
+
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
60
74
|
const calendarAction = getByRole("button");
|
|
61
75
|
const d = new Date(2010, 0, 1);
|
|
62
76
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -68,7 +82,8 @@ describe("NewDate component tests", () => {
|
|
|
68
82
|
});
|
|
69
83
|
|
|
70
84
|
test("Calendar renders with correct date: invalid date, renders with today's date", () => {
|
|
71
|
-
const
|
|
85
|
+
const onBlur = jest.fn();
|
|
86
|
+
const { getByText, getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
72
87
|
const calendarAction = getByRole("button");
|
|
73
88
|
const d = new Date();
|
|
74
89
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -76,17 +91,18 @@ describe("NewDate component tests", () => {
|
|
|
76
91
|
|
|
77
92
|
userEvent.type(input, "01-01-xxxx");
|
|
78
93
|
fireEvent.blur(input);
|
|
79
|
-
expect(
|
|
94
|
+
expect(onBlur).toHaveBeenCalled();
|
|
95
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "01-01-xxxx", error: "Invalid date.", date: null });
|
|
80
96
|
userEvent.click(calendarAction);
|
|
81
97
|
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
82
98
|
});
|
|
83
99
|
|
|
84
100
|
test("Selecting a date from the calendar with an specific format", () => {
|
|
85
|
-
const { getByText, getByRole } = render(<
|
|
101
|
+
const { getByText, getByRole } = render(<DxcDateInput label="With format M-dd-yyyy" format="M-dd-yyyy" />);
|
|
86
102
|
const input = getByRole("textbox");
|
|
87
103
|
const calendarAction = getByRole("button");
|
|
88
104
|
userEvent.click(calendarAction);
|
|
89
|
-
const dayButton =
|
|
105
|
+
const dayButton = getByText("10").closest("button");
|
|
90
106
|
fireEvent.click(dayButton);
|
|
91
107
|
const d = new Date();
|
|
92
108
|
d.setDate(10);
|
|
@@ -97,7 +113,7 @@ describe("NewDate component tests", () => {
|
|
|
97
113
|
});
|
|
98
114
|
|
|
99
115
|
test("Selecting a date from the calendar (using keyboard presses)", () => {
|
|
100
|
-
const { getByRole } = render(<
|
|
116
|
+
const { getByRole } = render(<DxcDateInput />);
|
|
101
117
|
const calendarAction = getByRole("button");
|
|
102
118
|
const input = getByRole("textbox");
|
|
103
119
|
|
|
@@ -114,14 +130,14 @@ describe("NewDate component tests", () => {
|
|
|
114
130
|
test("onChange & onBlur functions are called correctly", () => {
|
|
115
131
|
const onBlur = jest.fn();
|
|
116
132
|
const onChange = jest.fn();
|
|
117
|
-
const { getByRole } = render(<
|
|
133
|
+
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
118
134
|
const input = getByRole("textbox");
|
|
119
135
|
const d = new Date(2011, 9, 10);
|
|
120
136
|
|
|
121
137
|
userEvent.type(input, "10-10-2011");
|
|
122
138
|
expect(input.value).toBe("10-10-2011");
|
|
123
139
|
expect(onChange).toHaveBeenCalledTimes(10);
|
|
124
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", date: d });
|
|
140
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
125
141
|
fireEvent.blur(input);
|
|
126
142
|
expect(onBlur).toHaveBeenCalled();
|
|
127
143
|
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
@@ -130,14 +146,13 @@ describe("NewDate component tests", () => {
|
|
|
130
146
|
test("onChange & onBlur functions are called correctly, also with errors", () => {
|
|
131
147
|
const onBlur = jest.fn();
|
|
132
148
|
const onChange = jest.fn();
|
|
133
|
-
const { getByRole } = render(<
|
|
149
|
+
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
134
150
|
const input = getByRole("textbox");
|
|
135
|
-
const d = new Date(2011, 9, 10);
|
|
136
151
|
|
|
137
152
|
userEvent.type(input, "10-10-");
|
|
138
153
|
expect(input.value).toBe("10-10-");
|
|
139
154
|
expect(onChange).toHaveBeenCalledTimes(6);
|
|
140
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", date: null });
|
|
155
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
141
156
|
fireEvent.blur(input);
|
|
142
157
|
expect(onBlur).toHaveBeenCalled();
|
|
143
158
|
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
@@ -145,7 +160,7 @@ describe("NewDate component tests", () => {
|
|
|
145
160
|
|
|
146
161
|
test("onBlur function removes the error when it is fixed", () => {
|
|
147
162
|
const onBlur = jest.fn();
|
|
148
|
-
const { getByRole } = render(<
|
|
163
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
149
164
|
const input = getByRole("textbox");
|
|
150
165
|
const d = new Date(2002, 1, 20);
|
|
151
166
|
|
|
@@ -164,7 +179,7 @@ describe("NewDate component tests", () => {
|
|
|
164
179
|
|
|
165
180
|
test("onBlur function removes the error when the input is empty", () => {
|
|
166
181
|
const onBlur = jest.fn();
|
|
167
|
-
const { getByRole } = render(<
|
|
182
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} optional />);
|
|
168
183
|
const input = getByRole("textbox");
|
|
169
184
|
|
|
170
185
|
userEvent.type(input, "test");
|
|
@@ -178,8 +193,32 @@ describe("NewDate component tests", () => {
|
|
|
178
193
|
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null, date: null });
|
|
179
194
|
});
|
|
180
195
|
|
|
181
|
-
test("
|
|
182
|
-
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 />);
|
|
183
222
|
const calendarAction = getByRole("button");
|
|
184
223
|
const d = new Date();
|
|
185
224
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -190,7 +229,7 @@ describe("NewDate component tests", () => {
|
|
|
190
229
|
});
|
|
191
230
|
|
|
192
231
|
test("Input has correct accesibility attributes", () => {
|
|
193
|
-
const { getByRole } = render(<
|
|
232
|
+
const { getByRole } = render(<DxcDateInput label="Date input label" />);
|
|
194
233
|
const input = getByRole("textbox");
|
|
195
234
|
expect(input.getAttribute("aria-autocomplete")).toBeNull();
|
|
196
235
|
expect(input.getAttribute("aria-controls")).toBeNull();
|