@dxc-technology/halstack-react 0.0.0-c24450b → 0.0.0-c6243ef
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.config.js +6 -2
- package/dist/BackgroundColorContext.js +46 -0
- package/dist/ThemeContext.js +235 -2
- package/dist/accordion/Accordion.js +170 -81
- package/dist/accordion-group/AccordionGroup.js +186 -0
- package/dist/alert/Alert.js +184 -83
- package/dist/alert/index.d.ts +51 -0
- package/dist/badge/Badge.js +63 -0
- package/dist/box/Box.js +31 -23
- package/dist/button/Button.js +82 -27
- package/dist/card/Card.js +72 -35
- package/dist/checkbox/Checkbox.js +108 -32
- package/dist/chip/Chip.js +129 -35
- package/dist/common/RequiredComponent.js +2 -8
- package/dist/common/utils.js +2 -22
- package/dist/common/variables.js +1457 -210
- package/dist/date/Date.js +81 -59
- package/dist/dialog/Dialog.js +58 -37
- package/dist/dropdown/Dropdown.js +229 -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/footer/Footer.js +87 -38
- package/dist/footer/dxc_logo.svg +15 -0
- package/dist/footer/readme.md +1 -1
- package/dist/header/Header.js +121 -72
- package/dist/header/dxc_logo_black.svg +8 -0
- package/dist/header/readme.md +1 -1
- package/dist/heading/Heading.js +81 -22
- package/dist/input-text/InputText.js +289 -101
- package/dist/layout/ApplicationLayout.js +331 -0
- package/dist/layout/facebook.svg +45 -0
- package/dist/layout/linkedin.svg +50 -0
- package/dist/layout/twitter.svg +53 -0
- package/dist/link/Link.js +136 -35
- package/dist/main.d.ts +8 -0
- package/dist/main.js +105 -1
- package/dist/new-date/NewDate.js +400 -0
- package/dist/new-date/index.d.ts +95 -0
- package/dist/new-select/NewSelect.js +836 -0
- package/dist/new-select/index.d.ts +53 -0
- package/dist/new-textarea/NewTextarea.js +369 -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 +160 -49
- package/dist/password-input/PasswordInput.js +198 -0
- package/dist/password-input/index.d.ts +94 -0
- package/dist/progress-bar/ProgressBar.js +97 -44
- package/dist/radio/Radio.js +39 -21
- package/dist/resultsetTable/ResultsetTable.js +93 -69
- package/dist/select/Select.js +250 -143
- package/dist/sidenav/Sidenav.js +85 -143
- package/dist/slider/Slider.js +206 -70
- package/dist/spinner/Spinner.js +249 -64
- package/dist/switch/Switch.js +51 -26
- package/dist/table/Table.js +63 -15
- package/dist/tabs/Tabs.js +208 -35
- package/dist/tabs-for-sections/TabsForSections.js +1 -16
- package/dist/tag/Tag.js +100 -35
- package/dist/text-input/TextInput.js +971 -0
- package/dist/text-input/index.d.ts +135 -0
- package/dist/textarea/Textarea.js +81 -43
- package/dist/toggle/Toggle.js +16 -19
- package/dist/toggle-group/ToggleGroup.js +327 -0
- package/dist/upload/Upload.js +13 -8
- package/dist/upload/buttons-upload/ButtonsUpload.js +34 -20
- package/dist/upload/dragAndDropArea/DragAndDropArea.js +78 -31
- package/dist/upload/file-upload/FileToUpload.js +50 -24
- package/dist/upload/files-upload/FilesToUpload.js +16 -16
- package/dist/upload/transaction/Transaction.js +44 -24
- package/dist/upload/transactions/Transactions.js +38 -20
- package/dist/useTheme.js +22 -0
- package/dist/wizard/Wizard.js +142 -51
- package/dist/wizard/invalid_icon.svg +4 -5
- package/dist/wizard/valid_icon.svg +4 -5
- package/package.json +14 -6
- package/test/AccordionGroup.test.js +125 -0
- package/test/Date.test.js +13 -13
- package/test/Dropdown.test.js +19 -4
- package/test/FileInput.test.js +201 -0
- package/test/InputText.test.js +30 -26
- package/test/Link.test.js +25 -7
- package/test/NewDate.test.js +232 -0
- package/test/NewTextarea.test.js +195 -0
- package/test/Number.test.js +257 -0
- package/test/Paginator.test.js +72 -60
- package/test/PasswordInput.test.js +83 -0
- package/test/ResultsetTable.test.js +66 -19
- package/test/Select.test.js +55 -34
- package/test/Sidenav.test.js +22 -64
- package/test/Slider.test.js +17 -0
- package/test/Spinner.test.js +5 -0
- package/test/Tabs.test.js +21 -0
- package/test/TextInput.test.js +732 -0
- package/test/ToggleGroup.test.js +85 -0
- package/dist/accordion/Accordion.stories.js +0 -207
- package/dist/accordion/readme.md +0 -96
- package/dist/alert/Alert.stories.js +0 -158
- package/dist/alert/close.svg +0 -4
- package/dist/alert/error.svg +0 -4
- package/dist/alert/info.svg +0 -4
- package/dist/alert/readme.md +0 -43
- package/dist/alert/success.svg +0 -4
- package/dist/alert/warning.svg +0 -4
- package/dist/button/Button.stories.js +0 -224
- package/dist/button/readme.md +0 -93
- package/dist/common/services/example-service.js +0 -10
- package/dist/common/services/example-service.test.js +0 -12
- package/dist/date/calendar.svg +0 -1
- package/dist/date/calendar_dark.svg +0 -1
- package/dist/dialog/Dialog.stories.js +0 -217
- package/dist/dialog/readme.md +0 -32
- package/dist/dropdown/Dropdown.stories.js +0 -249
- package/dist/dropdown/baseline-arrow_drop_down.svg +0 -1
- package/dist/dropdown/baseline-arrow_drop_down_wh.svg +0 -4
- package/dist/dropdown/baseline-arrow_drop_up.svg +0 -1
- package/dist/dropdown/baseline-arrow_drop_up_wh.svg +0 -4
- package/dist/dropdown/readme.md +0 -69
- package/dist/footer/Footer.stories.js +0 -94
- package/dist/footer/dxc_logo_wht.png +0 -0
- package/dist/header/dxc_logo_black.png +0 -0
- package/dist/header/dxc_logo_white.png +0 -0
- package/dist/input-text/InputText.stories.js +0 -209
- package/dist/select/Select.stories.js +0 -235
- package/dist/select/readme.md +0 -72
- package/dist/sidenav/arrow_icon.svg +0 -3
- package/test/Toggle.test.js +0 -43
package/test/InputText.test.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { render, fireEvent, waitFor, screen, act, waitForElementToBeRemoved } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
3
5
|
import icon from "../../app/src/images/invision.svg";
|
|
4
6
|
|
|
5
|
-
import DxcInputText from "../
|
|
7
|
+
import DxcInputText from "../src/input-text/InputText";
|
|
6
8
|
|
|
7
9
|
const countries = ["Albania", "Andorra", "Armenia", "Austria", "Azerbaijan"];
|
|
8
10
|
|
|
@@ -18,6 +20,7 @@ jest.mock("popper.js", () => {
|
|
|
18
20
|
return {
|
|
19
21
|
destroy: () => {},
|
|
20
22
|
scheduleUpdate: () => {},
|
|
23
|
+
update: () => {},
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
26
|
};
|
|
@@ -26,7 +29,6 @@ jest.mock("popper.js", () => {
|
|
|
26
29
|
describe("InputText component tests", () => {
|
|
27
30
|
test("Input renders with correct label", () => {
|
|
28
31
|
const { getByText } = render(<DxcInputText label="Input label" />);
|
|
29
|
-
|
|
30
32
|
expect(getByText("Input label")).toBeTruthy();
|
|
31
33
|
});
|
|
32
34
|
|
|
@@ -34,7 +36,7 @@ describe("InputText component tests", () => {
|
|
|
34
36
|
const onChange = jest.fn();
|
|
35
37
|
const { getByRole } = render(<DxcInputText label="Input label" onChange={onChange} />);
|
|
36
38
|
const input = getByRole("textbox");
|
|
37
|
-
|
|
39
|
+
userEvent.type(input, "20000");
|
|
38
40
|
expect(onChange).toHaveBeenCalled();
|
|
39
41
|
expect(onChange).toHaveBeenCalledWith("20000");
|
|
40
42
|
});
|
|
@@ -44,7 +46,7 @@ describe("InputText component tests", () => {
|
|
|
44
46
|
|
|
45
47
|
const { getByRole } = render(<DxcInputText label="Input label" onChange={onChange} onBlur={onBlur} />);
|
|
46
48
|
const input = getByRole("textbox");
|
|
47
|
-
|
|
49
|
+
userEvent.type(input, "Test value");
|
|
48
50
|
fireEvent.blur(input);
|
|
49
51
|
expect(onBlur).toHaveBeenCalled();
|
|
50
52
|
expect(onBlur).toHaveBeenCalledWith("Test value");
|
|
@@ -54,7 +56,7 @@ describe("InputText component tests", () => {
|
|
|
54
56
|
const onChange = jest.fn();
|
|
55
57
|
const { getByRole } = render(<DxcInputText label="Input label" onChange={onChange} />);
|
|
56
58
|
const input = getByRole("textbox");
|
|
57
|
-
|
|
59
|
+
userEvent.type(input, "20000");
|
|
58
60
|
expect(onChange).toHaveBeenCalled();
|
|
59
61
|
expect(onChange).toHaveBeenCalledWith("20000");
|
|
60
62
|
expect(input.value).toBe("20000");
|
|
@@ -67,9 +69,8 @@ describe("InputText component tests", () => {
|
|
|
67
69
|
<DxcInputText label="Input label" value="Test value" onChange={onChange} onBlur={onBlur} />
|
|
68
70
|
);
|
|
69
71
|
const input = getByRole("textbox");
|
|
70
|
-
|
|
72
|
+
userEvent.type(input, "20000");
|
|
71
73
|
expect(onChange).toHaveBeenCalled();
|
|
72
|
-
expect(onChange).toHaveBeenCalledWith("20000");
|
|
73
74
|
expect(input.value).toBe("Test value");
|
|
74
75
|
fireEvent.blur(input);
|
|
75
76
|
expect(onBlur).toHaveBeenCalled();
|
|
@@ -79,14 +80,14 @@ describe("InputText component tests", () => {
|
|
|
79
80
|
const onClick = jest.fn();
|
|
80
81
|
const { getByRole } = render(<DxcInputText label="Input label" prefixIconSrc={icon} onClickPrefix={onClick} />);
|
|
81
82
|
const prefixIcon = getByRole("img");
|
|
82
|
-
|
|
83
|
+
userEvent.click(prefixIcon);
|
|
83
84
|
expect(onClick).toHaveBeenCalled();
|
|
84
85
|
});
|
|
85
86
|
test("Suffix icon onClick", () => {
|
|
86
87
|
const onClick = jest.fn();
|
|
87
88
|
const { getByRole } = render(<DxcInputText label="Input label" suffixIconSrc={icon} onClickSuffix={onClick} />);
|
|
88
89
|
const suffixIcon = getByRole("img");
|
|
89
|
-
|
|
90
|
+
userEvent.click(suffixIcon);
|
|
90
91
|
expect(onClick).toHaveBeenCalled();
|
|
91
92
|
});
|
|
92
93
|
});
|
|
@@ -98,9 +99,9 @@ describe("Autocomplete component Synchronous tests", () => {
|
|
|
98
99
|
<DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
|
|
99
100
|
);
|
|
100
101
|
const input = screen.getByRole("textbox");
|
|
101
|
-
|
|
102
|
+
fireEvent.focus(input);
|
|
102
103
|
expect(screen.getByText("Andorra")).toBeTruthy();
|
|
103
|
-
|
|
104
|
+
userEvent.type(input, "X");
|
|
104
105
|
expect(screen.getByText("No matches found.")).toBeTruthy();
|
|
105
106
|
});
|
|
106
107
|
|
|
@@ -110,7 +111,7 @@ describe("Autocomplete component Synchronous tests", () => {
|
|
|
110
111
|
<DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
|
|
111
112
|
);
|
|
112
113
|
const input = screen.getByRole("textbox");
|
|
113
|
-
|
|
114
|
+
fireEvent.focus(input);
|
|
114
115
|
expect(screen.getByText("Andorra")).toBeTruthy();
|
|
115
116
|
});
|
|
116
117
|
|
|
@@ -120,14 +121,14 @@ describe("Autocomplete component Synchronous tests", () => {
|
|
|
120
121
|
<DxcInputText label="Autocomplete Countries" autocompleteOptions={countries} onChange={onChangeAtocomplete} />
|
|
121
122
|
);
|
|
122
123
|
const input = screen.getByRole("textbox");
|
|
123
|
-
|
|
124
|
+
fireEvent.focus(input);
|
|
124
125
|
expect(screen.getByText("Andorra")).toBeTruthy();
|
|
125
|
-
|
|
126
|
+
userEvent.type(screen.getByRole("textbox"), "Alb");
|
|
126
127
|
expect(onChangeAtocomplete).toHaveBeenCalled();
|
|
127
128
|
expect(screen.getByText("Albania")).toBeTruthy();
|
|
128
129
|
const suggestion1 = screen.getByText("Albania");
|
|
129
130
|
act(() => {
|
|
130
|
-
|
|
131
|
+
userEvent.click(suggestion1);
|
|
131
132
|
});
|
|
132
133
|
|
|
133
134
|
// expect(onChangeAtocomplete).toHaveBeenCalledWith("Albania");
|
|
@@ -144,19 +145,20 @@ describe("Autocomplete component Synchronous tests", () => {
|
|
|
144
145
|
onChange={onChangeAtocomplete}
|
|
145
146
|
/>
|
|
146
147
|
);
|
|
147
|
-
screen.getByRole("textbox")
|
|
148
|
-
|
|
148
|
+
const input = screen.getByRole("textbox");
|
|
149
|
+
fireEvent.focus(input);
|
|
149
150
|
expect(screen.getByText("Andorra")).toBeTruthy();
|
|
150
151
|
|
|
151
152
|
expect(screen.getByText("Andorra")).toBeTruthy();
|
|
152
153
|
const suggestion1 = screen.getByText("Andorra");
|
|
153
154
|
act(() => {
|
|
154
|
-
|
|
155
|
+
userEvent.click(suggestion1);
|
|
155
156
|
});
|
|
156
157
|
|
|
157
158
|
expect(onChangeAtocomplete).toHaveBeenCalledWith("Andorra");
|
|
158
159
|
});
|
|
159
160
|
});
|
|
161
|
+
|
|
160
162
|
describe("InputText component Asynchronous Autocomplete tests", () => {
|
|
161
163
|
test("Autocomplete Searching is shown", async () => {
|
|
162
164
|
const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 1000)));
|
|
@@ -166,7 +168,7 @@ describe("InputText component Asynchronous Autocomplete tests", () => {
|
|
|
166
168
|
<DxcInputText label="Autocomplete Countries" autocompleteOptions={callbackFunc} onChange={onChangeAtocomplete} />
|
|
167
169
|
);
|
|
168
170
|
const input = screen.getByRole("textbox");
|
|
169
|
-
|
|
171
|
+
fireEvent.focus(input);
|
|
170
172
|
await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
|
|
171
173
|
expect(screen.getByText("Italy")).toBeTruthy();
|
|
172
174
|
expect(screen.getByText("Spain")).toBeTruthy();
|
|
@@ -179,18 +181,19 @@ describe("InputText component Asynchronous Autocomplete tests", () => {
|
|
|
179
181
|
<DxcInputText label="Autocomplete Countries" onChange={onChangeAtocomplete} autocompleteOptions={callbackFunc} />
|
|
180
182
|
);
|
|
181
183
|
const input = screen.getByRole("textbox");
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
fireEvent.focus(input);
|
|
185
|
+
userEvent.type(input, "And");
|
|
184
186
|
await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
|
|
185
187
|
expect(screen.getByText("Italy")).toBeTruthy();
|
|
186
188
|
expect(screen.getByText("Spain")).toBeTruthy();
|
|
187
189
|
const suggestion1 = screen.getByText("Spain");
|
|
188
190
|
act(() => {
|
|
189
|
-
|
|
191
|
+
userEvent.click(suggestion1);
|
|
190
192
|
});
|
|
191
193
|
expect(onChangeAtocomplete).toHaveBeenCalledWith("Spain");
|
|
192
194
|
expect(screen.getByRole("textbox").value).toBe("Spain");
|
|
193
195
|
});
|
|
196
|
+
|
|
194
197
|
test("Asynchronous CONTROLLED autocomplete tests", async () => {
|
|
195
198
|
const callbackFunc = jest.fn(() => new Promise((resolve) => setTimeout(resolve(["Italy", "Spain"]), 3000)));
|
|
196
199
|
const onChangeAtocomplete = jest.fn();
|
|
@@ -203,18 +206,19 @@ describe("InputText component Asynchronous Autocomplete tests", () => {
|
|
|
203
206
|
/>
|
|
204
207
|
);
|
|
205
208
|
const input = screen.getByRole("textbox");
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
fireEvent.focus(input);
|
|
210
|
+
userEvent.type(input, "And");
|
|
208
211
|
await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
|
|
209
212
|
expect(screen.getByText("Italy")).toBeTruthy();
|
|
210
213
|
expect(screen.getByText("Spain")).toBeTruthy();
|
|
211
214
|
const suggestion1 = screen.getByText("Spain");
|
|
212
215
|
act(() => {
|
|
213
|
-
|
|
216
|
+
userEvent.click(suggestion1);
|
|
214
217
|
});
|
|
215
218
|
expect(onChangeAtocomplete).toHaveBeenCalledWith("Spain");
|
|
216
219
|
expect(screen.getByRole("textbox").value).toBe("test value");
|
|
217
220
|
});
|
|
221
|
+
|
|
218
222
|
test("Asynchronous autocomplete request failed", async () => {
|
|
219
223
|
const errorCallbackFunc = jest.fn(() => new Promise((resolve, reject) => setTimeout(reject("E"), 3000)));
|
|
220
224
|
const onChangeAtocomplete = jest.fn();
|
|
@@ -229,7 +233,7 @@ describe("InputText component Asynchronous Autocomplete tests", () => {
|
|
|
229
233
|
);
|
|
230
234
|
|
|
231
235
|
const input = screen.getByRole("textbox");
|
|
232
|
-
|
|
236
|
+
fireEvent.focus(input);
|
|
233
237
|
await waitForElementToBeRemoved(() => screen.getByText(/Searching.../i));
|
|
234
238
|
expect(screen.getByText("Error fetching data")).toBeTruthy();
|
|
235
239
|
});
|
package/test/Link.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { render } from "@testing-library/react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
3
|
import DxcLink from "../src/link/Link";
|
|
4
4
|
|
|
5
5
|
describe("Link component tests", () => {
|
|
@@ -9,17 +9,35 @@ describe("Link component tests", () => {
|
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
test("Link renders with correct href", () => {
|
|
12
|
-
const {
|
|
13
|
-
expect(
|
|
12
|
+
const { getByRole } = render(<DxcLink text="Link" href="/testPage" />);
|
|
13
|
+
expect(getByRole("link").getAttribute("href")).toEqual("/testPage");
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
test("Link renders with
|
|
16
|
+
test("Link renders with correct disabled state", () => {
|
|
17
17
|
const { getByText } = render(<DxcLink text="Link" href="/testPage" disabled={true} />);
|
|
18
|
-
expect(getByText("Link").hasAttribute("
|
|
18
|
+
expect(getByText("Link").hasAttribute("href")).toBeFalsy();
|
|
19
|
+
const { getByText: getByTextLinkButton } = render(<DxcLink text="LinkButton" onClick={() => console.log("Andorra")} disabled={true} />);
|
|
20
|
+
expect(getByTextLinkButton("LinkButton").hasAttribute("onclick")).toBeFalsy();
|
|
19
21
|
});
|
|
20
22
|
|
|
21
23
|
test("Link open new tab", () => {
|
|
22
|
-
const {
|
|
23
|
-
expect(
|
|
24
|
+
const { getByRole } = render(<DxcLink text="Link" href="/testPage" newWindow={true} />);
|
|
25
|
+
expect(getByRole("link").getAttribute("target")).toEqual("_blank");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("Link onClick called", () => {
|
|
29
|
+
const onClick = jest.fn();
|
|
30
|
+
const { getByText } = render(<DxcLink text="Link" onClick={onClick} />);
|
|
31
|
+
const link = getByText("Link");
|
|
32
|
+
fireEvent.click(link);
|
|
33
|
+
expect(onClick).toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("Disabled link onClick not called", () => {
|
|
37
|
+
const onClick = jest.fn();
|
|
38
|
+
const { getByText } = render(<DxcLink text="Link" onClick={onClick} disabled={true} />);
|
|
39
|
+
const link = getByText("Link");
|
|
40
|
+
fireEvent.click(link);
|
|
41
|
+
expect(onClick).toHaveBeenCalledTimes(0);
|
|
24
42
|
});
|
|
25
43
|
});
|
|
@@ -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
|
+
});
|