@dxc-technology/halstack-react 0.0.0-c5f6a2f → 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/dist/ThemeContext.js +130 -98
- package/dist/accordion/Accordion.js +80 -83
- package/dist/accordion-group/AccordionGroup.js +1 -3
- package/dist/alert/Alert.js +168 -83
- package/dist/alert/index.d.ts +51 -0
- package/dist/badge/Badge.js +3 -1
- package/dist/box/Box.js +1 -9
- package/dist/button/Button.js +30 -20
- package/dist/card/Card.js +15 -8
- package/dist/checkbox/Checkbox.js +88 -21
- package/dist/chip/Chip.js +63 -21
- package/dist/common/variables.js +1105 -418
- package/dist/date/Date.js +60 -40
- package/dist/dialog/Dialog.js +44 -29
- package/dist/dropdown/Dropdown.js +162 -74
- 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 +132 -56
- package/dist/layout/ApplicationLayout.js +3 -3
- package/dist/link/Link.js +71 -46
- 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-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 +10 -4
- package/dist/password-input/PasswordInput.js +198 -0
- package/dist/password-input/index.d.ts +94 -0
- package/dist/progress-bar/ProgressBar.js +63 -27
- package/dist/radio/Radio.js +28 -9
- package/dist/resultsetTable/ResultsetTable.js +64 -38
- package/dist/select/Select.js +207 -148
- package/dist/sidenav/Sidenav.js +11 -15
- package/dist/slider/Slider.js +190 -63
- package/dist/spinner/Spinner.js +226 -59
- package/dist/switch/Switch.js +3 -3
- package/dist/table/Table.js +19 -5
- package/dist/tabs/Tabs.js +6 -10
- package/dist/tag/Tag.js +50 -36
- package/dist/text-input/TextInput.js +971 -0
- package/dist/text-input/index.d.ts +135 -0
- package/dist/textarea/Textarea.js +59 -33
- package/dist/toggle-group/ToggleGroup.js +130 -44
- package/dist/upload/Upload.js +1 -5
- package/dist/upload/buttons-upload/ButtonsUpload.js +27 -11
- package/dist/upload/dragAndDropArea/DragAndDropArea.js +54 -18
- package/dist/upload/file-upload/FileToUpload.js +37 -15
- package/dist/upload/files-upload/FilesToUpload.js +3 -3
- package/dist/upload/transaction/Transaction.js +39 -16
- package/dist/upload/transactions/Transactions.js +24 -8
- package/dist/wizard/Wizard.js +84 -56
- package/dist/wizard/invalid_icon.svg +4 -5
- package/dist/wizard/valid_icon.svg +4 -5
- package/package.json +4 -2
- package/test/Date.test.js +13 -13
- package/test/Dropdown.test.js +15 -0
- package/test/FileInput.test.js +201 -0
- package/test/Link.test.js +3 -2
- 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 +1 -1
- package/test/PasswordInput.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/test/TextInput.test.js +732 -0
- package/test/ToggleGroup.test.js +5 -1
- 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/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_blk_rgb.svg +0 -6
- 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/toggle-group/readme.md +0 -82
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import DxcNumber from "../src/number/Number";
|
|
5
|
+
|
|
6
|
+
describe("Number component tests", () => {
|
|
7
|
+
test("Number renders with label", () => {
|
|
8
|
+
const { getByText } = render(<DxcNumber label="Number label" />);
|
|
9
|
+
expect(getByText("Number label")).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("Number renders with helper text", () => {
|
|
13
|
+
const { getByText } = render(<DxcNumber helperText="Helper text" />);
|
|
14
|
+
expect(getByText("Helper text")).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("Number renders with placeholder", () => {
|
|
18
|
+
const { getByLabelText } = render(<DxcNumber label="Number label" placeholder="Placeholder" />);
|
|
19
|
+
const number = getByLabelText("Number label");
|
|
20
|
+
expect(number.getAttribute("placeholder")).toBe("Placeholder");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("Number renders increment and decrement buttons", () => {
|
|
24
|
+
const { queryAllByRole } = render(<DxcNumber label="Number label" />);
|
|
25
|
+
expect(queryAllByRole("button").length).toBe(2);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("Number is disabled", () => {
|
|
29
|
+
const { getByLabelText } = render(<DxcNumber label="Number label" disabled />);
|
|
30
|
+
const number = getByLabelText("Number label");
|
|
31
|
+
expect(number.disabled).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("Number is optional", () => {
|
|
35
|
+
const { getByText } = render(<DxcNumber label="Number label" optional />);
|
|
36
|
+
expect(getByText("(Optional)")).toBeTruthy();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("Number is not optional: required field, displays error if not filled in", () => {
|
|
40
|
+
const onBlur = jest.fn();
|
|
41
|
+
const onChange = jest.fn();
|
|
42
|
+
const { getByRole } = render(<DxcNumber onBlur={onBlur} onChange={onChange} />);
|
|
43
|
+
const input = getByRole("textbox");
|
|
44
|
+
|
|
45
|
+
userEvent.type(input, "1");
|
|
46
|
+
userEvent.clear(input);
|
|
47
|
+
fireEvent.blur(input);
|
|
48
|
+
expect(onBlur).toHaveBeenCalled();
|
|
49
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
50
|
+
expect(onChange).toHaveBeenCalled();
|
|
51
|
+
expect(onChange).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("Suffix and prefix must be shown)", () => {
|
|
55
|
+
const { getByText } = render(<DxcNumber label="Number label" prefix="+34" suffix="USD" />);
|
|
56
|
+
expect(getByText("+34")).toBeTruthy();
|
|
57
|
+
expect(getByText("USD")).toBeTruthy();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("Invalid number renders error", () => {
|
|
61
|
+
const { getByText } = render(<DxcNumber error="Error message." />);
|
|
62
|
+
expect(getByText("Error message.")).toBeTruthy();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("onChange function is called correctly", () => {
|
|
66
|
+
const onChange = jest.fn();
|
|
67
|
+
const { getByLabelText } = render(<DxcNumber label="Number label" onChange={onChange} />);
|
|
68
|
+
const number = getByLabelText("Number label");
|
|
69
|
+
userEvent.type(number, "t");
|
|
70
|
+
expect(onChange).not.toHaveBeenCalledWith({ value: "t", error: null });
|
|
71
|
+
expect(number.value).toBe("");
|
|
72
|
+
userEvent.type(number, "1");
|
|
73
|
+
expect(onChange).toHaveBeenCalledWith({ value: "1", error: null });
|
|
74
|
+
expect(number.value).toBe("1");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("Error message is shown if the value is less than the min value", () => {
|
|
78
|
+
const onChange = jest.fn(({ value, error }) => {
|
|
79
|
+
expect(value).toBe("1");
|
|
80
|
+
expect(error).toBe("Value must be greater than or equal to 5.");
|
|
81
|
+
});
|
|
82
|
+
const onBlur = jest.fn(({ value, error }) => {
|
|
83
|
+
expect(value).toBe("1");
|
|
84
|
+
expect(error).toBe("Value must be greater than or equal to 5.");
|
|
85
|
+
});
|
|
86
|
+
const { getByLabelText } = render(
|
|
87
|
+
<DxcNumber label="Number label" min={5} onBlur={onBlur} onChange={onChange} />
|
|
88
|
+
);
|
|
89
|
+
const number = getByLabelText("Number label");
|
|
90
|
+
|
|
91
|
+
userEvent.type(number, "1");
|
|
92
|
+
fireEvent.blur(number);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("Cannot decrement the value if it is less than the min value", () => {
|
|
96
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumber label="Number label" min={5} />);
|
|
97
|
+
const number = getByLabelText("Number label");
|
|
98
|
+
userEvent.type(number, "1");
|
|
99
|
+
fireEvent.blur(number);
|
|
100
|
+
expect(number.value).toBe("1");
|
|
101
|
+
const decrement = getAllByRole("button")[0];
|
|
102
|
+
userEvent.click(decrement);
|
|
103
|
+
expect(number.value).toBe("1");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("Increment the value when it is less than the min value", () => {
|
|
107
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumber label="Number label" min={5} />);
|
|
108
|
+
const number = getByLabelText("Number label");
|
|
109
|
+
userEvent.type(number, "1");
|
|
110
|
+
fireEvent.blur(number);
|
|
111
|
+
expect(number.value).toBe("1");
|
|
112
|
+
const increment = getAllByRole("button")[1];
|
|
113
|
+
userEvent.click(increment);
|
|
114
|
+
expect(number.value).toBe("5");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("Error message is shown if the value is greater than the max value", () => {
|
|
118
|
+
const onChange = jest.fn();
|
|
119
|
+
const onBlur = jest.fn();
|
|
120
|
+
const { getByLabelText } = render(<DxcNumber label="Number label" max={10} onBlur={onBlur} onChange={onChange} />);
|
|
121
|
+
const number = getByLabelText("Number label");
|
|
122
|
+
|
|
123
|
+
userEvent.type(number, "12");
|
|
124
|
+
expect(onChange).toHaveBeenCalledTimes(2);
|
|
125
|
+
expect(onChange).toHaveBeenCalledWith({ value: "12", error: "Value must be less than or equal to 10." });
|
|
126
|
+
fireEvent.blur(number);
|
|
127
|
+
expect(onBlur).toHaveBeenCalled();
|
|
128
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "12", error: "Value must be less than or equal to 10." });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("Cannot increment the value if it is greater than the max value", () => {
|
|
132
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumber label="Number label" max={10} />);
|
|
133
|
+
const number = getByLabelText("Number label");
|
|
134
|
+
userEvent.type(number, "12");
|
|
135
|
+
fireEvent.blur(number);
|
|
136
|
+
expect(number.value).toBe("12");
|
|
137
|
+
const decrement = getAllByRole("button")[1];
|
|
138
|
+
userEvent.click(decrement);
|
|
139
|
+
expect(number.value).toBe("12");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("Decrement the value when it is greater than the max value", () => {
|
|
143
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumber label="Number label" max={10} />);
|
|
144
|
+
const number = getByLabelText("Number label");
|
|
145
|
+
userEvent.type(number, "12");
|
|
146
|
+
fireEvent.blur(number);
|
|
147
|
+
expect(number.value).toBe("12");
|
|
148
|
+
const decrement = getAllByRole("button")[0];
|
|
149
|
+
userEvent.click(decrement);
|
|
150
|
+
expect(number.value).toBe("10");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("Increment and decrement the value with min and max values", () => {
|
|
154
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumber label="Number label" min={5} max={10} />);
|
|
155
|
+
const number = getByLabelText("Number label");
|
|
156
|
+
userEvent.type(number, "1");
|
|
157
|
+
fireEvent.blur(number);
|
|
158
|
+
expect(number.value).toBe("1");
|
|
159
|
+
const decrement = getAllByRole("button")[0];
|
|
160
|
+
userEvent.click(decrement);
|
|
161
|
+
expect(number.value).toBe("1");
|
|
162
|
+
const increment = getAllByRole("button")[1];
|
|
163
|
+
userEvent.click(increment);
|
|
164
|
+
expect(number.value).toBe("5");
|
|
165
|
+
userEvent.click(increment);
|
|
166
|
+
userEvent.click(increment);
|
|
167
|
+
userEvent.click(increment);
|
|
168
|
+
userEvent.click(increment);
|
|
169
|
+
userEvent.click(increment);
|
|
170
|
+
expect(number.value).toBe("10");
|
|
171
|
+
userEvent.click(increment);
|
|
172
|
+
expect(number.value).toBe("10");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("Increment and decrement the value with step", () => {
|
|
176
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumber label="Number label" step={5} />);
|
|
177
|
+
const number = getByLabelText("Number label");
|
|
178
|
+
userEvent.type(number, "10");
|
|
179
|
+
fireEvent.blur(number);
|
|
180
|
+
expect(number.value).toBe("10");
|
|
181
|
+
const increment = getAllByRole("button")[1];
|
|
182
|
+
userEvent.click(increment);
|
|
183
|
+
expect(number.value).toBe("15");
|
|
184
|
+
userEvent.click(increment);
|
|
185
|
+
expect(number.value).toBe("20");
|
|
186
|
+
const decrement = getAllByRole("button")[0];
|
|
187
|
+
userEvent.click(decrement);
|
|
188
|
+
expect(number.value).toBe("15");
|
|
189
|
+
userEvent.click(decrement);
|
|
190
|
+
expect(number.value).toBe("10");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("Increment and decrement the value with min, max and step", () => {
|
|
194
|
+
const onBlur = jest.fn(({ value, error }) => {
|
|
195
|
+
expect(value).toBe("1");
|
|
196
|
+
expect(error).toBe("Value must be greater than or equal to 5.");
|
|
197
|
+
});
|
|
198
|
+
const { getByLabelText, getAllByRole } = render(
|
|
199
|
+
<DxcNumber label="Number label" min={5} max={20} step={8} onBlur={onBlur} />
|
|
200
|
+
);
|
|
201
|
+
const number = getByLabelText("Number label");
|
|
202
|
+
userEvent.type(number, "1");
|
|
203
|
+
fireEvent.blur(number);
|
|
204
|
+
const increment = getAllByRole("button")[1];
|
|
205
|
+
userEvent.click(increment);
|
|
206
|
+
expect(number.value).toBe("5");
|
|
207
|
+
userEvent.click(increment);
|
|
208
|
+
expect(number.value).toBe("13");
|
|
209
|
+
userEvent.click(increment);
|
|
210
|
+
expect(number.value).toBe("20");
|
|
211
|
+
userEvent.click(increment);
|
|
212
|
+
expect(number.value).toBe("20");
|
|
213
|
+
const decrement = getAllByRole("button")[0];
|
|
214
|
+
userEvent.click(decrement);
|
|
215
|
+
expect(number.value).toBe("12");
|
|
216
|
+
userEvent.click(decrement);
|
|
217
|
+
expect(number.value).toBe("5");
|
|
218
|
+
userEvent.click(decrement);
|
|
219
|
+
expect(number.value).toBe("5");
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test("Increment and decrement the value with min, max and step using the arrows in keyboard", () => {
|
|
223
|
+
const { getByLabelText } = render(<DxcNumber label="Number label" min={5} max={20} step={5} />);
|
|
224
|
+
const number = getByLabelText("Number label");
|
|
225
|
+
userEvent.type(number, "1");
|
|
226
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
227
|
+
expect(number.value).toBe("5");
|
|
228
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
229
|
+
expect(number.value).toBe("10");
|
|
230
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
231
|
+
expect(number.value).toBe("15");
|
|
232
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
233
|
+
expect(number.value).toBe("20");
|
|
234
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
235
|
+
expect(number.value).toBe("20");
|
|
236
|
+
fireEvent.keyDown(number, { keyCode: 40 });
|
|
237
|
+
expect(number.value).toBe("15");
|
|
238
|
+
fireEvent.keyDown(number, { keyCode: 40 });
|
|
239
|
+
expect(number.value).toBe("10");
|
|
240
|
+
fireEvent.keyDown(number, { keyCode: 40 });
|
|
241
|
+
expect(number.value).toBe("5");
|
|
242
|
+
fireEvent.keyDown(number, { keyCode: 40 });
|
|
243
|
+
expect(number.value).toBe("5");
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test("Number has correct accesibility attributes", () => {
|
|
247
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumber label="Number label" />);
|
|
248
|
+
const number = getByLabelText("Number label");
|
|
249
|
+
expect(number.getAttribute("aria-autocomplete")).toBeNull();
|
|
250
|
+
expect(number.getAttribute("aria-controls")).toBeNull();
|
|
251
|
+
expect(number.getAttribute("aria-expanded")).toBeNull();
|
|
252
|
+
const decrement = getAllByRole("button")[0];
|
|
253
|
+
expect(decrement.getAttribute("aria-label")).toBe("Decrement");
|
|
254
|
+
const increment = getAllByRole("button")[1];
|
|
255
|
+
expect(increment.getAttribute("aria-label")).toBe("Increment");
|
|
256
|
+
});
|
|
257
|
+
});
|
package/test/Paginator.test.js
CHANGED
|
@@ -62,7 +62,7 @@ describe("Paginator component tests", () => {
|
|
|
62
62
|
act(() => {
|
|
63
63
|
userEvent.click(goToPageSelect);
|
|
64
64
|
});
|
|
65
|
-
const goToPageOption =
|
|
65
|
+
const goToPageOption = getByText("2");
|
|
66
66
|
act(() => {
|
|
67
67
|
userEvent.click(goToPageOption);
|
|
68
68
|
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import DxcPasswordInput from "../src/password-input/PasswordInput";
|
|
5
|
+
|
|
6
|
+
describe("Password input component tests", () => {
|
|
7
|
+
test("Password input renders with label", () => {
|
|
8
|
+
const { getByText } = render(<DxcPasswordInput label="Password input label" />);
|
|
9
|
+
expect(getByText("Password input label")).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("Password input renders with helper text", () => {
|
|
13
|
+
const { getByText } = render(<DxcPasswordInput helperText="Helper text" />);
|
|
14
|
+
expect(getByText("Helper text")).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("Password input renders error", () => {
|
|
18
|
+
const { getByText } = render(<DxcPasswordInput error="Error message." />);
|
|
19
|
+
expect(getByText("Error message.")).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("onChange function is called correctly", () => {
|
|
23
|
+
const onChange = jest.fn();
|
|
24
|
+
const { getByRole } = render(<DxcPasswordInput label="Password input" onChange={onChange} />);
|
|
25
|
+
const passwordInput = getByRole("textbox");
|
|
26
|
+
userEvent.type(passwordInput, "Pa$$w0rd");
|
|
27
|
+
expect(onChange).toHaveBeenCalledWith({ value: "P", error: null });
|
|
28
|
+
expect(passwordInput.value).toBe("Pa$$w0rd");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("onBlur function is called correctly", () => {
|
|
32
|
+
const onBlur = jest.fn();
|
|
33
|
+
const { getByRole } = render(<DxcPasswordInput label="Password input" onBlur={onBlur} />);
|
|
34
|
+
const passwordInput = getByRole("textbox");
|
|
35
|
+
userEvent.type(passwordInput, "Pa$$w0rd");
|
|
36
|
+
fireEvent.blur(passwordInput);
|
|
37
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Pa$$w0rd", error: null });
|
|
38
|
+
expect(passwordInput.value).toBe("Pa$$w0rd");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("Clear password input value", () => {
|
|
42
|
+
const { getAllByRole, getByRole } = render(<DxcPasswordInput label="Password input" clearable />);
|
|
43
|
+
const passwordInput = getByRole("textbox");
|
|
44
|
+
userEvent.type(passwordInput, "Pa$$w0rd");
|
|
45
|
+
expect(passwordInput.value).toBe("Pa$$w0rd");
|
|
46
|
+
const clearButton = getAllByRole("button")[0];
|
|
47
|
+
userEvent.click(clearButton);
|
|
48
|
+
expect(passwordInput.value).toBe("");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("Non clearable password input has no clear icon", () => {
|
|
52
|
+
const { getAllByRole, getByRole } = render(<DxcPasswordInput label="Password input" />);
|
|
53
|
+
const passwordInput = getByRole("textbox");
|
|
54
|
+
userEvent.type(passwordInput, "Pa$$w0rd");
|
|
55
|
+
expect(passwordInput.value).toBe("Pa$$w0rd");
|
|
56
|
+
const buttons = getAllByRole("button");
|
|
57
|
+
expect(buttons.length).toBe(1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("Show/hide password input button works correctly", () => {
|
|
61
|
+
const { getAllByRole, getByRole } = render(<DxcPasswordInput label="Password input" clearable />);
|
|
62
|
+
const passwordInput = getByRole("textbox");
|
|
63
|
+
userEvent.type(passwordInput, "Pa$$w0rd");
|
|
64
|
+
expect(passwordInput.value).toBe("Pa$$w0rd");
|
|
65
|
+
expect(passwordInput.type).toBe("password");
|
|
66
|
+
const showButton = getAllByRole("button")[1];
|
|
67
|
+
userEvent.click(showButton);
|
|
68
|
+
expect(passwordInput.type).toBe("text");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("Password input has correct accesibility attributes", () => {
|
|
72
|
+
const { getByRole } = render(<DxcPasswordInput label="Password input" />);
|
|
73
|
+
const passwordInput = getByRole("textbox");
|
|
74
|
+
expect(passwordInput.getAttribute("aria-autocomplete")).toBeNull();
|
|
75
|
+
expect(passwordInput.getAttribute("aria-controls")).toBeNull();
|
|
76
|
+
const showButton = getByRole("button");
|
|
77
|
+
expect(showButton.getAttribute("aria-expanded")).toBe("false");
|
|
78
|
+
expect(showButton.getAttribute("aria-label")).toBe("Show");
|
|
79
|
+
userEvent.click(showButton);
|
|
80
|
+
expect(showButton.getAttribute("aria-expanded")).toBe("true");
|
|
81
|
+
expect(showButton.getAttribute("aria-label")).toBe("Hide");
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -266,13 +266,12 @@ describe("ResultsetTable component tests", () => {
|
|
|
266
266
|
act(() => {
|
|
267
267
|
userEvent.click(goToPageSelect);
|
|
268
268
|
});
|
|
269
|
-
const goToPageOption =
|
|
269
|
+
const goToPageOption = getByText("2");
|
|
270
270
|
act(() => {
|
|
271
271
|
userEvent.click(goToPageOption);
|
|
272
272
|
});
|
|
273
273
|
|
|
274
274
|
expect(getByText("4 to 6 of 10")).toBeTruthy();
|
|
275
|
-
// expect(getByText("Page: 2 of 4")).toBeTruthy();
|
|
276
275
|
expect(getByText("Rick")).toBeTruthy();
|
|
277
276
|
expect(getByText("Mark")).toBeTruthy();
|
|
278
277
|
expect(getByText("Cris")).toBeTruthy();
|
package/test/Select.test.js
CHANGED
|
@@ -21,18 +21,43 @@ const optionsWithoutIcon = [
|
|
|
21
21
|
const optionsWithIcons = [
|
|
22
22
|
{
|
|
23
23
|
value: 1,
|
|
24
|
-
label: "
|
|
25
|
-
|
|
24
|
+
label: "Image 1",
|
|
25
|
+
icon: (
|
|
26
|
+
<svg
|
|
27
|
+
data-testid="image-1"
|
|
28
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
29
|
+
height="24px"
|
|
30
|
+
viewBox="0 0 24 24"
|
|
31
|
+
width="24px"
|
|
32
|
+
fill="currentColor"
|
|
33
|
+
>
|
|
34
|
+
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
35
|
+
<path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" />
|
|
36
|
+
</svg>
|
|
37
|
+
),
|
|
26
38
|
},
|
|
27
39
|
{
|
|
28
40
|
value: 2,
|
|
29
|
-
label: "
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
label: "Image 2",
|
|
42
|
+
icon: (
|
|
43
|
+
<svg
|
|
44
|
+
data-testid="image-2"
|
|
45
|
+
version="1.1"
|
|
46
|
+
x="0px"
|
|
47
|
+
y="0px"
|
|
48
|
+
width="24px"
|
|
49
|
+
height="24px"
|
|
50
|
+
viewBox="0 0 24 24"
|
|
51
|
+
enable-background="new 0 0 24 24"
|
|
52
|
+
>
|
|
53
|
+
<g id="Bounding_Box">
|
|
54
|
+
<rect fill="none" width="24" height="24" />
|
|
55
|
+
</g>
|
|
56
|
+
<g id="Master">
|
|
57
|
+
<path d="M19,9.3V4h-3v2.6L12,3L2,12h3v8h5v-6h4v6h5v-8h3L19,9.3z M10,10c0-1.1,0.9-2,2-2s2,0.9,2,2H10z" />
|
|
58
|
+
</g>
|
|
59
|
+
</svg>
|
|
60
|
+
),
|
|
36
61
|
},
|
|
37
62
|
];
|
|
38
63
|
|
|
@@ -60,29 +85,27 @@ describe("Select component tests", () => {
|
|
|
60
85
|
});
|
|
61
86
|
|
|
62
87
|
test("Select renders options with icons before", () => {
|
|
63
|
-
const { getByRole,
|
|
88
|
+
const { getByRole, getByTestId } = render(
|
|
64
89
|
<DxcSelect label="test-select-name" options={optionsWithIcons}></DxcSelect>
|
|
65
90
|
);
|
|
66
91
|
const select = getByRole("button");
|
|
67
92
|
act(() => {
|
|
68
93
|
userEvent.click(select);
|
|
69
94
|
});
|
|
70
|
-
expect(
|
|
71
|
-
expect(
|
|
72
|
-
expect(getAllByRole("img")[2].getAttribute("src")).toEqual("/testIconLinkedin");
|
|
95
|
+
expect(getByTestId("image-1")).toBeTruthy();
|
|
96
|
+
expect(getByTestId("image-2")).toBeTruthy();
|
|
73
97
|
});
|
|
74
98
|
|
|
75
99
|
test("Select renders options with icons after", () => {
|
|
76
|
-
const { getByRole,
|
|
100
|
+
const { getByRole, getByTestId } = render(
|
|
77
101
|
<DxcSelect label="test-select-name" options={optionsWithIcons} iconPosition="after"></DxcSelect>
|
|
78
102
|
);
|
|
79
103
|
const select = getByRole("button");
|
|
80
104
|
act(() => {
|
|
81
105
|
userEvent.click(select);
|
|
82
106
|
});
|
|
83
|
-
expect(
|
|
84
|
-
expect(
|
|
85
|
-
expect(getAllByRole("img")[2].getAttribute("src")).toEqual("/testIconLinkedin");
|
|
107
|
+
expect(getByTestId("image-1")).toBeTruthy();
|
|
108
|
+
expect(getByTestId("image-2")).toBeTruthy();
|
|
86
109
|
});
|
|
87
110
|
|
|
88
111
|
test("Select renders with a default value", () => {
|
|
@@ -166,25 +189,22 @@ describe("Select component tests", () => {
|
|
|
166
189
|
act(() => {
|
|
167
190
|
userEvent.click(select);
|
|
168
191
|
});
|
|
169
|
-
const option1 = getByText("Amazon");
|
|
170
|
-
const option2 = getByText("Ebay");
|
|
171
|
-
const option3 = getByText("Apple");
|
|
172
192
|
act(() => {
|
|
173
|
-
userEvent.click(
|
|
193
|
+
userEvent.click(getByText("Amazon"));
|
|
174
194
|
});
|
|
175
195
|
expect(onChange).toHaveBeenCalledWith([1]);
|
|
176
196
|
act(() => {
|
|
177
|
-
userEvent.click(
|
|
197
|
+
userEvent.click(getByText("Ebay"));
|
|
178
198
|
});
|
|
179
199
|
expect(onChange).toHaveBeenCalledWith([1, 2]);
|
|
180
200
|
expect(getByText("Amazon, Ebay")).toBeTruthy();
|
|
181
201
|
act(() => {
|
|
182
|
-
userEvent.click(
|
|
202
|
+
userEvent.click(getByText("Apple"));
|
|
183
203
|
});
|
|
184
204
|
expect(onChange).toHaveBeenCalledWith([1, 2, 3]);
|
|
185
205
|
expect(getByText("Amazon, Ebay, Apple")).toBeTruthy();
|
|
186
206
|
act(() => {
|
|
187
|
-
userEvent.click(
|
|
207
|
+
userEvent.click(getByText("Amazon"));
|
|
188
208
|
});
|
|
189
209
|
expect(onChange).toHaveBeenCalledWith([2, 3]);
|
|
190
210
|
expect(getByText("Ebay, Apple")).toBeTruthy();
|
package/test/Spinner.test.js
CHANGED
|
@@ -24,4 +24,9 @@ describe("Spinner component tests", () => {
|
|
|
24
24
|
expect(getByText("test-loading")).toBeTruthy();
|
|
25
25
|
expect(getByText("75%")).toBeTruthy();
|
|
26
26
|
});
|
|
27
|
+
|
|
28
|
+
test("Get spinner by role", () => {
|
|
29
|
+
const { getByRole } = render(<DxcSpinner label="test-loading" value={75} showValue></DxcSpinner>);
|
|
30
|
+
expect(getByRole("progressbar")).toBeTruthy();
|
|
31
|
+
});
|
|
27
32
|
});
|