@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,193 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import DxcTextarea from "../src/textarea/Textarea";
|
|
5
|
+
|
|
6
|
+
describe("Textarea component tests", () => {
|
|
7
|
+
test("Renders with correct label", () => {
|
|
8
|
+
const { getByText } = render(<DxcTextarea label="Example label" />);
|
|
9
|
+
expect(getByText("Example label")).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
test("Renders with correct label and helper text", () => {
|
|
12
|
+
const { getByText } = render(<DxcTextarea label="Example label" helperText="Example helper text" />);
|
|
13
|
+
expect(getByText("Example label")).toBeTruthy();
|
|
14
|
+
expect(getByText("Example helper text")).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
test("Renders with correct label and optional", () => {
|
|
17
|
+
const { getByText, getByRole } = render(
|
|
18
|
+
<DxcTextarea label="Example label" helperText="Example helper text" optional />
|
|
19
|
+
);
|
|
20
|
+
const textarea = getByRole("textbox");
|
|
21
|
+
expect(getByText("Example label")).toBeTruthy();
|
|
22
|
+
expect(getByText("(Optional)")).toBeTruthy();
|
|
23
|
+
expect(getByText("Example helper text")).toBeTruthy();
|
|
24
|
+
expect(textarea.getAttribute("aria-required")).toBe("false");
|
|
25
|
+
});
|
|
26
|
+
test("Renders with correct placeholder", () => {
|
|
27
|
+
const { getByRole } = render(<DxcTextarea placeholder="Placeholder" />);
|
|
28
|
+
const textarea = getByRole("textbox");
|
|
29
|
+
expect(textarea.getAttribute("placeholder")).toBe("Placeholder");
|
|
30
|
+
});
|
|
31
|
+
test("Renders with error message", () => {
|
|
32
|
+
const { getByText, getByRole } = render(<DxcTextarea error="Error message." />);
|
|
33
|
+
const textarea = getByRole("textbox");
|
|
34
|
+
expect(getByText("Error message.")).toBeTruthy();
|
|
35
|
+
expect(textarea.getAttribute("aria-invalid")).toBe("true");
|
|
36
|
+
expect(textarea.getAttribute("aria-describedBy")).not.toBeNull();
|
|
37
|
+
});
|
|
38
|
+
test("Renders with correct default rows", () => {
|
|
39
|
+
const { getByLabelText } = render(<DxcTextarea label="Example label" rows={10} />);
|
|
40
|
+
const textarea = getByLabelText("Example label");
|
|
41
|
+
expect(textarea.rows).toBe(10);
|
|
42
|
+
});
|
|
43
|
+
test("Renders with correct accesibility attributes", () => {
|
|
44
|
+
const { getByLabelText } = render(<DxcTextarea label="Example label" />);
|
|
45
|
+
const textarea = getByLabelText("Example label");
|
|
46
|
+
expect(textarea.getAttribute("aria-invalid")).toBe("false");
|
|
47
|
+
expect(textarea.getAttribute("aria-describedBy")).toBeNull();
|
|
48
|
+
expect(textarea.getAttribute("aria-required")).toBe("true");
|
|
49
|
+
});
|
|
50
|
+
test("Not optional constraint (onBlur)", () => {
|
|
51
|
+
const onChange = jest.fn();
|
|
52
|
+
const onBlur = jest.fn();
|
|
53
|
+
const { getByLabelText } = render(
|
|
54
|
+
<DxcTextarea label="Example label" placeholder="Placeholder" onChange={onChange} onBlur={onBlur} />
|
|
55
|
+
);
|
|
56
|
+
const textarea = getByLabelText("Example label");
|
|
57
|
+
|
|
58
|
+
fireEvent.focus(textarea);
|
|
59
|
+
fireEvent.blur(textarea);
|
|
60
|
+
expect(onBlur).toHaveBeenCalled();
|
|
61
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
62
|
+
fireEvent.change(textarea, { target: { value: "Test" } });
|
|
63
|
+
fireEvent.blur(textarea);
|
|
64
|
+
expect(onBlur).toHaveBeenCalled();
|
|
65
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Test", error: null });
|
|
66
|
+
});
|
|
67
|
+
test("Not optional constraint (onChange)", () => {
|
|
68
|
+
const onChange = jest.fn();
|
|
69
|
+
const { getByLabelText } = render(
|
|
70
|
+
<DxcTextarea label="Example label" placeholder="Placeholder" onChange={onChange} />
|
|
71
|
+
);
|
|
72
|
+
const textarea = getByLabelText("Example label");
|
|
73
|
+
|
|
74
|
+
fireEvent.focus(textarea);
|
|
75
|
+
fireEvent.change(textarea, { target: { value: "Test" } });
|
|
76
|
+
expect(onChange).toHaveBeenCalled();
|
|
77
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Test", error: null });
|
|
78
|
+
userEvent.clear(textarea);
|
|
79
|
+
expect(onChange).toHaveBeenCalled();
|
|
80
|
+
expect(onChange).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
81
|
+
});
|
|
82
|
+
test("Pattern constraint", () => {
|
|
83
|
+
const onChange = jest.fn();
|
|
84
|
+
const onBlur = jest.fn();
|
|
85
|
+
const { getByLabelText } = render(
|
|
86
|
+
<DxcTextarea
|
|
87
|
+
label="Example label"
|
|
88
|
+
placeholder="Placeholder"
|
|
89
|
+
onChange={onChange}
|
|
90
|
+
onBlur={onBlur}
|
|
91
|
+
margin={{ left: "medium", right: "medium" }}
|
|
92
|
+
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
const textarea = getByLabelText("Example label");
|
|
96
|
+
|
|
97
|
+
fireEvent.change(textarea, { target: { value: "pattern test" } });
|
|
98
|
+
expect(onChange).toHaveBeenCalled();
|
|
99
|
+
expect(onChange).toHaveBeenCalledWith({ value: "pattern test", error: "Please match the format requested." });
|
|
100
|
+
fireEvent.blur(textarea);
|
|
101
|
+
expect(onBlur).toHaveBeenCalled();
|
|
102
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "pattern test", error: "Please match the format requested." });
|
|
103
|
+
userEvent.clear(textarea);
|
|
104
|
+
fireEvent.change(textarea, { target: { value: "pattern4&" } });
|
|
105
|
+
expect(onChange).toHaveBeenCalled();
|
|
106
|
+
expect(onChange).toHaveBeenCalledWith({ value: "pattern4&", error: null });
|
|
107
|
+
fireEvent.blur(textarea);
|
|
108
|
+
expect(onBlur).toHaveBeenCalled();
|
|
109
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "pattern4&", error: null });
|
|
110
|
+
});
|
|
111
|
+
test("Length constraint", () => {
|
|
112
|
+
const onChange = jest.fn();
|
|
113
|
+
const onBlur = jest.fn();
|
|
114
|
+
const { getByLabelText } = render(
|
|
115
|
+
<DxcTextarea
|
|
116
|
+
label="Example label"
|
|
117
|
+
placeholder="Placeholder"
|
|
118
|
+
onChange={onChange}
|
|
119
|
+
onBlur={onBlur}
|
|
120
|
+
margin={{ left: "medium", right: "medium" }}
|
|
121
|
+
length={{ min: 5, max: 10 }}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
const textarea = getByLabelText("Example label");
|
|
125
|
+
|
|
126
|
+
fireEvent.change(textarea, { target: { value: "test" } });
|
|
127
|
+
expect(onChange).toHaveBeenCalled();
|
|
128
|
+
expect(onChange).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
129
|
+
fireEvent.blur(textarea);
|
|
130
|
+
expect(onBlur).toHaveBeenCalled();
|
|
131
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
132
|
+
userEvent.clear(textarea);
|
|
133
|
+
fireEvent.change(textarea, { target: { value: "length" } });
|
|
134
|
+
expect(onChange).toHaveBeenCalled();
|
|
135
|
+
expect(onChange).toHaveBeenCalledWith({ value: "length", error: null });
|
|
136
|
+
fireEvent.blur(textarea);
|
|
137
|
+
expect(onBlur).toHaveBeenCalled();
|
|
138
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "length", error: null });
|
|
139
|
+
});
|
|
140
|
+
test("Pattern and length constraints", () => {
|
|
141
|
+
const onChange = jest.fn();
|
|
142
|
+
const onBlur = jest.fn();
|
|
143
|
+
const { getByLabelText, getByText, queryByText } = render(
|
|
144
|
+
<DxcTextarea
|
|
145
|
+
label="Example label"
|
|
146
|
+
placeholder="Placeholder"
|
|
147
|
+
onChange={onChange}
|
|
148
|
+
onBlur={onBlur}
|
|
149
|
+
margin={{ left: "medium", right: "medium" }}
|
|
150
|
+
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
151
|
+
length={{ min: 5, max: 10 }}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
154
|
+
const textarea = getByLabelText("Example label");
|
|
155
|
+
|
|
156
|
+
fireEvent.change(textarea, { target: { value: "test" } });
|
|
157
|
+
expect(onChange).toHaveBeenCalled();
|
|
158
|
+
expect(onChange).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
159
|
+
fireEvent.blur(textarea);
|
|
160
|
+
expect(onBlur).toHaveBeenCalled();
|
|
161
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Min length 5, max length 10." });
|
|
162
|
+
fireEvent.change(textarea, { target: { value: "tests" } });
|
|
163
|
+
expect(onChange).toHaveBeenCalled();
|
|
164
|
+
expect(onChange).toHaveBeenCalledWith({ value: "tests", error: "Please match the format requested." });
|
|
165
|
+
fireEvent.blur(textarea);
|
|
166
|
+
expect(onBlur).toHaveBeenCalled();
|
|
167
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "tests", error: "Please match the format requested." });
|
|
168
|
+
fireEvent.change(textarea, { target: { value: "tests4&" } });
|
|
169
|
+
expect(onChange).toHaveBeenCalled();
|
|
170
|
+
expect(onChange).toHaveBeenCalledWith({ value: "tests4&", error: null });
|
|
171
|
+
fireEvent.blur(textarea);
|
|
172
|
+
expect(onBlur).toHaveBeenCalled();
|
|
173
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "tests4&", error: null });
|
|
174
|
+
});
|
|
175
|
+
test("onBlur function is called correctly", () => {
|
|
176
|
+
const onBlur = jest.fn();
|
|
177
|
+
const { getByLabelText } = render(<DxcTextarea label="Example label" onBlur={onBlur} />);
|
|
178
|
+
const textarea = getByLabelText("Example label");
|
|
179
|
+
fireEvent.change(textarea, { target: { value: "Blur test" } });
|
|
180
|
+
fireEvent.blur(textarea);
|
|
181
|
+
expect(onBlur).toHaveBeenCalled();
|
|
182
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "Blur test", error: null });
|
|
183
|
+
});
|
|
184
|
+
test("onChange function is called correctly", () => {
|
|
185
|
+
const onChange = jest.fn();
|
|
186
|
+
const { getByLabelText } = render(<DxcTextarea label="Example label" value="Test value" onChange={onChange} />);
|
|
187
|
+
const textarea = getByLabelText("Example label");
|
|
188
|
+
fireEvent.change(textarea, { target: { value: "Controlled test" } });
|
|
189
|
+
expect(onChange).toHaveBeenCalled();
|
|
190
|
+
expect(onChange).toHaveBeenCalledWith({ value: "Controlled test", error: null });
|
|
191
|
+
expect(textarea.value).toBe("Test value");
|
|
192
|
+
});
|
|
193
|
+
});
|
package/test/ToggleGroup.test.js
CHANGED
|
@@ -23,7 +23,11 @@ const options = [
|
|
|
23
23
|
|
|
24
24
|
describe("Toggle group component tests", () => {
|
|
25
25
|
test("Toggle group renders with correct labels", () => {
|
|
26
|
-
const { getByText } = render(
|
|
26
|
+
const { getByText } = render(
|
|
27
|
+
<DxcToggleGroup label="Toggle group label" helperText="Toggle group helper text" options={options} />
|
|
28
|
+
);
|
|
29
|
+
expect(getByText("Toggle group label")).toBeTruthy();
|
|
30
|
+
expect(getByText("Toggle group helper text")).toBeTruthy();
|
|
27
31
|
expect(getByText("Amazon")).toBeTruthy();
|
|
28
32
|
expect(getByText("Ebay")).toBeTruthy();
|
|
29
33
|
expect(getByText("Apple")).toBeTruthy();
|
package/test/Upload.test.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { render, fireEvent, act, createEvent } from "@testing-library/react";
|
|
3
|
-
import
|
|
3
|
+
import V3DxcUpload from "../src/upload/Upload";
|
|
4
4
|
|
|
5
5
|
describe("Upload component tests", () => {
|
|
6
6
|
test("Upload renders with correct text", () => {
|
|
7
|
-
const { getByText } = render(<
|
|
7
|
+
const { getByText } = render(<V3DxcUpload margin="small"></V3DxcUpload>);
|
|
8
8
|
expect(getByText("There are no files to upload")).toBeTruthy();
|
|
9
9
|
expect(getByText("Drag and drop your files here or choose one from your computer")).toBeTruthy();
|
|
10
10
|
expect(getByText("CHOOSE FILES")).toBeTruthy();
|
|
@@ -12,7 +12,7 @@ describe("Upload component tests", () => {
|
|
|
12
12
|
|
|
13
13
|
test("Upload shows file information", () => {
|
|
14
14
|
const myfunction = jest.fn();
|
|
15
|
-
const { getByText } = render(<
|
|
15
|
+
const { getByText } = render(<V3DxcUpload margin="small"></V3DxcUpload>);
|
|
16
16
|
|
|
17
17
|
const dropZone = getByText("There are no files to upload");
|
|
18
18
|
const dropEvent = createEvent.drop(dropZone);
|
|
@@ -34,9 +34,9 @@ describe("Upload component tests", () => {
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test("Calls correct function callbackUpload", () => {
|
|
37
|
-
const onCallbackUpload = jest.fn(() => new Promise(resolve => setTimeout(resolve, 1000)));
|
|
37
|
+
const onCallbackUpload = jest.fn(() => new Promise((resolve) => setTimeout(resolve, 1000)));
|
|
38
38
|
const myfunction = jest.fn();
|
|
39
|
-
const { getByText } = render(<
|
|
39
|
+
const { getByText } = render(<V3DxcUpload margin="small" callbackUpload={onCallbackUpload}></V3DxcUpload>);
|
|
40
40
|
|
|
41
41
|
const dropZone = getByText("There are no files to upload");
|
|
42
42
|
const dropEvent = createEvent.drop(dropZone);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { render,
|
|
3
|
-
import
|
|
2
|
+
import { render, act } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import V3DxcSelect from "../src/V3Select/V3Select";
|
|
4
5
|
|
|
5
6
|
const optionsWithoutIcon = [
|
|
6
7
|
{
|
|
@@ -20,30 +21,55 @@ const optionsWithoutIcon = [
|
|
|
20
21
|
const optionsWithIcons = [
|
|
21
22
|
{
|
|
22
23
|
value: 1,
|
|
23
|
-
label: "
|
|
24
|
-
|
|
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
|
+
),
|
|
25
38
|
},
|
|
26
39
|
{
|
|
27
40
|
value: 2,
|
|
28
|
-
label: "
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
),
|
|
35
61
|
},
|
|
36
62
|
];
|
|
37
63
|
|
|
38
64
|
describe("Select component tests", () => {
|
|
39
65
|
test("Select renders with correct label", () => {
|
|
40
|
-
const { getByText } = render(<
|
|
66
|
+
const { getByText } = render(<V3DxcSelect label="test-select-label"></V3DxcSelect>);
|
|
41
67
|
expect(getByText("test-select-label")).toBeTruthy();
|
|
42
68
|
});
|
|
43
69
|
|
|
44
70
|
test("Select renders options when select is clicked", () => {
|
|
45
71
|
const { getByText, getByRole, queryByText } = render(
|
|
46
|
-
<
|
|
72
|
+
<V3DxcSelect label="test-select-name" options={optionsWithoutIcon}></V3DxcSelect>
|
|
47
73
|
);
|
|
48
74
|
//Before are not shown
|
|
49
75
|
expect(queryByText("Amazon")).toBeFalsy();
|
|
@@ -51,7 +77,7 @@ describe("Select component tests", () => {
|
|
|
51
77
|
expect(queryByText("Apple")).toBeFalsy();
|
|
52
78
|
const select = getByRole("button");
|
|
53
79
|
act(() => {
|
|
54
|
-
|
|
80
|
+
userEvent.click(select);
|
|
55
81
|
});
|
|
56
82
|
expect(getByText("Amazon")).toBeTruthy();
|
|
57
83
|
expect(getByText("Ebay")).toBeTruthy();
|
|
@@ -59,55 +85,53 @@ describe("Select component tests", () => {
|
|
|
59
85
|
});
|
|
60
86
|
|
|
61
87
|
test("Select renders options with icons before", () => {
|
|
62
|
-
const { getByRole,
|
|
63
|
-
<
|
|
88
|
+
const { getByRole, getByTestId } = render(
|
|
89
|
+
<V3DxcSelect label="test-select-name" options={optionsWithIcons}></V3DxcSelect>
|
|
64
90
|
);
|
|
65
91
|
const select = getByRole("button");
|
|
66
92
|
act(() => {
|
|
67
|
-
|
|
93
|
+
userEvent.click(select);
|
|
68
94
|
});
|
|
69
|
-
expect(
|
|
70
|
-
expect(
|
|
71
|
-
expect(getAllByRole("img")[2].getAttribute("src")).toEqual("/testIconLinkedin");
|
|
95
|
+
expect(getByTestId("image-1")).toBeTruthy();
|
|
96
|
+
expect(getByTestId("image-2")).toBeTruthy();
|
|
72
97
|
});
|
|
73
98
|
|
|
74
99
|
test("Select renders options with icons after", () => {
|
|
75
|
-
const { getByRole,
|
|
76
|
-
<
|
|
100
|
+
const { getByRole, getByTestId } = render(
|
|
101
|
+
<V3DxcSelect label="test-select-name" options={optionsWithIcons} iconPosition="after"></V3DxcSelect>
|
|
77
102
|
);
|
|
78
103
|
const select = getByRole("button");
|
|
79
104
|
act(() => {
|
|
80
|
-
|
|
105
|
+
userEvent.click(select);
|
|
81
106
|
});
|
|
82
|
-
expect(
|
|
83
|
-
expect(
|
|
84
|
-
expect(getAllByRole("img")[2].getAttribute("src")).toEqual("/testIconLinkedin");
|
|
107
|
+
expect(getByTestId("image-1")).toBeTruthy();
|
|
108
|
+
expect(getByTestId("image-2")).toBeTruthy();
|
|
85
109
|
});
|
|
86
110
|
|
|
87
111
|
test("Select renders with a default value", () => {
|
|
88
112
|
const { getByText } = render(
|
|
89
|
-
<
|
|
113
|
+
<V3DxcSelect label="test-select-name" options={optionsWithoutIcon} value={1}></V3DxcSelect>
|
|
90
114
|
);
|
|
91
115
|
expect(getByText("Amazon")).toBeTruthy();
|
|
92
116
|
});
|
|
93
117
|
|
|
94
118
|
test("Select renders with multiple default values", () => {
|
|
95
119
|
const { getByText } = render(
|
|
96
|
-
<
|
|
120
|
+
<V3DxcSelect label="test-select-name" options={optionsWithoutIcon} value={[1, 2]} multiple></V3DxcSelect>
|
|
97
121
|
);
|
|
98
122
|
expect(getByText("Amazon, Ebay")).toBeTruthy();
|
|
99
123
|
});
|
|
100
124
|
|
|
101
125
|
test("Disabled select is not clickable", () => {
|
|
102
126
|
const { getByText, queryByText } = render(
|
|
103
|
-
<
|
|
127
|
+
<V3DxcSelect label="test-select-name" options={optionsWithoutIcon} disabled></V3DxcSelect>
|
|
104
128
|
);
|
|
105
129
|
expect(queryByText("Amazon")).toBeFalsy();
|
|
106
130
|
expect(queryByText("Ebay")).toBeFalsy();
|
|
107
131
|
expect(queryByText("Apple")).toBeFalsy();
|
|
108
132
|
const select = getByText("test-select-name");
|
|
109
133
|
act(() => {
|
|
110
|
-
|
|
134
|
+
userEvent.click(select);
|
|
111
135
|
});
|
|
112
136
|
expect(queryByText("Amazon")).toBeFalsy();
|
|
113
137
|
expect(queryByText("Ebay")).toBeFalsy();
|
|
@@ -117,15 +141,15 @@ describe("Select component tests", () => {
|
|
|
117
141
|
test("Controlled select with unique value", () => {
|
|
118
142
|
const onChange = jest.fn();
|
|
119
143
|
const { getByText, getAllByText } = render(
|
|
120
|
-
<
|
|
144
|
+
<V3DxcSelect label="test-select-name" options={optionsWithoutIcon} value={1} onChange={onChange}></V3DxcSelect>
|
|
121
145
|
);
|
|
122
146
|
const select = getByText("Amazon");
|
|
123
147
|
act(() => {
|
|
124
|
-
|
|
148
|
+
userEvent.click(select);
|
|
125
149
|
});
|
|
126
150
|
const option2 = getByText("Ebay");
|
|
127
151
|
act(() => {
|
|
128
|
-
|
|
152
|
+
userEvent.click(option2);
|
|
129
153
|
});
|
|
130
154
|
expect(onChange).toHaveBeenCalledWith(2);
|
|
131
155
|
//The value is not changed
|
|
@@ -135,21 +159,21 @@ describe("Select component tests", () => {
|
|
|
135
159
|
test("Controlled select with multiple values", () => {
|
|
136
160
|
const onChange = jest.fn();
|
|
137
161
|
const { getByText } = render(
|
|
138
|
-
<
|
|
162
|
+
<V3DxcSelect
|
|
139
163
|
label="test-select-name"
|
|
140
164
|
options={optionsWithoutIcon}
|
|
141
165
|
value={[1, 2]}
|
|
142
166
|
multiple
|
|
143
167
|
onChange={onChange}
|
|
144
|
-
></
|
|
168
|
+
></V3DxcSelect>
|
|
145
169
|
);
|
|
146
170
|
const select = getByText("Amazon, Ebay");
|
|
147
171
|
act(() => {
|
|
148
|
-
|
|
172
|
+
userEvent.click(select);
|
|
149
173
|
});
|
|
150
174
|
const option3 = getByText("Apple");
|
|
151
175
|
act(() => {
|
|
152
|
-
|
|
176
|
+
userEvent.click(option3);
|
|
153
177
|
});
|
|
154
178
|
expect(onChange).toHaveBeenCalledWith([1, 2, 3]);
|
|
155
179
|
//The value is not changed
|
|
@@ -159,31 +183,28 @@ describe("Select component tests", () => {
|
|
|
159
183
|
test("Uncontrolled select with multiple values", () => {
|
|
160
184
|
const onChange = jest.fn();
|
|
161
185
|
const { getByText, getByRole } = render(
|
|
162
|
-
<
|
|
186
|
+
<V3DxcSelect label="test-select-name" options={optionsWithoutIcon} multiple onChange={onChange}></V3DxcSelect>
|
|
163
187
|
);
|
|
164
188
|
const select = getByRole("button");
|
|
165
189
|
act(() => {
|
|
166
|
-
|
|
190
|
+
userEvent.click(select);
|
|
167
191
|
});
|
|
168
|
-
const option1 = getByText("Amazon");
|
|
169
|
-
const option2 = getByText("Ebay");
|
|
170
|
-
const option3 = getByText("Apple");
|
|
171
192
|
act(() => {
|
|
172
|
-
|
|
193
|
+
userEvent.click(getByText("Amazon"));
|
|
173
194
|
});
|
|
174
195
|
expect(onChange).toHaveBeenCalledWith([1]);
|
|
175
196
|
act(() => {
|
|
176
|
-
|
|
197
|
+
userEvent.click(getByText("Ebay"));
|
|
177
198
|
});
|
|
178
199
|
expect(onChange).toHaveBeenCalledWith([1, 2]);
|
|
179
200
|
expect(getByText("Amazon, Ebay")).toBeTruthy();
|
|
180
201
|
act(() => {
|
|
181
|
-
|
|
202
|
+
userEvent.click(getByText("Apple"));
|
|
182
203
|
});
|
|
183
204
|
expect(onChange).toHaveBeenCalledWith([1, 2, 3]);
|
|
184
205
|
expect(getByText("Amazon, Ebay, Apple")).toBeTruthy();
|
|
185
206
|
act(() => {
|
|
186
|
-
|
|
207
|
+
userEvent.click(getByText("Amazon"));
|
|
187
208
|
});
|
|
188
209
|
expect(onChange).toHaveBeenCalledWith([2, 3]);
|
|
189
210
|
expect(getByText("Ebay, Apple")).toBeTruthy();
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
-
import
|
|
3
|
+
import V3DxcTextarea from "../src/V3Textarea/V3Textarea";
|
|
4
4
|
|
|
5
5
|
describe("TextArea component tests", () => {
|
|
6
6
|
test("TextArea renders with correct text", () => {
|
|
7
|
-
const { getByText } = render(<
|
|
7
|
+
const { getByText } = render(<V3DxcTextarea label="TextArea label" />);
|
|
8
8
|
expect(getByText("TextArea label")).toBeTruthy();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
test("onChange function is called correctly", () => {
|
|
12
12
|
const onChange = jest.fn();
|
|
13
13
|
|
|
14
|
-
const { getByRole } = render(<
|
|
14
|
+
const { getByRole } = render(<V3DxcTextarea label="TextArea label" onChange={onChange} />);
|
|
15
15
|
const input = getByRole("textbox");
|
|
16
16
|
fireEvent.change(input, { target: { value: "Testing..." } });
|
|
17
17
|
expect(onChange).toHaveBeenCalled();
|
|
@@ -21,7 +21,7 @@ describe("TextArea component tests", () => {
|
|
|
21
21
|
test("onBlur function is called correctly", () => {
|
|
22
22
|
const onBlur = jest.fn();
|
|
23
23
|
|
|
24
|
-
const { getByRole } = render(<
|
|
24
|
+
const { getByRole } = render(<V3DxcTextarea label="TextArea label" onBlur={onBlur} />);
|
|
25
25
|
const input = getByRole("textbox");
|
|
26
26
|
fireEvent.change(input, { target: { value: "Testing..." } });
|
|
27
27
|
fireEvent.blur(input);
|
|
@@ -31,7 +31,7 @@ describe("TextArea component tests", () => {
|
|
|
31
31
|
|
|
32
32
|
test("Controlled component", () => {
|
|
33
33
|
const onChange = jest.fn();
|
|
34
|
-
const { getByRole } = render(<
|
|
34
|
+
const { getByRole } = render(<V3DxcTextarea label="TextArea label" value="TextArea Value" onChange={onChange} />);
|
|
35
35
|
const input = getByRole("textbox");
|
|
36
36
|
fireEvent.change(input, { target: { value: "Tests" } });
|
|
37
37
|
expect(onChange).toHaveBeenCalled();
|
|
@@ -41,12 +41,11 @@ describe("TextArea component tests", () => {
|
|
|
41
41
|
|
|
42
42
|
test("Uncontrolled component", () => {
|
|
43
43
|
const onChange = jest.fn();
|
|
44
|
-
const { getByRole } = render(<
|
|
44
|
+
const { getByRole } = render(<V3DxcTextarea label="TextArea label" onChange={onChange} />);
|
|
45
45
|
const input = getByRole("textbox");
|
|
46
46
|
fireEvent.change(input, { target: { value: "Tests" } });
|
|
47
47
|
expect(onChange).toHaveBeenCalled();
|
|
48
48
|
expect(onChange).toHaveBeenCalledWith("Tests");
|
|
49
49
|
expect(input.value).toBe("Tests");
|
|
50
50
|
});
|
|
51
|
-
|
|
52
51
|
});
|