@react-aria/test-utils 1.0.0-alpha.0 → 1.0.0-alpha.2
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 +137 -0
- package/dist/combobox.main.js.map +1 -0
- package/dist/combobox.mjs +132 -0
- package/dist/combobox.module.js +132 -0
- package/dist/combobox.module.js.map +1 -0
- package/dist/events.main.js +25 -10
- package/dist/events.main.js.map +1 -1
- package/dist/events.mjs +26 -11
- package/dist/events.module.js +25 -10
- package/dist/events.module.js.map +1 -1
- package/dist/gridlist.main.js +97 -0
- package/dist/gridlist.main.js.map +1 -0
- package/dist/gridlist.mjs +92 -0
- package/dist/gridlist.module.js +92 -0
- package/dist/gridlist.module.js.map +1 -0
- package/dist/import.mjs +4 -2
- package/dist/main.js +10 -18
- package/dist/main.js.map +1 -1
- package/dist/menu.main.js +176 -0
- package/dist/menu.main.js.map +1 -0
- package/dist/menu.mjs +171 -0
- package/dist/menu.module.js +171 -0
- package/dist/menu.module.js.map +1 -0
- package/dist/module.js +4 -2
- package/dist/module.js.map +1 -1
- package/dist/select.main.js +113 -0
- package/dist/select.main.js.map +1 -0
- package/dist/select.mjs +108 -0
- package/dist/select.module.js +108 -0
- package/dist/select.module.js.map +1 -0
- package/dist/table.main.js +191 -0
- package/dist/table.main.js.map +1 -0
- package/dist/table.mjs +186 -0
- package/dist/table.module.js +186 -0
- package/dist/table.module.js.map +1 -0
- package/dist/testSetup.main.js +1 -1
- package/dist/testSetup.mjs +2 -2
- package/dist/testSetup.module.js +1 -1
- package/dist/types.d.ts +180 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/user.main.js +65 -0
- package/dist/user.main.js.map +1 -0
- package/dist/user.mjs +56 -0
- package/dist/user.module.js +56 -0
- package/dist/user.module.js.map +1 -0
- package/dist/userEventMaps.main.js +15 -15
- package/dist/userEventMaps.mjs +16 -16
- package/dist/userEventMaps.module.js +15 -15
- package/package.json +6 -7
- package/src/combobox.ts +188 -0
- package/src/events.ts +28 -8
- package/src/gridlist.ts +116 -0
- package/src/index.ts +6 -3
- package/src/menu.ts +246 -0
- package/src/select.ts +158 -0
- package/src/table.ts +282 -0
- package/src/user.ts +73 -0
- package/LICENSE +0 -201
package/dist/menu.mjs
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
|
|
2
|
+
import {within as $gS6KO$within, act as $gS6KO$act, waitFor as $gS6KO$waitFor} from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
class $74b93f0617179929$export$f73bbc9212ed861e {
|
|
17
|
+
get trigger() {
|
|
18
|
+
return this._trigger;
|
|
19
|
+
}
|
|
20
|
+
get menu() {
|
|
21
|
+
let menuId = this.trigger.getAttribute('aria-controls');
|
|
22
|
+
return menuId ? document.getElementById(menuId) : undefined;
|
|
23
|
+
}
|
|
24
|
+
get options() {
|
|
25
|
+
let menu = this.menu;
|
|
26
|
+
let options = [];
|
|
27
|
+
if (menu) {
|
|
28
|
+
options = (0, $gS6KO$within)(menu).queryAllByRole('menuitem');
|
|
29
|
+
if (options.length === 0) {
|
|
30
|
+
options = (0, $gS6KO$within)(menu).queryAllByRole('menuitemradio');
|
|
31
|
+
if (options.length === 0) options = (0, $gS6KO$within)(menu).queryAllByRole('menuitemcheckbox');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return options;
|
|
35
|
+
}
|
|
36
|
+
get sections() {
|
|
37
|
+
let menu = this.menu;
|
|
38
|
+
if (menu) return (0, $gS6KO$within)(menu).queryAllByRole('group');
|
|
39
|
+
else return [];
|
|
40
|
+
}
|
|
41
|
+
get submenuTriggers() {
|
|
42
|
+
let options = this.options;
|
|
43
|
+
if (options.length > 0) return this.options.filter((item)=>item.getAttribute('aria-haspopup') != null);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
constructor(opts){
|
|
47
|
+
this.setInteractionType = (type)=>{
|
|
48
|
+
this._interactionType = type;
|
|
49
|
+
};
|
|
50
|
+
// 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
|
|
51
|
+
// One difference will be that it supports long press as well
|
|
52
|
+
this.open = async (opts = {})=>{
|
|
53
|
+
let { needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
|
|
54
|
+
let trigger = this.trigger;
|
|
55
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
56
|
+
if (interactionType === 'mouse' || interactionType === 'touch') {
|
|
57
|
+
if (needsLongPress) {
|
|
58
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
59
|
+
let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';
|
|
60
|
+
await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
|
|
61
|
+
element: trigger,
|
|
62
|
+
advanceTimer: this._advanceTimer,
|
|
63
|
+
pointerOpts: {
|
|
64
|
+
pointerType: pointerType
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
} else if (interactionType === 'mouse') await this.user.click(trigger);
|
|
68
|
+
else await this.user.pointer({
|
|
69
|
+
target: trigger,
|
|
70
|
+
keys: '[TouchA]'
|
|
71
|
+
});
|
|
72
|
+
} else if (interactionType === 'keyboard' && !isDisabled) {
|
|
73
|
+
(0, $gS6KO$act)(()=>trigger.focus());
|
|
74
|
+
await this.user.keyboard('[Enter]');
|
|
75
|
+
}
|
|
76
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
77
|
+
if (trigger.getAttribute('aria-controls') == null && !isDisabled) throw new Error('No aria-controls found on menu trigger element.');
|
|
78
|
+
else return true;
|
|
79
|
+
});
|
|
80
|
+
if (!isDisabled) {
|
|
81
|
+
let menuId = trigger.getAttribute('aria-controls');
|
|
82
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
83
|
+
if (!menuId || document.getElementById(menuId) == null) throw new Error(`Menu with id of ${menuId} not found in document.`);
|
|
84
|
+
else return true;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// TODO: also very similar to select, barring potential long press support
|
|
89
|
+
// Close on select is also kinda specific?
|
|
90
|
+
this.selectOption = async (opts)=>{
|
|
91
|
+
let { optionText: optionText, menuSelectionMode: menuSelectionMode = 'single', needsLongPress: needsLongPress, closesOnSelect: closesOnSelect = true, option: option, interactionType: interactionType = this._interactionType } = opts;
|
|
92
|
+
let trigger = this.trigger;
|
|
93
|
+
if (!trigger.getAttribute('aria-controls')) await this.open({
|
|
94
|
+
needsLongPress: needsLongPress
|
|
95
|
+
});
|
|
96
|
+
let menu = this.menu;
|
|
97
|
+
if (menu) {
|
|
98
|
+
if (!option && optionText) option = (0, $gS6KO$within)(menu).getByText(optionText);
|
|
99
|
+
if (interactionType === 'keyboard') {
|
|
100
|
+
if (document.activeElement !== menu || !menu.contains(document.activeElement)) (0, $gS6KO$act)(()=>menu.focus());
|
|
101
|
+
await this.user.keyboard(optionText);
|
|
102
|
+
await this.user.keyboard('[Enter]');
|
|
103
|
+
} else if (interactionType === 'mouse') await this.user.click(option);
|
|
104
|
+
else await this.user.pointer({
|
|
105
|
+
target: option,
|
|
106
|
+
keys: '[TouchA]'
|
|
107
|
+
});
|
|
108
|
+
if (option && option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect) {
|
|
109
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
110
|
+
if (document.activeElement !== trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the menu trigger but got ${document.activeElement}`);
|
|
111
|
+
else return true;
|
|
112
|
+
});
|
|
113
|
+
if (document.contains(menu)) throw new Error('Expected menu element to not be in the document after selecting an option');
|
|
114
|
+
}
|
|
115
|
+
} else throw new Error("Attempted to select a option in the menu, but menu wasn't found.");
|
|
116
|
+
};
|
|
117
|
+
// TODO: update this to remove needsLongPress if we wanna make the user call open first always
|
|
118
|
+
this.openSubmenu = async (opts)=>{
|
|
119
|
+
let { submenuTrigger: submenuTrigger, submenuTriggerText: submenuTriggerText, needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
|
|
120
|
+
let trigger = this.trigger;
|
|
121
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
122
|
+
if (!trigger.getAttribute('aria-controls') && !isDisabled) await this.open({
|
|
123
|
+
needsLongPress: needsLongPress
|
|
124
|
+
});
|
|
125
|
+
if (!isDisabled) {
|
|
126
|
+
let menu = this.menu;
|
|
127
|
+
if (menu) {
|
|
128
|
+
let submenu;
|
|
129
|
+
if (submenuTrigger) submenu = submenuTrigger;
|
|
130
|
+
else if (submenuTriggerText) submenu = (0, $gS6KO$within)(menu).getByText(submenuTriggerText);
|
|
131
|
+
let submenuTriggerTester = new $74b93f0617179929$export$f73bbc9212ed861e({
|
|
132
|
+
user: this.user,
|
|
133
|
+
interactionType: interactionType,
|
|
134
|
+
root: submenu
|
|
135
|
+
});
|
|
136
|
+
await submenuTriggerTester.open();
|
|
137
|
+
return submenuTriggerTester;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
};
|
|
142
|
+
this.close = async ()=>{
|
|
143
|
+
let menu = this.menu;
|
|
144
|
+
if (menu) {
|
|
145
|
+
(0, $gS6KO$act)(()=>menu.focus());
|
|
146
|
+
await this.user.keyboard('[Escape]');
|
|
147
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
148
|
+
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}`);
|
|
149
|
+
else return true;
|
|
150
|
+
});
|
|
151
|
+
if (document.contains(menu)) throw new Error('Expected the menu to not be in the document after closing it.');
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
155
|
+
this.user = user;
|
|
156
|
+
this._interactionType = interactionType || 'mouse';
|
|
157
|
+
this._advanceTimer = advanceTimer;
|
|
158
|
+
// Handle case where a submenu trigger is provided to the tester
|
|
159
|
+
if (root.getAttribute('role') === 'menuitem') this._trigger = root;
|
|
160
|
+
else {
|
|
161
|
+
// Handle case where element provided is a wrapper of the trigger button
|
|
162
|
+
let trigger = (0, $gS6KO$within)(root).queryByRole('button');
|
|
163
|
+
if (trigger) this._trigger = trigger;
|
|
164
|
+
else this._trigger = root;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
export {$74b93f0617179929$export$f73bbc9212ed861e as MenuTester};
|
|
171
|
+
//# sourceMappingURL=menu.module.js.map
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
|
|
2
|
+
import {within as $gS6KO$within, act as $gS6KO$act, waitFor as $gS6KO$waitFor} from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
class $74b93f0617179929$export$f73bbc9212ed861e {
|
|
17
|
+
get trigger() {
|
|
18
|
+
return this._trigger;
|
|
19
|
+
}
|
|
20
|
+
get menu() {
|
|
21
|
+
let menuId = this.trigger.getAttribute('aria-controls');
|
|
22
|
+
return menuId ? document.getElementById(menuId) : undefined;
|
|
23
|
+
}
|
|
24
|
+
get options() {
|
|
25
|
+
let menu = this.menu;
|
|
26
|
+
let options = [];
|
|
27
|
+
if (menu) {
|
|
28
|
+
options = (0, $gS6KO$within)(menu).queryAllByRole('menuitem');
|
|
29
|
+
if (options.length === 0) {
|
|
30
|
+
options = (0, $gS6KO$within)(menu).queryAllByRole('menuitemradio');
|
|
31
|
+
if (options.length === 0) options = (0, $gS6KO$within)(menu).queryAllByRole('menuitemcheckbox');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return options;
|
|
35
|
+
}
|
|
36
|
+
get sections() {
|
|
37
|
+
let menu = this.menu;
|
|
38
|
+
if (menu) return (0, $gS6KO$within)(menu).queryAllByRole('group');
|
|
39
|
+
else return [];
|
|
40
|
+
}
|
|
41
|
+
get submenuTriggers() {
|
|
42
|
+
let options = this.options;
|
|
43
|
+
if (options.length > 0) return this.options.filter((item)=>item.getAttribute('aria-haspopup') != null);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
constructor(opts){
|
|
47
|
+
this.setInteractionType = (type)=>{
|
|
48
|
+
this._interactionType = type;
|
|
49
|
+
};
|
|
50
|
+
// 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
|
|
51
|
+
// One difference will be that it supports long press as well
|
|
52
|
+
this.open = async (opts = {})=>{
|
|
53
|
+
let { needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
|
|
54
|
+
let trigger = this.trigger;
|
|
55
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
56
|
+
if (interactionType === 'mouse' || interactionType === 'touch') {
|
|
57
|
+
if (needsLongPress) {
|
|
58
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
59
|
+
let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';
|
|
60
|
+
await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
|
|
61
|
+
element: trigger,
|
|
62
|
+
advanceTimer: this._advanceTimer,
|
|
63
|
+
pointerOpts: {
|
|
64
|
+
pointerType: pointerType
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
} else if (interactionType === 'mouse') await this.user.click(trigger);
|
|
68
|
+
else await this.user.pointer({
|
|
69
|
+
target: trigger,
|
|
70
|
+
keys: '[TouchA]'
|
|
71
|
+
});
|
|
72
|
+
} else if (interactionType === 'keyboard' && !isDisabled) {
|
|
73
|
+
(0, $gS6KO$act)(()=>trigger.focus());
|
|
74
|
+
await this.user.keyboard('[Enter]');
|
|
75
|
+
}
|
|
76
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
77
|
+
if (trigger.getAttribute('aria-controls') == null && !isDisabled) throw new Error('No aria-controls found on menu trigger element.');
|
|
78
|
+
else return true;
|
|
79
|
+
});
|
|
80
|
+
if (!isDisabled) {
|
|
81
|
+
let menuId = trigger.getAttribute('aria-controls');
|
|
82
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
83
|
+
if (!menuId || document.getElementById(menuId) == null) throw new Error(`Menu with id of ${menuId} not found in document.`);
|
|
84
|
+
else return true;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// TODO: also very similar to select, barring potential long press support
|
|
89
|
+
// Close on select is also kinda specific?
|
|
90
|
+
this.selectOption = async (opts)=>{
|
|
91
|
+
let { optionText: optionText, menuSelectionMode: menuSelectionMode = 'single', needsLongPress: needsLongPress, closesOnSelect: closesOnSelect = true, option: option, interactionType: interactionType = this._interactionType } = opts;
|
|
92
|
+
let trigger = this.trigger;
|
|
93
|
+
if (!trigger.getAttribute('aria-controls')) await this.open({
|
|
94
|
+
needsLongPress: needsLongPress
|
|
95
|
+
});
|
|
96
|
+
let menu = this.menu;
|
|
97
|
+
if (menu) {
|
|
98
|
+
if (!option && optionText) option = (0, $gS6KO$within)(menu).getByText(optionText);
|
|
99
|
+
if (interactionType === 'keyboard') {
|
|
100
|
+
if (document.activeElement !== menu || !menu.contains(document.activeElement)) (0, $gS6KO$act)(()=>menu.focus());
|
|
101
|
+
await this.user.keyboard(optionText);
|
|
102
|
+
await this.user.keyboard('[Enter]');
|
|
103
|
+
} else if (interactionType === 'mouse') await this.user.click(option);
|
|
104
|
+
else await this.user.pointer({
|
|
105
|
+
target: option,
|
|
106
|
+
keys: '[TouchA]'
|
|
107
|
+
});
|
|
108
|
+
if (option && option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect) {
|
|
109
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
110
|
+
if (document.activeElement !== trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the menu trigger but got ${document.activeElement}`);
|
|
111
|
+
else return true;
|
|
112
|
+
});
|
|
113
|
+
if (document.contains(menu)) throw new Error('Expected menu element to not be in the document after selecting an option');
|
|
114
|
+
}
|
|
115
|
+
} else throw new Error("Attempted to select a option in the menu, but menu wasn't found.");
|
|
116
|
+
};
|
|
117
|
+
// TODO: update this to remove needsLongPress if we wanna make the user call open first always
|
|
118
|
+
this.openSubmenu = async (opts)=>{
|
|
119
|
+
let { submenuTrigger: submenuTrigger, submenuTriggerText: submenuTriggerText, needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
|
|
120
|
+
let trigger = this.trigger;
|
|
121
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
122
|
+
if (!trigger.getAttribute('aria-controls') && !isDisabled) await this.open({
|
|
123
|
+
needsLongPress: needsLongPress
|
|
124
|
+
});
|
|
125
|
+
if (!isDisabled) {
|
|
126
|
+
let menu = this.menu;
|
|
127
|
+
if (menu) {
|
|
128
|
+
let submenu;
|
|
129
|
+
if (submenuTrigger) submenu = submenuTrigger;
|
|
130
|
+
else if (submenuTriggerText) submenu = (0, $gS6KO$within)(menu).getByText(submenuTriggerText);
|
|
131
|
+
let submenuTriggerTester = new $74b93f0617179929$export$f73bbc9212ed861e({
|
|
132
|
+
user: this.user,
|
|
133
|
+
interactionType: interactionType,
|
|
134
|
+
root: submenu
|
|
135
|
+
});
|
|
136
|
+
await submenuTriggerTester.open();
|
|
137
|
+
return submenuTriggerTester;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
};
|
|
142
|
+
this.close = async ()=>{
|
|
143
|
+
let menu = this.menu;
|
|
144
|
+
if (menu) {
|
|
145
|
+
(0, $gS6KO$act)(()=>menu.focus());
|
|
146
|
+
await this.user.keyboard('[Escape]');
|
|
147
|
+
await (0, $gS6KO$waitFor)(()=>{
|
|
148
|
+
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}`);
|
|
149
|
+
else return true;
|
|
150
|
+
});
|
|
151
|
+
if (document.contains(menu)) throw new Error('Expected the menu to not be in the document after closing it.');
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
155
|
+
this.user = user;
|
|
156
|
+
this._interactionType = interactionType || 'mouse';
|
|
157
|
+
this._advanceTimer = advanceTimer;
|
|
158
|
+
// Handle case where a submenu trigger is provided to the tester
|
|
159
|
+
if (root.getAttribute('role') === 'menuitem') this._trigger = root;
|
|
160
|
+
else {
|
|
161
|
+
// Handle case where element provided is a wrapper of the trigger button
|
|
162
|
+
let trigger = (0, $gS6KO$within)(root).queryByRole('button');
|
|
163
|
+
if (trigger) this._trigger = trigger;
|
|
164
|
+
else this._trigger = root;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
export {$74b93f0617179929$export$f73bbc9212ed861e as MenuTester};
|
|
171
|
+
//# sourceMappingURL=menu.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAwLX,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAO;QACT,IAAI,SAAS,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QACvC,OAAO,SAAS,SAAS,cAAc,CAAC,UAAU;IACpD;IAEA,IAAI,UAAmC;QACrC,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,UAAU,EAAE;QAChB,IAAI,MAAM;YACR,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;YACtC,IAAI,QAAQ,MAAM,KAAK,GAAG;gBACxB,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;gBACtC,IAAI,QAAQ,MAAM,KAAK,GACrB,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;YAE1C;QACF;QAEA,OAAO;IACT;IAEA,IAAI,WAAW;QACb,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,MACF,OAAO,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;aAEnC,OAAO,EAAE;IAEb;IAEA,IAAI,kBAAkB;QACpB,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,QAAQ,MAAM,GAAG,GACnB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA,OAAQ,KAAK,YAAY,CAAC,oBAAoB;QAG3E,OAAO,EAAE;IACX;IA3NA,YAAY,IAAiB,CAAE;aAoB/B,qBAAqB,CAAC;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AAa,GAAG;QAErB,gEAAgE;QAChE,IAAI,KAAK,YAAY,CAAC,YAAY,YAChC,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,wEAAwE;YACxE,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC;YACvC,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;iBAEhB,IAAI,CAAC,QAAQ,GAAG;QAEpB;IACF;AA0MF","sources":["packages/@react-aria/test-utils/src/menu.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\nimport {triggerLongPress} from './events';\n\nexport interface MenuOptions extends UserOpts, BaseTesterOpts {\n user: any\n}\nexport class MenuTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _trigger: HTMLElement;\n\n constructor(opts: MenuOptions) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n\n // Handle case where a submenu trigger is provided to the tester\n if (root.getAttribute('role') === 'menuitem') {\n this._trigger = root;\n } else {\n // Handle case where element provided is a wrapper of the trigger button\n let trigger = within(root).queryByRole('button');\n if (trigger) {\n this._trigger = trigger;\n } else {\n this._trigger = root;\n }\n }\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n // 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\n // One difference will be that it supports long press as well\n open = async (opts: {needsLongPress?: boolean, interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (interactionType === 'mouse' || interactionType === 'touch') {\n if (needsLongPress) {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';\n await triggerLongPress({element: trigger, advanceTimer: this._advanceTimer, pointerOpts: {pointerType}});\n } else if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n } else if (interactionType === 'keyboard' && !isDisabled) {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null && !isDisabled) {\n throw new Error('No aria-controls found on menu trigger element.');\n } else {\n return true;\n }\n });\n if (!isDisabled) {\n let menuId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n };\n\n // TODO: also very similar to select, barring potential long press support\n // Close on select is also kinda specific?\n selectOption = async (opts: {option?: HTMLElement, optionText?: string, menuSelectionMode?: 'single' | 'multiple', needsLongPress?: boolean, closesOnSelect?: boolean, interactionType?: UserOpts['interactionType']}) => {\n let {\n optionText,\n menuSelectionMode = 'single',\n needsLongPress,\n closesOnSelect = true,\n option,\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open({needsLongPress});\n }\n\n let menu = this.menu;\n if (menu) {\n if (!option && optionText) {\n option = within(menu).getByText(optionText);\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== menu || !menu.contains(document.activeElement)) {\n act(() => menu.focus());\n }\n\n await this.user.keyboard(optionText);\n await this.user.keyboard('[Enter]');\n } else {\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n if (option && option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect) {\n await waitFor(() => {\n if (document.activeElement !== trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the menu trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(menu)) {\n throw new Error('Expected menu element to not be in the document after selecting an option');\n }\n }\n } else {\n throw new Error(\"Attempted to select a option in the menu, but menu wasn't found.\");\n }\n };\n\n // TODO: update this to remove needsLongPress if we wanna make the user call open first always\n openSubmenu = async (opts: {submenuTrigger?: HTMLElement, submenuTriggerText?: string, needsLongPress?: boolean, interactionType?: UserOpts['interactionType']}): Promise<MenuTester | null> => {\n let {\n submenuTrigger,\n submenuTriggerText,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (!trigger.getAttribute('aria-controls') && !isDisabled) {\n await this.open({needsLongPress});\n }\n if (!isDisabled) {\n let menu = this.menu;\n if (menu) {\n let submenu;\n if (submenuTrigger) {\n submenu = submenuTrigger;\n } else if (submenuTriggerText) {\n submenu = within(menu).getByText(submenuTriggerText);\n }\n\n let submenuTriggerTester = new MenuTester({user: this.user, interactionType: interactionType, root: submenu});\n await submenuTriggerTester.open();\n\n return submenuTriggerTester;\n }\n }\n\n return null;\n };\n\n close = async () => {\n let menu = this.menu;\n if (menu) {\n act(() => menu.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.activeElement !== this.trigger) {\n throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(menu)) {\n throw new Error('Expected the menu to not be in the document after closing it.');\n }\n }\n };\n\n get trigger() {\n return this._trigger;\n }\n\n get menu() {\n let menuId = this.trigger.getAttribute('aria-controls');\n return menuId ? document.getElementById(menuId) : undefined;\n }\n\n get options(): HTMLElement[] | never[] {\n let menu = this.menu;\n let options = [];\n if (menu) {\n options = within(menu).queryAllByRole('menuitem');\n if (options.length === 0) {\n options = within(menu).queryAllByRole('menuitemradio');\n if (options.length === 0) {\n options = within(menu).queryAllByRole('menuitemcheckbox');\n }\n }\n }\n\n return options;\n }\n\n get sections() {\n let menu = this.menu;\n if (menu) {\n return within(menu).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n get submenuTriggers() {\n let options = this.options;\n if (options.length > 0) {\n return this.options.filter(item => item.getAttribute('aria-haspopup') != null);\n }\n\n return [];\n }\n}\n"],"names":[],"version":3,"file":"menu.module.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
|
|
2
2
|
import {installMouseEvent as $68df97871cfb5e33$export$de31e3987c917741, installPointerEvent as $68df97871cfb5e33$export$82f0b04c1d69a901} from "./testSetup.module.js";
|
|
3
3
|
import {pointerMap as $50ecfb18069ec897$export$7dbde2c4caaa8d35} from "./userEventMaps.module.js";
|
|
4
|
+
import {User as $0d71b4e9cc4df40a$export$1f44aaf2ec115b54} from "./user.module.js";
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
* Copyright 2023 Adobe. All rights reserved.
|
|
@@ -17,5 +18,6 @@ import {pointerMap as $50ecfb18069ec897$export$7dbde2c4caaa8d35} from "./userEve
|
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
export {$5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $68df97871cfb5e33$export$de31e3987c917741 as installMouseEvent, $68df97871cfb5e33$export$82f0b04c1d69a901 as installPointerEvent, $50ecfb18069ec897$export$7dbde2c4caaa8d35 as pointerMap, $0d71b4e9cc4df40a$export$1f44aaf2ec115b54 as User};
|
|
21
23
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\n\nexport type {UserOpts} from './user';\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var $bBwW0$testinglibraryreact = require("@testing-library/react");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
$parcel$export(module.exports, "SelectTester", () => $b97d5a42df7c75b2$export$d1859707465446a9);
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
21
|
+
get trigger() {
|
|
22
|
+
return this._trigger;
|
|
23
|
+
}
|
|
24
|
+
get listbox() {
|
|
25
|
+
let listBoxId = this.trigger.getAttribute('aria-controls');
|
|
26
|
+
return listBoxId ? document.getElementById(listBoxId) : undefined;
|
|
27
|
+
}
|
|
28
|
+
get options() {
|
|
29
|
+
let listbox = this.listbox;
|
|
30
|
+
return listbox ? (0, $bBwW0$testinglibraryreact.within)(listbox).queryAllByRole('option') : [];
|
|
31
|
+
}
|
|
32
|
+
get sections() {
|
|
33
|
+
let listbox = this.listbox;
|
|
34
|
+
return listbox ? (0, $bBwW0$testinglibraryreact.within)(listbox).queryAllByRole('group') : [];
|
|
35
|
+
}
|
|
36
|
+
constructor(opts){
|
|
37
|
+
this.setInteractionType = (type)=>{
|
|
38
|
+
this._interactionType = type;
|
|
39
|
+
};
|
|
40
|
+
this.open = async (opts = {})=>{
|
|
41
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
42
|
+
let trigger = this.trigger;
|
|
43
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
44
|
+
if (interactionType === 'mouse') await this.user.click(this._trigger);
|
|
45
|
+
else if (interactionType === 'keyboard') {
|
|
46
|
+
(0, $bBwW0$testinglibraryreact.act)(()=>trigger.focus());
|
|
47
|
+
await this.user.keyboard('[Enter]');
|
|
48
|
+
} else if (interactionType === 'touch') await this.user.pointer({
|
|
49
|
+
target: this._trigger,
|
|
50
|
+
keys: '[TouchA]'
|
|
51
|
+
});
|
|
52
|
+
await (0, $bBwW0$testinglibraryreact.waitFor)(()=>{
|
|
53
|
+
if (!isDisabled && trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on select element trigger.');
|
|
54
|
+
else return true;
|
|
55
|
+
});
|
|
56
|
+
let listBoxId = trigger.getAttribute('aria-controls');
|
|
57
|
+
await (0, $bBwW0$testinglibraryreact.waitFor)(()=>{
|
|
58
|
+
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`ListBox with id of ${listBoxId} not found in document.`);
|
|
59
|
+
else return true;
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
this.selectOption = async (opts)=>{
|
|
63
|
+
let { optionText: optionText, interactionType: interactionType = this._interactionType } = opts || {};
|
|
64
|
+
let trigger = this.trigger;
|
|
65
|
+
if (!trigger.getAttribute('aria-controls')) await this.open();
|
|
66
|
+
let listbox = this.listbox;
|
|
67
|
+
if (listbox) {
|
|
68
|
+
let option = (0, $bBwW0$testinglibraryreact.within)(listbox).getByText(optionText);
|
|
69
|
+
if (interactionType === 'keyboard') {
|
|
70
|
+
if (document.activeElement !== listbox || !listbox.contains(document.activeElement)) (0, $bBwW0$testinglibraryreact.act)(()=>listbox.focus());
|
|
71
|
+
// TODO: this simulates typeahead, do we want to add a helper util for that? Not sure if users would really need that for
|
|
72
|
+
// their test
|
|
73
|
+
await this.user.keyboard(optionText);
|
|
74
|
+
await this.user.keyboard('[Enter]');
|
|
75
|
+
} else // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)
|
|
76
|
+
if (interactionType === 'mouse') await this.user.click(option);
|
|
77
|
+
else await this.user.pointer({
|
|
78
|
+
target: option,
|
|
79
|
+
keys: '[TouchA]'
|
|
80
|
+
});
|
|
81
|
+
if (option.getAttribute('href') == null) {
|
|
82
|
+
await (0, $bBwW0$testinglibraryreact.waitFor)(()=>{
|
|
83
|
+
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);
|
|
84
|
+
else return true;
|
|
85
|
+
});
|
|
86
|
+
if (document.contains(listbox)) throw new Error('Expected select element listbox to not be in the document after selecting an option');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this.close = async ()=>{
|
|
91
|
+
let listbox = this.listbox;
|
|
92
|
+
if (listbox) {
|
|
93
|
+
(0, $bBwW0$testinglibraryreact.act)(()=>listbox.focus());
|
|
94
|
+
await this.user.keyboard('[Escape]');
|
|
95
|
+
}
|
|
96
|
+
await (0, $bBwW0$testinglibraryreact.waitFor)(()=>{
|
|
97
|
+
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);
|
|
98
|
+
else return true;
|
|
99
|
+
});
|
|
100
|
+
if (listbox && document.contains(listbox)) throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');
|
|
101
|
+
};
|
|
102
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
103
|
+
this.user = user;
|
|
104
|
+
this._interactionType = interactionType || 'mouse';
|
|
105
|
+
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
106
|
+
let triggerButton = (0, $bBwW0$testinglibraryreact.within)(root).queryByRole('button');
|
|
107
|
+
if (triggerButton == null) triggerButton = root;
|
|
108
|
+
this._trigger = triggerButton;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=select.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AASM,MAAM;IAwHX,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QAC1C,OAAO,YAAY,SAAS,cAAc,CAAC,aAAa;IAC1D;IAEA,IAAI,UAAU;QACZ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC,YAAY,EAAE;IAChE;IAEA,IAAI,WAAW;QACb,IAAI,UAAU,IAAI,CAAC,OAAO;QAC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a,CAAC,CAAC;qBAE5J,OAAO;YAEX;YAEA,IAAI,WAAW,SAAS,QAAQ,CAAC,UAC/B,MAAM,IAAI,MAAM;QAEpB;QAhHE,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,8FAA8F;QAC9F,IAAI,gBAAgB,CAAA,GAAA,iCAAK,EAAE,MAAM,WAAW,CAAC;QAC7C,IAAI,iBAAiB,MACnB,gBAAgB;QAElB,IAAI,CAAC,QAAQ,GAAG;IAClB;AA2HF","sources":["packages/@react-aria/test-utils/src/select.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\n\nexport interface SelectOptions extends UserOpts, BaseTesterOpts {\n // TODO: I think the type grabbed from the testing library dist for UserEvent is breaking the build, will need to figure out a better place to grab from\n user: any\n}\nexport class SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectOptions) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n // Handle case where the wrapper element is provided rather than the Select's button (aka RAC)\n let triggerButton = within(root).queryByRole('button');\n if (triggerButton == null) {\n triggerButton = root;\n }\n this._trigger = triggerButton;\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n open = async (opts: {interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n await this.user.click(this._trigger);\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: this._trigger, keys: '[TouchA]'});\n }\n\n await waitFor(() => {\n if (!isDisabled && trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on select element trigger.');\n } else {\n return true;\n }\n });\n let listBoxId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`ListBox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n };\n\n selectOption = async (opts: {optionText: string, interactionType?: UserOpts['interactionType']}) => {\n let {\n optionText,\n interactionType = this._interactionType\n } = opts || {};\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open();\n }\n let listbox = this.listbox;\n if (listbox) {\n let option = within(listbox).getByText(optionText);\n if (interactionType === 'keyboard') {\n if (document.activeElement !== listbox || !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n\n // TODO: this simulates typeahead, do we want to add a helper util for that? Not sure if users would really need that for\n // their test\n await this.user.keyboard(optionText);\n await this.user.keyboard('[Enter]');\n } else {\n // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n if (option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(listbox)) {\n throw new Error('Expected select element listbox to not be in the document after selecting an option');\n }\n }\n }\n };\n\n close = async () => {\n let listbox = this.listbox;\n if (listbox) {\n act(() => listbox.focus());\n await this.user.keyboard('[Escape]');\n }\n\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (listbox && document.contains(listbox)) {\n throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');\n }\n };\n\n get trigger() {\n return this._trigger;\n }\n\n get listbox() {\n let listBoxId = this.trigger.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : undefined;\n }\n\n get options() {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('option') : [];\n }\n\n get sections() {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.main.js.map"}
|
package/dist/select.mjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {within as $7v0pZ$within, act as $7v0pZ$act, waitFor as $7v0pZ$waitFor} from "@testing-library/react";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
15
|
+
get trigger() {
|
|
16
|
+
return this._trigger;
|
|
17
|
+
}
|
|
18
|
+
get listbox() {
|
|
19
|
+
let listBoxId = this.trigger.getAttribute('aria-controls');
|
|
20
|
+
return listBoxId ? document.getElementById(listBoxId) : undefined;
|
|
21
|
+
}
|
|
22
|
+
get options() {
|
|
23
|
+
let listbox = this.listbox;
|
|
24
|
+
return listbox ? (0, $7v0pZ$within)(listbox).queryAllByRole('option') : [];
|
|
25
|
+
}
|
|
26
|
+
get sections() {
|
|
27
|
+
let listbox = this.listbox;
|
|
28
|
+
return listbox ? (0, $7v0pZ$within)(listbox).queryAllByRole('group') : [];
|
|
29
|
+
}
|
|
30
|
+
constructor(opts){
|
|
31
|
+
this.setInteractionType = (type)=>{
|
|
32
|
+
this._interactionType = type;
|
|
33
|
+
};
|
|
34
|
+
this.open = async (opts = {})=>{
|
|
35
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
36
|
+
let trigger = this.trigger;
|
|
37
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
38
|
+
if (interactionType === 'mouse') await this.user.click(this._trigger);
|
|
39
|
+
else if (interactionType === 'keyboard') {
|
|
40
|
+
(0, $7v0pZ$act)(()=>trigger.focus());
|
|
41
|
+
await this.user.keyboard('[Enter]');
|
|
42
|
+
} else if (interactionType === 'touch') await this.user.pointer({
|
|
43
|
+
target: this._trigger,
|
|
44
|
+
keys: '[TouchA]'
|
|
45
|
+
});
|
|
46
|
+
await (0, $7v0pZ$waitFor)(()=>{
|
|
47
|
+
if (!isDisabled && trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on select element trigger.');
|
|
48
|
+
else return true;
|
|
49
|
+
});
|
|
50
|
+
let listBoxId = trigger.getAttribute('aria-controls');
|
|
51
|
+
await (0, $7v0pZ$waitFor)(()=>{
|
|
52
|
+
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`ListBox with id of ${listBoxId} not found in document.`);
|
|
53
|
+
else return true;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
this.selectOption = async (opts)=>{
|
|
57
|
+
let { optionText: optionText, interactionType: interactionType = this._interactionType } = opts || {};
|
|
58
|
+
let trigger = this.trigger;
|
|
59
|
+
if (!trigger.getAttribute('aria-controls')) await this.open();
|
|
60
|
+
let listbox = this.listbox;
|
|
61
|
+
if (listbox) {
|
|
62
|
+
let option = (0, $7v0pZ$within)(listbox).getByText(optionText);
|
|
63
|
+
if (interactionType === 'keyboard') {
|
|
64
|
+
if (document.activeElement !== listbox || !listbox.contains(document.activeElement)) (0, $7v0pZ$act)(()=>listbox.focus());
|
|
65
|
+
// TODO: this simulates typeahead, do we want to add a helper util for that? Not sure if users would really need that for
|
|
66
|
+
// their test
|
|
67
|
+
await this.user.keyboard(optionText);
|
|
68
|
+
await this.user.keyboard('[Enter]');
|
|
69
|
+
} else // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)
|
|
70
|
+
if (interactionType === 'mouse') await this.user.click(option);
|
|
71
|
+
else await this.user.pointer({
|
|
72
|
+
target: option,
|
|
73
|
+
keys: '[TouchA]'
|
|
74
|
+
});
|
|
75
|
+
if (option.getAttribute('href') == null) {
|
|
76
|
+
await (0, $7v0pZ$waitFor)(()=>{
|
|
77
|
+
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);
|
|
78
|
+
else return true;
|
|
79
|
+
});
|
|
80
|
+
if (document.contains(listbox)) throw new Error('Expected select element listbox to not be in the document after selecting an option');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
this.close = async ()=>{
|
|
85
|
+
let listbox = this.listbox;
|
|
86
|
+
if (listbox) {
|
|
87
|
+
(0, $7v0pZ$act)(()=>listbox.focus());
|
|
88
|
+
await this.user.keyboard('[Escape]');
|
|
89
|
+
}
|
|
90
|
+
await (0, $7v0pZ$waitFor)(()=>{
|
|
91
|
+
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);
|
|
92
|
+
else return true;
|
|
93
|
+
});
|
|
94
|
+
if (listbox && document.contains(listbox)) throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');
|
|
95
|
+
};
|
|
96
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
97
|
+
this.user = user;
|
|
98
|
+
this._interactionType = interactionType || 'mouse';
|
|
99
|
+
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
100
|
+
let triggerButton = (0, $7v0pZ$within)(root).queryByRole('button');
|
|
101
|
+
if (triggerButton == null) triggerButton = root;
|
|
102
|
+
this._trigger = triggerButton;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
export {$4350df3e19e40e36$export$d1859707465446a9 as SelectTester};
|
|
108
|
+
//# sourceMappingURL=select.module.js.map
|