@react-aria/test-utils 1.0.0-alpha.3 → 1.0.0-alpha.5
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/combobox.main.js +116 -82
- package/dist/combobox.main.js.map +1 -1
- package/dist/combobox.mjs +117 -83
- package/dist/combobox.module.js +117 -83
- package/dist/combobox.module.js.map +1 -1
- package/dist/events.main.js +42 -4
- package/dist/events.main.js.map +1 -1
- package/dist/events.mjs +42 -4
- package/dist/events.module.js +42 -4
- package/dist/events.module.js.map +1 -1
- package/dist/gridlist.main.js +102 -59
- package/dist/gridlist.main.js.map +1 -1
- package/dist/gridlist.mjs +103 -60
- package/dist/gridlist.module.js +103 -60
- package/dist/gridlist.module.js.map +1 -1
- package/dist/listbox.main.js +135 -0
- package/dist/listbox.main.js.map +1 -0
- package/dist/listbox.mjs +130 -0
- package/dist/listbox.module.js +130 -0
- package/dist/listbox.module.js.map +1 -0
- package/dist/main.js.map +1 -1
- package/dist/menu.main.js +195 -161
- package/dist/menu.main.js.map +1 -1
- package/dist/menu.mjs +196 -162
- package/dist/menu.module.js +196 -162
- package/dist/menu.module.js.map +1 -1
- package/dist/module.js.map +1 -1
- package/dist/select.main.js +116 -70
- package/dist/select.main.js.map +1 -1
- package/dist/select.mjs +117 -71
- package/dist/select.module.js +117 -71
- package/dist/select.module.js.map +1 -1
- package/dist/table.main.js +166 -139
- package/dist/table.main.js.map +1 -1
- package/dist/table.mjs +167 -140
- package/dist/table.module.js +167 -140
- package/dist/table.module.js.map +1 -1
- package/dist/tabs.main.js +133 -0
- package/dist/tabs.main.js.map +1 -0
- package/dist/tabs.mjs +128 -0
- package/dist/tabs.module.js +128 -0
- package/dist/tabs.module.js.map +1 -0
- package/dist/tree.main.js +165 -0
- package/dist/tree.main.js.map +1 -0
- package/dist/tree.mjs +160 -0
- package/dist/tree.module.js +160 -0
- package/dist/tree.module.js.map +1 -0
- package/dist/types.d.ts +607 -145
- package/dist/types.d.ts.map +1 -1
- package/dist/user.main.js +15 -4
- package/dist/user.main.js.map +1 -1
- package/dist/user.mjs +15 -4
- package/dist/user.module.js +15 -4
- package/dist/user.module.js.map +1 -1
- package/package.json +3 -4
- package/src/combobox.ts +105 -36
- package/src/events.ts +29 -4
- package/src/gridlist.ts +146 -59
- package/src/index.ts +1 -1
- package/src/listbox.ts +226 -0
- package/src/menu.ts +152 -62
- package/src/select.ts +137 -44
- package/src/table.ts +130 -69
- package/src/tabs.ts +198 -0
- package/src/tree.ts +248 -0
- package/src/types.ts +133 -0
- package/src/user.ts +62 -37
package/dist/menu.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import {act as $gS6KO$act, waitFor as $gS6KO$waitFor, within as $gS6KO$within} from "@testing-library/react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* Copyright 2024 Adobe. All rights reserved.
|
|
@@ -14,186 +14,220 @@ import {within as $gS6KO$within, act as $gS6KO$act, waitFor as $gS6KO$waitFor} f
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
class $74b93f0617179929$export$f73bbc9212ed861e {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Set the interaction type used by the menu tester.
|
|
19
|
+
*/ setInteractionType(type) {
|
|
20
|
+
this._interactionType = type;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
// TODO: this has been common to select as well, maybe make select use it? Or make a generic method. Will need to make error messages generic
|
|
23
|
+
// One difference will be that it supports long press as well
|
|
24
|
+
/**
|
|
25
|
+
* Opens the menu. Defaults to using the interaction type set on the menu tester.
|
|
26
|
+
*/ async open(opts = {}) {
|
|
27
|
+
let { needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType, direction: direction } = opts;
|
|
28
|
+
let trigger = this.trigger;
|
|
29
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
30
|
+
if (interactionType === 'mouse' || interactionType === 'touch') {
|
|
31
|
+
if (needsLongPress) {
|
|
32
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
33
|
+
let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';
|
|
34
|
+
await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
|
|
35
|
+
element: trigger,
|
|
36
|
+
advanceTimer: this._advanceTimer,
|
|
37
|
+
pointerOpts: {
|
|
38
|
+
pointerType: pointerType
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
} else if (interactionType === 'mouse') await this.user.click(trigger);
|
|
42
|
+
else await this.user.pointer({
|
|
43
|
+
target: trigger,
|
|
44
|
+
keys: '[TouchA]'
|
|
45
|
+
});
|
|
46
|
+
} else if (interactionType === 'keyboard' && !isDisabled) {
|
|
47
|
+
if (direction === 'up') {
|
|
48
|
+
(0, $gS6KO$act)(()=>trigger.focus());
|
|
49
|
+
await this.user.keyboard('[ArrowUp]');
|
|
50
|
+
} else if (direction === 'down') {
|
|
51
|
+
(0, $gS6KO$act)(()=>trigger.focus());
|
|
52
|
+
await this.user.keyboard('[ArrowDown]');
|
|
53
|
+
} else {
|
|
54
|
+
(0, $gS6KO$act)(()=>trigger.focus());
|
|
55
|
+
await this.user.keyboard('[Enter]');
|
|
33
56
|
}
|
|
34
57
|
}
|
|
35
|
-
|
|
58
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
59
|
+
if (trigger.getAttribute('aria-controls') == null && !isDisabled) throw new Error('No aria-controls found on menu trigger element.');
|
|
60
|
+
else return true;
|
|
61
|
+
});
|
|
62
|
+
if (!isDisabled) {
|
|
63
|
+
let menuId = trigger.getAttribute('aria-controls');
|
|
64
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
65
|
+
if (!menuId || document.getElementById(menuId) == null) throw new Error(`Menu with id of ${menuId} not found in document.`);
|
|
66
|
+
else return true;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
36
69
|
}
|
|
37
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Returns a option matching the specified index or text content.
|
|
72
|
+
*/ findOption(opts) {
|
|
73
|
+
let { optionIndexOrText: optionIndexOrText } = opts;
|
|
74
|
+
let option;
|
|
75
|
+
let options = this.options();
|
|
38
76
|
let menu = this.menu;
|
|
39
|
-
if (
|
|
40
|
-
else
|
|
41
|
-
|
|
42
|
-
get submenuTriggers() {
|
|
43
|
-
let options = this.options;
|
|
44
|
-
if (options.length > 0) return this.options.filter((item)=>item.getAttribute('aria-haspopup') != null);
|
|
45
|
-
return [];
|
|
77
|
+
if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
|
|
78
|
+
else if (typeof optionIndexOrText === 'string' && menu != null) option = (0, $gS6KO$within)(menu).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]');
|
|
79
|
+
return option;
|
|
46
80
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
else await this.user.pointer({
|
|
71
|
-
target: trigger,
|
|
72
|
-
keys: '[TouchA]'
|
|
81
|
+
// TODO: also very similar to select, barring potential long press support
|
|
82
|
+
// Close on select is also kinda specific?
|
|
83
|
+
/**
|
|
84
|
+
* Selects the desired menu option. Defaults to using the interaction type set on the menu tester. If necessary, will open the menu dropdown beforehand.
|
|
85
|
+
* The desired option can be targeted via the option's node, the option's text, or the option's index.
|
|
86
|
+
*/ async selectOption(opts) {
|
|
87
|
+
let { menuSelectionMode: menuSelectionMode = 'single', needsLongPress: needsLongPress, closesOnSelect: closesOnSelect = true, option: option, interactionType: interactionType = this._interactionType, keyboardActivation: keyboardActivation = 'Enter' } = opts;
|
|
88
|
+
let trigger = this.trigger;
|
|
89
|
+
if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) await this.open({
|
|
90
|
+
needsLongPress: needsLongPress
|
|
91
|
+
});
|
|
92
|
+
let menu = this.menu;
|
|
93
|
+
if (!menu) throw new Error('Menu not found.');
|
|
94
|
+
if (menu) {
|
|
95
|
+
if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
|
|
96
|
+
optionIndexOrText: option
|
|
97
|
+
});
|
|
98
|
+
if (!option) throw new Error('Target option not found in the menu.');
|
|
99
|
+
if (interactionType === 'keyboard') {
|
|
100
|
+
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
101
|
+
if (document.activeElement !== menu || !menu.contains(document.activeElement)) (0, $gS6KO$act)(()=>menu.focus());
|
|
102
|
+
await this.keyboardNavigateToOption({
|
|
103
|
+
option: option
|
|
73
104
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
(0, $gS6KO$act)(()=>trigger.focus());
|
|
83
|
-
await this.user.keyboard('[Enter]');
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
await (0, $gS6KO$waitFor)(()=>{
|
|
87
|
-
if (trigger.getAttribute('aria-controls') == null && !isDisabled) throw new Error('No aria-controls found on menu trigger element.');
|
|
88
|
-
else return true;
|
|
105
|
+
await this.user.keyboard(`[${keyboardActivation}]`);
|
|
106
|
+
} else if (interactionType === 'mouse') await this.user.click(option);
|
|
107
|
+
else await this.user.pointer({
|
|
108
|
+
target: option,
|
|
109
|
+
keys: '[TouchA]'
|
|
110
|
+
});
|
|
111
|
+
(0, $gS6KO$act)(()=>{
|
|
112
|
+
jest.runAllTimers();
|
|
89
113
|
});
|
|
90
|
-
if (!
|
|
91
|
-
let menuId = trigger.getAttribute('aria-controls');
|
|
114
|
+
if (option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect && keyboardActivation !== 'Space' && !this._isSubmenu) {
|
|
92
115
|
await (0, $gS6KO$waitFor)(()=>{
|
|
93
|
-
if (
|
|
116
|
+
if (document.activeElement !== trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the menu trigger but got ${document.activeElement}`);
|
|
94
117
|
else return true;
|
|
95
118
|
});
|
|
119
|
+
if (document.contains(menu)) throw new Error('Expected menu element to not be in the document after selecting an option');
|
|
96
120
|
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
121
|
+
} else throw new Error("Attempted to select a option in the menu, but menu wasn't found.");
|
|
122
|
+
}
|
|
123
|
+
// TODO: update this to remove needsLongPress if we wanna make the user call open first always
|
|
124
|
+
/**
|
|
125
|
+
* Opens the submenu. Defaults to using the interaction type set on the menu tester. The submenu trigger can be targeted via the trigger's node or the trigger's text.
|
|
126
|
+
*/ async openSubmenu(opts) {
|
|
127
|
+
let { submenuTrigger: submenuTrigger, needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
|
|
128
|
+
let trigger = this.trigger;
|
|
129
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
130
|
+
if (!trigger.getAttribute('aria-controls') && !isDisabled) await this.open({
|
|
131
|
+
needsLongPress: needsLongPress
|
|
132
|
+
});
|
|
133
|
+
if (!isDisabled) {
|
|
106
134
|
let menu = this.menu;
|
|
107
135
|
if (menu) {
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
await this.user.keyboard(`[${keyboardActivation}]`);
|
|
116
|
-
} else if (interactionType === 'mouse') await this.user.click(option);
|
|
117
|
-
else await this.user.pointer({
|
|
118
|
-
target: option,
|
|
119
|
-
keys: '[TouchA]'
|
|
120
|
-
});
|
|
121
|
-
(0, $gS6KO$act)(()=>{
|
|
122
|
-
jest.runAllTimers();
|
|
136
|
+
if (typeof submenuTrigger === 'string') submenuTrigger = (0, $gS6KO$within)(menu).getByText(submenuTrigger).closest('[role=menuitem]');
|
|
137
|
+
let submenuTriggerTester = new $74b93f0617179929$export$f73bbc9212ed861e({
|
|
138
|
+
user: this.user,
|
|
139
|
+
interactionType: this._interactionType,
|
|
140
|
+
root: submenuTrigger,
|
|
141
|
+
isSubmenu: true
|
|
123
142
|
});
|
|
124
|
-
if (
|
|
125
|
-
await (
|
|
126
|
-
|
|
127
|
-
else return true;
|
|
143
|
+
if (interactionType === 'mouse') {
|
|
144
|
+
await this.user.pointer({
|
|
145
|
+
target: submenuTrigger
|
|
128
146
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
} else throw new Error("Attempted to select a option in the menu, but menu wasn't found.");
|
|
132
|
-
};
|
|
133
|
-
// TODO: update this to remove needsLongPress if we wanna make the user call open first always
|
|
134
|
-
this.openSubmenu = async (opts)=>{
|
|
135
|
-
let { submenuTrigger: submenuTrigger, submenuTriggerText: submenuTriggerText, needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
|
|
136
|
-
let trigger = this.trigger;
|
|
137
|
-
let isDisabled = trigger.hasAttribute('disabled');
|
|
138
|
-
if (!trigger.getAttribute('aria-controls') && !isDisabled) await this.open({
|
|
139
|
-
needsLongPress: needsLongPress
|
|
140
|
-
});
|
|
141
|
-
if (!isDisabled) {
|
|
142
|
-
let menu = this.menu;
|
|
143
|
-
if (menu) {
|
|
144
|
-
let submenu;
|
|
145
|
-
if (submenuTrigger) submenu = submenuTrigger;
|
|
146
|
-
else if (submenuTriggerText) submenu = (0, $gS6KO$within)(menu).getByText(submenuTriggerText);
|
|
147
|
-
let submenuTriggerTester = new $74b93f0617179929$export$f73bbc9212ed861e({
|
|
148
|
-
user: this.user,
|
|
149
|
-
interactionType: this._interactionType,
|
|
150
|
-
root: submenu,
|
|
151
|
-
isSubmenu: true
|
|
147
|
+
(0, $gS6KO$act)(()=>{
|
|
148
|
+
jest.runAllTimers();
|
|
152
149
|
});
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
});
|
|
164
|
-
await this.user.keyboard('[ArrowRight]');
|
|
165
|
-
(0, $gS6KO$act)(()=>{
|
|
166
|
-
jest.runAllTimers();
|
|
167
|
-
});
|
|
168
|
-
} else await submenuTriggerTester.open();
|
|
169
|
-
return submenuTriggerTester;
|
|
170
|
-
}
|
|
150
|
+
} else if (interactionType === 'keyboard') {
|
|
151
|
+
await this.keyboardNavigateToOption({
|
|
152
|
+
option: submenuTrigger
|
|
153
|
+
});
|
|
154
|
+
await this.user.keyboard('[ArrowRight]');
|
|
155
|
+
(0, $gS6KO$act)(()=>{
|
|
156
|
+
jest.runAllTimers();
|
|
157
|
+
});
|
|
158
|
+
} else await submenuTriggerTester.open();
|
|
159
|
+
return submenuTriggerTester;
|
|
171
160
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (document.
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
async keyboardNavigateToOption(opts) {
|
|
165
|
+
let { option: option } = opts;
|
|
166
|
+
let options = this.options();
|
|
167
|
+
let targetIndex = options.findIndex((opt)=>opt === option || opt.contains(option));
|
|
168
|
+
if (targetIndex === -1) throw new Error('Option provided is not in the menu');
|
|
169
|
+
if (document.activeElement === this.menu) await this.user.keyboard('[ArrowDown]');
|
|
170
|
+
let currIndex = options.indexOf(document.activeElement);
|
|
171
|
+
if (currIndex === -1) throw new Error('ActiveElement is not in the menu');
|
|
172
|
+
let direction = targetIndex > currIndex ? 'down' : 'up';
|
|
173
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Closes the menu.
|
|
177
|
+
*/ async close() {
|
|
178
|
+
let menu = this.menu;
|
|
179
|
+
if (menu) {
|
|
180
|
+
(0, $gS6KO$act)(()=>menu.focus());
|
|
181
|
+
await this.user.keyboard('[Escape]');
|
|
182
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
183
|
+
if (document.activeElement !== this.trigger) throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);
|
|
184
|
+
else return true;
|
|
185
|
+
});
|
|
186
|
+
if (document.contains(menu)) throw new Error('Expected the menu to not be in the document after closing it.');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Returns the menu's trigger.
|
|
191
|
+
*/ get trigger() {
|
|
192
|
+
if (!this._trigger) throw new Error('No trigger element found for menu.');
|
|
193
|
+
return this._trigger;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Returns the menu if present.
|
|
197
|
+
*/ get menu() {
|
|
198
|
+
let menuId = this.trigger.getAttribute('aria-controls');
|
|
199
|
+
return menuId ? document.getElementById(menuId) : null;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Returns the menu's sections if any.
|
|
203
|
+
*/ get sections() {
|
|
204
|
+
let menu = this.menu;
|
|
205
|
+
if (menu) return (0, $gS6KO$within)(menu).queryAllByRole('group');
|
|
206
|
+
else return [];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Returns the menu's options if present. Can be filtered to a subsection of the menu if provided via `element`.
|
|
210
|
+
*/ options(opts = {}) {
|
|
211
|
+
let { element: element = this.menu } = opts;
|
|
212
|
+
let options = [];
|
|
213
|
+
if (element) {
|
|
214
|
+
options = (0, $gS6KO$within)(element).queryAllByRole('menuitem');
|
|
215
|
+
if (options.length === 0) {
|
|
216
|
+
options = (0, $gS6KO$within)(element).queryAllByRole('menuitemradio');
|
|
217
|
+
if (options.length === 0) options = (0, $gS6KO$within)(element).queryAllByRole('menuitemcheckbox');
|
|
195
218
|
}
|
|
196
|
-
}
|
|
219
|
+
}
|
|
220
|
+
return options;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Returns the menu's submenu triggers if any.
|
|
224
|
+
*/ get submenuTriggers() {
|
|
225
|
+
let options = this.options();
|
|
226
|
+
if (options.length > 0) return options.filter((item)=>item.getAttribute('aria-haspopup') != null);
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
constructor(opts){
|
|
230
|
+
this._isSubmenu = false;
|
|
197
231
|
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer, isSubmenu: isSubmenu } = opts;
|
|
198
232
|
this.user = user;
|
|
199
233
|
this._interactionType = interactionType || 'mouse';
|