@dxc-technology/halstack-react 0.0.0-c7d5596 → 0.0.0-c7ec4d1
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/README.md +1 -1
- package/babel.config.js +6 -2
- package/dist/BackgroundColorContext.js +46 -0
- package/dist/ThemeContext.js +237 -2
- package/dist/V3Select/V3Select.js +549 -0
- package/dist/V3Textarea/V3Textarea.js +264 -0
- package/dist/accordion/Accordion.js +152 -67
- package/dist/accordion-group/AccordionGroup.js +186 -0
- package/dist/alert/Alert.js +183 -84
- 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 +63 -27
- package/dist/card/Card.js +72 -35
- package/dist/checkbox/Checkbox.js +99 -40
- package/dist/chip/Chip.js +97 -40
- package/dist/common/RequiredComponent.js +2 -8
- package/dist/common/utils.js +2 -22
- package/dist/common/variables.js +1452 -304
- package/dist/date/Date.js +80 -57
- package/dist/date-input/DateInput.js +400 -0
- package/dist/date-input/index.d.ts +95 -0
- package/dist/dialog/Dialog.js +58 -37
- package/dist/dropdown/Dropdown.js +177 -82
- package/dist/file-input/FileInput.js +644 -0
- package/dist/file-input/FileItem.js +287 -0
- package/dist/file-input/index.d.ts +81 -0
- package/dist/footer/Footer.js +90 -40
- package/dist/footer/Icons.js +77 -0
- package/dist/header/Header.js +192 -95
- package/dist/header/Icons.js +59 -0
- package/dist/heading/Heading.js +93 -16
- package/dist/input-text/Icons.js +22 -0
- package/dist/input-text/InputText.js +251 -116
- package/dist/layout/ApplicationLayout.js +18 -26
- package/dist/layout/Icons.js +55 -0
- package/dist/link/Link.js +89 -41
- package/dist/main.d.ts +8 -0
- package/dist/main.js +98 -18
- package/dist/number-input/NumberInput.js +136 -0
- package/dist/number-input/NumberInputContext.js +16 -0
- package/dist/number-input/index.d.ts +113 -0
- package/dist/paginator/Icons.js +66 -0
- package/dist/paginator/Paginator.js +122 -66
- package/dist/password-input/PasswordInput.js +203 -0
- package/dist/password-input/index.d.ts +94 -0
- package/dist/progress-bar/ProgressBar.js +95 -38
- package/dist/radio/Radio.js +31 -17
- package/dist/resultsetTable/ResultsetTable.js +82 -65
- package/dist/select/Select.js +896 -284
- package/dist/select/index.d.ts +53 -0
- package/dist/sidenav/Sidenav.js +66 -15
- package/dist/slider/Slider.js +211 -73
- package/dist/spinner/Spinner.js +247 -59
- package/dist/switch/Switch.js +50 -27
- package/dist/table/Table.js +51 -24
- package/dist/tabs/Tabs.js +193 -35
- package/dist/tag/Tag.js +68 -35
- package/dist/text-input/TextInput.js +974 -0
- package/dist/text-input/index.d.ts +135 -0
- package/dist/textarea/Textarea.js +248 -106
- package/dist/textarea/index.d.ts +117 -0
- package/dist/toggle/Toggle.js +16 -19
- package/dist/toggle-group/ToggleGroup.js +142 -41
- package/dist/upload/Upload.js +16 -11
- package/dist/upload/buttons-upload/ButtonsUpload.js +32 -19
- package/dist/upload/buttons-upload/Icons.js +40 -0
- package/dist/upload/dragAndDropArea/DragAndDropArea.js +84 -34
- package/dist/upload/dragAndDropArea/Icons.js +39 -0
- package/dist/upload/file-upload/FileToUpload.js +64 -33
- package/dist/upload/file-upload/Icons.js +66 -0
- package/dist/upload/files-upload/FilesToUpload.js +16 -16
- package/dist/upload/transaction/Icons.js +160 -0
- package/dist/upload/transaction/Transaction.js +42 -49
- package/dist/upload/transactions/Transactions.js +38 -20
- package/dist/useTheme.js +22 -0
- package/dist/wizard/Icons.js +65 -0
- package/dist/wizard/Wizard.js +125 -60
- package/package.json +14 -11
- package/test/AccordionGroup.test.js +125 -0
- package/test/Date.test.js +49 -45
- package/test/DateInput.test.js +242 -0
- package/test/Dropdown.test.js +15 -0
- package/test/FileInput.test.js +201 -0
- package/test/Footer.test.js +2 -7
- package/test/Header.test.js +5 -10
- package/test/Heading.test.js +60 -12
- package/test/InputText.test.js +53 -41
- package/test/Link.test.js +12 -2
- package/test/NumberInput.test.js +259 -0
- package/test/Paginator.test.js +50 -77
- package/test/PasswordInput.test.js +83 -0
- package/test/ResultsetTable.test.js +61 -25
- package/test/Slider.test.js +9 -17
- package/test/Spinner.test.js +5 -0
- package/test/Tabs.test.js +21 -0
- package/test/TextInput.test.js +732 -0
- package/test/Textarea.test.js +193 -0
- package/test/ToggleGroup.test.js +5 -1
- package/test/Upload.test.js +5 -5
- package/test/{Select.test.js → V3Select.test.js} +67 -46
- package/test/{TextArea.test.js → V3TextArea.test.js} +6 -7
- 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/checkbox/Checkbox.stories.js +0 -144
- package/dist/checkbox/readme.md +0 -116
- package/dist/common/services/example-service.js +0 -10
- package/dist/common/services/example-service.test.js +0 -12
- package/dist/date/Date.stories.js +0 -205
- package/dist/date/calendar.svg +0 -1
- package/dist/date/calendar_dark.svg +0 -1
- package/dist/date/readme.md +0 -73
- 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/footer/readme.md +0 -41
- package/dist/header/Header.stories.js +0 -176
- package/dist/header/close_icon.svg +0 -1
- 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/header/hamb_menu_black.svg +0 -1
- package/dist/header/hamb_menu_white.svg +0 -1
- package/dist/header/readme.md +0 -33
- package/dist/input-text/InputText.stories.js +0 -209
- package/dist/input-text/error.svg +0 -1
- package/dist/input-text/readme.md +0 -91
- package/dist/layout/facebook.svg +0 -45
- package/dist/layout/linkedin.svg +0 -50
- package/dist/layout/twitter.svg +0 -53
- package/dist/link/readme.md +0 -51
- package/dist/paginator/images/next.svg +0 -3
- package/dist/paginator/images/nextPage.svg +0 -3
- package/dist/paginator/images/previous.svg +0 -3
- package/dist/paginator/images/previousPage.svg +0 -3
- package/dist/paginator/readme.md +0 -50
- package/dist/progress-bar/ProgressBar.stories.js +0 -280
- package/dist/progress-bar/readme.md +0 -63
- package/dist/radio/Radio.stories.js +0 -166
- package/dist/radio/readme.md +0 -70
- package/dist/resultsetTable/arrow_downward-24px_wht.svg +0 -1
- package/dist/resultsetTable/arrow_upward-24px_wht.svg +0 -1
- package/dist/resultsetTable/unfold_more-24px_wht.svg +0 -1
- package/dist/select/Select.stories.js +0 -235
- package/dist/select/readme.md +0 -72
- package/dist/slider/Slider.stories.js +0 -241
- package/dist/slider/readme.md +0 -64
- package/dist/spinner/Spinner.stories.js +0 -183
- package/dist/spinner/readme.md +0 -65
- package/dist/switch/Switch.stories.js +0 -134
- package/dist/switch/readme.md +0 -133
- package/dist/tabs/Tabs.stories.js +0 -130
- package/dist/tabs/readme.md +0 -78
- package/dist/tabs-for-sections/TabsForSections.js +0 -92
- package/dist/tabs-for-sections/readme.md +0 -78
- package/dist/toggle/Toggle.stories.js +0 -297
- package/dist/toggle/readme.md +0 -80
- package/dist/toggle-group/readme.md +0 -82
- package/dist/upload/Upload.stories.js +0 -72
- package/dist/upload/buttons-upload/drag-drop-icon.svg +0 -4
- package/dist/upload/buttons-upload/upload-button.svg +0 -1
- package/dist/upload/dragAndDropArea/upload_drop.svg +0 -4
- package/dist/upload/dragAndDropArea/upload_file.svg +0 -4
- package/dist/upload/file-upload/audio-icon.svg +0 -4
- package/dist/upload/file-upload/close.svg +0 -4
- package/dist/upload/file-upload/file-icon.svg +0 -4
- package/dist/upload/file-upload/video-icon.svg +0 -4
- package/dist/upload/readme.md +0 -37
- package/dist/upload/transaction/audio-icon-err.svg +0 -4
- package/dist/upload/transaction/audio-icon.svg +0 -4
- package/dist/upload/transaction/error-icon.svg +0 -4
- package/dist/upload/transaction/file-icon-err.svg +0 -4
- package/dist/upload/transaction/file-icon.svg +0 -4
- package/dist/upload/transaction/image-icon-err.svg +0 -4
- package/dist/upload/transaction/image-icon.svg +0 -4
- package/dist/upload/transaction/success-icon.svg +0 -4
- package/dist/upload/transaction/video-icon-err.svg +0 -4
- package/dist/upload/transaction/video-icon.svg +0 -4
- package/dist/wizard/invalid_icon.svg +0 -6
- package/dist/wizard/valid_icon.svg +0 -6
- package/dist/wizard/validation-wrong.svg +0 -6
- package/test/TabsForSections.test.js +0 -34
- package/test/Toggle.test.js +0 -43
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import DxcNumberInput from "../src/number-input/NumberInput";
|
|
5
|
+
|
|
6
|
+
describe("Number input component tests", () => {
|
|
7
|
+
test("Number input renders with label", () => {
|
|
8
|
+
const { getByText } = render(<DxcNumberInput label="Number input label" />);
|
|
9
|
+
expect(getByText("Number input label")).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("Number input renders with helper text", () => {
|
|
13
|
+
const { getByText } = render(<DxcNumberInput helperText="Helper text" />);
|
|
14
|
+
expect(getByText("Helper text")).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("Number input renders with placeholder", () => {
|
|
18
|
+
const { getByLabelText } = render(<DxcNumberInput label="Number label" placeholder="Placeholder" />);
|
|
19
|
+
const number = getByLabelText("Number label");
|
|
20
|
+
expect(number.getAttribute("placeholder")).toBe("Placeholder");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("Number input renders increment and decrement buttons", () => {
|
|
24
|
+
const { queryAllByRole } = render(<DxcNumberInput label="Number label" />);
|
|
25
|
+
expect(queryAllByRole("button").length).toBe(2);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("Number input is disabled", () => {
|
|
29
|
+
const { getByLabelText } = render(<DxcNumberInput label="Number label" disabled />);
|
|
30
|
+
const number = getByLabelText("Number label");
|
|
31
|
+
expect(number.disabled).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("Number input is optional", () => {
|
|
35
|
+
const { getByText } = render(<DxcNumberInput label="Number label" optional />);
|
|
36
|
+
expect(getByText("(Optional)")).toBeTruthy();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("Number input 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(<DxcNumberInput 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(<DxcNumberInput label="Number input label" prefix="+34" suffix="USD" />);
|
|
56
|
+
expect(getByText("+34")).toBeTruthy();
|
|
57
|
+
expect(getByText("USD")).toBeTruthy();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("Invalid number input renders error", () => {
|
|
61
|
+
const { getByText } = render(<DxcNumberInput 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(<DxcNumberInput label="Number input label" onChange={onChange} />);
|
|
68
|
+
const number = getByLabelText("Number input 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
|
+
<DxcNumberInput label="Number input label" min={5} onBlur={onBlur} onChange={onChange} />
|
|
88
|
+
);
|
|
89
|
+
const number = getByLabelText("Number input 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(<DxcNumberInput label="Number input label" min={5} />);
|
|
97
|
+
const number = getByLabelText("Number input 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(<DxcNumberInput label="Number input label" min={5} />);
|
|
108
|
+
const number = getByLabelText("Number input 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(
|
|
121
|
+
<DxcNumberInput label="Number input label" max={10} onBlur={onBlur} onChange={onChange} />
|
|
122
|
+
);
|
|
123
|
+
const number = getByLabelText("Number input label");
|
|
124
|
+
|
|
125
|
+
userEvent.type(number, "12");
|
|
126
|
+
expect(onChange).toHaveBeenCalledTimes(2);
|
|
127
|
+
expect(onChange).toHaveBeenCalledWith({ value: "12", error: "Value must be less than or equal to 10." });
|
|
128
|
+
fireEvent.blur(number);
|
|
129
|
+
expect(onBlur).toHaveBeenCalled();
|
|
130
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "12", error: "Value must be less than or equal to 10." });
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("Cannot increment the value if it is greater than the max value", () => {
|
|
134
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" max={10} />);
|
|
135
|
+
const number = getByLabelText("Number input label");
|
|
136
|
+
userEvent.type(number, "12");
|
|
137
|
+
fireEvent.blur(number);
|
|
138
|
+
expect(number.value).toBe("12");
|
|
139
|
+
const decrement = getAllByRole("button")[1];
|
|
140
|
+
userEvent.click(decrement);
|
|
141
|
+
expect(number.value).toBe("12");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("Decrement the value when it is greater than the max value", () => {
|
|
145
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" max={10} />);
|
|
146
|
+
const number = getByLabelText("Number input label");
|
|
147
|
+
userEvent.type(number, "12");
|
|
148
|
+
fireEvent.blur(number);
|
|
149
|
+
expect(number.value).toBe("12");
|
|
150
|
+
const decrement = getAllByRole("button")[0];
|
|
151
|
+
userEvent.click(decrement);
|
|
152
|
+
expect(number.value).toBe("10");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("Increment and decrement the value with min and max values", () => {
|
|
156
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" min={5} max={10} />);
|
|
157
|
+
const number = getByLabelText("Number input label");
|
|
158
|
+
userEvent.type(number, "1");
|
|
159
|
+
fireEvent.blur(number);
|
|
160
|
+
expect(number.value).toBe("1");
|
|
161
|
+
const decrement = getAllByRole("button")[0];
|
|
162
|
+
userEvent.click(decrement);
|
|
163
|
+
expect(number.value).toBe("1");
|
|
164
|
+
const increment = getAllByRole("button")[1];
|
|
165
|
+
userEvent.click(increment);
|
|
166
|
+
expect(number.value).toBe("5");
|
|
167
|
+
userEvent.click(increment);
|
|
168
|
+
userEvent.click(increment);
|
|
169
|
+
userEvent.click(increment);
|
|
170
|
+
userEvent.click(increment);
|
|
171
|
+
userEvent.click(increment);
|
|
172
|
+
expect(number.value).toBe("10");
|
|
173
|
+
userEvent.click(increment);
|
|
174
|
+
expect(number.value).toBe("10");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("Increment and decrement the value with step", () => {
|
|
178
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" step={5} />);
|
|
179
|
+
const number = getByLabelText("Number input label");
|
|
180
|
+
userEvent.type(number, "10");
|
|
181
|
+
fireEvent.blur(number);
|
|
182
|
+
expect(number.value).toBe("10");
|
|
183
|
+
const increment = getAllByRole("button")[1];
|
|
184
|
+
userEvent.click(increment);
|
|
185
|
+
expect(number.value).toBe("15");
|
|
186
|
+
userEvent.click(increment);
|
|
187
|
+
expect(number.value).toBe("20");
|
|
188
|
+
const decrement = getAllByRole("button")[0];
|
|
189
|
+
userEvent.click(decrement);
|
|
190
|
+
expect(number.value).toBe("15");
|
|
191
|
+
userEvent.click(decrement);
|
|
192
|
+
expect(number.value).toBe("10");
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("Increment and decrement the value with min, max and step", () => {
|
|
196
|
+
const onBlur = jest.fn(({ value, error }) => {
|
|
197
|
+
expect(value).toBe("1");
|
|
198
|
+
expect(error).toBe("Value must be greater than or equal to 5.");
|
|
199
|
+
});
|
|
200
|
+
const { getByLabelText, getAllByRole } = render(
|
|
201
|
+
<DxcNumberInput label="Number input label" min={5} max={20} step={8} onBlur={onBlur} />
|
|
202
|
+
);
|
|
203
|
+
const number = getByLabelText("Number input label");
|
|
204
|
+
userEvent.type(number, "1");
|
|
205
|
+
fireEvent.blur(number);
|
|
206
|
+
const increment = getAllByRole("button")[1];
|
|
207
|
+
userEvent.click(increment);
|
|
208
|
+
expect(number.value).toBe("5");
|
|
209
|
+
userEvent.click(increment);
|
|
210
|
+
expect(number.value).toBe("13");
|
|
211
|
+
userEvent.click(increment);
|
|
212
|
+
expect(number.value).toBe("20");
|
|
213
|
+
userEvent.click(increment);
|
|
214
|
+
expect(number.value).toBe("20");
|
|
215
|
+
const decrement = getAllByRole("button")[0];
|
|
216
|
+
userEvent.click(decrement);
|
|
217
|
+
expect(number.value).toBe("12");
|
|
218
|
+
userEvent.click(decrement);
|
|
219
|
+
expect(number.value).toBe("5");
|
|
220
|
+
userEvent.click(decrement);
|
|
221
|
+
expect(number.value).toBe("5");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("Increment and decrement the value with min, max and step using the arrows in keyboard", () => {
|
|
225
|
+
const { getByLabelText } = render(<DxcNumberInput label="Number input label" min={5} max={20} step={5} />);
|
|
226
|
+
const number = getByLabelText("Number input label");
|
|
227
|
+
userEvent.type(number, "1");
|
|
228
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
229
|
+
expect(number.value).toBe("5");
|
|
230
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
231
|
+
expect(number.value).toBe("10");
|
|
232
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
233
|
+
expect(number.value).toBe("15");
|
|
234
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
235
|
+
expect(number.value).toBe("20");
|
|
236
|
+
fireEvent.keyDown(number, { keyCode: 38 });
|
|
237
|
+
expect(number.value).toBe("20");
|
|
238
|
+
fireEvent.keyDown(number, { keyCode: 40 });
|
|
239
|
+
expect(number.value).toBe("15");
|
|
240
|
+
fireEvent.keyDown(number, { keyCode: 40 });
|
|
241
|
+
expect(number.value).toBe("10");
|
|
242
|
+
fireEvent.keyDown(number, { keyCode: 40 });
|
|
243
|
+
expect(number.value).toBe("5");
|
|
244
|
+
fireEvent.keyDown(number, { keyCode: 40 });
|
|
245
|
+
expect(number.value).toBe("5");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("Number has correct accesibility attributes", () => {
|
|
249
|
+
const { getByLabelText, getAllByRole } = render(<DxcNumberInput label="Number input label" />);
|
|
250
|
+
const number = getByLabelText("Number input label");
|
|
251
|
+
expect(number.getAttribute("aria-autocomplete")).toBeNull();
|
|
252
|
+
expect(number.getAttribute("aria-controls")).toBeNull();
|
|
253
|
+
expect(number.getAttribute("aria-expanded")).toBeNull();
|
|
254
|
+
const decrement = getAllByRole("button")[0];
|
|
255
|
+
expect(decrement.getAttribute("aria-label")).toBe("Decrement");
|
|
256
|
+
const increment = getAllByRole("button")[1];
|
|
257
|
+
expect(increment.getAttribute("aria-label")).toBe("Increment");
|
|
258
|
+
});
|
|
259
|
+
});
|
package/test/Paginator.test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { render,
|
|
2
|
+
import { render, act } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
3
4
|
import DxcPaginator from "../src/paginator/Paginator";
|
|
4
5
|
|
|
5
6
|
describe("Paginator component tests", () => {
|
|
@@ -16,15 +17,7 @@ describe("Paginator component tests", () => {
|
|
|
16
17
|
|
|
17
18
|
test("Paginator renders with itemsPerPageOptions", () => {
|
|
18
19
|
const { getByText } = render(
|
|
19
|
-
<DxcPaginator
|
|
20
|
-
currentPage={1}
|
|
21
|
-
itemsPerPage={10}
|
|
22
|
-
itemsPerPageOptions={[
|
|
23
|
-
{ label: 10, value: 10 },
|
|
24
|
-
{ label: 15, value: 15 },
|
|
25
|
-
]}
|
|
26
|
-
totalItems={20}
|
|
27
|
-
></DxcPaginator>
|
|
20
|
+
<DxcPaginator currentPage={1} itemsPerPage={10} itemsPerPageOptions={[10, 15]} totalItems={20}></DxcPaginator>
|
|
28
21
|
);
|
|
29
22
|
expect(getByText("Items per page")).toBeTruthy();
|
|
30
23
|
});
|
|
@@ -47,43 +40,42 @@ describe("Paginator component tests", () => {
|
|
|
47
40
|
expect(getByText("Page: 2 of 2")).toBeTruthy();
|
|
48
41
|
});
|
|
49
42
|
|
|
50
|
-
test("
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
<DxcPaginator nextFunction={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
43
|
+
test("Paginator renders goToPage select", () => {
|
|
44
|
+
const { getByText } = render(
|
|
45
|
+
<DxcPaginator currentPage={2} showGoToPage={true} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
54
46
|
);
|
|
55
|
-
|
|
56
|
-
fireEvent.click(nextButton);
|
|
57
|
-
expect(onClick).toHaveBeenCalled();
|
|
47
|
+
expect(getByText("Go to page:")).toBeTruthy();
|
|
58
48
|
});
|
|
59
49
|
|
|
60
|
-
test("
|
|
50
|
+
test("Paginator goToPage call correct function", () => {
|
|
61
51
|
const onClick = jest.fn();
|
|
62
|
-
const { getByRole } = render(
|
|
63
|
-
<DxcPaginator
|
|
52
|
+
const { getByText, getAllByRole, getByRole } = render(
|
|
53
|
+
<DxcPaginator
|
|
54
|
+
currentPage={1}
|
|
55
|
+
itemsPerPage={10}
|
|
56
|
+
totalItems={27}
|
|
57
|
+
showGoToPage={true}
|
|
58
|
+
onPageChange={onClick}
|
|
59
|
+
></DxcPaginator>
|
|
64
60
|
);
|
|
65
|
-
const
|
|
66
|
-
|
|
61
|
+
const goToPageSelect = getAllByRole("button")[2];
|
|
62
|
+
act(() => {
|
|
63
|
+
userEvent.click(goToPageSelect);
|
|
64
|
+
});
|
|
65
|
+
const goToPageOption = getByText("2");
|
|
66
|
+
act(() => {
|
|
67
|
+
userEvent.click(goToPageOption);
|
|
68
|
+
});
|
|
67
69
|
expect(onClick).toHaveBeenCalledWith(2);
|
|
68
70
|
});
|
|
69
71
|
|
|
70
|
-
test("Call correct
|
|
71
|
-
const onClick = jest.fn();
|
|
72
|
-
const { getByRole } = render(
|
|
73
|
-
<DxcPaginator prevFunction={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
74
|
-
);
|
|
75
|
-
const prevButton = getByRole("button");
|
|
76
|
-
fireEvent.click(prevButton);
|
|
77
|
-
expect(onClick).toHaveBeenCalled();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("Call correct firstFunction", () => {
|
|
72
|
+
test("Call correct goToPageFunction", () => {
|
|
81
73
|
const onClick = jest.fn();
|
|
82
|
-
const {
|
|
83
|
-
<DxcPaginator
|
|
74
|
+
const { getAllByRole } = render(
|
|
75
|
+
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
84
76
|
);
|
|
85
|
-
const
|
|
86
|
-
|
|
77
|
+
const nextButton = getAllByRole("button")[2];
|
|
78
|
+
userEvent.click(nextButton);
|
|
87
79
|
expect(onClick).toHaveBeenCalled();
|
|
88
80
|
});
|
|
89
81
|
|
|
@@ -93,81 +85,70 @@ describe("Paginator component tests", () => {
|
|
|
93
85
|
<DxcPaginator
|
|
94
86
|
currentPage={1}
|
|
95
87
|
itemsPerPage={10}
|
|
96
|
-
itemsPerPageOptions={[
|
|
97
|
-
{ label: 10, value: 10 },
|
|
98
|
-
{ label: 15, value: 15 },
|
|
99
|
-
]}
|
|
88
|
+
itemsPerPageOptions={[10, 15]}
|
|
100
89
|
itemsPerPageFunction={onClick}
|
|
101
90
|
totalItems={20}
|
|
102
91
|
></DxcPaginator>
|
|
103
92
|
);
|
|
104
93
|
const select = getAllByText("10")[0];
|
|
105
94
|
act(() => {
|
|
106
|
-
|
|
95
|
+
userEvent.click(select);
|
|
107
96
|
});
|
|
108
97
|
const itemPerPageOption = getByText("15");
|
|
109
98
|
act(() => {
|
|
110
|
-
|
|
99
|
+
userEvent.click(itemPerPageOption);
|
|
111
100
|
});
|
|
112
101
|
expect(onClick).toHaveBeenCalledWith(15);
|
|
113
102
|
});
|
|
114
103
|
|
|
115
104
|
test("Next button is disable in last page", () => {
|
|
116
105
|
const onClick = jest.fn();
|
|
117
|
-
const {
|
|
118
|
-
<DxcPaginator
|
|
106
|
+
const { getAllByRole } = render(
|
|
107
|
+
<DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
119
108
|
);
|
|
120
|
-
const nextButton =
|
|
109
|
+
const nextButton = getAllByRole("button")[2];
|
|
121
110
|
expect(nextButton.hasAttribute("disabled")).toBeTruthy();
|
|
122
|
-
|
|
111
|
+
userEvent.click(nextButton);
|
|
123
112
|
expect(onClick).toHaveBeenCalledTimes(0);
|
|
124
113
|
});
|
|
125
114
|
|
|
126
115
|
test("Last button is disable in last page", () => {
|
|
127
116
|
const onClick = jest.fn();
|
|
128
|
-
const {
|
|
129
|
-
<DxcPaginator
|
|
117
|
+
const { getAllByRole } = render(
|
|
118
|
+
<DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
130
119
|
);
|
|
131
|
-
const lastButton =
|
|
120
|
+
const lastButton = getAllByRole("button")[3];
|
|
132
121
|
expect(lastButton.hasAttribute("disabled")).toBeTruthy();
|
|
133
|
-
|
|
122
|
+
userEvent.click(lastButton);
|
|
134
123
|
expect(onClick).toHaveBeenCalledTimes(0);
|
|
135
124
|
});
|
|
136
125
|
|
|
137
126
|
test("First button is disable in first page", () => {
|
|
138
127
|
const onClick = jest.fn();
|
|
139
|
-
const {
|
|
140
|
-
<DxcPaginator
|
|
128
|
+
const { getAllByRole } = render(
|
|
129
|
+
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
141
130
|
);
|
|
142
|
-
const lastButton =
|
|
131
|
+
const lastButton = getAllByRole("button")[0];
|
|
143
132
|
expect(lastButton.hasAttribute("disabled")).toBeTruthy();
|
|
144
|
-
|
|
133
|
+
userEvent.click(lastButton);
|
|
145
134
|
expect(onClick).toHaveBeenCalledTimes(0);
|
|
146
135
|
});
|
|
147
136
|
|
|
148
137
|
test("Previous button is disable in first page", () => {
|
|
149
138
|
const onClick = jest.fn();
|
|
150
|
-
const {
|
|
151
|
-
<DxcPaginator
|
|
139
|
+
const { getAllByRole } = render(
|
|
140
|
+
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
152
141
|
);
|
|
153
|
-
const lastButton =
|
|
142
|
+
const lastButton = getAllByRole("button")[1];
|
|
154
143
|
expect(lastButton.hasAttribute("disabled")).toBeTruthy();
|
|
155
|
-
|
|
144
|
+
userEvent.click(lastButton);
|
|
156
145
|
expect(onClick).toHaveBeenCalledTimes(0);
|
|
157
146
|
});
|
|
158
147
|
|
|
159
148
|
test("Last and next buttons are disable in last page", () => {
|
|
160
149
|
const onClick = jest.fn();
|
|
161
150
|
const { getAllByRole } = render(
|
|
162
|
-
<DxcPaginator
|
|
163
|
-
prevFunction={onClick}
|
|
164
|
-
firstFunction={onClick}
|
|
165
|
-
nextFunction={onClick}
|
|
166
|
-
lastFunction={onClick}
|
|
167
|
-
currentPage={2}
|
|
168
|
-
itemsPerPage={10}
|
|
169
|
-
totalItems={20}
|
|
170
|
-
></DxcPaginator>
|
|
151
|
+
<DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
171
152
|
);
|
|
172
153
|
const firstButton = getAllByRole("button")[0];
|
|
173
154
|
const prevButton = getAllByRole("button")[1];
|
|
@@ -182,15 +163,7 @@ describe("Paginator component tests", () => {
|
|
|
182
163
|
test("First and previous buttons are disable in first page", () => {
|
|
183
164
|
const onClick = jest.fn();
|
|
184
165
|
const { getAllByRole } = render(
|
|
185
|
-
<DxcPaginator
|
|
186
|
-
prevFunction={onClick}
|
|
187
|
-
firstFunction={onClick}
|
|
188
|
-
nextFunction={onClick}
|
|
189
|
-
lastFunction={onClick}
|
|
190
|
-
currentPage={1}
|
|
191
|
-
itemsPerPage={10}
|
|
192
|
-
totalItems={20}
|
|
193
|
-
></DxcPaginator>
|
|
166
|
+
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
|
|
194
167
|
);
|
|
195
168
|
const firstButton = getAllByRole("button")[0];
|
|
196
169
|
const prevButton = getAllByRole("button")[1];
|
|
@@ -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
|
+
});
|