@dxc-technology/halstack-react 0.0.0-92f4a00 → 0.0.0-9427b76
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 +66 -58
- package/dist/alert/index.d.ts +51 -0
- package/dist/common/variables.js +141 -58
- package/dist/date/Date.js +4 -6
- package/dist/file-input/FileInput.js +641 -0
- package/dist/file-input/FileItem.js +280 -0
- package/dist/file-input/index.d.ts +81 -0
- package/dist/layout/ApplicationLayout.js +1 -1
- package/dist/link/Link.js +4 -8
- package/dist/main.d.ts +7 -0
- package/dist/main.js +8 -0
- package/dist/new-date/NewDate.js +64 -67
- package/dist/new-date/index.d.ts +95 -0
- package/dist/new-input-text/NewInputText.js +160 -157
- package/dist/new-input-text/index.d.ts +135 -0
- package/dist/new-textarea/NewTextarea.js +53 -37
- package/dist/new-textarea/index.d.ts +117 -0
- package/dist/number/Number.js +1 -3
- package/dist/number/index.d.ts +113 -0
- package/dist/password/Password.js +3 -3
- package/dist/password/index.d.ts +94 -0
- package/dist/progress-bar/ProgressBar.js +1 -1
- package/dist/select/Select.js +122 -149
- package/dist/sidenav/Sidenav.js +6 -4
- package/dist/tag/Tag.js +26 -32
- package/package.json +2 -1
- package/test/FileInput.test.js +201 -0
- package/test/NewDate.test.js +41 -12
- package/test/NewInputText.test.js +104 -187
- package/test/NewTextarea.test.js +95 -101
- package/test/Number.test.js +44 -28
- package/test/Paginator.test.js +1 -1
- package/test/Password.test.js +15 -8
- package/test/ResultsetTable.test.js +1 -2
- package/test/Select.test.js +40 -17
- package/dist/select/Select.stories.js +0 -235
- package/dist/select/readme.md +0 -72
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-9427b76",
|
|
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");
|