@dxc-technology/halstack-react 0.0.0-13e0035 → 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 +44 -39
- package/dist/accordion-group/AccordionGroup.js +1 -3
- package/dist/alert/Alert.js +124 -113
- package/dist/alert/index.d.ts +51 -0
- package/dist/button/Button.js +31 -25
- package/dist/checkbox/Checkbox.js +19 -13
- package/dist/common/variables.js +507 -344
- package/dist/date/Date.js +5 -7
- package/dist/dialog/Dialog.js +8 -30
- package/dist/dropdown/Dropdown.js +108 -68
- 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/header/Header.js +3 -23
- 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 +16 -0
- package/dist/new-date/NewDate.js +68 -67
- package/dist/new-date/index.d.ts +95 -0
- package/dist/new-input-text/NewInputText.js +169 -159
- 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 +60 -37
- package/dist/new-textarea/index.d.ts +117 -0
- package/dist/number/Number.js +5 -3
- package/dist/number/index.d.ts +113 -0
- package/dist/password/Password.js +7 -3
- package/dist/password/index.d.ts +94 -0
- package/dist/progress-bar/ProgressBar.js +62 -26
- package/dist/select/Select.js +122 -158
- package/dist/sidenav/Sidenav.js +6 -4
- package/dist/slider/Slider.js +56 -52
- package/dist/spinner/Spinner.js +217 -54
- package/dist/tag/Tag.js +26 -32
- package/dist/toggle-group/ToggleGroup.js +21 -39
- package/dist/upload/transaction/Transaction.js +2 -2
- package/package.json +2 -1
- package/test/FileInput.test.js +201 -0
- package/test/NewDate.test.js +41 -12
- package/test/NewInputText.test.js +106 -189
- package/test/NewTextarea.test.js +96 -102
- package/test/Number.test.js +46 -30
- package/test/Paginator.test.js +1 -1
- package/test/Password.test.js +17 -10
- package/test/ResultsetTable.test.js +1 -2
- package/test/Select.test.js +40 -17
- 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/select/Select.stories.js +0 -235
- package/dist/select/readme.md +0 -72
- package/dist/toggle-group/readme.md +0 -82
|
@@ -27,18 +27,8 @@ var _variables = require("../common/variables.js");
|
|
|
27
27
|
|
|
28
28
|
var _useTheme = _interopRequireDefault(require("../useTheme.js"));
|
|
29
29
|
|
|
30
|
-
function _templateObject6() {
|
|
31
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n height: ", ";\n width: ", ";\n overflow: hidden;\n display: flex;\n img,\n svg {\n height: 100%;\n width: 100%;\n }\n"]);
|
|
32
|
-
|
|
33
|
-
_templateObject6 = function _templateObject6() {
|
|
34
|
-
return data;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
30
|
function _templateObject5() {
|
|
41
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n height: ", ";\n width: ", ";\n"]);
|
|
31
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n height: ", ";\n width: ", ";\n overflow: hidden;\n display: flex;\n img,\n svg {\n height: 100%;\n width: 100%;\n }\n"]);
|
|
42
32
|
|
|
43
33
|
_templateObject5 = function _templateObject5() {
|
|
44
34
|
return data;
|
|
@@ -48,7 +38,7 @@ function _templateObject5() {
|
|
|
48
38
|
}
|
|
49
39
|
|
|
50
40
|
function _templateObject4() {
|
|
51
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
41
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n height: ", ";\n width: ", ";\n"]);
|
|
52
42
|
|
|
53
43
|
_templateObject4 = function _templateObject4() {
|
|
54
44
|
return data;
|
|
@@ -58,7 +48,7 @@ function _templateObject4() {
|
|
|
58
48
|
}
|
|
59
49
|
|
|
60
50
|
function _templateObject3() {
|
|
61
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
51
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n"]);
|
|
62
52
|
|
|
63
53
|
_templateObject3 = function _templateObject3() {
|
|
64
54
|
return data;
|
|
@@ -68,7 +58,7 @@ function _templateObject3() {
|
|
|
68
58
|
}
|
|
69
59
|
|
|
70
60
|
function _templateObject2() {
|
|
71
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n"]);
|
|
61
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: column;\n justify-content: center;\n\n ", "\n"]);
|
|
72
62
|
|
|
73
63
|
_templateObject2 = function _templateObject2() {
|
|
74
64
|
return data;
|
|
@@ -78,7 +68,7 @@ function _templateObject2() {
|
|
|
78
68
|
}
|
|
79
69
|
|
|
80
70
|
function _templateObject() {
|
|
81
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n\n display: flex;\n flex-direction:
|
|
71
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n\n display: flex;\n flex-direction: row;\n opacity: 1;\n min-height: 40px;\n"]);
|
|
82
72
|
|
|
83
73
|
_templateObject = function _templateObject() {
|
|
84
74
|
return data;
|
|
@@ -123,27 +113,25 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
|
123
113
|
}
|
|
124
114
|
|
|
125
115
|
setSelectedValue(newSelectedOptions);
|
|
126
|
-
} else
|
|
127
|
-
setSelectedValue(selectedOption === selectedValue ? null : selectedOption);
|
|
128
|
-
}
|
|
116
|
+
} else setSelectedValue(selectedOption === selectedValue ? null : selectedOption);
|
|
129
117
|
} else if (multiple) {
|
|
130
118
|
newSelectedOptions = value.map(function (v) {
|
|
131
119
|
return v;
|
|
132
120
|
});
|
|
133
|
-
newSelectedOptions.push(selectedOption);
|
|
134
|
-
}
|
|
135
121
|
|
|
136
|
-
|
|
137
|
-
|
|
122
|
+
if (newSelectedOptions.includes(selectedOption)) {
|
|
123
|
+
var _index = newSelectedOptions.indexOf(selectedOption);
|
|
124
|
+
|
|
125
|
+
newSelectedOptions.splice(_index, 1);
|
|
126
|
+
} else newSelectedOptions.push(selectedOption);
|
|
138
127
|
}
|
|
128
|
+
|
|
129
|
+
typeof onChange === "function" && onChange(multiple ? newSelectedOptions : selectedOption);
|
|
139
130
|
};
|
|
140
131
|
|
|
141
132
|
var handleKeyPress = function handleKeyPress(event, optionValue) {
|
|
142
133
|
event.preventDefault();
|
|
143
|
-
|
|
144
|
-
if (!disabled && (event.nativeEvent.code === "Enter" || event.nativeEvent.code === "Space")) {
|
|
145
|
-
handleToggleChange(optionValue);
|
|
146
|
-
}
|
|
134
|
+
if (!disabled && (event.nativeEvent.code === "Enter" || event.nativeEvent.code === "Space")) handleToggleChange(optionValue);
|
|
147
135
|
};
|
|
148
136
|
|
|
149
137
|
return _react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
@@ -151,7 +139,7 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
|
151
139
|
}, _react["default"].createElement(ToggleGroup, {
|
|
152
140
|
margin: margin,
|
|
153
141
|
disabled: disabled
|
|
154
|
-
},
|
|
142
|
+
}, options.map(function (option, i) {
|
|
155
143
|
return _react["default"].createElement(ToggleContainer, {
|
|
156
144
|
selected: multiple ? value ? value.includes(option.value) : selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
|
|
157
145
|
tabIndex: !disabled ? tabIndex : -1,
|
|
@@ -171,7 +159,7 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
|
171
159
|
}) : _react["default"].createElement(LabelContainer, {
|
|
172
160
|
disabled: disabled
|
|
173
161
|
}, option.label));
|
|
174
|
-
})))
|
|
162
|
+
})));
|
|
175
163
|
};
|
|
176
164
|
|
|
177
165
|
var ToggleGroup = _styledComponents["default"].div(_templateObject(), function (props) {
|
|
@@ -186,13 +174,11 @@ var ToggleGroup = _styledComponents["default"].div(_templateObject(), function (
|
|
|
186
174
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
187
175
|
});
|
|
188
176
|
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
var ToggleContainer = _styledComponents["default"].div(_templateObject3(), function (props) {
|
|
192
|
-
return "\n background-color: ".concat(props.selected ? props.disabled ? props.theme.disabledSelectedBackgroundColor : props.theme.selectedBackgroundColor : props.disabled ? props.theme.disabledUnselectedBackgroundColor : props.theme.unselectedBackgroundColor, ";\n &:focus {\n outline: ").concat(props.theme.focusColor, " auto 1px;\n }\n border-radius: ").concat(props.isFirst ? "4px 0 0 4px" : props.isLast ? "0 4px 4px 0" : "0", ";\n color: ").concat(props.selected ? props.theme.selectedFontColor : props.theme.unselectedFontColor, ";\n padding: ").concat(props.isIcon ? "".concat(props.theme.iconPaddingTop, " ").concat(props.theme.iconPaddingRight, " ").concat(props.theme.iconPaddingBottom, " ").concat(props.theme.iconPaddingLeft) : "".concat(props.theme.labelPaddingTop, " ").concat(props.theme.labelPaddingRight, " ").concat(props.theme.labelPaddingBottom, " ").concat(props.theme.labelPaddingLeft), ";\n ").concat(!props.disabled ? "&:hover {\n background-color: ".concat(props.selected ? props.theme.selectedHoverBackgroundColor : props.theme.unselectedHoverBackgroundColor, ";\n color: ").concat(props.selected ? props.theme.selectedHoverFontColor : props.theme.unselectedHoverFontColor, " !important;\n }\n cursor: pointer;") : "color: ".concat(props.selected ? props.theme.disabledSelectedFontColor : props.theme.disabledUnselectedFontColor, " !important;\n cursor: not-allowed;"), "\n ");
|
|
177
|
+
var ToggleContainer = _styledComponents["default"].div(_templateObject2(), function (props) {
|
|
178
|
+
return "\n background-color: ".concat(props.selected ? props.disabled ? props.theme.selectedDisabledBackgroundColor : props.theme.selectedBackgroundColor : props.disabled ? props.theme.unselectedDisabledBackgroundColor : props.theme.unselectedBackgroundColor, ";\n border-radius: ").concat(props.isFirst ? "4px 0 0 4px" : props.isLast ? "0 4px 4px 0" : "0", ";\n color: ").concat(props.selected ? props.theme.selectedFontColor : props.theme.unselectedFontColor, ";\n padding: ").concat(props.isIcon ? "".concat(props.theme.iconPaddingTop, " ").concat(props.theme.iconPaddingRight, " ").concat(props.theme.iconPaddingBottom, " ").concat(props.theme.iconPaddingLeft) : "".concat(props.theme.labelPaddingTop, " ").concat(props.theme.labelPaddingRight, " ").concat(props.theme.labelPaddingBottom, " ").concat(props.theme.labelPaddingLeft), ";\n \n ").concat(!props.disabled ? ":hover {\n background-color: ".concat(props.selected ? props.theme.selectedHoverBackgroundColor : props.theme.unselectedHoverBackgroundColor, ";\n }\n :active {\n background-color: ").concat(props.selected ? props.theme.selectedActiveBackgroundColor : props.theme.unselectedActiveBackgroundColor, ";\n color: #ffffff;\n } \n :focus {\n outline: ").concat(props.theme.focusColor, " solid 2px;\n outline-offset: -2px;\n }\n cursor: pointer;") : "color: ".concat(props.selected ? props.theme.selectedDisabledFontColor : props.theme.unselectedDisabledFontColor, " !important;\n cursor: not-allowed;"), "\n ");
|
|
193
179
|
});
|
|
194
180
|
|
|
195
|
-
var LabelContainer = _styledComponents["default"].span(
|
|
181
|
+
var LabelContainer = _styledComponents["default"].span(_templateObject3(), function (props) {
|
|
196
182
|
return props.theme.fontFamily;
|
|
197
183
|
}, function (props) {
|
|
198
184
|
return props.theme.fontSize;
|
|
@@ -200,19 +186,15 @@ var LabelContainer = _styledComponents["default"].span(_templateObject4(), funct
|
|
|
200
186
|
return props.theme.fontStyle;
|
|
201
187
|
}, function (props) {
|
|
202
188
|
return props.theme.fontWeight;
|
|
203
|
-
}, function (props) {
|
|
204
|
-
return props.theme.fontTextTransform;
|
|
205
|
-
}, function (props) {
|
|
206
|
-
return props.theme.fontLetterSpacing;
|
|
207
189
|
});
|
|
208
190
|
|
|
209
|
-
var Icon = _styledComponents["default"].img(
|
|
191
|
+
var Icon = _styledComponents["default"].img(_templateObject4(), function (props) {
|
|
210
192
|
return props.theme.iconSize;
|
|
211
193
|
}, function (props) {
|
|
212
194
|
return props.theme.iconSize;
|
|
213
195
|
});
|
|
214
196
|
|
|
215
|
-
var IconContainer = _styledComponents["default"].div(
|
|
197
|
+
var IconContainer = _styledComponents["default"].div(_templateObject5(), function (props) {
|
|
216
198
|
return props.theme.iconSize;
|
|
217
199
|
}, function (props) {
|
|
218
200
|
return props.theme.iconSize;
|
|
@@ -119,8 +119,8 @@ var DxcTransaction = function DxcTransaction(_ref) {
|
|
|
119
119
|
color: colorsTheme.upload.backgroundColor
|
|
120
120
|
}, _react["default"].createElement(_Spinner["default"], {
|
|
121
121
|
mode: "small"
|
|
122
|
-
}))) || status === "success" && _react["default"].createElement(FileData, null, _react["default"].createElement(FileName, null, name), _react["default"].createElement(
|
|
123
|
-
|
|
122
|
+
}))) || status === "success" && _react["default"].createElement(FileData, null, _react["default"].createElement(FileName, null, name), _react["default"].createElement(FileStatus, {
|
|
123
|
+
status: status
|
|
124
124
|
})) || status === "error" && _react["default"].createElement(FileData, null, _react["default"].createElement(_Tooltip["default"], {
|
|
125
125
|
title: message
|
|
126
126
|
}, _react["default"].createElement(FileName, null, name)), _react["default"].createElement(FileStatus, {
|
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",
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent, waitFor } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import DxcFileInput from "../src/file-input/FileInput";
|
|
6
|
+
|
|
7
|
+
describe("FileInput component tests", () => {
|
|
8
|
+
const file1 = new File(["file1"], "file1.png", { type: "image/png" });
|
|
9
|
+
const file2 = new File(["file2"], "file2.txt", {
|
|
10
|
+
type: "text/plain",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const files = [
|
|
14
|
+
{
|
|
15
|
+
error: null,
|
|
16
|
+
preview: null,
|
|
17
|
+
file: file1,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
error: "Error message",
|
|
21
|
+
preview: null,
|
|
22
|
+
file: file2,
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
test("Renders with correct labels and helper text in file mode", () => {
|
|
27
|
+
const { getByText } = render(<DxcFileInput label="File input label" helperText="File input helper text" />);
|
|
28
|
+
expect(getByText("File input label")).toBeTruthy();
|
|
29
|
+
expect(getByText("File input helper text")).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
test("Renders with correct button label in file mode", () => {
|
|
32
|
+
const { getByText } = render(<DxcFileInput label="File input label" helperText="File input helper text" />);
|
|
33
|
+
expect(getByText("Select files")).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
test("Renders with correct labels in filedrop mode", () => {
|
|
36
|
+
const { getByText } = render(
|
|
37
|
+
<DxcFileInput label="File input label" helperText="File input helper text" mode="filedrop" />
|
|
38
|
+
);
|
|
39
|
+
expect(getByText("Select")).toBeTruthy();
|
|
40
|
+
expect(getByText("or drop files")).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
test("Renders with correct labels in dropzone mode", () => {
|
|
43
|
+
const { getByText } = render(
|
|
44
|
+
<DxcFileInput label="File input label" helperText="File input helper text" mode="dropzone" />
|
|
45
|
+
);
|
|
46
|
+
expect(getByText("Select")).toBeTruthy();
|
|
47
|
+
expect(getByText("or drop files")).toBeTruthy();
|
|
48
|
+
});
|
|
49
|
+
test("Disabled file input", () => {
|
|
50
|
+
const { getByText, getByRole } = render(
|
|
51
|
+
<DxcFileInput label="File input label" helperText="File input helper text" disabled />
|
|
52
|
+
);
|
|
53
|
+
expect(getByText("Select files")).toBeTruthy();
|
|
54
|
+
const button = getByRole("button");
|
|
55
|
+
expect(button.disabled).toBeTruthy();
|
|
56
|
+
});
|
|
57
|
+
test("Renders file items passed in value when multiple file input", () => {
|
|
58
|
+
const callbackFile = jest.fn();
|
|
59
|
+
const { getByText } = render(
|
|
60
|
+
<DxcFileInput
|
|
61
|
+
label="File input label"
|
|
62
|
+
helperText="File input helper text"
|
|
63
|
+
value={files}
|
|
64
|
+
callbackFile={callbackFile}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
expect(getByText("file1.png")).toBeTruthy();
|
|
68
|
+
expect(getByText("file2.txt")).toBeTruthy();
|
|
69
|
+
expect(getByText("Error message")).toBeTruthy();
|
|
70
|
+
});
|
|
71
|
+
test("Renders file items when single file input", () => {
|
|
72
|
+
const callbackFile = jest.fn();
|
|
73
|
+
const { getByText } = render(
|
|
74
|
+
<DxcFileInput
|
|
75
|
+
label="File input label"
|
|
76
|
+
helperText="File input helper text"
|
|
77
|
+
multiple={false}
|
|
78
|
+
value={files}
|
|
79
|
+
callbackFile={callbackFile}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
expect(getByText("file1.png")).toBeTruthy();
|
|
83
|
+
expect(getByText("file2.txt")).toBeTruthy();
|
|
84
|
+
expect(getByText("Error message")).toBeTruthy();
|
|
85
|
+
});
|
|
86
|
+
test("Add file item when single file input", async () => {
|
|
87
|
+
const newFile = new File(["newFile"], "newFile.pdf", { type: "pdf" });
|
|
88
|
+
const callbackFile = jest.fn();
|
|
89
|
+
const { getByText, getByLabelText } = render(
|
|
90
|
+
<DxcFileInput
|
|
91
|
+
label="File input label"
|
|
92
|
+
helperText="File input helper text"
|
|
93
|
+
value={files}
|
|
94
|
+
callbackFile={callbackFile}
|
|
95
|
+
multiple={false}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
expect(getByText("file1.png")).toBeTruthy();
|
|
99
|
+
expect(getByText("file2.txt")).toBeTruthy();
|
|
100
|
+
expect(getByText("Error message")).toBeTruthy();
|
|
101
|
+
const inputFile = getByLabelText("File input label", { hidden: true });
|
|
102
|
+
fireEvent.change(inputFile, { target: { files: [newFile] } });
|
|
103
|
+
await waitFor(() => {
|
|
104
|
+
expect(callbackFile).toHaveBeenCalledWith([
|
|
105
|
+
{
|
|
106
|
+
error: undefined,
|
|
107
|
+
file: newFile,
|
|
108
|
+
preview: (
|
|
109
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
|
110
|
+
<path fill="none" d="M0 0h24v24H0V0z" />
|
|
111
|
+
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
112
|
+
</svg>
|
|
113
|
+
),
|
|
114
|
+
},
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
test("Renders file items and delete one file", async () => {
|
|
119
|
+
const callbackFile = jest.fn();
|
|
120
|
+
const { getByText, getAllByRole } = render(
|
|
121
|
+
<DxcFileInput
|
|
122
|
+
label="File input label"
|
|
123
|
+
helperText="File input helper text"
|
|
124
|
+
value={files}
|
|
125
|
+
callbackFile={callbackFile}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
expect(getByText("file1.png")).toBeTruthy();
|
|
129
|
+
expect(getByText("file2.txt")).toBeTruthy();
|
|
130
|
+
expect(getByText("Error message")).toBeTruthy();
|
|
131
|
+
const removeBtn = getAllByRole("button")[1];
|
|
132
|
+
userEvent.click(removeBtn);
|
|
133
|
+
await waitFor(() => {
|
|
134
|
+
expect(callbackFile).toHaveBeenCalledWith([{ error: "Error message", file: file2, preview: null }]);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("CallbackFile is correctly called", async () => {
|
|
139
|
+
const newFile = new File(["newFile"], "newFile.pdf", { type: "pdf" });
|
|
140
|
+
const callbackFile = jest.fn();
|
|
141
|
+
const { getByLabelText } = render(
|
|
142
|
+
<DxcFileInput
|
|
143
|
+
label="File input label"
|
|
144
|
+
helperText="File input helper text"
|
|
145
|
+
value={files}
|
|
146
|
+
callbackFile={callbackFile}
|
|
147
|
+
/>
|
|
148
|
+
);
|
|
149
|
+
const inputFile = getByLabelText("File input label", { hidden: true });
|
|
150
|
+
fireEvent.change(inputFile, { target: { files: [newFile] } });
|
|
151
|
+
await waitFor(() => {
|
|
152
|
+
expect(callbackFile).toHaveBeenCalledWith([
|
|
153
|
+
{ error: null, preview: null, file: file1 },
|
|
154
|
+
{ error: "Error message", preview: null, file: file2 },
|
|
155
|
+
{
|
|
156
|
+
error: undefined,
|
|
157
|
+
file: newFile,
|
|
158
|
+
preview: (
|
|
159
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
|
160
|
+
<path fill="none" d="M0 0h24v24H0V0z" />
|
|
161
|
+
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
162
|
+
</svg>
|
|
163
|
+
),
|
|
164
|
+
},
|
|
165
|
+
]);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("Callback called correctly when a file size does not comply minSize or maxSize", async () => {
|
|
170
|
+
const newFile = new File(["newFile"], "newFile.pdf", { type: "pdf" });
|
|
171
|
+
const callbackFile = jest.fn();
|
|
172
|
+
const { getByLabelText } = render(
|
|
173
|
+
<DxcFileInput
|
|
174
|
+
label="File input label"
|
|
175
|
+
helperText="File input helper text"
|
|
176
|
+
minSize={1000}
|
|
177
|
+
maxSize={20000}
|
|
178
|
+
value={files}
|
|
179
|
+
callbackFile={callbackFile}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
const inputFile = getByLabelText("File input label", { hidden: true });
|
|
183
|
+
fireEvent.change(inputFile, { target: { files: [newFile] } });
|
|
184
|
+
await waitFor(() => {
|
|
185
|
+
expect(callbackFile).toHaveBeenCalledWith([
|
|
186
|
+
{ error: null, preview: null, file: file1 },
|
|
187
|
+
{ error: "Error message", preview: null, file: file2 },
|
|
188
|
+
{
|
|
189
|
+
error: "File size must be greater than min size.",
|
|
190
|
+
file: newFile,
|
|
191
|
+
preview: (
|
|
192
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
|
193
|
+
<path fill="none" d="M0 0h24v24H0V0z" />
|
|
194
|
+
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
195
|
+
</svg>
|
|
196
|
+
),
|
|
197
|
+
},
|
|
198
|
+
]);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
package/test/NewDate.test.js
CHANGED
|
@@ -14,7 +14,7 @@ describe("NewDate component tests", () => {
|
|
|
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("");
|
|
@@ -22,17 +22,29 @@ describe("NewDate component tests", () => {
|
|
|
22
22
|
|
|
23
23
|
test("Renders with personalized error", () => {
|
|
24
24
|
const { getByText } = render(<DxcNewDate error="Personalized error." />);
|
|
25
|
-
|
|
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(<DxcNewDate 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(<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 });
|
|
36
48
|
});
|
|
37
49
|
|
|
38
50
|
test("Calendar renders with correct date: today's date", () => {
|
|
@@ -68,7 +80,8 @@ describe("NewDate component tests", () => {
|
|
|
68
80
|
});
|
|
69
81
|
|
|
70
82
|
test("Calendar renders with correct date: invalid date, renders with today's date", () => {
|
|
71
|
-
const
|
|
83
|
+
const onBlur = jest.fn();
|
|
84
|
+
const { getByText, getByRole } = render(<DxcNewDate onBlur={onBlur} />);
|
|
72
85
|
const calendarAction = getByRole("button");
|
|
73
86
|
const d = new Date();
|
|
74
87
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -76,7 +89,8 @@ describe("NewDate component tests", () => {
|
|
|
76
89
|
|
|
77
90
|
userEvent.type(input, "01-01-xxxx");
|
|
78
91
|
fireEvent.blur(input);
|
|
79
|
-
expect(
|
|
92
|
+
expect(onBlur).toHaveBeenCalled();
|
|
93
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "01-01-xxxx", error: "Invalid date.", date: null });
|
|
80
94
|
userEvent.click(calendarAction);
|
|
81
95
|
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
82
96
|
});
|
|
@@ -86,7 +100,7 @@ describe("NewDate component tests", () => {
|
|
|
86
100
|
const input = getByRole("textbox");
|
|
87
101
|
const calendarAction = getByRole("button");
|
|
88
102
|
userEvent.click(calendarAction);
|
|
89
|
-
const dayButton =
|
|
103
|
+
const dayButton = getByText("10").closest('button');
|
|
90
104
|
fireEvent.click(dayButton);
|
|
91
105
|
const d = new Date();
|
|
92
106
|
d.setDate(10);
|
|
@@ -121,7 +135,7 @@ describe("NewDate component tests", () => {
|
|
|
121
135
|
userEvent.type(input, "10-10-2011");
|
|
122
136
|
expect(input.value).toBe("10-10-2011");
|
|
123
137
|
expect(onChange).toHaveBeenCalledTimes(10);
|
|
124
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", date: d });
|
|
138
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
125
139
|
fireEvent.blur(input);
|
|
126
140
|
expect(onBlur).toHaveBeenCalled();
|
|
127
141
|
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
@@ -132,12 +146,11 @@ describe("NewDate component tests", () => {
|
|
|
132
146
|
const onChange = jest.fn();
|
|
133
147
|
const { getByRole } = render(<DxcNewDate onChange={onChange} onBlur={onBlur} />);
|
|
134
148
|
const input = getByRole("textbox");
|
|
135
|
-
const d = new Date(2011, 9, 10);
|
|
136
149
|
|
|
137
150
|
userEvent.type(input, "10-10-");
|
|
138
151
|
expect(input.value).toBe("10-10-");
|
|
139
152
|
expect(onChange).toHaveBeenCalledTimes(6);
|
|
140
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", date: null });
|
|
153
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
141
154
|
fireEvent.blur(input);
|
|
142
155
|
expect(onBlur).toHaveBeenCalled();
|
|
143
156
|
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
@@ -164,7 +177,7 @@ describe("NewDate component tests", () => {
|
|
|
164
177
|
|
|
165
178
|
test("onBlur function removes the error when the input is empty", () => {
|
|
166
179
|
const onBlur = jest.fn();
|
|
167
|
-
const { getByRole } = render(<DxcNewDate onBlur={onBlur} />);
|
|
180
|
+
const { getByRole } = render(<DxcNewDate onBlur={onBlur} optional />);
|
|
168
181
|
const input = getByRole("textbox");
|
|
169
182
|
|
|
170
183
|
userEvent.type(input, "test");
|
|
@@ -178,6 +191,22 @@ describe("NewDate component tests", () => {
|
|
|
178
191
|
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null, date: null });
|
|
179
192
|
});
|
|
180
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
|
+
|
|
181
210
|
test("Disabled date (calendar action must be shown but not clickable)", () => {
|
|
182
211
|
const { getByRole, queryByText } = render(<DxcNewDate disabled />);
|
|
183
212
|
const calendarAction = getByRole("button");
|