@dxc-technology/halstack-react 0.0.0-9bd9511 → 0.0.0-9c20370
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/BackgroundColorContext.d.ts +3 -3
- package/BackgroundColorContext.js +12 -2
- package/HalstackContext.d.ts +1330 -7
- package/HalstackContext.js +84 -67
- package/accordion/Accordion.d.ts +1 -1
- package/accordion/Accordion.js +74 -55
- package/accordion/Accordion.stories.tsx +3 -101
- package/accordion/Accordion.test.js +34 -19
- package/accordion/types.d.ts +4 -16
- package/accordion-group/AccordionGroup.d.ts +4 -3
- package/accordion-group/AccordionGroup.js +49 -42
- package/accordion-group/AccordionGroup.stories.tsx +77 -76
- package/accordion-group/AccordionGroup.test.js +62 -54
- package/accordion-group/AccordionGroupAccordion.d.ts +4 -0
- package/accordion-group/AccordionGroupAccordion.js +43 -0
- package/accordion-group/types.d.ts +6 -18
- package/alert/Alert.js +47 -20
- package/alert/Alert.test.js +46 -29
- package/alert/types.d.ts +3 -3
- package/badge/Badge.js +14 -2
- package/badge/types.d.ts +1 -1
- package/bleed/Bleed.js +21 -13
- package/bleed/Bleed.stories.tsx +1 -0
- package/bleed/types.d.ts +2 -2
- package/box/Box.d.ts +1 -1
- package/box/Box.js +33 -33
- package/box/Box.stories.tsx +25 -53
- package/box/Box.test.js +7 -2
- package/box/types.d.ts +3 -15
- package/bulleted-list/BulletedList.js +36 -9
- package/bulleted-list/BulletedList.stories.tsx +7 -1
- package/bulleted-list/types.d.ts +32 -5
- package/button/Button.d.ts +1 -1
- package/button/Button.js +83 -71
- package/button/Button.stories.tsx +4 -4
- package/button/Button.test.js +28 -8
- package/button/types.d.ts +8 -4
- package/card/Card.d.ts +1 -1
- package/card/Card.js +67 -62
- package/card/Card.stories.tsx +12 -42
- package/card/Card.test.js +22 -11
- package/card/types.d.ts +4 -10
- package/checkbox/Checkbox.js +71 -27
- package/checkbox/Checkbox.test.js +60 -33
- package/checkbox/types.d.ts +4 -4
- package/chip/Chip.js +51 -48
- package/chip/Chip.stories.tsx +25 -17
- package/chip/Chip.test.js +29 -17
- package/chip/types.d.ts +4 -4
- package/common/OpenSans.css +68 -80
- package/common/coreTokens.d.ts +146 -0
- package/common/coreTokens.js +167 -0
- package/common/utils.d.ts +1 -0
- package/common/utils.js +8 -3
- package/common/variables.d.ts +226 -175
- package/common/variables.js +956 -1133
- package/date-input/Calendar.js +55 -12
- package/date-input/DateInput.js +82 -35
- package/date-input/DateInput.test.js +351 -164
- package/date-input/DatePicker.js +38 -8
- package/date-input/Icons.js +12 -0
- package/date-input/YearPicker.js +30 -5
- package/date-input/types.d.ts +7 -7
- package/dialog/Dialog.d.ts +1 -1
- package/dialog/Dialog.js +83 -86
- package/dialog/Dialog.stories.tsx +127 -221
- package/dialog/Dialog.test.js +331 -18
- package/dialog/types.d.ts +1 -14
- package/dropdown/Dropdown.js +86 -32
- package/dropdown/Dropdown.test.js +211 -104
- package/dropdown/DropdownMenu.js +22 -8
- package/dropdown/DropdownMenuItem.js +15 -6
- package/dropdown/types.d.ts +8 -8
- package/file-input/FileInput.js +218 -134
- package/file-input/FileInput.test.js +343 -331
- package/file-input/FileItem.js +39 -12
- package/file-input/types.d.ts +10 -10
- package/flex/Flex.js +39 -25
- package/flex/Flex.stories.tsx +35 -26
- package/flex/types.d.ts +74 -9
- package/footer/Footer.d.ts +1 -1
- package/footer/Footer.js +80 -68
- package/footer/Footer.stories.tsx +12 -89
- package/footer/Footer.test.js +47 -40
- package/footer/Icons.js +4 -0
- package/footer/types.d.ts +15 -17
- package/grid/Grid.d.ts +7 -0
- package/grid/Grid.js +91 -0
- package/grid/Grid.stories.tsx +219 -0
- package/grid/types.d.ts +115 -0
- package/header/Header.d.ts +4 -3
- package/header/Header.js +72 -55
- package/header/Header.stories.tsx +7 -71
- package/header/Header.test.js +26 -13
- package/header/Icons.js +4 -0
- package/header/types.d.ts +2 -16
- package/heading/Heading.js +28 -7
- package/heading/Heading.test.js +88 -71
- package/heading/types.d.ts +3 -3
- package/inset/Inset.js +21 -13
- package/inset/Inset.stories.tsx +2 -1
- package/inset/types.d.ts +2 -2
- package/layout/ApplicationLayout.d.ts +5 -5
- package/layout/ApplicationLayout.js +57 -15
- package/layout/Icons.js +10 -0
- package/layout/SidenavContext.d.ts +1 -1
- package/layout/SidenavContext.js +4 -0
- package/layout/types.d.ts +5 -6
- package/link/Link.js +41 -21
- package/link/Link.test.js +42 -26
- package/link/types.d.ts +4 -4
- package/main.d.ts +2 -1
- package/main.js +55 -0
- package/nav-tabs/NavTabs.d.ts +2 -2
- package/nav-tabs/NavTabs.js +43 -16
- package/nav-tabs/NavTabs.stories.tsx +14 -0
- package/nav-tabs/NavTabs.test.js +44 -37
- package/nav-tabs/Tab.js +71 -45
- package/nav-tabs/types.d.ts +10 -11
- package/number-input/NumberInput.js +30 -20
- package/number-input/NumberInput.test.js +249 -113
- package/number-input/NumberInputContext.js +5 -0
- package/number-input/numberInputContextTypes.d.ts +1 -1
- package/number-input/types.d.ts +4 -4
- package/package.json +7 -7
- package/paginator/Icons.js +10 -0
- package/paginator/Paginator.js +39 -17
- package/paginator/Paginator.test.js +156 -104
- package/paginator/types.d.ts +1 -1
- package/paragraph/Paragraph.d.ts +3 -4
- package/paragraph/Paragraph.js +18 -8
- package/password-input/PasswordInput.js +51 -22
- package/password-input/PasswordInput.test.js +94 -51
- package/password-input/types.d.ts +4 -4
- package/progress-bar/ProgressBar.d.ts +2 -2
- package/progress-bar/ProgressBar.js +39 -14
- package/progress-bar/ProgressBar.test.js +53 -36
- package/progress-bar/types.d.ts +4 -3
- package/quick-nav/QuickNav.js +24 -2
- package/quick-nav/types.d.ts +2 -2
- package/radio-group/Radio.js +53 -22
- package/radio-group/RadioGroup.js +84 -41
- package/radio-group/RadioGroup.test.js +288 -186
- package/radio-group/types.d.ts +4 -4
- package/resultsetTable/Icons.js +3 -0
- package/resultsetTable/ResultsetTable.js +56 -21
- package/resultsetTable/ResultsetTable.test.js +75 -42
- package/resultsetTable/types.d.ts +5 -5
- package/select/Icons.js +3 -0
- package/select/Listbox.js +35 -10
- package/select/Option.js +24 -8
- package/select/Select.js +143 -56
- package/select/Select.test.js +839 -456
- package/select/types.d.ts +12 -12
- package/sidenav/Icons.d.ts +7 -0
- package/sidenav/Icons.js +51 -0
- package/sidenav/Sidenav.d.ts +2 -2
- package/sidenav/Sidenav.js +116 -104
- package/sidenav/Sidenav.stories.tsx +60 -60
- package/sidenav/Sidenav.test.js +10 -3
- package/sidenav/types.d.ts +26 -23
- package/slider/Slider.js +84 -38
- package/slider/Slider.test.js +104 -76
- package/slider/types.d.ts +4 -4
- package/spinner/Spinner.js +51 -28
- package/spinner/Spinner.stories.jsx +28 -28
- package/spinner/Spinner.test.js +35 -26
- package/spinner/types.d.ts +3 -3
- package/switch/Switch.js +66 -24
- package/switch/Switch.test.js +97 -52
- package/switch/types.d.ts +4 -4
- package/table/Table.js +22 -4
- package/table/Table.test.js +7 -2
- package/table/types.d.ts +3 -3
- package/tabs/Tab.js +39 -22
- package/tabs/Tabs.js +131 -62
- package/tabs/Tabs.test.js +122 -67
- package/tabs/types.d.ts +8 -8
- package/tag/Tag.js +54 -27
- package/tag/Tag.test.js +31 -20
- package/tag/types.d.ts +7 -7
- package/text-input/Icons.js +3 -0
- package/text-input/Suggestion.js +24 -8
- package/text-input/Suggestions.js +36 -11
- package/text-input/TextInput.js +144 -59
- package/text-input/TextInput.stories.tsx +1 -1
- package/text-input/TextInput.test.js +858 -539
- package/text-input/types.d.ts +9 -9
- package/textarea/Textarea.js +73 -38
- package/textarea/Textarea.test.js +173 -98
- package/textarea/types.d.ts +4 -4
- package/toggle-group/ToggleGroup.d.ts +2 -2
- package/toggle-group/ToggleGroup.js +59 -21
- package/toggle-group/ToggleGroup.test.js +72 -40
- package/toggle-group/types.d.ts +11 -11
- package/typography/Typography.d.ts +2 -2
- package/typography/Typography.js +23 -110
- package/typography/Typography.stories.tsx +1 -1
- package/typography/types.d.ts +1 -1
- package/useTheme.d.ts +1234 -1
- package/useTheme.js +6 -0
- package/useTranslatedLabels.d.ts +84 -2
- package/useTranslatedLabels.js +5 -0
- package/utils/BaseTypography.d.ts +21 -0
- package/utils/BaseTypography.js +108 -0
- package/utils/FocusLock.d.ts +13 -0
- package/utils/FocusLock.js +138 -0
- package/wizard/Wizard.js +47 -13
- package/wizard/Wizard.test.js +81 -54
- package/wizard/types.d.ts +7 -8
- package/card/ice-cream.jpg +0 -0
- package/translatedLabelsType.d.ts +0 -82
- /package/{translatedLabelsType.js → grid/types.js} +0 -0
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
4
5
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
+
|
|
5
7
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
|
+
|
|
6
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
|
|
7
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
+
|
|
8
13
|
var _react = _interopRequireDefault(require("react"));
|
|
14
|
+
|
|
9
15
|
var _react2 = require("@testing-library/react");
|
|
16
|
+
|
|
10
17
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
11
|
-
|
|
18
|
+
|
|
19
|
+
var _TextInput = _interopRequireDefault(require("./TextInput.tsx"));
|
|
20
|
+
|
|
12
21
|
// Mocking DOMRect for Radix Primitive Popover
|
|
13
22
|
global.globalThis = global;
|
|
23
|
+
|
|
14
24
|
global.ResizeObserver = /*#__PURE__*/function () {
|
|
15
25
|
function ResizeObserver(cb) {
|
|
16
26
|
(0, _classCallCheck2["default"])(this, ResizeObserver);
|
|
17
27
|
this.cb = cb;
|
|
18
28
|
}
|
|
29
|
+
|
|
19
30
|
(0, _createClass2["default"])(ResizeObserver, [{
|
|
20
31
|
key: "observe",
|
|
21
32
|
value: function observe() {
|
|
@@ -32,6 +43,7 @@ global.ResizeObserver = /*#__PURE__*/function () {
|
|
|
32
43
|
}]);
|
|
33
44
|
return ResizeObserver;
|
|
34
45
|
}();
|
|
46
|
+
|
|
35
47
|
global.DOMRect = {
|
|
36
48
|
fromRect: function fromRect() {
|
|
37
49
|
return {
|
|
@@ -49,12 +61,13 @@ var specialCharacters = ["/", "\\", "*", "(", ")", "[", "]", "+", "?", "*{[]}|"]
|
|
|
49
61
|
describe("TextInput component tests", function () {
|
|
50
62
|
test("Renders with correct error aria attributes", function () {
|
|
51
63
|
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
label: "Error label",
|
|
65
|
+
placeholder: "Placeholder",
|
|
66
|
+
error: "Error message."
|
|
67
|
+
})),
|
|
68
|
+
getByText = _render.getByText,
|
|
69
|
+
getByRole = _render.getByRole;
|
|
70
|
+
|
|
58
71
|
var input = getByRole("textbox");
|
|
59
72
|
var errorMessage = getByText("Error message.");
|
|
60
73
|
expect(errorMessage).toBeTruthy();
|
|
@@ -64,39 +77,48 @@ describe("TextInput component tests", function () {
|
|
|
64
77
|
});
|
|
65
78
|
test("Renders with correct initial value", function () {
|
|
66
79
|
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
label: "Default label",
|
|
81
|
+
placeholder: "Placeholder",
|
|
82
|
+
defaultValue: "Example text"
|
|
83
|
+
})),
|
|
84
|
+
getByRole = _render2.getByRole;
|
|
85
|
+
|
|
72
86
|
var input = getByRole("textbox");
|
|
73
87
|
expect(input.value).toBe("Example text");
|
|
74
88
|
});
|
|
75
89
|
test("Not optional constraint (onBlur)", function () {
|
|
76
90
|
var onChange = jest.fn();
|
|
77
91
|
var onBlur = jest.fn();
|
|
92
|
+
|
|
78
93
|
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
94
|
+
label: "Input label",
|
|
95
|
+
placeholder: "Placeholder",
|
|
96
|
+
onChange: onChange,
|
|
97
|
+
onBlur: onBlur,
|
|
98
|
+
clearable: true
|
|
99
|
+
})),
|
|
100
|
+
getByRole = _render3.getByRole;
|
|
101
|
+
|
|
86
102
|
var input = getByRole("textbox");
|
|
103
|
+
|
|
87
104
|
_react2.fireEvent.focus(input);
|
|
105
|
+
|
|
88
106
|
_react2.fireEvent.blur(input);
|
|
107
|
+
|
|
89
108
|
expect(onBlur).toHaveBeenCalled();
|
|
90
109
|
expect(onBlur).toHaveBeenCalledWith({
|
|
91
110
|
value: "",
|
|
92
111
|
error: "This field is required. Please, enter a value."
|
|
93
112
|
});
|
|
113
|
+
|
|
94
114
|
_react2.fireEvent.change(input, {
|
|
95
115
|
target: {
|
|
96
116
|
value: "Test"
|
|
97
117
|
}
|
|
98
118
|
});
|
|
119
|
+
|
|
99
120
|
_react2.fireEvent.blur(input);
|
|
121
|
+
|
|
100
122
|
expect(onBlur).toHaveBeenCalled();
|
|
101
123
|
expect(onBlur).toHaveBeenCalledWith({
|
|
102
124
|
value: "Test"
|
|
@@ -104,24 +126,30 @@ describe("TextInput component tests", function () {
|
|
|
104
126
|
});
|
|
105
127
|
test("Not optional constraint (onChange)", function () {
|
|
106
128
|
var onChange = jest.fn();
|
|
129
|
+
|
|
107
130
|
var _render4 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
131
|
+
label: "Input label",
|
|
132
|
+
placeholder: "Placeholder",
|
|
133
|
+
onChange: onChange,
|
|
134
|
+
clearable: true
|
|
135
|
+
})),
|
|
136
|
+
getByRole = _render4.getByRole;
|
|
137
|
+
|
|
114
138
|
var input = getByRole("textbox");
|
|
139
|
+
|
|
115
140
|
_react2.fireEvent.change(input, {
|
|
116
141
|
target: {
|
|
117
142
|
value: "Test"
|
|
118
143
|
}
|
|
119
144
|
});
|
|
145
|
+
|
|
120
146
|
expect(onChange).toHaveBeenCalled();
|
|
121
147
|
expect(onChange).toHaveBeenCalledWith({
|
|
122
148
|
value: "Test"
|
|
123
149
|
});
|
|
150
|
+
|
|
124
151
|
_userEvent["default"].clear(input);
|
|
152
|
+
|
|
125
153
|
expect(onChange).toHaveBeenCalled();
|
|
126
154
|
expect(onChange).toHaveBeenCalledWith({
|
|
127
155
|
value: "",
|
|
@@ -131,47 +159,58 @@ describe("TextInput component tests", function () {
|
|
|
131
159
|
test("Pattern constraint", function () {
|
|
132
160
|
var onChange = jest.fn();
|
|
133
161
|
var onBlur = jest.fn();
|
|
162
|
+
|
|
134
163
|
var _render5 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
164
|
+
label: "Input label",
|
|
165
|
+
placeholder: "Placeholder",
|
|
166
|
+
onChange: onChange,
|
|
167
|
+
onBlur: onBlur,
|
|
168
|
+
margin: {
|
|
169
|
+
left: "medium",
|
|
170
|
+
right: "medium"
|
|
171
|
+
},
|
|
172
|
+
clearable: true,
|
|
173
|
+
pattern: "^.*(?=.*[a-zA-Z])(?=.*\\d)(?=.*[!&$%&? \"]).*$"
|
|
174
|
+
})),
|
|
175
|
+
getByRole = _render5.getByRole;
|
|
176
|
+
|
|
147
177
|
var input = getByRole("textbox");
|
|
178
|
+
|
|
148
179
|
_react2.fireEvent.change(input, {
|
|
149
180
|
target: {
|
|
150
181
|
value: "pattern test"
|
|
151
182
|
}
|
|
152
183
|
});
|
|
184
|
+
|
|
153
185
|
expect(onChange).toHaveBeenCalled();
|
|
154
186
|
expect(onChange).toHaveBeenCalledWith({
|
|
155
187
|
value: "pattern test",
|
|
156
188
|
error: "Please match the format requested."
|
|
157
189
|
});
|
|
190
|
+
|
|
158
191
|
_react2.fireEvent.blur(input);
|
|
192
|
+
|
|
159
193
|
expect(onBlur).toHaveBeenCalled();
|
|
160
194
|
expect(onBlur).toHaveBeenCalledWith({
|
|
161
195
|
value: "pattern test",
|
|
162
196
|
error: "Please match the format requested."
|
|
163
197
|
});
|
|
198
|
+
|
|
164
199
|
_userEvent["default"].clear(input);
|
|
200
|
+
|
|
165
201
|
_react2.fireEvent.change(input, {
|
|
166
202
|
target: {
|
|
167
203
|
value: "pattern4&"
|
|
168
204
|
}
|
|
169
205
|
});
|
|
206
|
+
|
|
170
207
|
expect(onChange).toHaveBeenCalled();
|
|
171
208
|
expect(onChange).toHaveBeenCalledWith({
|
|
172
209
|
value: "pattern4&"
|
|
173
210
|
});
|
|
211
|
+
|
|
174
212
|
_react2.fireEvent.blur(input);
|
|
213
|
+
|
|
175
214
|
expect(onBlur).toHaveBeenCalled();
|
|
176
215
|
expect(onBlur).toHaveBeenCalledWith({
|
|
177
216
|
value: "pattern4&"
|
|
@@ -180,48 +219,59 @@ describe("TextInput component tests", function () {
|
|
|
180
219
|
test("Length constraint", function () {
|
|
181
220
|
var onChange = jest.fn();
|
|
182
221
|
var onBlur = jest.fn();
|
|
222
|
+
|
|
183
223
|
var _render6 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
224
|
+
label: "Input label",
|
|
225
|
+
placeholder: "Placeholder",
|
|
226
|
+
onChange: onChange,
|
|
227
|
+
onBlur: onBlur,
|
|
228
|
+
margin: {
|
|
229
|
+
left: "medium",
|
|
230
|
+
right: "medium"
|
|
231
|
+
},
|
|
232
|
+
clearable: true,
|
|
233
|
+
minLength: 5,
|
|
234
|
+
maxLength: 10
|
|
235
|
+
})),
|
|
236
|
+
getByRole = _render6.getByRole;
|
|
237
|
+
|
|
197
238
|
var input = getByRole("textbox");
|
|
239
|
+
|
|
198
240
|
_react2.fireEvent.change(input, {
|
|
199
241
|
target: {
|
|
200
242
|
value: "test"
|
|
201
243
|
}
|
|
202
244
|
});
|
|
245
|
+
|
|
203
246
|
expect(onChange).toHaveBeenCalled();
|
|
204
247
|
expect(onChange).toHaveBeenCalledWith({
|
|
205
248
|
value: "test",
|
|
206
249
|
error: "Min length 5, max length 10."
|
|
207
250
|
});
|
|
251
|
+
|
|
208
252
|
_react2.fireEvent.blur(input);
|
|
253
|
+
|
|
209
254
|
expect(onBlur).toHaveBeenCalled();
|
|
210
255
|
expect(onBlur).toHaveBeenCalledWith({
|
|
211
256
|
value: "test",
|
|
212
257
|
error: "Min length 5, max length 10."
|
|
213
258
|
});
|
|
259
|
+
|
|
214
260
|
_userEvent["default"].clear(input);
|
|
261
|
+
|
|
215
262
|
_react2.fireEvent.change(input, {
|
|
216
263
|
target: {
|
|
217
264
|
value: "length"
|
|
218
265
|
}
|
|
219
266
|
});
|
|
267
|
+
|
|
220
268
|
expect(onChange).toHaveBeenCalled();
|
|
221
269
|
expect(onChange).toHaveBeenCalledWith({
|
|
222
270
|
value: "length"
|
|
223
271
|
});
|
|
272
|
+
|
|
224
273
|
_react2.fireEvent.blur(input);
|
|
274
|
+
|
|
225
275
|
expect(onBlur).toHaveBeenCalled();
|
|
226
276
|
expect(onBlur).toHaveBeenCalledWith({
|
|
227
277
|
value: "length"
|
|
@@ -230,64 +280,78 @@ describe("TextInput component tests", function () {
|
|
|
230
280
|
test("Pattern and length constraints", function () {
|
|
231
281
|
var onChange = jest.fn();
|
|
232
282
|
var onBlur = jest.fn();
|
|
283
|
+
|
|
233
284
|
var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
285
|
+
label: "Input label",
|
|
286
|
+
placeholder: "Placeholder",
|
|
287
|
+
onChange: onChange,
|
|
288
|
+
onBlur: onBlur,
|
|
289
|
+
margin: {
|
|
290
|
+
left: "medium",
|
|
291
|
+
right: "medium"
|
|
292
|
+
},
|
|
293
|
+
clearable: true,
|
|
294
|
+
pattern: "^.*(?=.*[a-zA-Z])(?=.*\\d)(?=.*[!&$%&? \"]).*$",
|
|
295
|
+
minLength: 5,
|
|
296
|
+
maxLength: 10
|
|
297
|
+
})),
|
|
298
|
+
getByRole = _render7.getByRole;
|
|
299
|
+
|
|
248
300
|
var input = getByRole("textbox");
|
|
301
|
+
|
|
249
302
|
_react2.fireEvent.change(input, {
|
|
250
303
|
target: {
|
|
251
304
|
value: "test"
|
|
252
305
|
}
|
|
253
306
|
});
|
|
307
|
+
|
|
254
308
|
expect(onChange).toHaveBeenCalled();
|
|
255
309
|
expect(onChange).toHaveBeenCalledWith({
|
|
256
310
|
value: "test",
|
|
257
311
|
error: "Min length 5, max length 10."
|
|
258
312
|
});
|
|
313
|
+
|
|
259
314
|
_react2.fireEvent.blur(input);
|
|
315
|
+
|
|
260
316
|
expect(onBlur).toHaveBeenCalled();
|
|
261
317
|
expect(onBlur).toHaveBeenCalledWith({
|
|
262
318
|
value: "test",
|
|
263
319
|
error: "Min length 5, max length 10."
|
|
264
320
|
});
|
|
321
|
+
|
|
265
322
|
_react2.fireEvent.change(input, {
|
|
266
323
|
target: {
|
|
267
324
|
value: "tests"
|
|
268
325
|
}
|
|
269
326
|
});
|
|
327
|
+
|
|
270
328
|
expect(onChange).toHaveBeenCalled();
|
|
271
329
|
expect(onChange).toHaveBeenCalledWith({
|
|
272
330
|
value: "tests",
|
|
273
331
|
error: "Please match the format requested."
|
|
274
332
|
});
|
|
333
|
+
|
|
275
334
|
_react2.fireEvent.blur(input);
|
|
335
|
+
|
|
276
336
|
expect(onBlur).toHaveBeenCalled();
|
|
277
337
|
expect(onBlur).toHaveBeenCalledWith({
|
|
278
338
|
value: "tests",
|
|
279
339
|
error: "Please match the format requested."
|
|
280
340
|
});
|
|
341
|
+
|
|
281
342
|
_react2.fireEvent.change(input, {
|
|
282
343
|
target: {
|
|
283
344
|
value: "tests4&"
|
|
284
345
|
}
|
|
285
346
|
});
|
|
347
|
+
|
|
286
348
|
expect(onChange).toHaveBeenCalled();
|
|
287
349
|
expect(onChange).toHaveBeenCalledWith({
|
|
288
350
|
value: "tests4&"
|
|
289
351
|
});
|
|
352
|
+
|
|
290
353
|
_react2.fireEvent.blur(input);
|
|
354
|
+
|
|
291
355
|
expect(onBlur).toHaveBeenCalled();
|
|
292
356
|
expect(onBlur).toHaveBeenCalledWith({
|
|
293
357
|
value: "tests4&"
|
|
@@ -295,13 +359,17 @@ describe("TextInput component tests", function () {
|
|
|
295
359
|
});
|
|
296
360
|
test("onChange function is called correctly", function () {
|
|
297
361
|
var onChange = jest.fn();
|
|
362
|
+
|
|
298
363
|
var _render8 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
364
|
+
label: "Input label",
|
|
365
|
+
onChange: onChange
|
|
366
|
+
})),
|
|
367
|
+
getByRole = _render8.getByRole;
|
|
368
|
+
|
|
303
369
|
var input = getByRole("textbox");
|
|
370
|
+
|
|
304
371
|
_userEvent["default"].type(input, "onchange event test");
|
|
372
|
+
|
|
305
373
|
expect(input.value).toBe("onchange event test");
|
|
306
374
|
expect(onChange).toHaveBeenCalled();
|
|
307
375
|
expect(onChange).toHaveBeenCalledWith({
|
|
@@ -311,19 +379,24 @@ describe("TextInput component tests", function () {
|
|
|
311
379
|
test("onBlur function is called correctly", function () {
|
|
312
380
|
var onBlur = jest.fn();
|
|
313
381
|
var onChange = jest.fn();
|
|
382
|
+
|
|
314
383
|
var _render9 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
384
|
+
label: "Input label",
|
|
385
|
+
onChange: onChange,
|
|
386
|
+
onBlur: onBlur
|
|
387
|
+
})),
|
|
388
|
+
getByRole = _render9.getByRole;
|
|
389
|
+
|
|
320
390
|
var input = getByRole("textbox");
|
|
391
|
+
|
|
321
392
|
_react2.fireEvent.change(input, {
|
|
322
393
|
target: {
|
|
323
394
|
value: "Blur test"
|
|
324
395
|
}
|
|
325
396
|
});
|
|
397
|
+
|
|
326
398
|
_react2.fireEvent.blur(input);
|
|
399
|
+
|
|
327
400
|
expect(onBlur).toHaveBeenCalled();
|
|
328
401
|
expect(onBlur).toHaveBeenCalledWith({
|
|
329
402
|
value: "Blur test"
|
|
@@ -331,35 +404,45 @@ describe("TextInput component tests", function () {
|
|
|
331
404
|
});
|
|
332
405
|
test("Clear action tooltip is correct", function () {
|
|
333
406
|
var _render10 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
407
|
+
label: "Input label",
|
|
408
|
+
value: "Text",
|
|
409
|
+
clearable: true
|
|
410
|
+
})),
|
|
411
|
+
getByTitle = _render10.getByTitle;
|
|
412
|
+
|
|
339
413
|
expect(getByTitle("Clear field")).toBeTruthy();
|
|
340
414
|
});
|
|
341
415
|
test("Clear action onClick cleans the input", function () {
|
|
342
416
|
var _render11 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
417
|
+
label: "Input label",
|
|
418
|
+
clearable: true
|
|
419
|
+
})),
|
|
420
|
+
getByRole = _render11.getByRole;
|
|
421
|
+
|
|
347
422
|
var input = getByRole("textbox");
|
|
423
|
+
|
|
348
424
|
_userEvent["default"].type(input, "Test");
|
|
425
|
+
|
|
349
426
|
var closeAction = getByRole("button");
|
|
427
|
+
|
|
350
428
|
_userEvent["default"].click(closeAction);
|
|
429
|
+
|
|
351
430
|
expect(input.value).toBe("");
|
|
352
431
|
});
|
|
353
432
|
test("Disabled input renders with correct aria and can not be modified", function () {
|
|
354
433
|
var onChange = jest.fn();
|
|
434
|
+
|
|
355
435
|
var _render12 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
436
|
+
label: "Input label",
|
|
437
|
+
onChange: onChange,
|
|
438
|
+
disabled: true
|
|
439
|
+
})),
|
|
440
|
+
getByRole = _render12.getByRole;
|
|
441
|
+
|
|
361
442
|
var input = getByRole("textbox");
|
|
443
|
+
|
|
362
444
|
_userEvent["default"].type(input, "Test");
|
|
445
|
+
|
|
363
446
|
expect(onChange).not.toHaveBeenCalled();
|
|
364
447
|
});
|
|
365
448
|
test("Disabled input (action must be shown but not clickable)", function () {
|
|
@@ -380,40 +463,46 @@ describe("TextInput component tests", function () {
|
|
|
380
463
|
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"
|
|
381
464
|
}))
|
|
382
465
|
};
|
|
466
|
+
|
|
383
467
|
var _render13 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
468
|
+
label: "Disabled input label",
|
|
469
|
+
action: action,
|
|
470
|
+
disabled: true
|
|
471
|
+
})),
|
|
472
|
+
getByRole = _render13.getByRole;
|
|
473
|
+
|
|
389
474
|
var input = getByRole("textbox");
|
|
390
475
|
expect(input.disabled).toBeTruthy();
|
|
476
|
+
|
|
391
477
|
_userEvent["default"].click(getByRole("button"));
|
|
478
|
+
|
|
392
479
|
expect(onClick).not.toHaveBeenCalled();
|
|
393
480
|
});
|
|
394
481
|
test("Disabled input (clear default action should not be displayed, even with text written on the input)", function () {
|
|
395
482
|
var _render14 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
483
|
+
label: "Disabled input label",
|
|
484
|
+
value: "Sample text",
|
|
485
|
+
disabled: true,
|
|
486
|
+
clearable: true
|
|
487
|
+
})),
|
|
488
|
+
getByRole = _render14.getByRole,
|
|
489
|
+
queryByRole = _render14.queryByRole;
|
|
490
|
+
|
|
403
491
|
var input = getByRole("textbox");
|
|
404
492
|
expect(input.disabled).toBeTruthy();
|
|
405
493
|
expect(queryByRole("button")).toBeFalsy();
|
|
406
494
|
});
|
|
407
495
|
test("Disabled input (suffix and preffix must be displayed)", function () {
|
|
408
496
|
var _render15 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
497
|
+
label: "Disabled input label",
|
|
498
|
+
value: "Sample text",
|
|
499
|
+
prefix: "+34",
|
|
500
|
+
suffix: "USD",
|
|
501
|
+
disabled: true
|
|
502
|
+
})),
|
|
503
|
+
getByRole = _render15.getByRole,
|
|
504
|
+
getByText = _render15.getByText;
|
|
505
|
+
|
|
417
506
|
var input = getByRole("textbox");
|
|
418
507
|
expect(input.disabled).toBeTruthy();
|
|
419
508
|
expect(getByText("+34")).toBeTruthy();
|
|
@@ -438,16 +527,20 @@ describe("TextInput component tests", function () {
|
|
|
438
527
|
})),
|
|
439
528
|
title: "Search"
|
|
440
529
|
};
|
|
530
|
+
|
|
441
531
|
var _render16 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
532
|
+
label: "Input label",
|
|
533
|
+
action: action
|
|
534
|
+
})),
|
|
535
|
+
getByRole = _render16.getByRole,
|
|
536
|
+
getByTestId = _render16.getByTestId,
|
|
537
|
+
getByTitle = _render16.getByTitle;
|
|
538
|
+
|
|
448
539
|
expect(getByTestId("image")).toBeTruthy();
|
|
449
540
|
expect(getByTitle("Search")).toBeTruthy();
|
|
541
|
+
|
|
450
542
|
_userEvent["default"].click(getByRole("button"));
|
|
543
|
+
|
|
451
544
|
expect(onClick).toHaveBeenCalled();
|
|
452
545
|
});
|
|
453
546
|
test("Text input submit correctly value in form", function () {
|
|
@@ -477,35 +570,44 @@ describe("TextInput component tests", function () {
|
|
|
477
570
|
data: "test"
|
|
478
571
|
});
|
|
479
572
|
});
|
|
573
|
+
|
|
480
574
|
var _render17 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement("form", {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
575
|
+
onSubmit: handlerOnSubmit
|
|
576
|
+
}, /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
577
|
+
label: "Input label",
|
|
578
|
+
name: "data",
|
|
579
|
+
action: action
|
|
580
|
+
}), /*#__PURE__*/_react["default"].createElement("button", {
|
|
581
|
+
type: "submit"
|
|
582
|
+
}, "Submit"))),
|
|
583
|
+
getByText = _render17.getByText,
|
|
584
|
+
getAllByRole = _render17.getAllByRole,
|
|
585
|
+
getByRole = _render17.getByRole;
|
|
586
|
+
|
|
492
587
|
var search = getAllByRole("button")[0];
|
|
493
588
|
var submit = getByText("Submit");
|
|
494
589
|
var input = getByRole("textbox");
|
|
590
|
+
|
|
495
591
|
_userEvent["default"].type(input, "test");
|
|
592
|
+
|
|
496
593
|
expect(input.value).toBe("test");
|
|
594
|
+
|
|
497
595
|
_userEvent["default"].click(search);
|
|
596
|
+
|
|
498
597
|
expect(handlerOnSubmit).not.toHaveBeenCalled();
|
|
598
|
+
|
|
499
599
|
_userEvent["default"].click(submit);
|
|
600
|
+
|
|
500
601
|
expect(handlerOnSubmit).toHaveBeenCalled();
|
|
501
602
|
});
|
|
502
603
|
test("Renders with correct prefix and suffix", function () {
|
|
503
604
|
var _render18 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
605
|
+
label: "Input label",
|
|
606
|
+
prefix: "+34",
|
|
607
|
+
suffix: "USD"
|
|
608
|
+
})),
|
|
609
|
+
getByText = _render18.getByText;
|
|
610
|
+
|
|
509
611
|
expect(getByText("+34")).toBeTruthy();
|
|
510
612
|
expect(getByText("USD")).toBeTruthy();
|
|
511
613
|
});
|
|
@@ -528,13 +630,15 @@ describe("TextInput component tests", function () {
|
|
|
528
630
|
})),
|
|
529
631
|
title: "Search"
|
|
530
632
|
};
|
|
633
|
+
|
|
531
634
|
var _render19 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
635
|
+
label: "Example label",
|
|
636
|
+
clearable: true,
|
|
637
|
+
action: action
|
|
638
|
+
})),
|
|
639
|
+
getByRole = _render19.getByRole,
|
|
640
|
+
getAllByRole = _render19.getAllByRole;
|
|
641
|
+
|
|
538
642
|
var input = getByRole("textbox");
|
|
539
643
|
expect(input.getAttribute("aria-autocomplete")).toBeNull();
|
|
540
644
|
expect(input.getAttribute("aria-controls")).toBeNull();
|
|
@@ -544,7 +648,9 @@ describe("TextInput component tests", function () {
|
|
|
544
648
|
expect(input.getAttribute("aria-invalid")).toBe("false");
|
|
545
649
|
expect(input.getAttribute("aria-errormessage")).toBeNull();
|
|
546
650
|
expect(input.getAttribute("aria-required")).toBe("true");
|
|
651
|
+
|
|
547
652
|
_userEvent["default"].type(input, "Text");
|
|
653
|
+
|
|
548
654
|
var clear = getAllByRole("button")[0];
|
|
549
655
|
expect(clear.getAttribute("aria-label")).toBe("Clear field");
|
|
550
656
|
var search = getAllByRole("button")[1];
|
|
@@ -552,18 +658,21 @@ describe("TextInput component tests", function () {
|
|
|
552
658
|
});
|
|
553
659
|
test("Autosuggest has correct accesibility attributes", function () {
|
|
554
660
|
var _render20 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
661
|
+
label: "Autocomplete Countries",
|
|
662
|
+
optional: true,
|
|
663
|
+
suggestions: countries
|
|
664
|
+
})),
|
|
665
|
+
getByRole = _render20.getByRole,
|
|
666
|
+
getAllByRole = _render20.getAllByRole;
|
|
667
|
+
|
|
561
668
|
var input = getByRole("combobox");
|
|
562
669
|
expect(input.getAttribute("aria-autocomplete")).toBe("list");
|
|
563
670
|
expect(input.getAttribute("aria-expanded")).toBe("false");
|
|
564
671
|
expect(input.getAttribute("aria-haspopup")).toBe("listbox");
|
|
565
672
|
expect(input.getAttribute("aria-required")).toBe("false");
|
|
673
|
+
|
|
566
674
|
_react2.fireEvent.focus(input);
|
|
675
|
+
|
|
567
676
|
var list = getByRole("listbox");
|
|
568
677
|
expect(input.getAttribute("aria-controls")).toBe(list.id);
|
|
569
678
|
expect(input.getAttribute("aria-expanded")).toBe("true");
|
|
@@ -574,15 +683,19 @@ describe("TextInput component tests", function () {
|
|
|
574
683
|
describe("TextInput component synchronous autosuggest tests", function () {
|
|
575
684
|
test("Autosuggest is displayed when the input gains focus", function () {
|
|
576
685
|
var onChange = jest.fn();
|
|
686
|
+
|
|
577
687
|
var _render21 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
688
|
+
label: "Autocomplete Countries",
|
|
689
|
+
suggestions: countries,
|
|
690
|
+
onChange: onChange
|
|
691
|
+
})),
|
|
692
|
+
getByRole = _render21.getByRole,
|
|
693
|
+
getByText = _render21.getByText;
|
|
694
|
+
|
|
584
695
|
var input = getByRole("combobox");
|
|
696
|
+
|
|
585
697
|
_react2.fireEvent.focus(input);
|
|
698
|
+
|
|
586
699
|
var list = getByRole("listbox");
|
|
587
700
|
expect(list).toBeTruthy();
|
|
588
701
|
expect(getByText("Afghanistan")).toBeTruthy();
|
|
@@ -592,15 +705,19 @@ describe("TextInput component synchronous autosuggest tests", function () {
|
|
|
592
705
|
});
|
|
593
706
|
test("Autosuggest is displayed when the user clicks the input", function () {
|
|
594
707
|
var onChange = jest.fn();
|
|
708
|
+
|
|
595
709
|
var _render22 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
710
|
+
label: "Autocomplete Countries",
|
|
711
|
+
suggestions: countries,
|
|
712
|
+
onChange: onChange
|
|
713
|
+
})),
|
|
714
|
+
getByRole = _render22.getByRole,
|
|
715
|
+
getByText = _render22.getByText;
|
|
716
|
+
|
|
602
717
|
var input = getByRole("combobox");
|
|
718
|
+
|
|
603
719
|
_react2.fireEvent.focus(input);
|
|
720
|
+
|
|
604
721
|
var list = getByRole("listbox");
|
|
605
722
|
expect(list).toBeTruthy();
|
|
606
723
|
expect(getByText("Afghanistan")).toBeTruthy();
|
|
@@ -610,27 +727,35 @@ describe("TextInput component synchronous autosuggest tests", function () {
|
|
|
610
727
|
});
|
|
611
728
|
test("Autosuggest is displayed while the user is writing (if closed previously, if it is open stays open)", function () {
|
|
612
729
|
var onChange = jest.fn();
|
|
730
|
+
|
|
613
731
|
var _render23 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
732
|
+
label: "Autocomplete Countries",
|
|
733
|
+
suggestions: countries,
|
|
734
|
+
onChange: onChange
|
|
735
|
+
})),
|
|
736
|
+
getByRole = _render23.getByRole,
|
|
737
|
+
queryByRole = _render23.queryByRole,
|
|
738
|
+
getByText = _render23.getByText,
|
|
739
|
+
getAllByText = _render23.getAllByText;
|
|
740
|
+
|
|
622
741
|
var input = getByRole("combobox");
|
|
742
|
+
|
|
623
743
|
_react2.fireEvent.focus(input);
|
|
744
|
+
|
|
624
745
|
var list = getByRole("listbox");
|
|
625
746
|
expect(list).toBeTruthy();
|
|
747
|
+
|
|
626
748
|
_react2.fireEvent.keyDown(input, {
|
|
627
749
|
key: "Esc",
|
|
628
750
|
code: "Esc",
|
|
629
751
|
keyCode: 27,
|
|
630
752
|
charCode: 27
|
|
631
753
|
});
|
|
754
|
+
|
|
632
755
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
756
|
+
|
|
633
757
|
_userEvent["default"].type(input, "B");
|
|
758
|
+
|
|
634
759
|
expect(list).toBeTruthy();
|
|
635
760
|
expect(getAllByText("B").length).toBe(4);
|
|
636
761
|
expect(getByText("ahamas")).toBeTruthy();
|
|
@@ -640,125 +765,163 @@ describe("TextInput component synchronous autosuggest tests", function () {
|
|
|
640
765
|
});
|
|
641
766
|
test("Autosuggest displays filtered when the input has a default value", function () {
|
|
642
767
|
var _render24 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
768
|
+
label: "Uncontrolled suggestions filtered by default",
|
|
769
|
+
helperText: "Example of helper text",
|
|
770
|
+
placeholder: "Placeholder",
|
|
771
|
+
margin: "medium",
|
|
772
|
+
defaultValue: "Suggestion 2",
|
|
773
|
+
suggestions: ["Suggestion 11", "Suggestion 12", "Suggestion 23", "Suggestion 24"],
|
|
774
|
+
clearable: true
|
|
775
|
+
})),
|
|
776
|
+
getByRole = _render24.getByRole,
|
|
777
|
+
getByText = _render24.getByText,
|
|
778
|
+
getAllByText = _render24.getAllByText;
|
|
779
|
+
|
|
654
780
|
var input = getByRole("combobox");
|
|
655
781
|
expect(input.value).toBe("Suggestion 2");
|
|
782
|
+
|
|
656
783
|
_react2.fireEvent.focus(input);
|
|
784
|
+
|
|
657
785
|
expect(getAllByText("Suggestion 2").length).toBe(2);
|
|
658
786
|
expect(getByText("3")).toBeTruthy();
|
|
659
787
|
expect(getByText("4")).toBeTruthy();
|
|
660
788
|
});
|
|
661
789
|
test("Autosuggest is not displayed when prop suggestions is an empty array", function () {
|
|
662
790
|
var onChange = jest.fn();
|
|
791
|
+
|
|
663
792
|
var _render25 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
793
|
+
label: "Autocomplete Countries",
|
|
794
|
+
suggestions: [],
|
|
795
|
+
onChange: onChange
|
|
796
|
+
})),
|
|
797
|
+
queryByRole = _render25.queryByRole;
|
|
798
|
+
|
|
669
799
|
var input = queryByRole("textbox");
|
|
800
|
+
|
|
670
801
|
_react2.fireEvent.focus(input);
|
|
802
|
+
|
|
671
803
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
672
804
|
});
|
|
673
805
|
test("Autosuggest closes the listbox when there are no matches for the user's input", function () {
|
|
674
806
|
var onChange = jest.fn();
|
|
807
|
+
|
|
675
808
|
var _render26 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
809
|
+
label: "Autocomplete Countries",
|
|
810
|
+
suggestions: countries,
|
|
811
|
+
onChange: onChange
|
|
812
|
+
})),
|
|
813
|
+
getByRole = _render26.getByRole,
|
|
814
|
+
queryByRole = _render26.queryByRole,
|
|
815
|
+
getByText = _render26.getByText;
|
|
816
|
+
|
|
683
817
|
var input = getByRole("combobox");
|
|
818
|
+
|
|
684
819
|
_react2.fireEvent.focus(input);
|
|
820
|
+
|
|
685
821
|
var list = getByRole("listbox");
|
|
686
822
|
expect(list).toBeTruthy();
|
|
687
823
|
expect(getByText("Afghanistan")).toBeTruthy();
|
|
824
|
+
|
|
688
825
|
_userEvent["default"].type(input, "x");
|
|
826
|
+
|
|
689
827
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
690
828
|
});
|
|
691
829
|
test("Autosuggest with no matches founded doesn't let the listbox to be opened", function () {
|
|
692
830
|
var onChange = jest.fn();
|
|
831
|
+
|
|
693
832
|
var _render27 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
833
|
+
label: "Autocomplete Countries",
|
|
834
|
+
suggestions: countries,
|
|
835
|
+
onChange: onChange
|
|
836
|
+
})),
|
|
837
|
+
getByRole = _render27.getByRole,
|
|
838
|
+
queryByRole = _render27.queryByRole,
|
|
839
|
+
getByText = _render27.getByText;
|
|
840
|
+
|
|
701
841
|
var input = getByRole("combobox");
|
|
842
|
+
|
|
702
843
|
_react2.fireEvent.focus(input);
|
|
844
|
+
|
|
703
845
|
var list = getByRole("listbox");
|
|
704
846
|
expect(list).toBeTruthy();
|
|
705
847
|
expect(getByText("Afghanistan")).toBeTruthy();
|
|
848
|
+
|
|
706
849
|
_userEvent["default"].type(input, "x");
|
|
850
|
+
|
|
707
851
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
852
|
+
|
|
708
853
|
_react2.fireEvent.focus(input);
|
|
854
|
+
|
|
709
855
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
856
|
+
|
|
710
857
|
_react2.fireEvent.keyDown(input, {
|
|
711
858
|
key: "ArrowUp",
|
|
712
859
|
code: "ArrowUp",
|
|
713
860
|
keyCode: 38,
|
|
714
861
|
charCode: 38
|
|
715
862
|
});
|
|
863
|
+
|
|
716
864
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
865
|
+
|
|
717
866
|
_react2.fireEvent.keyDown(input, {
|
|
718
867
|
key: "ArrowDown",
|
|
719
868
|
code: "ArrowDown",
|
|
720
869
|
keyCode: 40,
|
|
721
870
|
charCode: 40
|
|
722
871
|
});
|
|
872
|
+
|
|
723
873
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
724
874
|
});
|
|
725
875
|
test("Autosuggest uncontrolled - Suggestion selected by click", function () {
|
|
726
876
|
var onChange = jest.fn();
|
|
877
|
+
|
|
727
878
|
var _render28 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
879
|
+
label: "Autocomplete Countries",
|
|
880
|
+
suggestions: countries,
|
|
881
|
+
onChange: onChange
|
|
882
|
+
})),
|
|
883
|
+
getByRole = _render28.getByRole,
|
|
884
|
+
getByText = _render28.getByText,
|
|
885
|
+
queryByRole = _render28.queryByRole;
|
|
886
|
+
|
|
735
887
|
var input = getByRole("combobox");
|
|
888
|
+
|
|
736
889
|
_react2.fireEvent.focus(input);
|
|
890
|
+
|
|
737
891
|
_userEvent["default"].type(input, "Alba");
|
|
892
|
+
|
|
738
893
|
expect(onChange).toHaveBeenCalled();
|
|
739
894
|
expect(getByText("Alba")).toBeTruthy();
|
|
740
895
|
expect(getByText("nia")).toBeTruthy();
|
|
896
|
+
|
|
741
897
|
_userEvent["default"].click(getByRole("option"));
|
|
898
|
+
|
|
742
899
|
expect(input.value).toBe("Albania");
|
|
743
900
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
744
901
|
});
|
|
745
902
|
test("Autosuggest controlled - Suggestion selected by click", function () {
|
|
746
903
|
var onChange = jest.fn();
|
|
904
|
+
|
|
747
905
|
var _render29 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
906
|
+
label: "Autocomplete Countries",
|
|
907
|
+
value: "Andor",
|
|
908
|
+
suggestions: countries,
|
|
909
|
+
onChange: onChange
|
|
910
|
+
})),
|
|
911
|
+
getByRole = _render29.getByRole,
|
|
912
|
+
getByText = _render29.getByText,
|
|
913
|
+
queryByRole = _render29.queryByRole;
|
|
914
|
+
|
|
756
915
|
var input = getByRole("combobox");
|
|
916
|
+
|
|
757
917
|
_userEvent["default"].click(getByText("Autocomplete Countries"));
|
|
918
|
+
|
|
758
919
|
expect(input.value).toBe("Andor");
|
|
759
920
|
expect(getByText("Andor")).toBeTruthy();
|
|
760
921
|
expect(getByText("ra")).toBeTruthy();
|
|
922
|
+
|
|
761
923
|
_userEvent["default"].click(getByRole("option"));
|
|
924
|
+
|
|
762
925
|
expect(onChange).toHaveBeenCalledWith({
|
|
763
926
|
value: "Andorra"
|
|
764
927
|
});
|
|
@@ -767,26 +930,35 @@ describe("TextInput component synchronous autosuggest tests", function () {
|
|
|
767
930
|
test("Autosuggest - Pattern constraint", function () {
|
|
768
931
|
var onChange = jest.fn();
|
|
769
932
|
var onBlur = jest.fn();
|
|
933
|
+
|
|
770
934
|
var _render30 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
935
|
+
label: "Autocomplete Countries",
|
|
936
|
+
suggestions: countries,
|
|
937
|
+
onChange: onChange,
|
|
938
|
+
onBlur: onBlur,
|
|
939
|
+
pattern: "^.*(?=.*[a-zA-Z])(?=.*\\d)(?=.*[!&$%&? \"]).*$"
|
|
940
|
+
})),
|
|
941
|
+
getByRole = _render30.getByRole,
|
|
942
|
+
getByText = _render30.getByText;
|
|
943
|
+
|
|
779
944
|
var input = getByRole("combobox");
|
|
945
|
+
|
|
780
946
|
_react2.fireEvent.focus(input);
|
|
947
|
+
|
|
781
948
|
_userEvent["default"].type(input, "Andor");
|
|
949
|
+
|
|
782
950
|
expect(getByText("Andor")).toBeTruthy();
|
|
783
951
|
expect(getByText("ra")).toBeTruthy();
|
|
952
|
+
|
|
784
953
|
_userEvent["default"].click(getByRole("option"));
|
|
954
|
+
|
|
785
955
|
expect(onChange).toHaveBeenCalledWith({
|
|
786
956
|
value: "Andorra",
|
|
787
957
|
error: "Please match the format requested."
|
|
788
958
|
});
|
|
959
|
+
|
|
789
960
|
_react2.fireEvent.blur(input);
|
|
961
|
+
|
|
790
962
|
expect(onBlur).toHaveBeenCalledWith({
|
|
791
963
|
value: "Andorra",
|
|
792
964
|
error: "Please match the format requested."
|
|
@@ -795,27 +967,36 @@ describe("TextInput component synchronous autosuggest tests", function () {
|
|
|
795
967
|
test("Autosuggest - Length constraint", function () {
|
|
796
968
|
var onChange = jest.fn();
|
|
797
969
|
var onBlur = jest.fn();
|
|
970
|
+
|
|
798
971
|
var _render31 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
972
|
+
label: "Autocomplete Countries",
|
|
973
|
+
suggestions: countries,
|
|
974
|
+
onChange: onChange,
|
|
975
|
+
onBlur: onBlur,
|
|
976
|
+
minLength: 5,
|
|
977
|
+
maxLength: 10
|
|
978
|
+
})),
|
|
979
|
+
getByText = _render31.getByText,
|
|
980
|
+
getByRole = _render31.getByRole;
|
|
981
|
+
|
|
808
982
|
var input = getByRole("combobox");
|
|
983
|
+
|
|
809
984
|
_react2.fireEvent.focus(input);
|
|
985
|
+
|
|
810
986
|
_userEvent["default"].type(input, "Cha");
|
|
987
|
+
|
|
811
988
|
expect(getByText("Cha")).toBeTruthy();
|
|
812
989
|
expect(getByText("d")).toBeTruthy();
|
|
990
|
+
|
|
813
991
|
_userEvent["default"].click(getByRole("option"));
|
|
992
|
+
|
|
814
993
|
expect(onChange).toHaveBeenCalledWith({
|
|
815
994
|
value: "Cha",
|
|
816
995
|
error: "Min length 5, max length 10."
|
|
817
996
|
});
|
|
997
|
+
|
|
818
998
|
_react2.fireEvent.blur(input);
|
|
999
|
+
|
|
819
1000
|
expect(onBlur).toHaveBeenCalledWith({
|
|
820
1001
|
value: "Chad",
|
|
821
1002
|
error: "Min length 5, max length 10."
|
|
@@ -823,224 +1004,281 @@ describe("TextInput component synchronous autosuggest tests", function () {
|
|
|
823
1004
|
});
|
|
824
1005
|
test("Autosuggest keys: arrow down key opens autosuggest, active first option is selected with Enter and closes the autosuggest", function () {
|
|
825
1006
|
var onChange = jest.fn();
|
|
1007
|
+
|
|
826
1008
|
var _render32 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
1009
|
+
label: "Autocomplete Countries",
|
|
1010
|
+
suggestions: countries,
|
|
1011
|
+
onChange: onChange
|
|
1012
|
+
})),
|
|
1013
|
+
getByRole = _render32.getByRole,
|
|
1014
|
+
queryByRole = _render32.queryByRole;
|
|
1015
|
+
|
|
833
1016
|
var input = getByRole("combobox");
|
|
1017
|
+
|
|
834
1018
|
_react2.fireEvent.keyDown(input, {
|
|
835
1019
|
key: "ArrowDown",
|
|
836
1020
|
code: "ArrowDown",
|
|
837
1021
|
keyCode: 40,
|
|
838
1022
|
charCode: 40
|
|
839
1023
|
});
|
|
1024
|
+
|
|
840
1025
|
var list = getByRole("listbox");
|
|
841
1026
|
expect(list).toBeTruthy();
|
|
1027
|
+
|
|
842
1028
|
_react2.fireEvent.keyDown(input, {
|
|
843
1029
|
key: "Enter",
|
|
844
1030
|
code: "Enter",
|
|
845
1031
|
keyCode: 13,
|
|
846
1032
|
charCode: 13
|
|
847
1033
|
});
|
|
1034
|
+
|
|
848
1035
|
expect(input.value).toBe("Afghanistan");
|
|
849
1036
|
expect(queryByRole("list")).toBeFalsy();
|
|
850
1037
|
});
|
|
851
1038
|
test("Autosuggest keys: arrow up key opens autosuggest, active last option is selected with Enter and closes the autosuggest", function () {
|
|
852
1039
|
var onChange = jest.fn();
|
|
1040
|
+
|
|
853
1041
|
var _render33 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
1042
|
+
label: "Autocomplete Countries",
|
|
1043
|
+
suggestions: countries,
|
|
1044
|
+
onChange: onChange
|
|
1045
|
+
})),
|
|
1046
|
+
getByRole = _render33.getByRole,
|
|
1047
|
+
queryByRole = _render33.queryByRole;
|
|
1048
|
+
|
|
860
1049
|
var input = getByRole("combobox");
|
|
1050
|
+
|
|
861
1051
|
_react2.fireEvent.keyDown(input, {
|
|
862
1052
|
key: "ArrowUp",
|
|
863
1053
|
code: "ArrowUp",
|
|
864
1054
|
keyCode: 38,
|
|
865
1055
|
charCode: 38
|
|
866
1056
|
});
|
|
1057
|
+
|
|
867
1058
|
var list = getByRole("listbox");
|
|
868
1059
|
expect(list).toBeTruthy();
|
|
1060
|
+
|
|
869
1061
|
_react2.fireEvent.keyDown(input, {
|
|
870
1062
|
key: "Enter",
|
|
871
1063
|
code: "Enter",
|
|
872
1064
|
keyCode: 13,
|
|
873
1065
|
charCode: 13
|
|
874
1066
|
});
|
|
1067
|
+
|
|
875
1068
|
expect(input.value).toBe("Djibouti");
|
|
876
1069
|
expect(queryByRole("list")).toBeFalsy();
|
|
877
1070
|
});
|
|
878
1071
|
test("Autosuggest keys: Esc key closes the autosuggest and cleans the input", function () {
|
|
879
1072
|
var onChange = jest.fn();
|
|
1073
|
+
|
|
880
1074
|
var _render34 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
1075
|
+
label: "Autocomplete Countries",
|
|
1076
|
+
suggestions: countries,
|
|
1077
|
+
onChange: onChange
|
|
1078
|
+
})),
|
|
1079
|
+
getByRole = _render34.getByRole,
|
|
1080
|
+
queryByRole = _render34.queryByRole;
|
|
1081
|
+
|
|
887
1082
|
var input = getByRole("combobox");
|
|
1083
|
+
|
|
888
1084
|
_react2.fireEvent.focus(input);
|
|
1085
|
+
|
|
889
1086
|
_userEvent["default"].type(input, "Bangla");
|
|
1087
|
+
|
|
890
1088
|
var list = getByRole("listbox");
|
|
891
1089
|
expect(list).toBeTruthy();
|
|
1090
|
+
|
|
892
1091
|
_react2.fireEvent.keyDown(input, {
|
|
893
1092
|
key: "Esc",
|
|
894
1093
|
code: "Esc",
|
|
895
1094
|
keyCode: 27,
|
|
896
1095
|
charCode: 27
|
|
897
1096
|
});
|
|
1097
|
+
|
|
898
1098
|
expect(input.value).toBe("");
|
|
899
1099
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
900
1100
|
});
|
|
901
1101
|
test("Autosuggest keys: Enter, if no active suggestion closes the autosuggest", function () {
|
|
902
1102
|
var onChange = jest.fn();
|
|
1103
|
+
|
|
903
1104
|
var _render35 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1105
|
+
label: "Autocomplete Countries",
|
|
1106
|
+
suggestions: countries,
|
|
1107
|
+
onChange: onChange
|
|
1108
|
+
})),
|
|
1109
|
+
getByRole = _render35.getByRole,
|
|
1110
|
+
queryByRole = _render35.queryByRole;
|
|
1111
|
+
|
|
910
1112
|
var input = getByRole("combobox");
|
|
1113
|
+
|
|
911
1114
|
_react2.fireEvent.focus(input);
|
|
1115
|
+
|
|
912
1116
|
var list = getByRole("listbox");
|
|
913
1117
|
expect(list).toBeTruthy();
|
|
1118
|
+
|
|
914
1119
|
_react2.fireEvent.keyDown(input, {
|
|
915
1120
|
key: "Enter",
|
|
916
1121
|
code: "Enter",
|
|
917
1122
|
keyCode: 27,
|
|
918
1123
|
charCode: 27
|
|
919
1124
|
});
|
|
1125
|
+
|
|
920
1126
|
expect(input.value).toBe("");
|
|
921
1127
|
expect(queryByRole("list")).toBeFalsy();
|
|
922
1128
|
});
|
|
923
1129
|
test("Autosuggest complex key secuence: write, arrow up two times, arrow down and select with Enter. Then, clean with Esc.", function () {
|
|
924
1130
|
var onChange = jest.fn();
|
|
1131
|
+
|
|
925
1132
|
var _render36 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
1133
|
+
label: "Autocomplete Countries",
|
|
1134
|
+
suggestions: countries,
|
|
1135
|
+
onChange: onChange
|
|
1136
|
+
})),
|
|
1137
|
+
getByRole = _render36.getByRole,
|
|
1138
|
+
queryByRole = _render36.queryByRole;
|
|
1139
|
+
|
|
932
1140
|
var input = getByRole("combobox");
|
|
1141
|
+
|
|
933
1142
|
_react2.fireEvent.focus(input);
|
|
1143
|
+
|
|
934
1144
|
_userEvent["default"].type(input, "Ba");
|
|
1145
|
+
|
|
935
1146
|
_react2.fireEvent.keyDown(input, {
|
|
936
1147
|
key: "ArrowUp",
|
|
937
1148
|
code: "ArrowUp",
|
|
938
1149
|
keyCode: 38,
|
|
939
1150
|
charCode: 38
|
|
940
1151
|
});
|
|
1152
|
+
|
|
941
1153
|
_react2.fireEvent.keyDown(input, {
|
|
942
1154
|
key: "ArrowUp",
|
|
943
1155
|
code: "ArrowUpp",
|
|
944
1156
|
keyCode: 38,
|
|
945
1157
|
charCode: 38
|
|
946
1158
|
});
|
|
1159
|
+
|
|
947
1160
|
_react2.fireEvent.keyDown(input, {
|
|
948
1161
|
key: "ArrowDown",
|
|
949
1162
|
code: "ArrowDown",
|
|
950
1163
|
keyCode: 40,
|
|
951
1164
|
charCode: 40
|
|
952
1165
|
});
|
|
1166
|
+
|
|
953
1167
|
_react2.fireEvent.keyDown(input, {
|
|
954
1168
|
key: "Enter",
|
|
955
1169
|
code: "Enter",
|
|
956
1170
|
keyCode: 13,
|
|
957
1171
|
charCode: 13
|
|
958
1172
|
});
|
|
1173
|
+
|
|
959
1174
|
expect(input.value).toBe("Barbados");
|
|
960
1175
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
1176
|
+
|
|
961
1177
|
_react2.fireEvent.keyDown(input, {
|
|
962
1178
|
key: "Esc",
|
|
963
1179
|
code: "Esp",
|
|
964
1180
|
keyCode: 27,
|
|
965
1181
|
charCode: 27
|
|
966
1182
|
});
|
|
1183
|
+
|
|
967
1184
|
expect(input.value).toBe("");
|
|
968
1185
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
969
1186
|
});
|
|
970
1187
|
test("Autosuggest escapes special characters", function () {
|
|
971
1188
|
var onChange = jest.fn();
|
|
1189
|
+
|
|
972
1190
|
var _render37 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1191
|
+
label: "Autocomplete Countries",
|
|
1192
|
+
suggestions: specialCharacters,
|
|
1193
|
+
onChange: onChange
|
|
1194
|
+
})),
|
|
1195
|
+
getAllByText = _render37.getAllByText,
|
|
1196
|
+
getByRole = _render37.getByRole;
|
|
1197
|
+
|
|
980
1198
|
var input = getByRole("combobox");
|
|
1199
|
+
|
|
981
1200
|
_react2.fireEvent.focus(input);
|
|
1201
|
+
|
|
982
1202
|
var list = getByRole("listbox");
|
|
1203
|
+
|
|
983
1204
|
_react2.fireEvent.change(input, {
|
|
984
1205
|
target: {
|
|
985
1206
|
value: "/"
|
|
986
1207
|
}
|
|
987
1208
|
});
|
|
1209
|
+
|
|
988
1210
|
expect(list).toBeTruthy();
|
|
989
1211
|
expect(getAllByText("/").length).toBe(1);
|
|
1212
|
+
|
|
990
1213
|
_react2.fireEvent.change(input, {
|
|
991
1214
|
target: {
|
|
992
1215
|
value: "\\"
|
|
993
1216
|
}
|
|
994
1217
|
});
|
|
1218
|
+
|
|
995
1219
|
expect(list).toBeTruthy();
|
|
996
1220
|
expect(getAllByText("\\").length).toBe(1);
|
|
1221
|
+
|
|
997
1222
|
_react2.fireEvent.change(input, {
|
|
998
1223
|
target: {
|
|
999
1224
|
value: "*"
|
|
1000
1225
|
}
|
|
1001
1226
|
});
|
|
1227
|
+
|
|
1002
1228
|
expect(list).toBeTruthy();
|
|
1003
1229
|
expect(getAllByText("*").length).toBe(2);
|
|
1230
|
+
|
|
1004
1231
|
_react2.fireEvent.change(input, {
|
|
1005
1232
|
target: {
|
|
1006
1233
|
value: "("
|
|
1007
1234
|
}
|
|
1008
1235
|
});
|
|
1236
|
+
|
|
1009
1237
|
expect(list).toBeTruthy();
|
|
1010
1238
|
expect(getAllByText("(").length).toBe(1);
|
|
1239
|
+
|
|
1011
1240
|
_react2.fireEvent.change(input, {
|
|
1012
1241
|
target: {
|
|
1013
1242
|
value: ")"
|
|
1014
1243
|
}
|
|
1015
1244
|
});
|
|
1245
|
+
|
|
1016
1246
|
expect(list).toBeTruthy();
|
|
1017
1247
|
expect(getAllByText(")").length).toBe(1);
|
|
1248
|
+
|
|
1018
1249
|
_react2.fireEvent.change(input, {
|
|
1019
1250
|
target: {
|
|
1020
1251
|
value: "["
|
|
1021
1252
|
}
|
|
1022
1253
|
});
|
|
1254
|
+
|
|
1023
1255
|
expect(list).toBeTruthy();
|
|
1024
1256
|
expect(getAllByText("[").length).toBe(1);
|
|
1257
|
+
|
|
1025
1258
|
_react2.fireEvent.change(input, {
|
|
1026
1259
|
target: {
|
|
1027
1260
|
value: "]"
|
|
1028
1261
|
}
|
|
1029
1262
|
});
|
|
1263
|
+
|
|
1030
1264
|
expect(list).toBeTruthy();
|
|
1031
1265
|
expect(getAllByText("]").length).toBe(1);
|
|
1266
|
+
|
|
1032
1267
|
_react2.fireEvent.change(input, {
|
|
1033
1268
|
target: {
|
|
1034
1269
|
value: "+"
|
|
1035
1270
|
}
|
|
1036
1271
|
});
|
|
1272
|
+
|
|
1037
1273
|
expect(list).toBeTruthy();
|
|
1038
1274
|
expect(getAllByText("+").length).toBe(1);
|
|
1275
|
+
|
|
1039
1276
|
_react2.fireEvent.change(input, {
|
|
1040
1277
|
target: {
|
|
1041
1278
|
value: "?"
|
|
1042
1279
|
}
|
|
1043
1280
|
});
|
|
1281
|
+
|
|
1044
1282
|
expect(list).toBeTruthy();
|
|
1045
1283
|
expect(getAllByText("?").length).toBe(1);
|
|
1046
1284
|
});
|
|
@@ -1048,60 +1286,73 @@ describe("TextInput component synchronous autosuggest tests", function () {
|
|
|
1048
1286
|
describe("TextInput component asynchronous autosuggest tests", function () {
|
|
1049
1287
|
test("Autosuggest 'Searching...' message is shown", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
1050
1288
|
var callbackFunc, onChange, _render38, getByRole, getByText, input;
|
|
1289
|
+
|
|
1051
1290
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
1052
|
-
while (1)
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1291
|
+
while (1) {
|
|
1292
|
+
switch (_context.prev = _context.next) {
|
|
1293
|
+
case 0:
|
|
1294
|
+
callbackFunc = jest.fn(function (newValue) {
|
|
1295
|
+
var result = new Promise(function (resolve) {
|
|
1296
|
+
return setTimeout(function () {
|
|
1297
|
+
resolve(newValue ? countries.filter(function (option) {
|
|
1298
|
+
return option.toUpperCase().includes(newValue.toUpperCase());
|
|
1299
|
+
}) : countries);
|
|
1300
|
+
}, 100);
|
|
1301
|
+
});
|
|
1302
|
+
return result;
|
|
1303
|
+
});
|
|
1304
|
+
onChange = jest.fn();
|
|
1305
|
+
_render38 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
1306
|
+
label: "Autosuggest Countries",
|
|
1307
|
+
suggestions: callbackFunc,
|
|
1308
|
+
onChange: onChange
|
|
1309
|
+
})), getByRole = _render38.getByRole, getByText = _render38.getByText;
|
|
1310
|
+
input = getByRole("combobox");
|
|
1311
|
+
|
|
1312
|
+
_react2.fireEvent.focus(input);
|
|
1313
|
+
|
|
1314
|
+
expect(getByRole("listbox")).toBeTruthy();
|
|
1315
|
+
_context.next = 8;
|
|
1316
|
+
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1317
|
+
return getByText("Searching...");
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
case 8:
|
|
1321
|
+
expect(getByText("Afghanistan")).toBeTruthy();
|
|
1322
|
+
expect(getByText("Albania")).toBeTruthy();
|
|
1323
|
+
expect(getByText("Algeria")).toBeTruthy();
|
|
1324
|
+
expect(getByText("Andorra")).toBeTruthy();
|
|
1325
|
+
|
|
1326
|
+
_userEvent["default"].type(input, "Ab");
|
|
1327
|
+
|
|
1328
|
+
_context.next = 15;
|
|
1329
|
+
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1330
|
+
return getByText("Searching...");
|
|
1331
|
+
});
|
|
1332
|
+
|
|
1333
|
+
case 15:
|
|
1334
|
+
expect(getByText("Cabo Verde")).toBeTruthy();
|
|
1335
|
+
|
|
1336
|
+
_react2.fireEvent.keyDown(input, {
|
|
1337
|
+
key: "ArrowUp",
|
|
1338
|
+
code: "ArrowUp",
|
|
1339
|
+
keyCode: 38,
|
|
1340
|
+
charCode: 38
|
|
1061
1341
|
});
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
});
|
|
1077
|
-
case 8:
|
|
1078
|
-
expect(getByText("Afghanistan")).toBeTruthy();
|
|
1079
|
-
expect(getByText("Albania")).toBeTruthy();
|
|
1080
|
-
expect(getByText("Algeria")).toBeTruthy();
|
|
1081
|
-
expect(getByText("Andorra")).toBeTruthy();
|
|
1082
|
-
_userEvent["default"].type(input, "Ab");
|
|
1083
|
-
_context.next = 15;
|
|
1084
|
-
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1085
|
-
return getByText("Searching...");
|
|
1086
|
-
});
|
|
1087
|
-
case 15:
|
|
1088
|
-
expect(getByText("Cabo Verde")).toBeTruthy();
|
|
1089
|
-
_react2.fireEvent.keyDown(input, {
|
|
1090
|
-
key: "ArrowUp",
|
|
1091
|
-
code: "ArrowUp",
|
|
1092
|
-
keyCode: 38,
|
|
1093
|
-
charCode: 38
|
|
1094
|
-
});
|
|
1095
|
-
_react2.fireEvent.keyDown(input, {
|
|
1096
|
-
key: "Enter",
|
|
1097
|
-
code: "Enter",
|
|
1098
|
-
keyCode: 13,
|
|
1099
|
-
charCode: 13
|
|
1100
|
-
});
|
|
1101
|
-
expect(input.value).toBe("Cabo Verde");
|
|
1102
|
-
case 19:
|
|
1103
|
-
case "end":
|
|
1104
|
-
return _context.stop();
|
|
1342
|
+
|
|
1343
|
+
_react2.fireEvent.keyDown(input, {
|
|
1344
|
+
key: "Enter",
|
|
1345
|
+
code: "Enter",
|
|
1346
|
+
keyCode: 13,
|
|
1347
|
+
charCode: 13
|
|
1348
|
+
});
|
|
1349
|
+
|
|
1350
|
+
expect(input.value).toBe("Cabo Verde");
|
|
1351
|
+
|
|
1352
|
+
case 19:
|
|
1353
|
+
case "end":
|
|
1354
|
+
return _context.stop();
|
|
1355
|
+
}
|
|
1105
1356
|
}
|
|
1106
1357
|
}, _callee);
|
|
1107
1358
|
})));
|
|
@@ -1117,287 +1368,355 @@ describe("TextInput component asynchronous autosuggest tests", function () {
|
|
|
1117
1368
|
return result;
|
|
1118
1369
|
});
|
|
1119
1370
|
var onChange = jest.fn();
|
|
1371
|
+
|
|
1120
1372
|
var _render39 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1373
|
+
label: "Autosuggest Countries",
|
|
1374
|
+
suggestions: callbackFunc,
|
|
1375
|
+
onChange: onChange
|
|
1376
|
+
})),
|
|
1377
|
+
getByRole = _render39.getByRole,
|
|
1378
|
+
queryByText = _render39.queryByText,
|
|
1379
|
+
queryByRole = _render39.queryByRole;
|
|
1380
|
+
|
|
1128
1381
|
var input = getByRole("combobox");
|
|
1382
|
+
|
|
1129
1383
|
_react2.fireEvent.focus(input);
|
|
1384
|
+
|
|
1130
1385
|
expect(getByRole("listbox")).toBeTruthy();
|
|
1386
|
+
|
|
1131
1387
|
_userEvent["default"].type(input, "Ab");
|
|
1388
|
+
|
|
1132
1389
|
_react2.fireEvent.keyDown(input, {
|
|
1133
1390
|
key: "Esc",
|
|
1134
1391
|
code: "Esc",
|
|
1135
1392
|
keyCode: 27,
|
|
1136
1393
|
charCode: 27
|
|
1137
1394
|
});
|
|
1395
|
+
|
|
1138
1396
|
expect(queryByRole("listbox")).toBeFalsy();
|
|
1139
1397
|
expect(queryByText("Searching...")).toBeFalsy();
|
|
1140
1398
|
expect(input.value).toBe("");
|
|
1141
1399
|
});
|
|
1142
1400
|
test("Autosuggest Esc + arrow down working while 'Searching...' message is shown", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
1143
1401
|
var callbackFunc, onChange, _render40, getByRole, getByText, queryByText, queryByRole, input, list;
|
|
1402
|
+
|
|
1144
1403
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
1145
|
-
while (1)
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1404
|
+
while (1) {
|
|
1405
|
+
switch (_context2.prev = _context2.next) {
|
|
1406
|
+
case 0:
|
|
1407
|
+
callbackFunc = jest.fn(function (newValue) {
|
|
1408
|
+
var result = new Promise(function (resolve) {
|
|
1409
|
+
return setTimeout(function () {
|
|
1410
|
+
resolve(newValue ? countries.filter(function (option) {
|
|
1411
|
+
return option.toUpperCase().includes(newValue.toUpperCase());
|
|
1412
|
+
}) : countries);
|
|
1413
|
+
}, 100);
|
|
1414
|
+
});
|
|
1415
|
+
return result;
|
|
1416
|
+
});
|
|
1417
|
+
onChange = jest.fn();
|
|
1418
|
+
_render40 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
1419
|
+
label: "Autosuggest Countries",
|
|
1420
|
+
suggestions: callbackFunc,
|
|
1421
|
+
onChange: onChange
|
|
1422
|
+
})), getByRole = _render40.getByRole, getByText = _render40.getByText, queryByText = _render40.queryByText, queryByRole = _render40.queryByRole;
|
|
1423
|
+
input = getByRole("combobox");
|
|
1424
|
+
|
|
1425
|
+
_react2.fireEvent.focus(input);
|
|
1426
|
+
|
|
1427
|
+
list = getByRole("listbox");
|
|
1428
|
+
expect(list).toBeTruthy();
|
|
1429
|
+
|
|
1430
|
+
_userEvent["default"].type(input, "Ab");
|
|
1431
|
+
|
|
1432
|
+
_react2.fireEvent.keyDown(input, {
|
|
1433
|
+
key: "Esc",
|
|
1434
|
+
code: "Esc",
|
|
1435
|
+
keyCode: 27,
|
|
1436
|
+
charCode: 27
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1439
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
1440
|
+
expect(queryByText("Searching...")).toBeFalsy();
|
|
1441
|
+
expect(input.value).toBe("");
|
|
1442
|
+
|
|
1443
|
+
_react2.fireEvent.keyDown(input, {
|
|
1444
|
+
key: "ArrowDown",
|
|
1445
|
+
code: "ArrowDown",
|
|
1446
|
+
keyCode: 40,
|
|
1447
|
+
charCode: 40
|
|
1448
|
+
});
|
|
1449
|
+
|
|
1450
|
+
expect(list).toBeTruthy();
|
|
1451
|
+
_context2.next = 16;
|
|
1452
|
+
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1453
|
+
return getByText("Searching...");
|
|
1154
1454
|
});
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
expect(list).toBeTruthy();
|
|
1167
|
-
_userEvent["default"].type(input, "Ab");
|
|
1168
|
-
_react2.fireEvent.keyDown(input, {
|
|
1169
|
-
key: "Esc",
|
|
1170
|
-
code: "Esc",
|
|
1171
|
-
keyCode: 27,
|
|
1172
|
-
charCode: 27
|
|
1173
|
-
});
|
|
1174
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
1175
|
-
expect(queryByText("Searching...")).toBeFalsy();
|
|
1176
|
-
expect(input.value).toBe("");
|
|
1177
|
-
_react2.fireEvent.keyDown(input, {
|
|
1178
|
-
key: "ArrowDown",
|
|
1179
|
-
code: "ArrowDown",
|
|
1180
|
-
keyCode: 40,
|
|
1181
|
-
charCode: 40
|
|
1182
|
-
});
|
|
1183
|
-
expect(list).toBeTruthy();
|
|
1184
|
-
_context2.next = 16;
|
|
1185
|
-
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1186
|
-
return getByText("Searching...");
|
|
1187
|
-
});
|
|
1188
|
-
case 16:
|
|
1189
|
-
expect(getByText("Afghanistan")).toBeTruthy();
|
|
1190
|
-
expect(getByText("Albania")).toBeTruthy();
|
|
1191
|
-
expect(getByText("Algeria")).toBeTruthy();
|
|
1192
|
-
expect(getByText("Andorra")).toBeTruthy();
|
|
1193
|
-
case 20:
|
|
1194
|
-
case "end":
|
|
1195
|
-
return _context2.stop();
|
|
1455
|
+
|
|
1456
|
+
case 16:
|
|
1457
|
+
expect(getByText("Afghanistan")).toBeTruthy();
|
|
1458
|
+
expect(getByText("Albania")).toBeTruthy();
|
|
1459
|
+
expect(getByText("Algeria")).toBeTruthy();
|
|
1460
|
+
expect(getByText("Andorra")).toBeTruthy();
|
|
1461
|
+
|
|
1462
|
+
case 20:
|
|
1463
|
+
case "end":
|
|
1464
|
+
return _context2.stop();
|
|
1465
|
+
}
|
|
1196
1466
|
}
|
|
1197
1467
|
}, _callee2);
|
|
1198
1468
|
})));
|
|
1199
1469
|
test("Asynchronous uncontrolled autosuggest test", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
|
1200
1470
|
var callbackFunc, onChange, _render41, getByRole, getByText, input;
|
|
1471
|
+
|
|
1201
1472
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
1202
|
-
while (1)
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1473
|
+
while (1) {
|
|
1474
|
+
switch (_context3.prev = _context3.next) {
|
|
1475
|
+
case 0:
|
|
1476
|
+
callbackFunc = jest.fn(function (newValue) {
|
|
1477
|
+
var result = new Promise(function (resolve) {
|
|
1478
|
+
return setTimeout(function () {
|
|
1479
|
+
resolve(newValue ? countries.filter(function (option) {
|
|
1480
|
+
return option.toUpperCase().includes(newValue.toUpperCase());
|
|
1481
|
+
}) : countries);
|
|
1482
|
+
}, 100);
|
|
1483
|
+
});
|
|
1484
|
+
return result;
|
|
1211
1485
|
});
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
return
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1486
|
+
onChange = jest.fn();
|
|
1487
|
+
_render41 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
1488
|
+
label: "Autosuggest Countries",
|
|
1489
|
+
onChange: onChange,
|
|
1490
|
+
suggestions: callbackFunc
|
|
1491
|
+
})), getByRole = _render41.getByRole, getByText = _render41.getByText;
|
|
1492
|
+
input = getByRole("combobox");
|
|
1493
|
+
|
|
1494
|
+
_react2.fireEvent.focus(input);
|
|
1495
|
+
|
|
1496
|
+
_userEvent["default"].type(input, "Den");
|
|
1497
|
+
|
|
1498
|
+
_context3.next = 8;
|
|
1499
|
+
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1500
|
+
return getByText("Searching...");
|
|
1501
|
+
});
|
|
1502
|
+
|
|
1503
|
+
case 8:
|
|
1504
|
+
expect(getByText("Denmark")).toBeTruthy();
|
|
1505
|
+
|
|
1506
|
+
_userEvent["default"].click(getByRole("option"));
|
|
1507
|
+
|
|
1508
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
1509
|
+
value: "Denmark"
|
|
1510
|
+
});
|
|
1511
|
+
expect(input.value).toBe("Denmark");
|
|
1512
|
+
|
|
1513
|
+
case 12:
|
|
1514
|
+
case "end":
|
|
1515
|
+
return _context3.stop();
|
|
1516
|
+
}
|
|
1237
1517
|
}
|
|
1238
1518
|
}, _callee3);
|
|
1239
1519
|
})));
|
|
1240
1520
|
test("Asynchronous controlled autosuggest test", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
1241
1521
|
var callbackFunc, onChange, _render42, getByRole, getByText, queryByRole, input;
|
|
1522
|
+
|
|
1242
1523
|
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
1243
|
-
while (1)
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1524
|
+
while (1) {
|
|
1525
|
+
switch (_context4.prev = _context4.next) {
|
|
1526
|
+
case 0:
|
|
1527
|
+
callbackFunc = jest.fn(function (newValue) {
|
|
1528
|
+
var result = new Promise(function (resolve) {
|
|
1529
|
+
return setTimeout(function () {
|
|
1530
|
+
resolve(newValue ? countries.filter(function (option) {
|
|
1531
|
+
return option.toUpperCase().includes(newValue.toUpperCase());
|
|
1532
|
+
}) : countries);
|
|
1533
|
+
}, 100);
|
|
1534
|
+
});
|
|
1535
|
+
return result;
|
|
1536
|
+
});
|
|
1537
|
+
onChange = jest.fn();
|
|
1538
|
+
_render42 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
1539
|
+
label: "Autosuggest Countries",
|
|
1540
|
+
value: "Denm",
|
|
1541
|
+
onChange: onChange,
|
|
1542
|
+
suggestions: callbackFunc
|
|
1543
|
+
})), getByRole = _render42.getByRole, getByText = _render42.getByText, queryByRole = _render42.queryByRole;
|
|
1544
|
+
input = getByRole("combobox");
|
|
1545
|
+
expect(input.value).toBe("Denm");
|
|
1546
|
+
|
|
1547
|
+
_userEvent["default"].click(getByText("Autosuggest Countries"));
|
|
1548
|
+
|
|
1549
|
+
_context4.next = 8;
|
|
1550
|
+
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1551
|
+
return getByText("Searching...");
|
|
1552
|
+
});
|
|
1553
|
+
|
|
1554
|
+
case 8:
|
|
1555
|
+
expect(getByText("Denmark")).toBeTruthy();
|
|
1556
|
+
|
|
1557
|
+
_react2.fireEvent.focus(getByRole("option"));
|
|
1558
|
+
|
|
1559
|
+
_userEvent["default"].click(getByText("Denmark"));
|
|
1560
|
+
|
|
1561
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
1562
|
+
value: "Denmark"
|
|
1252
1563
|
});
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
onChange: onChange,
|
|
1260
|
-
suggestions: callbackFunc
|
|
1261
|
-
})), getByRole = _render42.getByRole, getByText = _render42.getByText, queryByRole = _render42.queryByRole;
|
|
1262
|
-
input = getByRole("combobox");
|
|
1263
|
-
expect(input.value).toBe("Denm");
|
|
1264
|
-
_userEvent["default"].click(getByText("Autosuggest Countries"));
|
|
1265
|
-
_context4.next = 8;
|
|
1266
|
-
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1267
|
-
return getByText("Searching...");
|
|
1268
|
-
});
|
|
1269
|
-
case 8:
|
|
1270
|
-
expect(getByText("Denmark")).toBeTruthy();
|
|
1271
|
-
_react2.fireEvent.focus(getByRole("option"));
|
|
1272
|
-
_userEvent["default"].click(getByText("Denmark"));
|
|
1273
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
1274
|
-
value: "Denmark"
|
|
1275
|
-
});
|
|
1276
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
1277
|
-
case 13:
|
|
1278
|
-
case "end":
|
|
1279
|
-
return _context4.stop();
|
|
1564
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
1565
|
+
|
|
1566
|
+
case 13:
|
|
1567
|
+
case "end":
|
|
1568
|
+
return _context4.stop();
|
|
1569
|
+
}
|
|
1280
1570
|
}
|
|
1281
1571
|
}, _callee4);
|
|
1282
1572
|
})));
|
|
1283
1573
|
test("Asynchronous autosuggest closes the listbox after finishing no matches search", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
|
|
1284
1574
|
var callbackFunc, onChange, _render43, getByText, getByRole, queryByRole, input;
|
|
1575
|
+
|
|
1285
1576
|
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
1286
|
-
while (1)
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1577
|
+
while (1) {
|
|
1578
|
+
switch (_context5.prev = _context5.next) {
|
|
1579
|
+
case 0:
|
|
1580
|
+
callbackFunc = jest.fn(function (newValue) {
|
|
1581
|
+
var result = new Promise(function (resolve) {
|
|
1582
|
+
return setTimeout(function () {
|
|
1583
|
+
resolve(newValue ? countries.filter(function (option) {
|
|
1584
|
+
return option.toUpperCase().includes(newValue.toUpperCase());
|
|
1585
|
+
}) : countries);
|
|
1586
|
+
}, 100);
|
|
1587
|
+
});
|
|
1588
|
+
return result;
|
|
1295
1589
|
});
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
return
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1590
|
+
onChange = jest.fn();
|
|
1591
|
+
_render43 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
1592
|
+
label: "Autosuggest Countries",
|
|
1593
|
+
onChange: onChange,
|
|
1594
|
+
suggestions: callbackFunc
|
|
1595
|
+
})), getByText = _render43.getByText, getByRole = _render43.getByRole, queryByRole = _render43.queryByRole;
|
|
1596
|
+
input = getByRole("combobox");
|
|
1597
|
+
|
|
1598
|
+
_react2.fireEvent.focus(input);
|
|
1599
|
+
|
|
1600
|
+
_userEvent["default"].type(input, "Example text");
|
|
1601
|
+
|
|
1602
|
+
_context5.next = 8;
|
|
1603
|
+
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1604
|
+
return getByText("Searching...");
|
|
1605
|
+
});
|
|
1606
|
+
|
|
1607
|
+
case 8:
|
|
1608
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
1609
|
+
|
|
1610
|
+
case 9:
|
|
1611
|
+
case "end":
|
|
1612
|
+
return _context5.stop();
|
|
1613
|
+
}
|
|
1316
1614
|
}
|
|
1317
1615
|
}, _callee5);
|
|
1318
1616
|
})));
|
|
1319
1617
|
test("Asynchronous autosuggest with no matches founded doesn't let the listbox to be opened", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() {
|
|
1320
1618
|
var callbackFunc, onChange, _render44, getByText, getByRole, queryByRole, input;
|
|
1619
|
+
|
|
1321
1620
|
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
1322
|
-
while (1)
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1621
|
+
while (1) {
|
|
1622
|
+
switch (_context6.prev = _context6.next) {
|
|
1623
|
+
case 0:
|
|
1624
|
+
callbackFunc = jest.fn(function (newValue) {
|
|
1625
|
+
var result = new Promise(function (resolve) {
|
|
1626
|
+
return setTimeout(function () {
|
|
1627
|
+
resolve(newValue ? countries.filter(function (option) {
|
|
1628
|
+
return option.toUpperCase().includes(newValue.toUpperCase());
|
|
1629
|
+
}) : countries);
|
|
1630
|
+
}, 100);
|
|
1631
|
+
});
|
|
1632
|
+
return result;
|
|
1331
1633
|
});
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
return
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1634
|
+
onChange = jest.fn();
|
|
1635
|
+
_render44 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
1636
|
+
label: "Autosuggest Countries",
|
|
1637
|
+
onChange: onChange,
|
|
1638
|
+
suggestions: callbackFunc
|
|
1639
|
+
})), getByText = _render44.getByText, getByRole = _render44.getByRole, queryByRole = _render44.queryByRole;
|
|
1640
|
+
input = getByRole("combobox");
|
|
1641
|
+
|
|
1642
|
+
_react2.fireEvent.focus(input);
|
|
1643
|
+
|
|
1644
|
+
_userEvent["default"].type(input, "wrong");
|
|
1645
|
+
|
|
1646
|
+
_context6.next = 8;
|
|
1647
|
+
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1648
|
+
return getByText("Searching...");
|
|
1649
|
+
});
|
|
1650
|
+
|
|
1651
|
+
case 8:
|
|
1652
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
1653
|
+
|
|
1654
|
+
_react2.fireEvent.focus(input);
|
|
1655
|
+
|
|
1656
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
1657
|
+
|
|
1658
|
+
_react2.fireEvent.keyDown(input, {
|
|
1659
|
+
key: "ArrowUp",
|
|
1660
|
+
code: "ArrowUp",
|
|
1661
|
+
keyCode: 38,
|
|
1662
|
+
charCode: 38
|
|
1663
|
+
});
|
|
1664
|
+
|
|
1665
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
1666
|
+
|
|
1667
|
+
_react2.fireEvent.keyDown(input, {
|
|
1668
|
+
key: "ArrowDown",
|
|
1669
|
+
code: "ArrowDown",
|
|
1670
|
+
keyCode: 40,
|
|
1671
|
+
charCode: 40
|
|
1672
|
+
});
|
|
1673
|
+
|
|
1674
|
+
expect(queryByRole("listbox")).toBeFalsy();
|
|
1675
|
+
|
|
1676
|
+
case 15:
|
|
1677
|
+
case "end":
|
|
1678
|
+
return _context6.stop();
|
|
1679
|
+
}
|
|
1368
1680
|
}
|
|
1369
1681
|
}, _callee6);
|
|
1370
1682
|
})));
|
|
1371
1683
|
test("Asynchronous autosuggest request failed, shows 'Error fetching data' message", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
|
|
1372
1684
|
var errorCallbackFunc, onChange, _render45, getByRole, getByText, input;
|
|
1685
|
+
|
|
1373
1686
|
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
1374
|
-
while (1)
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1687
|
+
while (1) {
|
|
1688
|
+
switch (_context7.prev = _context7.next) {
|
|
1689
|
+
case 0:
|
|
1690
|
+
errorCallbackFunc = jest.fn(function () {
|
|
1691
|
+
var result = new Promise(function (resolve, reject) {
|
|
1692
|
+
return setTimeout(function () {
|
|
1693
|
+
reject("err");
|
|
1694
|
+
}, 100);
|
|
1695
|
+
});
|
|
1696
|
+
return result;
|
|
1381
1697
|
});
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1698
|
+
onChange = jest.fn();
|
|
1699
|
+
_render45 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_TextInput["default"], {
|
|
1700
|
+
label: "Autosuggest Countries",
|
|
1701
|
+
onChange: onChange,
|
|
1702
|
+
suggestions: errorCallbackFunc
|
|
1703
|
+
})), getByRole = _render45.getByRole, getByText = _render45.getByText;
|
|
1704
|
+
input = getByRole("combobox");
|
|
1705
|
+
|
|
1706
|
+
_react2.fireEvent.focus(input);
|
|
1707
|
+
|
|
1708
|
+
_context7.next = 7;
|
|
1709
|
+
return (0, _react2.waitForElementToBeRemoved)(function () {
|
|
1710
|
+
return getByText("Searching...");
|
|
1711
|
+
});
|
|
1712
|
+
|
|
1713
|
+
case 7:
|
|
1714
|
+
expect(getByText("Error fetching data")).toBeTruthy();
|
|
1715
|
+
|
|
1716
|
+
case 8:
|
|
1717
|
+
case "end":
|
|
1718
|
+
return _context7.stop();
|
|
1719
|
+
}
|
|
1401
1720
|
}
|
|
1402
1721
|
}, _callee7);
|
|
1403
1722
|
})));
|