@dxc-technology/halstack-react 0.0.0-11cad3f → 0.0.0-1418b62
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 +130 -98
- 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 +31 -25
- package/dist/checkbox/Checkbox.js +23 -17
- package/dist/chip/Chip.js +21 -25
- package/dist/common/variables.js +906 -536
- package/dist/date/Date.js +7 -9
- package/dist/dialog/Dialog.js +15 -32
- package/dist/dropdown/Dropdown.js +118 -69
- 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 +25 -35
- package/dist/footer/dxc_logo.svg +15 -0
- package/dist/header/Header.js +14 -42
- package/dist/header/dxc_logo_black.svg +8 -0
- package/dist/heading/Heading.js +1 -5
- package/dist/input-text/InputText.js +93 -55
- package/dist/layout/ApplicationLayout.js +1 -1
- package/dist/link/Link.js +4 -8
- package/dist/main.d.ts +8 -0
- package/dist/main.js +56 -0
- package/dist/new-date/NewDate.js +400 -0
- package/dist/new-date/index.d.ts +95 -0
- package/dist/new-input-text/NewInputText.js +967 -0
- package/dist/new-input-text/index.d.ts +135 -0
- package/dist/new-select/NewSelect.js +836 -0
- package/dist/new-select/index.d.ts +53 -0
- package/dist/new-textarea/NewTextarea.js +365 -0
- package/dist/new-textarea/index.d.ts +117 -0
- package/dist/number/Number.js +136 -0
- package/dist/number/NumberContext.js +16 -0
- package/dist/number/index.d.ts +113 -0
- package/dist/paginator/Paginator.js +10 -4
- package/dist/password/Password.js +200 -0
- package/dist/password/index.d.ts +94 -0
- package/dist/password/styles.css +3 -0
- package/dist/progress-bar/ProgressBar.js +63 -27
- package/dist/select/Select.js +171 -185
- package/dist/sidenav/Sidenav.js +11 -15
- package/dist/slider/Slider.js +56 -52
- package/dist/spinner/Spinner.js +225 -58
- package/dist/table/Table.js +5 -1
- package/dist/tag/Tag.js +38 -36
- package/dist/textarea/Textarea.js +26 -22
- package/dist/toggle-group/ToggleGroup.js +21 -39
- package/dist/upload/buttons-upload/ButtonsUpload.js +5 -1
- package/dist/upload/dragAndDropArea/DragAndDropArea.js +10 -6
- package/dist/upload/file-upload/FileToUpload.js +1 -1
- package/dist/upload/transaction/Transaction.js +12 -8
- package/dist/upload/transactions/Transactions.js +11 -11
- package/dist/wizard/Wizard.js +8 -8
- package/package.json +4 -2
- package/test/Dropdown.test.js +15 -0
- package/test/FileInput.test.js +201 -0
- package/test/NewDate.test.js +232 -0
- package/test/NewInputText.test.js +734 -0
- package/test/NewTextarea.test.js +195 -0
- package/test/Number.test.js +257 -0
- package/test/Paginator.test.js +1 -1
- package/test/Password.test.js +83 -0
- package/test/ResultsetTable.test.js +1 -2
- package/test/Select.test.js +44 -24
- package/test/Spinner.test.js +5 -0
- 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/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/dxc_logo_wht.png +0 -0
- package/dist/header/dxc_logo_black.png +0 -0
- package/dist/header/dxc_logo_blk_rgb.svg +0 -6
- package/dist/header/dxc_logo_white.png +0 -0
- package/dist/select/Select.stories.js +0 -235
- package/dist/select/readme.md +0 -72
- package/dist/toggle-group/readme.md +0 -82
|
@@ -107,31 +107,31 @@ var DXCTransactions = _styledComponents["default"].div(_templateObject(), functi
|
|
|
107
107
|
var TransactionsText = _styledComponents["default"].span(_templateObject2());
|
|
108
108
|
|
|
109
109
|
var TransactionsTitle = _styledComponents["default"].span(_templateObject3(), function (props) {
|
|
110
|
-
return props.theme.
|
|
110
|
+
return props.theme.uploadedFilesTitleFontSize;
|
|
111
111
|
}, function (props) {
|
|
112
|
-
return props.theme.
|
|
112
|
+
return props.theme.uploadedFilesTitleFontStyle;
|
|
113
113
|
}, function (props) {
|
|
114
|
-
return props.theme.
|
|
114
|
+
return props.theme.uploadedFilesTitleFontWeight;
|
|
115
115
|
}, function (props) {
|
|
116
|
-
return props.theme.
|
|
116
|
+
return props.theme.uploadedFilesTitleFontTextTransform;
|
|
117
117
|
}, function (props) {
|
|
118
|
-
return props.theme.
|
|
118
|
+
return props.theme.uploadedFilesTitleFontColor;
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
var TransactionsSubTitle = _styledComponents["default"].span(_templateObject4(), function (props) {
|
|
122
|
-
return props.theme.
|
|
122
|
+
return props.theme.uploadedFilesSubtitleFontSize;
|
|
123
123
|
}, function (props) {
|
|
124
|
-
return props.theme.
|
|
124
|
+
return props.theme.uploadedFilesSubtitleFontStyle;
|
|
125
125
|
}, function (props) {
|
|
126
|
-
return props.theme.
|
|
126
|
+
return props.theme.uploadedFilesSubtitleFontWeight;
|
|
127
127
|
}, function (props) {
|
|
128
|
-
return props.theme.
|
|
128
|
+
return props.theme.uploadedFilesSubtitleFontTextTransform;
|
|
129
129
|
}, function (props) {
|
|
130
|
-
return props.theme.
|
|
130
|
+
return props.theme.uploadedFilesSubtitleFontColor;
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
var TransactionsNumber = _styledComponents["default"].span(_templateObject5(), function (props) {
|
|
134
|
-
return props.theme.
|
|
134
|
+
return props.theme.uploadedFilesNumberFontWeight;
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
var _default = DxcTransactions;
|
package/dist/wizard/Wizard.js
CHANGED
|
@@ -238,10 +238,10 @@ var DxcWizard = function DxcWizard(_ref) {
|
|
|
238
238
|
src: _invalid_icon["default"]
|
|
239
239
|
}) : ""), step.label || step.description ? _react["default"].createElement(InfoContainer, null, step.label ? _react["default"].createElement(Label, {
|
|
240
240
|
disabled: step.disabled,
|
|
241
|
-
|
|
241
|
+
visited: i <= innerCurrent
|
|
242
242
|
}, step.label) : "", step.description ? _react["default"].createElement(Description, {
|
|
243
243
|
disabled: step.disabled,
|
|
244
|
-
|
|
244
|
+
visited: i <= innerCurrent
|
|
245
245
|
}, step.description) : "") : ""), i === steps.length - 1 ? "" : _react["default"].createElement(StepSeparator, {
|
|
246
246
|
mode: mode
|
|
247
247
|
}));
|
|
@@ -289,15 +289,15 @@ var Step = _styledComponents["default"].button(_templateObject3(), function (pro
|
|
|
289
289
|
var StepHeader = _styledComponents["default"].div(_templateObject4());
|
|
290
290
|
|
|
291
291
|
var IconContainer = _styledComponents["default"].div(_templateObject5(), function (props) {
|
|
292
|
-
return props.disabled ? props.theme.
|
|
292
|
+
return props.disabled ? props.theme.disabledCircleWidth : props.current ? props.theme.selectedCircleWidth : props.theme.circleWidth;
|
|
293
293
|
}, function (props) {
|
|
294
|
-
return props.disabled ? props.theme.
|
|
294
|
+
return props.disabled ? props.theme.disabledCircleHeight : props.current ? props.theme.selectedCircleHeight : props.theme.circleHeight;
|
|
295
295
|
}, function (props) {
|
|
296
|
-
return "\n ".concat(!props.current && !props.disabled ? "border: ".concat(props.theme.circleBorderThickness, " ").concat(props.theme.circleBorderStyle, " ").concat(props.theme.circleBorderColor, ";") : props.current ? "border: ".concat(props.theme.
|
|
296
|
+
return "\n ".concat(!props.current && !props.disabled ? "border: ".concat(props.theme.circleBorderThickness, " ").concat(props.theme.circleBorderStyle, " ").concat(props.theme.circleBorderColor, ";") : props.current ? "border: ".concat(props.theme.selectedCircleBorderThickness, " ").concat(props.theme.selectedCircleBorderStyle, " ").concat(props.theme.selectedCircleBorderColor, ";") : props.disabled ? "border: ".concat(props.theme.disabledCircleBorderThickness, " ").concat(props.theme.disabledCircleBorderStyle, " ").concat(props.theme.disabledCircleBorderColor, ";") : "", "\n background: ").concat(props.disabled ? "".concat(props.theme.disabledBackgroundColor) : props.current ? "".concat(props.theme.stepContainerSelectedBackgroundColor) : "".concat(props.theme.stepContainerBackgroundColor), ";\n ");
|
|
297
297
|
}, function (props) {
|
|
298
298
|
return props.disabled ? "color: ".concat(props.theme.disabledFontColor, ";") : "color: ".concat(props.current ? props.theme.stepContainerSelectedFontColor : props.theme.stepContainerFontColor, ";");
|
|
299
299
|
}, function (props) {
|
|
300
|
-
return !props.current && !props.disabled ? props.theme.circleBorderRadius : props.current ? props.theme.
|
|
300
|
+
return !props.current && !props.disabled ? props.theme.circleBorderRadius : props.current ? props.theme.selectedCircleBorderRadius : props.disabled ? props.theme.disabledCircleBorderRadius : "";
|
|
301
301
|
});
|
|
302
302
|
|
|
303
303
|
var Icon = _styledComponents["default"].img(_templateObject6(), function (props) {
|
|
@@ -354,7 +354,7 @@ var Label = _styledComponents["default"].p(_templateObject12(), function (props)
|
|
|
354
354
|
}, function (props) {
|
|
355
355
|
return props.theme.labelLetterSpacing;
|
|
356
356
|
}, function (props) {
|
|
357
|
-
return props.disabled ? "color: ".concat(props.theme.disabledFontColor, ";") : "color: ".concat(props.
|
|
357
|
+
return props.disabled ? "color: ".concat(props.theme.disabledFontColor, ";") : "color: ".concat(props.visited ? props.theme.visitedLabelFontColor : props.theme.labelFontColor, ";");
|
|
358
358
|
}, function (props) {
|
|
359
359
|
return props.theme.labelFontTextTransform;
|
|
360
360
|
});
|
|
@@ -374,7 +374,7 @@ var Description = _styledComponents["default"].p(_templateObject13(), function (
|
|
|
374
374
|
}, function (props) {
|
|
375
375
|
return props.theme.descriptionFontTextTransform;
|
|
376
376
|
}, function (props) {
|
|
377
|
-
return props.disabled ? "color: ".concat(props.theme.disabledFontColor, ";") : "color: ".concat(props.
|
|
377
|
+
return props.disabled ? "color: ".concat(props.theme.disabledFontColor, ";") : "color: ".concat(props.visited ? props.theme.visitedDescriptionFontColor : props.theme.descriptionFontColor, ";");
|
|
378
378
|
});
|
|
379
379
|
|
|
380
380
|
var StepSeparator = _styledComponents["default"].div(_templateObject14(), function (props) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxc-technology/halstack-react",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-1418b62",
|
|
4
4
|
"description": "DXC Halstack React components library",
|
|
5
5
|
"repository": "dxc-technology/halstack-react",
|
|
6
6
|
"homepage": "http://developer.dxc.com/tools/react",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"url": "https://dxc.com"
|
|
12
12
|
},
|
|
13
13
|
"main": "./dist/main.js",
|
|
14
|
+
"types": "./dist/main.d.ts",
|
|
14
15
|
"peerDependencies": {
|
|
15
16
|
"react": "^16.8.6",
|
|
16
17
|
"react-dom": "^16.8.6",
|
|
@@ -29,7 +30,8 @@
|
|
|
29
30
|
"moment": "2.24.0",
|
|
30
31
|
"prop-types": "^15.7.2",
|
|
31
32
|
"react-use-scrollspy": "^2.0.0",
|
|
32
|
-
"rgb-hex": "^3.0.0"
|
|
33
|
+
"rgb-hex": "^3.0.0",
|
|
34
|
+
"uuid": "^8.3.2"
|
|
33
35
|
},
|
|
34
36
|
"scripts": {
|
|
35
37
|
"test": "jest",
|
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
|
+
});
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import DxcNewDate from "../src/new-date/NewDate";
|
|
6
|
+
|
|
7
|
+
describe("NewDate component tests", () => {
|
|
8
|
+
test("Renders with correct label, helper text, optional, placeholder and clearable action", () => {
|
|
9
|
+
const { getByText, getByRole, getAllByRole } = render(
|
|
10
|
+
<DxcNewDate 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(<DxcNewDate 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(<DxcNewDate 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(<DxcNewDate label="With format MM/dd/yyyy" format="MM/dd/yyyy" onChange={onChange} />);
|
|
43
|
+
const input = getByRole("textbox");
|
|
44
|
+
|
|
45
|
+
userEvent.type(input, "10/90/2010");
|
|
46
|
+
expect(onChange).toHaveBeenCalledTimes(10);
|
|
47
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10/90/2010", error: "Invalid date.", date: null });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("Calendar renders with correct date: today's date", () => {
|
|
51
|
+
const { getByText, getByRole } = render(<DxcNewDate />);
|
|
52
|
+
const calendarAction = getByRole("button");
|
|
53
|
+
const d = new Date();
|
|
54
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
55
|
+
|
|
56
|
+
userEvent.click(calendarAction);
|
|
57
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("Calendar renders with correct date: value prop", () => {
|
|
61
|
+
const { getByText, getByRole } = render(<DxcNewDate value="20-10-2019" />);
|
|
62
|
+
const calendarAction = getByRole("button");
|
|
63
|
+
const d = new Date(2019, 9, 20);
|
|
64
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
65
|
+
|
|
66
|
+
userEvent.click(calendarAction);
|
|
67
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("Calendar renders with correct date: user typed value", () => {
|
|
71
|
+
const { getByText, getByRole } = render(<DxcNewDate />);
|
|
72
|
+
const calendarAction = getByRole("button");
|
|
73
|
+
const d = new Date(2010, 0, 1);
|
|
74
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
75
|
+
const input = getByRole("textbox");
|
|
76
|
+
|
|
77
|
+
userEvent.type(input, "01-01-2010");
|
|
78
|
+
userEvent.click(calendarAction);
|
|
79
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("Calendar renders with correct date: invalid date, renders with today's date", () => {
|
|
83
|
+
const onBlur = jest.fn();
|
|
84
|
+
const { getByText, getByRole } = render(<DxcNewDate onBlur={onBlur} />);
|
|
85
|
+
const calendarAction = getByRole("button");
|
|
86
|
+
const d = new Date();
|
|
87
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
88
|
+
const input = getByRole("textbox");
|
|
89
|
+
|
|
90
|
+
userEvent.type(input, "01-01-xxxx");
|
|
91
|
+
fireEvent.blur(input);
|
|
92
|
+
expect(onBlur).toHaveBeenCalled();
|
|
93
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "01-01-xxxx", error: "Invalid date.", date: null });
|
|
94
|
+
userEvent.click(calendarAction);
|
|
95
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("Selecting a date from the calendar with an specific format", () => {
|
|
99
|
+
const { getByText, getByRole } = render(<DxcNewDate label="With format M-dd-yyyy" format="M-dd-yyyy" />);
|
|
100
|
+
const input = getByRole("textbox");
|
|
101
|
+
const calendarAction = getByRole("button");
|
|
102
|
+
userEvent.click(calendarAction);
|
|
103
|
+
const dayButton = getByText("10").closest('button');
|
|
104
|
+
fireEvent.click(dayButton);
|
|
105
|
+
const d = new Date();
|
|
106
|
+
d.setDate(10);
|
|
107
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
108
|
+
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
109
|
+
fireEvent.keyDown(document, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
110
|
+
expect(input.value).toBe(`${d.getMonth() + 1}-10-${d.getFullYear()}`);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("Selecting a date from the calendar (using keyboard presses)", () => {
|
|
114
|
+
const { getByRole } = render(<DxcNewDate />);
|
|
115
|
+
const calendarAction = getByRole("button");
|
|
116
|
+
const input = getByRole("textbox");
|
|
117
|
+
|
|
118
|
+
userEvent.type(input, "01-01-2010");
|
|
119
|
+
userEvent.click(calendarAction);
|
|
120
|
+
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
121
|
+
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
122
|
+
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
123
|
+
fireEvent.keyDown(document, { key: "ArrowLeft", code: "ArrowLeft", keyCode: 37, charCode: 37 });
|
|
124
|
+
fireEvent.keyDown(document, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
125
|
+
expect(input.value).toBe("03-01-2010");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("onChange & onBlur functions are called correctly", () => {
|
|
129
|
+
const onBlur = jest.fn();
|
|
130
|
+
const onChange = jest.fn();
|
|
131
|
+
const { getByRole } = render(<DxcNewDate onChange={onChange} onBlur={onBlur} />);
|
|
132
|
+
const input = getByRole("textbox");
|
|
133
|
+
const d = new Date(2011, 9, 10);
|
|
134
|
+
|
|
135
|
+
userEvent.type(input, "10-10-2011");
|
|
136
|
+
expect(input.value).toBe("10-10-2011");
|
|
137
|
+
expect(onChange).toHaveBeenCalledTimes(10);
|
|
138
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
139
|
+
fireEvent.blur(input);
|
|
140
|
+
expect(onBlur).toHaveBeenCalled();
|
|
141
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("onChange & onBlur functions are called correctly, also with errors", () => {
|
|
145
|
+
const onBlur = jest.fn();
|
|
146
|
+
const onChange = jest.fn();
|
|
147
|
+
const { getByRole } = render(<DxcNewDate onChange={onChange} onBlur={onBlur} />);
|
|
148
|
+
const input = getByRole("textbox");
|
|
149
|
+
|
|
150
|
+
userEvent.type(input, "10-10-");
|
|
151
|
+
expect(input.value).toBe("10-10-");
|
|
152
|
+
expect(onChange).toHaveBeenCalledTimes(6);
|
|
153
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
154
|
+
fireEvent.blur(input);
|
|
155
|
+
expect(onBlur).toHaveBeenCalled();
|
|
156
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("onBlur function removes the error when it is fixed", () => {
|
|
160
|
+
const onBlur = jest.fn();
|
|
161
|
+
const { getByRole } = render(<DxcNewDate onBlur={onBlur} />);
|
|
162
|
+
const input = getByRole("textbox");
|
|
163
|
+
const d = new Date(2002, 1, 20);
|
|
164
|
+
|
|
165
|
+
userEvent.type(input, "test");
|
|
166
|
+
expect(input.value).toBe("test");
|
|
167
|
+
fireEvent.blur(input);
|
|
168
|
+
expect(onBlur).toHaveBeenCalled();
|
|
169
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Invalid date.", date: null });
|
|
170
|
+
userEvent.clear(input);
|
|
171
|
+
userEvent.type(input, "20-02-2002");
|
|
172
|
+
expect(input.value).toBe("20-02-2002");
|
|
173
|
+
fireEvent.blur(input);
|
|
174
|
+
expect(onBlur).toHaveBeenCalled();
|
|
175
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "20-02-2002", error: null, date: d });
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("onBlur function removes the error when the input is empty", () => {
|
|
179
|
+
const onBlur = jest.fn();
|
|
180
|
+
const { getByRole } = render(<DxcNewDate onBlur={onBlur} optional />);
|
|
181
|
+
const input = getByRole("textbox");
|
|
182
|
+
|
|
183
|
+
userEvent.type(input, "test");
|
|
184
|
+
expect(input.value).toBe("test");
|
|
185
|
+
fireEvent.blur(input);
|
|
186
|
+
expect(onBlur).toHaveBeenCalled();
|
|
187
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Invalid date.", date: null });
|
|
188
|
+
userEvent.clear(input);
|
|
189
|
+
fireEvent.blur(input);
|
|
190
|
+
expect(onBlur).toHaveBeenCalled();
|
|
191
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null, date: null });
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test("onBlur & onChange functions error: required field (not optional)", () => {
|
|
195
|
+
const onBlur = jest.fn();
|
|
196
|
+
const onChange = jest.fn();
|
|
197
|
+
const { getByRole } = render(<DxcNewDate onBlur={onBlur} onChange={onChange} />);
|
|
198
|
+
const date = getByRole("textbox");
|
|
199
|
+
|
|
200
|
+
userEvent.type(date, "t");
|
|
201
|
+
expect(date.value).toBe("t");
|
|
202
|
+
userEvent.clear(date);
|
|
203
|
+
fireEvent.blur(date);
|
|
204
|
+
expect(onBlur).toHaveBeenCalled();
|
|
205
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value.", date: null });
|
|
206
|
+
expect(onChange).toHaveBeenCalled();
|
|
207
|
+
expect(onChange).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value.", date: null });
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("Disabled date (calendar action must be shown but not clickable)", () => {
|
|
211
|
+
const { getByRole, queryByText } = render(<DxcNewDate disabled />);
|
|
212
|
+
const calendarAction = getByRole("button");
|
|
213
|
+
const d = new Date();
|
|
214
|
+
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
215
|
+
|
|
216
|
+
expect(getByRole("textbox").disabled).toBeTruthy();
|
|
217
|
+
userEvent.click(calendarAction);
|
|
218
|
+
expect(queryByText(d.toLocaleString("en-US", options))).toBeFalsy();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("Input has correct accesibility attributes", () => {
|
|
222
|
+
const { getByRole } = render(<DxcNewDate label="Date label" />);
|
|
223
|
+
const input = getByRole("textbox");
|
|
224
|
+
expect(input.getAttribute("aria-autocomplete")).toBeNull();
|
|
225
|
+
expect(input.getAttribute("aria-controls")).toBeNull();
|
|
226
|
+
expect(input.getAttribute("aria-expanded")).toBeNull();
|
|
227
|
+
const calendarAction = getByRole("button");
|
|
228
|
+
userEvent.click(calendarAction);
|
|
229
|
+
const datePicker = getByRole("dialog");
|
|
230
|
+
expect(datePicker.getAttribute("aria-modal")).toBe("true");
|
|
231
|
+
});
|
|
232
|
+
});
|