@dxc-technology/halstack-react 3.4.1 → 4.0.0
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/BackgroundColorContext.js → BackgroundColorContext.js} +0 -0
- package/{dist/ThemeContext.js → ThemeContext.js} +74 -64
- package/{dist/select/Select.js → V3Select/V3Select.js} +127 -163
- package/V3Select/index.d.ts +27 -0
- package/{dist/textarea/Textarea.js → V3Textarea/V3Textarea.js} +4 -4
- package/V3Textarea/index.d.ts +27 -0
- package/{dist/accordion → accordion}/Accordion.js +0 -0
- package/accordion/index.d.ts +28 -0
- package/{dist/accordion-group → accordion-group}/AccordionGroup.js +0 -0
- package/accordion-group/index.d.ts +16 -0
- package/{dist/alert → alert}/Alert.js +6 -6
- package/alert/index.d.ts +51 -0
- package/{dist/badge → badge}/Badge.js +0 -0
- package/{dist/box → box}/Box.js +0 -0
- package/box/index.d.ts +25 -0
- package/{dist/button → button}/Button.js +3 -3
- package/button/Button.stories.js +27 -0
- package/button/index.d.ts +24 -0
- package/{dist/card → card}/Card.js +0 -0
- package/card/index.d.ts +22 -0
- package/{dist/checkbox → checkbox}/Checkbox.js +4 -5
- package/checkbox/index.d.ts +24 -0
- package/{dist/chip → chip}/Chip.js +0 -0
- package/chip/index.d.ts +22 -0
- package/{dist/common → common}/OpenSans.css +0 -0
- package/{dist/common → common}/RequiredComponent.js +0 -0
- package/{dist/common → common}/fonts/OpenSans-Bold.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-BoldItalic.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-ExtraBold.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-Italic.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-Light.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-LightItalic.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-Regular.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-SemiBold.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
- package/{dist/common → common}/utils.js +0 -0
- package/{dist/common → common}/variables.js +344 -138
- package/{dist/date → date}/Date.js +4 -6
- package/date/index.d.ts +27 -0
- package/{dist/new-date/NewDate.js → date-input/DateInput.js} +69 -72
- package/date-input/index.d.ts +95 -0
- package/{dist/dialog → dialog}/Dialog.js +0 -0
- package/dialog/index.d.ts +18 -0
- package/{dist/dropdown → dropdown}/Dropdown.js +0 -0
- package/dropdown/index.d.ts +26 -0
- package/file-input/FileInput.js +644 -0
- package/file-input/FileItem.js +287 -0
- package/file-input/index.d.ts +81 -0
- package/{dist/footer → footer}/Footer.js +44 -18
- package/footer/Icons.js +77 -0
- package/footer/index.d.ts +25 -0
- package/{dist/header → header}/Header.js +122 -55
- package/header/Icons.js +59 -0
- package/header/index.d.ts +25 -0
- package/{dist/heading → heading}/Heading.js +12 -0
- package/heading/index.d.ts +17 -0
- package/input-text/Icons.js +22 -0
- package/{dist/input-text → input-text}/InputText.js +7 -9
- package/input-text/index.d.ts +36 -0
- package/{dist/layout → layout}/ApplicationLayout.js +5 -9
- package/layout/Icons.js +55 -0
- package/{dist/link → link}/Link.js +4 -8
- package/link/index.d.ts +23 -0
- package/main.d.ts +40 -0
- package/{dist/main.js → main.js} +37 -29
- package/{dist/number/Number.js → number-input/NumberInput.js} +9 -11
- package/{dist/number/NumberContext.js → number-input/NumberInputContext.js} +2 -2
- package/number-input/index.d.ts +113 -0
- package/package.json +21 -16
- package/paginator/Icons.js +66 -0
- package/{dist/paginator → paginator}/Paginator.js +53 -37
- package/paginator/index.d.ts +20 -0
- package/{dist/password/Password.js → password-input/PasswordInput.js} +17 -14
- package/password-input/index.d.ts +94 -0
- package/{dist/progress-bar → progress-bar}/ProgressBar.js +1 -1
- package/progress-bar/index.d.ts +18 -0
- package/{dist/radio → radio}/Radio.js +0 -0
- package/radio/index.d.ts +23 -0
- package/{dist/resultsetTable → resultsetTable}/ResultsetTable.js +1 -1
- package/resultsetTable/index.d.ts +19 -0
- package/select/Select.js +1138 -0
- package/select/index.d.ts +131 -0
- package/{dist/sidenav → sidenav}/Sidenav.js +6 -4
- package/sidenav/index.d.ts +13 -0
- package/{dist/slider → slider}/Slider.js +104 -19
- package/slider/index.d.ts +29 -0
- package/{dist/spinner → spinner}/Spinner.js +0 -0
- package/spinner/index.d.ts +17 -0
- package/{dist/switch → switch}/Switch.js +0 -0
- package/switch/index.d.ts +24 -0
- package/{dist/table → table}/Table.js +0 -0
- package/table/index.d.ts +13 -0
- package/{dist/tabs → tabs}/Tabs.js +0 -0
- package/tabs/index.d.ts +19 -0
- package/{dist/tag → tag}/Tag.js +26 -32
- package/tag/index.d.ts +24 -0
- package/{dist/new-input-text/NewInputText.js → text-input/TextInput.js} +343 -312
- package/text-input/index.d.ts +135 -0
- package/{dist/new-textarea/NewTextarea.js → textarea/Textarea.js} +68 -45
- package/textarea/index.d.ts +117 -0
- package/{dist/toggle → toggle}/Toggle.js +0 -0
- package/toggle/index.d.ts +21 -0
- package/{dist/toggle-group → toggle-group}/ToggleGroup.js +132 -28
- package/toggle-group/index.d.ts +21 -0
- package/{dist/upload → upload}/Upload.js +0 -0
- package/{dist/upload → upload}/buttons-upload/ButtonsUpload.js +7 -11
- package/upload/buttons-upload/Icons.js +40 -0
- package/{dist/upload → upload}/dragAndDropArea/DragAndDropArea.js +14 -14
- package/upload/dragAndDropArea/Icons.js +39 -0
- package/{dist/upload → upload}/file-upload/FileToUpload.js +26 -21
- package/upload/file-upload/Icons.js +66 -0
- package/{dist/upload → upload}/files-upload/FilesToUpload.js +0 -0
- package/upload/index.d.ts +15 -0
- package/upload/transaction/Icons.js +160 -0
- package/{dist/upload → upload}/transaction/Transaction.js +11 -38
- package/{dist/upload → upload}/transactions/Transactions.js +0 -0
- package/{dist/useTheme.js → useTheme.js} +0 -0
- package/wizard/Icons.js +65 -0
- package/{dist/wizard → wizard}/Wizard.js +3 -9
- package/wizard/index.d.ts +18 -0
- package/README.md +0 -66
- package/babel.config.js +0 -8
- package/dist/checkbox/Checkbox.stories.js +0 -144
- package/dist/checkbox/readme.md +0 -116
- package/dist/date/Date.stories.js +0 -205
- package/dist/date/readme.md +0 -73
- package/dist/footer/Footer.stories.js +0 -94
- package/dist/footer/dxc_logo.svg +0 -15
- 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.svg +0 -8
- 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/password/styles.css +0 -3
- 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/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 -5
- package/dist/wizard/valid_icon.svg +0 -5
- package/dist/wizard/validation-wrong.svg +0 -6
- package/test/Accordion.test.js +0 -33
- package/test/AccordionGroup.test.js +0 -125
- package/test/Alert.test.js +0 -53
- package/test/Box.test.js +0 -10
- package/test/Button.test.js +0 -18
- package/test/Card.test.js +0 -30
- package/test/Checkbox.test.js +0 -45
- package/test/Chip.test.js +0 -25
- package/test/Date.test.js +0 -393
- package/test/Dialog.test.js +0 -23
- package/test/Dropdown.test.js +0 -145
- package/test/Footer.test.js +0 -99
- package/test/Header.test.js +0 -39
- package/test/Heading.test.js +0 -35
- package/test/InputText.test.js +0 -240
- package/test/Link.test.js +0 -43
- package/test/NewDate.test.js +0 -203
- package/test/NewInputText.test.js +0 -817
- package/test/NewTextarea.test.js +0 -201
- package/test/Number.test.js +0 -241
- package/test/Paginator.test.js +0 -177
- package/test/Password.test.js +0 -76
- package/test/ProgressBar.test.js +0 -35
- package/test/Radio.test.js +0 -37
- package/test/ResultsetTable.test.js +0 -330
- package/test/Select.test.js +0 -189
- package/test/Sidenav.test.js +0 -45
- package/test/Slider.test.js +0 -82
- package/test/Spinner.test.js +0 -32
- package/test/Switch.test.js +0 -45
- package/test/Table.test.js +0 -36
- package/test/Tabs.test.js +0 -109
- package/test/TabsForSections.test.js +0 -34
- package/test/Tag.test.js +0 -32
- package/test/TextArea.test.js +0 -52
- package/test/ToggleGroup.test.js +0 -81
- package/test/Upload.test.js +0 -60
- package/test/Wizard.test.js +0 -130
- package/test/mocks/pngMock.js +0 -1
- package/test/mocks/svgMock.js +0 -1
|
@@ -1,817 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { render, fireEvent, waitForElementToBeRemoved } from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
4
|
-
|
|
5
|
-
import DxcNewInputText from "../src/new-input-text/NewInputText";
|
|
6
|
-
|
|
7
|
-
const countries = [
|
|
8
|
-
"Afghanistan",
|
|
9
|
-
"Albania",
|
|
10
|
-
"Algeria",
|
|
11
|
-
"Andorra",
|
|
12
|
-
"Angola",
|
|
13
|
-
"Antigua and Barbuda",
|
|
14
|
-
"Bahamas",
|
|
15
|
-
"Bahrain",
|
|
16
|
-
"Bangladesh",
|
|
17
|
-
"Barbados",
|
|
18
|
-
"Cabo Verde",
|
|
19
|
-
"Cambodia",
|
|
20
|
-
"Cameroon",
|
|
21
|
-
"Canada",
|
|
22
|
-
"Cayman Islands, The",
|
|
23
|
-
"Central African Republic",
|
|
24
|
-
"Chad",
|
|
25
|
-
"Democratic Republic of the Congo",
|
|
26
|
-
"Dominican Republic",
|
|
27
|
-
"Dominica",
|
|
28
|
-
"Denmark",
|
|
29
|
-
"Djibouti",
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
describe("NewInputText component tests", () => {
|
|
33
|
-
test("Renders with correct label", () => {
|
|
34
|
-
const { getByText } = render(<DxcNewInputText label="Example label" />);
|
|
35
|
-
expect(getByText("Example label")).toBeTruthy();
|
|
36
|
-
});
|
|
37
|
-
test("Renders with correct label and helper text", () => {
|
|
38
|
-
const { getByText } = render(<DxcNewInputText label="Example label" helperText="Example helper text" />);
|
|
39
|
-
expect(getByText("Example label")).toBeTruthy();
|
|
40
|
-
expect(getByText("Example helper text")).toBeTruthy();
|
|
41
|
-
});
|
|
42
|
-
test("Renders with correct label and optional", () => {
|
|
43
|
-
const { getByText } = render(<DxcNewInputText label="Example label" helperText="Example helper text" optional />);
|
|
44
|
-
expect(getByText("Example label")).toBeTruthy();
|
|
45
|
-
expect(getByText("(Optional)")).toBeTruthy();
|
|
46
|
-
expect(getByText("Example helper text")).toBeTruthy();
|
|
47
|
-
});
|
|
48
|
-
test("Renders with correct placeholder", () => {
|
|
49
|
-
const { getByRole } = render(<DxcNewInputText label="Example label" placeholder="Placeholder" />);
|
|
50
|
-
const input = getByRole("textbox");
|
|
51
|
-
expect(input.getAttribute("placeholder")).toBe("Placeholder");
|
|
52
|
-
});
|
|
53
|
-
test("Renders with error message", () => {
|
|
54
|
-
const { getByText } = render(
|
|
55
|
-
<DxcNewInputText label="Error label" placeholder="Placeholder" error="Error message." />
|
|
56
|
-
);
|
|
57
|
-
expect(getByText("Error message.")).toBeTruthy();
|
|
58
|
-
});
|
|
59
|
-
test("Input Strict - Pattern constraint", () => {
|
|
60
|
-
const onChange = jest.fn();
|
|
61
|
-
const onBlur = jest.fn();
|
|
62
|
-
const { getByRole, getByText, queryByText } = render(
|
|
63
|
-
<DxcNewInputText
|
|
64
|
-
label="Input label"
|
|
65
|
-
placeholder="Placeholder"
|
|
66
|
-
onChange={onChange}
|
|
67
|
-
onBlur={onBlur}
|
|
68
|
-
margin={{ left: "medium", right: "medium" }}
|
|
69
|
-
clearable
|
|
70
|
-
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
71
|
-
/>
|
|
72
|
-
);
|
|
73
|
-
const input = getByRole("textbox");
|
|
74
|
-
userEvent.type(input, "pattern test");
|
|
75
|
-
fireEvent.blur(input);
|
|
76
|
-
expect(getByText("Please match the format requested.")).toBeTruthy();
|
|
77
|
-
userEvent.type(input, "pattern4&");
|
|
78
|
-
fireEvent.blur(input);
|
|
79
|
-
expect(queryByText("Please match the format requested.")).toBeFalsy();
|
|
80
|
-
});
|
|
81
|
-
test("Input Strict - Length constraint", () => {
|
|
82
|
-
const onChange = jest.fn();
|
|
83
|
-
const onBlur = jest.fn();
|
|
84
|
-
const { getByRole, getByText, queryByText } = render(
|
|
85
|
-
<DxcNewInputText
|
|
86
|
-
label="Input label"
|
|
87
|
-
placeholder="Placeholder"
|
|
88
|
-
onChange={onChange}
|
|
89
|
-
onBlur={onBlur}
|
|
90
|
-
margin={{ left: "medium", right: "medium" }}
|
|
91
|
-
clearable
|
|
92
|
-
length={{ min: 5, max: 10 }}
|
|
93
|
-
/>
|
|
94
|
-
);
|
|
95
|
-
const input = getByRole("textbox");
|
|
96
|
-
userEvent.type(input, "test");
|
|
97
|
-
fireEvent.blur(input);
|
|
98
|
-
expect(getByText("Min length 5, max length 10.")).toBeTruthy();
|
|
99
|
-
userEvent.type(input, "test ");
|
|
100
|
-
fireEvent.blur(input);
|
|
101
|
-
expect(queryByText(/Min length /)).toBeFalsy();
|
|
102
|
-
});
|
|
103
|
-
test("Input Strict - Pattern and length constraints", () => {
|
|
104
|
-
const onChange = jest.fn();
|
|
105
|
-
const onBlur = jest.fn();
|
|
106
|
-
const { getByRole, getByText, queryByText } = render(
|
|
107
|
-
<DxcNewInputText
|
|
108
|
-
label="Input label"
|
|
109
|
-
placeholder="Placeholder"
|
|
110
|
-
onChange={onChange}
|
|
111
|
-
onBlur={onBlur}
|
|
112
|
-
margin={{ left: "medium", right: "medium" }}
|
|
113
|
-
clearable
|
|
114
|
-
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
115
|
-
length={{ min: 5, max: 10 }}
|
|
116
|
-
/>
|
|
117
|
-
);
|
|
118
|
-
const input = getByRole("textbox");
|
|
119
|
-
userEvent.type(input, "test");
|
|
120
|
-
fireEvent.blur(input);
|
|
121
|
-
expect(getByText("Min length 5, max length 10.")).toBeTruthy();
|
|
122
|
-
userEvent.type(input, "test ");
|
|
123
|
-
fireEvent.blur(input);
|
|
124
|
-
expect(getByText("Please match the format requested.")).toBeTruthy();
|
|
125
|
-
userEvent.type(input, "test 4");
|
|
126
|
-
fireEvent.blur(input);
|
|
127
|
-
expect(queryByText("Please match the format requested.")).toBeFalsy();
|
|
128
|
-
});
|
|
129
|
-
test("Input Non Strict - Pattern constraint", () => {
|
|
130
|
-
const onChange = jest.fn((value) => {
|
|
131
|
-
expect(value).toBe("t");
|
|
132
|
-
});
|
|
133
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
134
|
-
expect(value).toBe("t");
|
|
135
|
-
expect(error).toBe("Please match the format requested.");
|
|
136
|
-
});
|
|
137
|
-
const { getByRole } = render(
|
|
138
|
-
<DxcNewInputText
|
|
139
|
-
label="Input label"
|
|
140
|
-
placeholder="Placeholder"
|
|
141
|
-
onChange={onChange}
|
|
142
|
-
onBlur={onBlur}
|
|
143
|
-
margin={{ left: "medium", right: "medium" }}
|
|
144
|
-
clearable
|
|
145
|
-
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
146
|
-
/>
|
|
147
|
-
);
|
|
148
|
-
const input = getByRole("textbox");
|
|
149
|
-
userEvent.type(input, "t");
|
|
150
|
-
fireEvent.blur(input);
|
|
151
|
-
});
|
|
152
|
-
test("Input Non Strict - Length constraint", () => {
|
|
153
|
-
const onChange = jest.fn((value) => {
|
|
154
|
-
expect(value).toBe("t");
|
|
155
|
-
});
|
|
156
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
157
|
-
expect(value).toBe("t");
|
|
158
|
-
expect(error).toBe("Min length 5, max length 10.");
|
|
159
|
-
});
|
|
160
|
-
const { getByRole } = render(
|
|
161
|
-
<DxcNewInputText
|
|
162
|
-
label="Input label"
|
|
163
|
-
placeholder="Placeholder"
|
|
164
|
-
onChange={onChange}
|
|
165
|
-
onBlur={onBlur}
|
|
166
|
-
margin={{ left: "medium", right: "medium" }}
|
|
167
|
-
clearable
|
|
168
|
-
length={{ min: 5, max: 10 }}
|
|
169
|
-
/>
|
|
170
|
-
);
|
|
171
|
-
const input = getByRole("textbox");
|
|
172
|
-
userEvent.type(input, "t");
|
|
173
|
-
fireEvent.blur(input);
|
|
174
|
-
});
|
|
175
|
-
test("Input Non Strict - Pattern and length constraints", () => {
|
|
176
|
-
const onChange = jest.fn((value) => {
|
|
177
|
-
expect(value).toBe("t");
|
|
178
|
-
});
|
|
179
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
180
|
-
expect(value).toBe("t");
|
|
181
|
-
expect(error).toBe("Min length 5, max length 10.");
|
|
182
|
-
});
|
|
183
|
-
const { getByRole } = render(
|
|
184
|
-
<DxcNewInputText
|
|
185
|
-
label="Input label"
|
|
186
|
-
placeholder="Placeholder"
|
|
187
|
-
onChange={onChange}
|
|
188
|
-
onBlur={onBlur}
|
|
189
|
-
margin={{ left: "medium", right: "medium" }}
|
|
190
|
-
clearable
|
|
191
|
-
length={{ min: 5, max: 10 }}
|
|
192
|
-
/>
|
|
193
|
-
);
|
|
194
|
-
const input = getByRole("textbox");
|
|
195
|
-
userEvent.type(input, "t");
|
|
196
|
-
fireEvent.blur(input);
|
|
197
|
-
});
|
|
198
|
-
test("onChange function is called correctly", () => {
|
|
199
|
-
const onChange = jest.fn();
|
|
200
|
-
const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} />);
|
|
201
|
-
const input = getByRole("textbox");
|
|
202
|
-
userEvent.type(input, "onchange event test");
|
|
203
|
-
expect(input.value).toBe("onchange event test");
|
|
204
|
-
expect(onChange).toHaveBeenCalled();
|
|
205
|
-
expect(onChange).toHaveBeenCalledWith("onchange event test");
|
|
206
|
-
});
|
|
207
|
-
test("onBlur function is called correctly", () => {
|
|
208
|
-
const onBlur = jest.fn();
|
|
209
|
-
const onChange = jest.fn();
|
|
210
|
-
const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} onBlur={onBlur} />);
|
|
211
|
-
const input = getByRole("textbox");
|
|
212
|
-
userEvent.type(input, "Test string");
|
|
213
|
-
fireEvent.blur(input);
|
|
214
|
-
expect(onBlur).toHaveBeenCalled();
|
|
215
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "Test string", error: null });
|
|
216
|
-
});
|
|
217
|
-
test("Uncontrolled input", () => {
|
|
218
|
-
const onChange = jest.fn();
|
|
219
|
-
const { getByRole } = render(<DxcNewInputText label="Input label" onChange={onChange} />);
|
|
220
|
-
const input = getByRole("textbox");
|
|
221
|
-
userEvent.type(input, "Uncontrolled test");
|
|
222
|
-
expect(onChange).toHaveBeenCalled();
|
|
223
|
-
expect(onChange).toHaveBeenCalledWith("Uncontrolled test");
|
|
224
|
-
expect(input.value).toBe("Uncontrolled test");
|
|
225
|
-
});
|
|
226
|
-
test("Controlled input", () => {
|
|
227
|
-
const onChange = jest.fn();
|
|
228
|
-
const onBlur = jest.fn();
|
|
229
|
-
const { getByRole } = render(
|
|
230
|
-
<DxcNewInputText label="Input label" value="Test value" onChange={onChange} onBlur={onBlur} />
|
|
231
|
-
);
|
|
232
|
-
const input = getByRole("textbox");
|
|
233
|
-
userEvent.type(input, "Example text");
|
|
234
|
-
expect(onChange).toHaveBeenCalled();
|
|
235
|
-
expect(input.value).toBe("Test value");
|
|
236
|
-
fireEvent.blur(input);
|
|
237
|
-
expect(onBlur).toHaveBeenCalled();
|
|
238
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "Test value", error: null });
|
|
239
|
-
});
|
|
240
|
-
test("Clear action onClick cleans the input", () => {
|
|
241
|
-
const { getByRole } = render(<DxcNewInputText label="Input label" clearable />);
|
|
242
|
-
const input = getByRole("textbox");
|
|
243
|
-
userEvent.type(input, "Test");
|
|
244
|
-
const closeAction = getByRole("button");
|
|
245
|
-
userEvent.click(closeAction);
|
|
246
|
-
expect(input.value).toBe("");
|
|
247
|
-
});
|
|
248
|
-
test("Disabled input (action must be shown but not clickable)", () => {
|
|
249
|
-
const onClick = jest.fn();
|
|
250
|
-
const action = {
|
|
251
|
-
onClick: onClick,
|
|
252
|
-
icon: (
|
|
253
|
-
<svg
|
|
254
|
-
data-testid="image"
|
|
255
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
256
|
-
height="24px"
|
|
257
|
-
viewBox="0 0 24 24"
|
|
258
|
-
width="24px"
|
|
259
|
-
fill="currentColor"
|
|
260
|
-
>
|
|
261
|
-
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
262
|
-
<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" />
|
|
263
|
-
</svg>
|
|
264
|
-
),
|
|
265
|
-
};
|
|
266
|
-
const { getByRole } = render(<DxcNewInputText label="Disabled input label" action={action} disabled />);
|
|
267
|
-
const input = getByRole("textbox");
|
|
268
|
-
expect(input.disabled).toBeTruthy();
|
|
269
|
-
userEvent.click(getByRole("button"));
|
|
270
|
-
expect(onClick).not.toHaveBeenCalled();
|
|
271
|
-
});
|
|
272
|
-
test("Disabled input (clear default action should not be displayed, even with text written on the input)", () => {
|
|
273
|
-
const { getByRole, queryByRole } = render(
|
|
274
|
-
<DxcNewInputText label="Disabled input label" value="Sample text" disabled clearable />
|
|
275
|
-
);
|
|
276
|
-
const input = getByRole("textbox");
|
|
277
|
-
expect(input.disabled).toBeTruthy();
|
|
278
|
-
expect(queryByRole("button")).toBeFalsy();
|
|
279
|
-
});
|
|
280
|
-
test("Disabled input (suffix and preffix must be displayed)", () => {
|
|
281
|
-
const { getByRole, getByText } = render(
|
|
282
|
-
<DxcNewInputText label="Disabled input label" value="Sample text" prefix="+34" suffix="USD" disabled />
|
|
283
|
-
);
|
|
284
|
-
const input = getByRole("textbox");
|
|
285
|
-
expect(input.disabled).toBeTruthy();
|
|
286
|
-
expect(getByText("+34")).toBeTruthy();
|
|
287
|
-
expect(getByText("USD")).toBeTruthy();
|
|
288
|
-
});
|
|
289
|
-
test("Action prop: image displayed and onClick event", () => {
|
|
290
|
-
const onClick = jest.fn();
|
|
291
|
-
const action = {
|
|
292
|
-
onClick: onClick,
|
|
293
|
-
icon: (
|
|
294
|
-
<svg
|
|
295
|
-
data-testid="image"
|
|
296
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
297
|
-
height="24px"
|
|
298
|
-
viewBox="0 0 24 24"
|
|
299
|
-
width="24px"
|
|
300
|
-
fill="currentColor"
|
|
301
|
-
>
|
|
302
|
-
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
303
|
-
<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" />
|
|
304
|
-
</svg>
|
|
305
|
-
),
|
|
306
|
-
};
|
|
307
|
-
const { getByRole, getByTestId } = render(<DxcNewInputText label="Input label" action={action} />);
|
|
308
|
-
expect(getByTestId("image")).toBeTruthy();
|
|
309
|
-
userEvent.click(getByRole("button"));
|
|
310
|
-
expect(onClick).toHaveBeenCalled();
|
|
311
|
-
});
|
|
312
|
-
test("Renders with correct prefix and suffix (text)", () => {
|
|
313
|
-
const { getByText } = render(<DxcNewInputText label="Input label" prefix="+34" suffix="USD" />);
|
|
314
|
-
expect(getByText("+34")).toBeTruthy();
|
|
315
|
-
expect(getByText("USD")).toBeTruthy();
|
|
316
|
-
});
|
|
317
|
-
test("Renders with correct prefix (icon)", () => {
|
|
318
|
-
const { getByTestId } = render(
|
|
319
|
-
<DxcNewInputText
|
|
320
|
-
label="Input label"
|
|
321
|
-
prefix={
|
|
322
|
-
<svg
|
|
323
|
-
data-testid="image"
|
|
324
|
-
version="1.1"
|
|
325
|
-
x="0px"
|
|
326
|
-
y="0px"
|
|
327
|
-
width="24px"
|
|
328
|
-
height="24px"
|
|
329
|
-
viewBox="0 0 24 24"
|
|
330
|
-
enable-background="new 0 0 24 24"
|
|
331
|
-
>
|
|
332
|
-
<g id="Bounding_Box">
|
|
333
|
-
<rect fill="none" width="24" height="24" />
|
|
334
|
-
</g>
|
|
335
|
-
<g id="Master">
|
|
336
|
-
<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" />
|
|
337
|
-
</g>
|
|
338
|
-
</svg>
|
|
339
|
-
}
|
|
340
|
-
/>
|
|
341
|
-
);
|
|
342
|
-
expect(getByTestId("image")).toBeTruthy();
|
|
343
|
-
});
|
|
344
|
-
test("Renders with correct suffix (icon)", () => {
|
|
345
|
-
const { getByTestId } = render(
|
|
346
|
-
<DxcNewInputText
|
|
347
|
-
label="Input label"
|
|
348
|
-
suffix={
|
|
349
|
-
<svg
|
|
350
|
-
data-testid="image"
|
|
351
|
-
version="1.1"
|
|
352
|
-
x="0px"
|
|
353
|
-
y="0px"
|
|
354
|
-
width="24px"
|
|
355
|
-
height="24px"
|
|
356
|
-
viewBox="0 0 24 24"
|
|
357
|
-
enable-background="new 0 0 24 24"
|
|
358
|
-
>
|
|
359
|
-
<g id="Bounding_Box">
|
|
360
|
-
<rect fill="none" width="24" height="24" />
|
|
361
|
-
</g>
|
|
362
|
-
<g id="Master">
|
|
363
|
-
<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" />
|
|
364
|
-
</g>
|
|
365
|
-
</svg>
|
|
366
|
-
}
|
|
367
|
-
/>
|
|
368
|
-
);
|
|
369
|
-
expect(getByTestId("image")).toBeTruthy();
|
|
370
|
-
});
|
|
371
|
-
test("Input has correct accesibility attributes", () => {
|
|
372
|
-
const onClick = jest.fn();
|
|
373
|
-
const action = {
|
|
374
|
-
onClick: onClick,
|
|
375
|
-
icon: (
|
|
376
|
-
<svg
|
|
377
|
-
data-testid="image"
|
|
378
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
379
|
-
height="24px"
|
|
380
|
-
viewBox="0 0 24 24"
|
|
381
|
-
width="24px"
|
|
382
|
-
fill="currentColor"
|
|
383
|
-
>
|
|
384
|
-
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
385
|
-
<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" />
|
|
386
|
-
</svg>
|
|
387
|
-
),
|
|
388
|
-
};
|
|
389
|
-
const { getByRole, getAllByRole } = render(
|
|
390
|
-
<DxcNewInputText label="Example label" clearable action={action} error="Error message." />
|
|
391
|
-
);
|
|
392
|
-
const input = getByRole("textbox");
|
|
393
|
-
expect(input.getAttribute("aria-autocomplete")).toBeNull();
|
|
394
|
-
expect(input.getAttribute("aria-controls")).toBeNull();
|
|
395
|
-
expect(input.getAttribute("aria-expanded")).toBeNull();
|
|
396
|
-
expect(input.getAttribute("aria-expanded")).toBeNull();
|
|
397
|
-
userEvent.type(input, "Text");
|
|
398
|
-
const clear = getAllByRole("button")[0];
|
|
399
|
-
expect(clear.getAttribute("aria-label")).toBe("Clear");
|
|
400
|
-
});
|
|
401
|
-
test("Autosuggest has correct accesibility attributes", () => {
|
|
402
|
-
const { getByRole, getAllByRole } = render(
|
|
403
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} />
|
|
404
|
-
);
|
|
405
|
-
const input = getByRole("combobox");
|
|
406
|
-
const inputId = input.id;
|
|
407
|
-
expect(input.getAttribute("aria-autocomplete")).toBe("list");
|
|
408
|
-
expect(input.getAttribute("aria-controls")).toBe(inputId);
|
|
409
|
-
expect(input.getAttribute("aria-expanded")).toBe("false");
|
|
410
|
-
fireEvent.focus(input);
|
|
411
|
-
const list = getByRole("listbox");
|
|
412
|
-
expect(list.getAttribute("aria-label")).toBe("Autocomplete Countries");
|
|
413
|
-
const options = getAllByRole("option");
|
|
414
|
-
expect(options[0].getAttribute("aria-selected")).toBe("false");
|
|
415
|
-
});
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
describe("NewInputText component synchronous autosuggest tests", () => {
|
|
419
|
-
test("Autosuggest is displayed when the input gains focus", async () => {
|
|
420
|
-
const onChange = jest.fn();
|
|
421
|
-
const { getByRole, getByText } = render(
|
|
422
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
423
|
-
);
|
|
424
|
-
const input = getByRole("combobox");
|
|
425
|
-
fireEvent.focus(input);
|
|
426
|
-
const list = getByRole("listbox");
|
|
427
|
-
expect(list).toBeTruthy();
|
|
428
|
-
expect(getByText("Afghanistan")).toBeTruthy();
|
|
429
|
-
expect(getByText("Albania")).toBeTruthy();
|
|
430
|
-
expect(getByText("Algeria")).toBeTruthy();
|
|
431
|
-
expect(getByText("Andorra")).toBeTruthy();
|
|
432
|
-
});
|
|
433
|
-
test("Autosuggest is displayed when the user clicks the input", async () => {
|
|
434
|
-
const onChange = jest.fn();
|
|
435
|
-
const { getByRole, getByText } = render(
|
|
436
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
437
|
-
);
|
|
438
|
-
const input = getByRole("combobox");
|
|
439
|
-
userEvent.click(input);
|
|
440
|
-
const list = getByRole("listbox");
|
|
441
|
-
expect(list).toBeTruthy();
|
|
442
|
-
expect(getByText("Afghanistan")).toBeTruthy();
|
|
443
|
-
expect(getByText("Albania")).toBeTruthy();
|
|
444
|
-
expect(getByText("Algeria")).toBeTruthy();
|
|
445
|
-
expect(getByText("Andorra")).toBeTruthy();
|
|
446
|
-
});
|
|
447
|
-
test("Autosuggest is displayed while the user is writing (if closed previously, if open stays open)", async () => {
|
|
448
|
-
const onChange = jest.fn();
|
|
449
|
-
const { getByRole, queryByRole, getByText, getAllByText } = render(
|
|
450
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
451
|
-
);
|
|
452
|
-
const input = getByRole("combobox");
|
|
453
|
-
fireEvent.focus(input);
|
|
454
|
-
const list = getByRole("listbox");
|
|
455
|
-
expect(list).toBeTruthy();
|
|
456
|
-
fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
457
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
458
|
-
userEvent.type(input, "B");
|
|
459
|
-
expect(list).toBeTruthy();
|
|
460
|
-
expect(getAllByText("B").length).toBe(4);
|
|
461
|
-
expect(getByText("ahamas")).toBeTruthy();
|
|
462
|
-
expect(getByText("ahrain")).toBeTruthy();
|
|
463
|
-
expect(getByText("angladesh")).toBeTruthy();
|
|
464
|
-
expect(getByText("arbados")).toBeTruthy();
|
|
465
|
-
});
|
|
466
|
-
test("Autosuggest is not displayed when prop suggestions is an empty array", async () => {
|
|
467
|
-
const onChange = jest.fn();
|
|
468
|
-
const { queryByRole } = render(
|
|
469
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={[]} onChange={onChange} />
|
|
470
|
-
);
|
|
471
|
-
const input = queryByRole("textbox");
|
|
472
|
-
fireEvent.focus(input);
|
|
473
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
474
|
-
});
|
|
475
|
-
test("Autosuggest shows 'No results found' message when there are no matches with the user's input", async () => {
|
|
476
|
-
const onChange = jest.fn();
|
|
477
|
-
const { getByRole, getByText } = render(
|
|
478
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
479
|
-
);
|
|
480
|
-
const input = getByRole("combobox");
|
|
481
|
-
fireEvent.focus(input);
|
|
482
|
-
const list = getByRole("listbox");
|
|
483
|
-
expect(list).toBeTruthy();
|
|
484
|
-
expect(getByText("Afghanistan")).toBeTruthy();
|
|
485
|
-
userEvent.type(input, "x");
|
|
486
|
-
expect(list).toBeTruthy();
|
|
487
|
-
expect(getByText("No results found")).toBeTruthy();
|
|
488
|
-
});
|
|
489
|
-
test("Autosuggest uncontrolled suggestion selected", async () => {
|
|
490
|
-
const onChange = jest.fn();
|
|
491
|
-
const { getByRole, getByText, queryByRole } = render(
|
|
492
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
493
|
-
);
|
|
494
|
-
const input = getByRole("combobox");
|
|
495
|
-
fireEvent.focus(input);
|
|
496
|
-
userEvent.type(input, "Alba");
|
|
497
|
-
expect(onChange).toHaveBeenCalled();
|
|
498
|
-
expect(getByText("Alba")).toBeTruthy();
|
|
499
|
-
expect(getByText("nia")).toBeTruthy();
|
|
500
|
-
fireEvent.mouseDown(getByRole("option"));
|
|
501
|
-
fireEvent.mouseUp(getByRole("option"));
|
|
502
|
-
expect(input.value).toBe("Albania");
|
|
503
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
504
|
-
});
|
|
505
|
-
test("Autosuggest controlled suggestions selected", async () => {
|
|
506
|
-
const onChange = jest.fn();
|
|
507
|
-
const { getByRole, getByText, queryByRole } = render(
|
|
508
|
-
<DxcNewInputText label="Autocomplete Countries" value="Andor" suggestions={countries} onChange={onChange} />
|
|
509
|
-
);
|
|
510
|
-
const input = getByRole("combobox");
|
|
511
|
-
fireEvent.focus(input);
|
|
512
|
-
expect(input.value).toBe("Andor");
|
|
513
|
-
expect(getByText("Andor")).toBeTruthy();
|
|
514
|
-
expect(getByText("ra")).toBeTruthy();
|
|
515
|
-
fireEvent.mouseDown(getByRole("option"));
|
|
516
|
-
fireEvent.mouseUp(getByRole("option"));
|
|
517
|
-
expect(onChange).toHaveBeenCalledWith("Andorra");
|
|
518
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
519
|
-
});
|
|
520
|
-
test("Autosuggest Strict - Pattern constraint", async () => {
|
|
521
|
-
const onChange = jest.fn();
|
|
522
|
-
const { getByRole, getByText, queryByText } = render(
|
|
523
|
-
<DxcNewInputText
|
|
524
|
-
label="Autocomplete Countries"
|
|
525
|
-
value="Andor"
|
|
526
|
-
suggestions={countries}
|
|
527
|
-
onChange={onChange}
|
|
528
|
-
pattern='^.*(?=.*[a-zA-Z])(?=.*\d)(?=.*[!&$%&? "]).*$'
|
|
529
|
-
/>
|
|
530
|
-
);
|
|
531
|
-
const input = getByRole("combobox");
|
|
532
|
-
fireEvent.focus(input);
|
|
533
|
-
userEvent.type(input, "Andor");
|
|
534
|
-
expect(getByText("Andor")).toBeTruthy();
|
|
535
|
-
expect(getByText("ra")).toBeTruthy();
|
|
536
|
-
fireEvent.mouseDown(getByRole("option"));
|
|
537
|
-
fireEvent.mouseUp(getByRole("option"));
|
|
538
|
-
expect(onChange).toHaveBeenCalledWith("Andorra");
|
|
539
|
-
fireEvent.blur(input);
|
|
540
|
-
expect(queryByText("Please match the format requested.")).toBeTruthy();
|
|
541
|
-
});
|
|
542
|
-
test("Autosuggest Strict - Length constraint", async () => {
|
|
543
|
-
const onChange = jest.fn();
|
|
544
|
-
const { getByRole, queryByText } = render(
|
|
545
|
-
<DxcNewInputText
|
|
546
|
-
label="Autocomplete Countries"
|
|
547
|
-
value="Cha"
|
|
548
|
-
suggestions={countries}
|
|
549
|
-
onChange={onChange}
|
|
550
|
-
length={{ min: 5, max: 10 }}
|
|
551
|
-
/>
|
|
552
|
-
);
|
|
553
|
-
const input = getByRole("combobox");
|
|
554
|
-
fireEvent.focus(input);
|
|
555
|
-
userEvent.type(input, "d");
|
|
556
|
-
const option = getByRole("option");
|
|
557
|
-
fireEvent.mouseDown(option);
|
|
558
|
-
fireEvent.mouseUp(option);
|
|
559
|
-
expect(onChange).toHaveBeenCalledWith("Chad");
|
|
560
|
-
fireEvent.blur(input);
|
|
561
|
-
expect(queryByText("Min length 5, max length 10.")).toBeTruthy();
|
|
562
|
-
});
|
|
563
|
-
test("Autosuggest keys: arrow down key opens autosuggest, active first option is selected with Enter and closes the autosuggest", async () => {
|
|
564
|
-
Element.prototype.scrollTo = () => {};
|
|
565
|
-
const onChange = jest.fn();
|
|
566
|
-
const { getByRole, queryByRole } = render(
|
|
567
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
568
|
-
);
|
|
569
|
-
const input = getByRole("combobox");
|
|
570
|
-
fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
571
|
-
const list = getByRole("listbox");
|
|
572
|
-
expect(list).toBeTruthy();
|
|
573
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
574
|
-
expect(input.value).toBe("Afghanistan");
|
|
575
|
-
expect(queryByRole("list")).toBeFalsy();
|
|
576
|
-
});
|
|
577
|
-
test("Autosuggest keys: arrow up key opens autosuggest, active last option is selected with Enter and closes the autosuggest", async () => {
|
|
578
|
-
Element.prototype.scrollTo = () => {};
|
|
579
|
-
const onChange = jest.fn();
|
|
580
|
-
const { getByRole, queryByRole } = render(
|
|
581
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
582
|
-
);
|
|
583
|
-
const input = getByRole("combobox");
|
|
584
|
-
fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
585
|
-
const list = getByRole("listbox");
|
|
586
|
-
expect(list).toBeTruthy();
|
|
587
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
588
|
-
expect(input.value).toBe("Djibouti");
|
|
589
|
-
expect(queryByRole("list")).toBeFalsy();
|
|
590
|
-
});
|
|
591
|
-
test("Autosuggest keys: Esc key closes the autosuggest and cleans the input", async () => {
|
|
592
|
-
Element.prototype.scrollTo = () => {};
|
|
593
|
-
const onChange = jest.fn();
|
|
594
|
-
const { getByRole, queryByRole } = render(
|
|
595
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
596
|
-
);
|
|
597
|
-
const input = getByRole("combobox");
|
|
598
|
-
fireEvent.focus(input);
|
|
599
|
-
userEvent.type(input, "Bangla");
|
|
600
|
-
const list = getByRole("listbox");
|
|
601
|
-
expect(list).toBeTruthy();
|
|
602
|
-
fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
603
|
-
expect(input.value).toBe("");
|
|
604
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
605
|
-
});
|
|
606
|
-
test("Autosuggest keys: Enter, if no active suggestion closes the autosuggest", async () => {
|
|
607
|
-
Element.prototype.scrollTo = () => {};
|
|
608
|
-
const onChange = jest.fn();
|
|
609
|
-
const { getByRole, queryByRole } = render(
|
|
610
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
611
|
-
);
|
|
612
|
-
const input = getByRole("combobox");
|
|
613
|
-
fireEvent.focus(input);
|
|
614
|
-
const list = getByRole("listbox");
|
|
615
|
-
expect(list).toBeTruthy();
|
|
616
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 27, charCode: 27 });
|
|
617
|
-
expect(input.value).toBe("");
|
|
618
|
-
expect(queryByRole("list")).toBeFalsy();
|
|
619
|
-
});
|
|
620
|
-
test("Autosuggest complex key secuence: write, arrow up two times, arrow down and select with Enter. Then, clean with Esc.", async () => {
|
|
621
|
-
Element.prototype.scrollTo = () => {};
|
|
622
|
-
const onChange = jest.fn();
|
|
623
|
-
const { getByRole, queryByRole } = render(
|
|
624
|
-
<DxcNewInputText label="Autocomplete Countries" suggestions={countries} onChange={onChange} />
|
|
625
|
-
);
|
|
626
|
-
const input = getByRole("combobox");
|
|
627
|
-
fireEvent.focus(input);
|
|
628
|
-
userEvent.type(input, "Ba");
|
|
629
|
-
fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
630
|
-
fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
631
|
-
fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
632
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
633
|
-
expect(input.value).toBe("Barbados");
|
|
634
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
635
|
-
fireEvent.keyDown(input, { key: "Esc", code: "Esp", keyCode: 27, charCode: 27 });
|
|
636
|
-
expect(input.value).toBe("");
|
|
637
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
638
|
-
});
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
describe("NewInputText component asynchronous autosuggest tests", () => {
|
|
642
|
-
test("Autosuggest 'Searching...' message is shown", async () => {
|
|
643
|
-
const callbackFunc = jest.fn((newValue) => {
|
|
644
|
-
const result = new Promise((resolve) =>
|
|
645
|
-
setTimeout(() => {
|
|
646
|
-
resolve(
|
|
647
|
-
newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
|
|
648
|
-
);
|
|
649
|
-
}, 1000)
|
|
650
|
-
);
|
|
651
|
-
return result;
|
|
652
|
-
});
|
|
653
|
-
const onChange = jest.fn();
|
|
654
|
-
const { getByRole, getByText } = render(
|
|
655
|
-
<DxcNewInputText label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
|
|
656
|
-
);
|
|
657
|
-
const input = getByRole("combobox");
|
|
658
|
-
fireEvent.focus(input);
|
|
659
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
660
|
-
await waitForElementToBeRemoved(() => getByText("Searching..."));
|
|
661
|
-
expect(getByText("Afghanistan")).toBeTruthy();
|
|
662
|
-
expect(getByText("Albania")).toBeTruthy();
|
|
663
|
-
expect(getByText("Algeria")).toBeTruthy();
|
|
664
|
-
expect(getByText("Andorra")).toBeTruthy();
|
|
665
|
-
userEvent.type(input, "Ab");
|
|
666
|
-
await waitForElementToBeRemoved(() => getByText("Searching..."));
|
|
667
|
-
expect(getByText("Cabo Verde")).toBeTruthy();
|
|
668
|
-
fireEvent.keyDown(input, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
669
|
-
fireEvent.keyDown(input, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
670
|
-
expect(input.value).toBe("Cabo Verde");
|
|
671
|
-
});
|
|
672
|
-
test("Autosuggest Esc key works while 'Searching...' message is shown", async () => {
|
|
673
|
-
const callbackFunc = jest.fn((newValue) => {
|
|
674
|
-
const result = new Promise((resolve) =>
|
|
675
|
-
setTimeout(() => {
|
|
676
|
-
resolve(
|
|
677
|
-
newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
|
|
678
|
-
);
|
|
679
|
-
}, 1000)
|
|
680
|
-
);
|
|
681
|
-
return result;
|
|
682
|
-
});
|
|
683
|
-
const onChange = jest.fn();
|
|
684
|
-
const { getByRole, queryByText, queryByRole } = render(
|
|
685
|
-
<DxcNewInputText label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
|
|
686
|
-
);
|
|
687
|
-
const input = getByRole("combobox");
|
|
688
|
-
fireEvent.focus(input);
|
|
689
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
690
|
-
userEvent.type(input, "Ab");
|
|
691
|
-
fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
692
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
693
|
-
expect(queryByText("Searching...")).toBeFalsy();
|
|
694
|
-
expect(input.value).toBe("");
|
|
695
|
-
});
|
|
696
|
-
test("Autosuggest Esc + arrow down working while 'Searching...' message is shown", async () => {
|
|
697
|
-
const callbackFunc = jest.fn((newValue) => {
|
|
698
|
-
const result = new Promise((resolve) =>
|
|
699
|
-
setTimeout(() => {
|
|
700
|
-
resolve(
|
|
701
|
-
newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
|
|
702
|
-
);
|
|
703
|
-
}, 1000)
|
|
704
|
-
);
|
|
705
|
-
return result;
|
|
706
|
-
});
|
|
707
|
-
const onChange = jest.fn();
|
|
708
|
-
const { getByRole, getByText, queryByText, queryByRole } = render(
|
|
709
|
-
<DxcNewInputText label="Autosuggest Countries" suggestions={callbackFunc} onChange={onChange} />
|
|
710
|
-
);
|
|
711
|
-
const input = getByRole("combobox");
|
|
712
|
-
fireEvent.focus(input);
|
|
713
|
-
const list = getByRole("listbox");
|
|
714
|
-
expect(list).toBeTruthy();
|
|
715
|
-
userEvent.type(input, "Ab");
|
|
716
|
-
fireEvent.keyDown(input, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
717
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
718
|
-
expect(queryByText("Searching...")).toBeFalsy();
|
|
719
|
-
expect(input.value).toBe("");
|
|
720
|
-
fireEvent.keyDown(input, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
721
|
-
expect(list).toBeTruthy();
|
|
722
|
-
await waitForElementToBeRemoved(() => getByText("Searching..."));
|
|
723
|
-
expect(getByText("Afghanistan")).toBeTruthy();
|
|
724
|
-
expect(getByText("Albania")).toBeTruthy();
|
|
725
|
-
expect(getByText("Algeria")).toBeTruthy();
|
|
726
|
-
expect(getByText("Andorra")).toBeTruthy();
|
|
727
|
-
});
|
|
728
|
-
test("Asynchronous uncontrolled autosuggest test", async () => {
|
|
729
|
-
const callbackFunc = jest.fn((newValue) => {
|
|
730
|
-
const result = new Promise((resolve) =>
|
|
731
|
-
setTimeout(() => {
|
|
732
|
-
resolve(
|
|
733
|
-
newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
|
|
734
|
-
);
|
|
735
|
-
}, 1000)
|
|
736
|
-
);
|
|
737
|
-
return result;
|
|
738
|
-
});
|
|
739
|
-
const onChange = jest.fn();
|
|
740
|
-
const { getByRole, getByText } = render(
|
|
741
|
-
<DxcNewInputText label="Autosuggest Countries" onChange={onChange} suggestions={callbackFunc} />
|
|
742
|
-
);
|
|
743
|
-
const input = getByRole("combobox");
|
|
744
|
-
fireEvent.focus(input);
|
|
745
|
-
userEvent.type(input, "Den");
|
|
746
|
-
await waitForElementToBeRemoved(() => getByText("Searching..."));
|
|
747
|
-
expect(getByText("Denmark")).toBeTruthy();
|
|
748
|
-
fireEvent.mouseDown(getByRole("option"));
|
|
749
|
-
fireEvent.mouseUp(getByRole("option"));
|
|
750
|
-
expect(onChange).toHaveBeenCalledWith("Denmark");
|
|
751
|
-
expect(input.value).toBe("Denmark");
|
|
752
|
-
});
|
|
753
|
-
test("Asynchronous controlled autosuggest test", async () => {
|
|
754
|
-
const callbackFunc = jest.fn((newValue) => {
|
|
755
|
-
const result = new Promise((resolve) =>
|
|
756
|
-
setTimeout(() => {
|
|
757
|
-
resolve(
|
|
758
|
-
newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
|
|
759
|
-
);
|
|
760
|
-
}, 1000)
|
|
761
|
-
);
|
|
762
|
-
return result;
|
|
763
|
-
});
|
|
764
|
-
const onChange = jest.fn();
|
|
765
|
-
const { getByRole, getByText, queryByRole } = render(
|
|
766
|
-
<DxcNewInputText label="Autosuggest Countries" value="Denm" onChange={onChange} suggestions={callbackFunc} />
|
|
767
|
-
);
|
|
768
|
-
const input = getByRole("combobox");
|
|
769
|
-
fireEvent.focus(input);
|
|
770
|
-
await waitForElementToBeRemoved(() => getByText("Searching..."));
|
|
771
|
-
expect(input.value).toBe("Denm");
|
|
772
|
-
expect(getByText("Denmark")).toBeTruthy();
|
|
773
|
-
fireEvent.mouseDown(getByRole("option"));
|
|
774
|
-
fireEvent.mouseUp(getByRole("option"));
|
|
775
|
-
expect(onChange).toHaveBeenCalledWith("Denmark");
|
|
776
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
777
|
-
});
|
|
778
|
-
test("Asynchronous autosuggest shows 'No results found' after finishing no matches search", async () => {
|
|
779
|
-
const callbackFunc = jest.fn((newValue) => {
|
|
780
|
-
const result = new Promise((resolve) =>
|
|
781
|
-
setTimeout(() => {
|
|
782
|
-
resolve(
|
|
783
|
-
newValue ? countries.filter((option) => option.toUpperCase().includes(newValue.toUpperCase())) : countries
|
|
784
|
-
);
|
|
785
|
-
}, 1000)
|
|
786
|
-
);
|
|
787
|
-
return result;
|
|
788
|
-
});
|
|
789
|
-
const onChange = jest.fn();
|
|
790
|
-
const { getByRole, getByText } = render(
|
|
791
|
-
<DxcNewInputText label="Autosuggest Countries" onChange={onChange} suggestions={callbackFunc} />
|
|
792
|
-
);
|
|
793
|
-
const input = getByRole("combobox");
|
|
794
|
-
fireEvent.focus(input);
|
|
795
|
-
userEvent.type(input, "Example text");
|
|
796
|
-
await waitForElementToBeRemoved(() => getByText("Searching..."));
|
|
797
|
-
expect(getByText("No results found")).toBeTruthy();
|
|
798
|
-
});
|
|
799
|
-
test("Asynchronous autosuggest request failed, shows 'Error fetching data' message", async () => {
|
|
800
|
-
const errorCallbackFunc = jest.fn(() => {
|
|
801
|
-
const result = new Promise((resolve, reject) =>
|
|
802
|
-
setTimeout(() => {
|
|
803
|
-
reject("err");
|
|
804
|
-
}, 1000)
|
|
805
|
-
);
|
|
806
|
-
return result;
|
|
807
|
-
});
|
|
808
|
-
const onChange = jest.fn();
|
|
809
|
-
const { getByRole, getByText } = render(
|
|
810
|
-
<DxcNewInputText label="Autosuggest Countries" onChange={onChange} suggestions={errorCallbackFunc} />
|
|
811
|
-
);
|
|
812
|
-
const input = getByRole("combobox");
|
|
813
|
-
fireEvent.focus(input);
|
|
814
|
-
await waitForElementToBeRemoved(() => getByText("Searching..."));
|
|
815
|
-
expect(getByText("Error fetching data")).toBeTruthy();
|
|
816
|
-
});
|
|
817
|
-
});
|