@react-aria/test-utils 1.0.0-alpha.3 → 1.0.0-alpha.4

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.
Files changed (64) hide show
  1. package/dist/combobox.main.js +116 -82
  2. package/dist/combobox.main.js.map +1 -1
  3. package/dist/combobox.mjs +117 -83
  4. package/dist/combobox.module.js +117 -83
  5. package/dist/combobox.module.js.map +1 -1
  6. package/dist/events.main.js.map +1 -1
  7. package/dist/events.module.js.map +1 -1
  8. package/dist/gridlist.main.js +102 -59
  9. package/dist/gridlist.main.js.map +1 -1
  10. package/dist/gridlist.mjs +103 -60
  11. package/dist/gridlist.module.js +103 -60
  12. package/dist/gridlist.module.js.map +1 -1
  13. package/dist/listbox.main.js +135 -0
  14. package/dist/listbox.main.js.map +1 -0
  15. package/dist/listbox.mjs +130 -0
  16. package/dist/listbox.module.js +130 -0
  17. package/dist/listbox.module.js.map +1 -0
  18. package/dist/main.js.map +1 -1
  19. package/dist/menu.main.js +195 -161
  20. package/dist/menu.main.js.map +1 -1
  21. package/dist/menu.mjs +196 -162
  22. package/dist/menu.module.js +196 -162
  23. package/dist/menu.module.js.map +1 -1
  24. package/dist/module.js.map +1 -1
  25. package/dist/select.main.js +116 -70
  26. package/dist/select.main.js.map +1 -1
  27. package/dist/select.mjs +117 -71
  28. package/dist/select.module.js +117 -71
  29. package/dist/select.module.js.map +1 -1
  30. package/dist/table.main.js +170 -139
  31. package/dist/table.main.js.map +1 -1
  32. package/dist/table.mjs +171 -140
  33. package/dist/table.module.js +171 -140
  34. package/dist/table.module.js.map +1 -1
  35. package/dist/tabs.main.js +133 -0
  36. package/dist/tabs.main.js.map +1 -0
  37. package/dist/tabs.mjs +128 -0
  38. package/dist/tabs.module.js +128 -0
  39. package/dist/tabs.module.js.map +1 -0
  40. package/dist/tree.main.js +165 -0
  41. package/dist/tree.main.js.map +1 -0
  42. package/dist/tree.mjs +160 -0
  43. package/dist/tree.module.js +160 -0
  44. package/dist/tree.module.js.map +1 -0
  45. package/dist/types.d.ts +607 -145
  46. package/dist/types.d.ts.map +1 -1
  47. package/dist/user.main.js +15 -4
  48. package/dist/user.main.js.map +1 -1
  49. package/dist/user.mjs +15 -4
  50. package/dist/user.module.js +15 -4
  51. package/dist/user.module.js.map +1 -1
  52. package/package.json +2 -3
  53. package/src/combobox.ts +105 -36
  54. package/src/events.ts +1 -1
  55. package/src/gridlist.ts +146 -59
  56. package/src/index.ts +1 -1
  57. package/src/listbox.ts +226 -0
  58. package/src/menu.ts +152 -62
  59. package/src/select.ts +137 -44
  60. package/src/table.ts +129 -64
  61. package/src/tabs.ts +198 -0
  62. package/src/tree.ts +248 -0
  63. package/src/types.ts +133 -0
  64. package/src/user.ts +62 -37
package/dist/menu.main.js CHANGED
@@ -20,186 +20,220 @@ $parcel$export(module.exports, "MenuTester", () => $31965f39292c8e99$export$f73b
20
20
  */
21
21
 
22
22
  class $31965f39292c8e99$export$f73bbc9212ed861e {
23
- get trigger() {
24
- if (!this._trigger) throw new Error('No trigger element found for menu.');
25
- return this._trigger;
23
+ /**
24
+ * Set the interaction type used by the menu tester.
25
+ */ setInteractionType(type) {
26
+ this._interactionType = type;
26
27
  }
27
- get menu() {
28
- let menuId = this.trigger.getAttribute('aria-controls');
29
- return menuId ? document.getElementById(menuId) : undefined;
30
- }
31
- get options() {
32
- let menu = this.menu;
33
- let options = [];
34
- if (menu) {
35
- options = (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('menuitem');
36
- if (options.length === 0) {
37
- options = (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('menuitemradio');
38
- if (options.length === 0) options = (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('menuitemcheckbox');
28
+ // 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
29
+ // One difference will be that it supports long press as well
30
+ /**
31
+ * Opens the menu. Defaults to using the interaction type set on the menu tester.
32
+ */ async open(opts = {}) {
33
+ let { needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType, direction: direction } = opts;
34
+ let trigger = this.trigger;
35
+ let isDisabled = trigger.hasAttribute('disabled');
36
+ if (interactionType === 'mouse' || interactionType === 'touch') {
37
+ if (needsLongPress) {
38
+ if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
39
+ let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';
40
+ await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
41
+ element: trigger,
42
+ advanceTimer: this._advanceTimer,
43
+ pointerOpts: {
44
+ pointerType: pointerType
45
+ }
46
+ });
47
+ } else if (interactionType === 'mouse') await this.user.click(trigger);
48
+ else await this.user.pointer({
49
+ target: trigger,
50
+ keys: '[TouchA]'
51
+ });
52
+ } else if (interactionType === 'keyboard' && !isDisabled) {
53
+ if (direction === 'up') {
54
+ (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
55
+ await this.user.keyboard('[ArrowUp]');
56
+ } else if (direction === 'down') {
57
+ (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
58
+ await this.user.keyboard('[ArrowDown]');
59
+ } else {
60
+ (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
61
+ await this.user.keyboard('[Enter]');
39
62
  }
40
63
  }
41
- return options;
64
+ await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
65
+ if (trigger.getAttribute('aria-controls') == null && !isDisabled) throw new Error('No aria-controls found on menu trigger element.');
66
+ else return true;
67
+ });
68
+ if (!isDisabled) {
69
+ let menuId = trigger.getAttribute('aria-controls');
70
+ await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
71
+ if (!menuId || document.getElementById(menuId) == null) throw new Error(`Menu with id of ${menuId} not found in document.`);
72
+ else return true;
73
+ });
74
+ }
42
75
  }
43
- get sections() {
76
+ /**
77
+ * Returns a option matching the specified index or text content.
78
+ */ findOption(opts) {
79
+ let { optionIndexOrText: optionIndexOrText } = opts;
80
+ let option;
81
+ let options = this.options();
44
82
  let menu = this.menu;
45
- if (menu) return (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('group');
46
- else return [];
47
- }
48
- get submenuTriggers() {
49
- let options = this.options;
50
- if (options.length > 0) return this.options.filter((item)=>item.getAttribute('aria-haspopup') != null);
51
- return [];
83
+ if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
84
+ else if (typeof optionIndexOrText === 'string' && menu != null) option = (0, $l5sJH$testinglibraryreact.within)(menu).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]');
85
+ return option;
52
86
  }
53
- constructor(opts){
54
- this._isSubmenu = false;
55
- this.setInteractionType = (type)=>{
56
- this._interactionType = type;
57
- };
58
- // 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
59
- // One difference will be that it supports long press as well
60
- this.open = async (opts = {})=>{
61
- let { needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType, direction: direction } = opts;
62
- let trigger = this.trigger;
63
- let isDisabled = trigger.hasAttribute('disabled');
64
- if (interactionType === 'mouse' || interactionType === 'touch') {
65
- if (needsLongPress) {
66
- if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
67
- let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';
68
- await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
69
- element: trigger,
70
- advanceTimer: this._advanceTimer,
71
- pointerOpts: {
72
- pointerType: pointerType
73
- }
74
- });
75
- } else if (interactionType === 'mouse') await this.user.click(trigger);
76
- else await this.user.pointer({
77
- target: trigger,
78
- keys: '[TouchA]'
87
+ // TODO: also very similar to select, barring potential long press support
88
+ // Close on select is also kinda specific?
89
+ /**
90
+ * Selects the desired menu option. Defaults to using the interaction type set on the menu tester. If necessary, will open the menu dropdown beforehand.
91
+ * The desired option can be targeted via the option's node, the option's text, or the option's index.
92
+ */ async selectOption(opts) {
93
+ let { menuSelectionMode: menuSelectionMode = 'single', needsLongPress: needsLongPress, closesOnSelect: closesOnSelect = true, option: option, interactionType: interactionType = this._interactionType, keyboardActivation: keyboardActivation = 'Enter' } = opts;
94
+ let trigger = this.trigger;
95
+ if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) await this.open({
96
+ needsLongPress: needsLongPress
97
+ });
98
+ let menu = this.menu;
99
+ if (!menu) throw new Error('Menu not found.');
100
+ if (menu) {
101
+ if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
102
+ optionIndexOrText: option
103
+ });
104
+ if (!option) throw new Error('Target option not found in the menu.');
105
+ if (interactionType === 'keyboard') {
106
+ if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
107
+ if (document.activeElement !== menu || !menu.contains(document.activeElement)) (0, $l5sJH$testinglibraryreact.act)(()=>menu.focus());
108
+ await this.keyboardNavigateToOption({
109
+ option: option
79
110
  });
80
- } else if (interactionType === 'keyboard' && !isDisabled) {
81
- if (direction === 'up') {
82
- (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
83
- await this.user.keyboard('[ArrowUp]');
84
- } else if (direction === 'down') {
85
- (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
86
- await this.user.keyboard('[ArrowDown]');
87
- } else {
88
- (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
89
- await this.user.keyboard('[Enter]');
90
- }
91
- }
92
- await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
93
- if (trigger.getAttribute('aria-controls') == null && !isDisabled) throw new Error('No aria-controls found on menu trigger element.');
94
- else return true;
111
+ await this.user.keyboard(`[${keyboardActivation}]`);
112
+ } else if (interactionType === 'mouse') await this.user.click(option);
113
+ else await this.user.pointer({
114
+ target: option,
115
+ keys: '[TouchA]'
116
+ });
117
+ (0, $l5sJH$testinglibraryreact.act)(()=>{
118
+ jest.runAllTimers();
95
119
  });
96
- if (!isDisabled) {
97
- let menuId = trigger.getAttribute('aria-controls');
120
+ if (option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect && keyboardActivation !== 'Space' && !this._isSubmenu) {
98
121
  await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
99
- if (!menuId || document.getElementById(menuId) == null) throw new Error(`Menu with id of ${menuId} not found in document.`);
122
+ if (document.activeElement !== trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the menu trigger but got ${document.activeElement}`);
100
123
  else return true;
101
124
  });
125
+ if (document.contains(menu)) throw new Error('Expected menu element to not be in the document after selecting an option');
102
126
  }
103
- };
104
- // TODO: also very similar to select, barring potential long press support
105
- // Close on select is also kinda specific?
106
- this.selectOption = async (opts)=>{
107
- let { optionText: optionText, menuSelectionMode: menuSelectionMode = 'single', needsLongPress: needsLongPress, closesOnSelect: closesOnSelect = true, option: option, interactionType: interactionType = this._interactionType, keyboardActivation: keyboardActivation = 'Enter' } = opts;
108
- let trigger = this.trigger;
109
- if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) await this.open({
110
- needsLongPress: needsLongPress
111
- });
127
+ } else throw new Error("Attempted to select a option in the menu, but menu wasn't found.");
128
+ }
129
+ // TODO: update this to remove needsLongPress if we wanna make the user call open first always
130
+ /**
131
+ * 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.
132
+ */ async openSubmenu(opts) {
133
+ let { submenuTrigger: submenuTrigger, needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
134
+ let trigger = this.trigger;
135
+ let isDisabled = trigger.hasAttribute('disabled');
136
+ if (!trigger.getAttribute('aria-controls') && !isDisabled) await this.open({
137
+ needsLongPress: needsLongPress
138
+ });
139
+ if (!isDisabled) {
112
140
  let menu = this.menu;
113
141
  if (menu) {
114
- if (!option && optionText) option = (0, $l5sJH$testinglibraryreact.within)(menu).getByText(optionText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]');
115
- if (!option) throw new Error('No option found in the menu.');
116
- if (interactionType === 'keyboard') {
117
- if (document.activeElement !== menu || !menu.contains(document.activeElement)) (0, $l5sJH$testinglibraryreact.act)(()=>menu.focus());
118
- await this.keyboardNavigateToOption({
119
- option: option
120
- });
121
- await this.user.keyboard(`[${keyboardActivation}]`);
122
- } else if (interactionType === 'mouse') await this.user.click(option);
123
- else await this.user.pointer({
124
- target: option,
125
- keys: '[TouchA]'
126
- });
127
- (0, $l5sJH$testinglibraryreact.act)(()=>{
128
- jest.runAllTimers();
142
+ if (typeof submenuTrigger === 'string') submenuTrigger = (0, $l5sJH$testinglibraryreact.within)(menu).getByText(submenuTrigger).closest('[role=menuitem]');
143
+ let submenuTriggerTester = new $31965f39292c8e99$export$f73bbc9212ed861e({
144
+ user: this.user,
145
+ interactionType: this._interactionType,
146
+ root: submenuTrigger,
147
+ isSubmenu: true
129
148
  });
130
- if (option && option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect && keyboardActivation !== 'Space' && !this._isSubmenu) {
131
- await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
132
- if (document.activeElement !== trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the menu trigger but got ${document.activeElement}`);
133
- else return true;
149
+ if (interactionType === 'mouse') {
150
+ await this.user.pointer({
151
+ target: submenuTrigger
134
152
  });
135
- if (document.contains(menu)) throw new Error('Expected menu element to not be in the document after selecting an option');
136
- }
137
- } else throw new Error("Attempted to select a option in the menu, but menu wasn't found.");
138
- };
139
- // TODO: update this to remove needsLongPress if we wanna make the user call open first always
140
- this.openSubmenu = async (opts)=>{
141
- let { submenuTrigger: submenuTrigger, submenuTriggerText: submenuTriggerText, needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
142
- let trigger = this.trigger;
143
- let isDisabled = trigger.hasAttribute('disabled');
144
- if (!trigger.getAttribute('aria-controls') && !isDisabled) await this.open({
145
- needsLongPress: needsLongPress
146
- });
147
- if (!isDisabled) {
148
- let menu = this.menu;
149
- if (menu) {
150
- let submenu;
151
- if (submenuTrigger) submenu = submenuTrigger;
152
- else if (submenuTriggerText) submenu = (0, $l5sJH$testinglibraryreact.within)(menu).getByText(submenuTriggerText);
153
- let submenuTriggerTester = new $31965f39292c8e99$export$f73bbc9212ed861e({
154
- user: this.user,
155
- interactionType: this._interactionType,
156
- root: submenu,
157
- isSubmenu: true
153
+ (0, $l5sJH$testinglibraryreact.act)(()=>{
154
+ jest.runAllTimers();
158
155
  });
159
- if (interactionType === 'mouse') {
160
- await this.user.pointer({
161
- target: submenu
162
- });
163
- (0, $l5sJH$testinglibraryreact.act)(()=>{
164
- jest.runAllTimers();
165
- });
166
- } else if (interactionType === 'keyboard') {
167
- await this.keyboardNavigateToOption({
168
- option: submenu
169
- });
170
- await this.user.keyboard('[ArrowRight]');
171
- (0, $l5sJH$testinglibraryreact.act)(()=>{
172
- jest.runAllTimers();
173
- });
174
- } else await submenuTriggerTester.open();
175
- return submenuTriggerTester;
176
- }
156
+ } else if (interactionType === 'keyboard') {
157
+ await this.keyboardNavigateToOption({
158
+ option: submenuTrigger
159
+ });
160
+ await this.user.keyboard('[ArrowRight]');
161
+ (0, $l5sJH$testinglibraryreact.act)(()=>{
162
+ jest.runAllTimers();
163
+ });
164
+ } else await submenuTriggerTester.open();
165
+ return submenuTriggerTester;
177
166
  }
178
- return null;
179
- };
180
- this.keyboardNavigateToOption = async (opts)=>{
181
- let { option: option } = opts;
182
- let options = this.options;
183
- let targetIndex = options.indexOf(option);
184
- if (targetIndex === -1) throw new Error('Option provided is not in the menu');
185
- if (document.activeElement === this.menu) await this.user.keyboard('[ArrowDown]');
186
- let currIndex = options.indexOf(document.activeElement);
187
- if (targetIndex === -1) throw new Error('ActiveElement is not in the menu');
188
- let direction = targetIndex > currIndex ? 'down' : 'up';
189
- for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
190
- };
191
- this.close = async ()=>{
192
- let menu = this.menu;
193
- if (menu) {
194
- (0, $l5sJH$testinglibraryreact.act)(()=>menu.focus());
195
- await this.user.keyboard('[Escape]');
196
- await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
197
- 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}`);
198
- else return true;
199
- });
200
- if (document.contains(menu)) throw new Error('Expected the menu to not be in the document after closing it.');
167
+ }
168
+ return null;
169
+ }
170
+ async keyboardNavigateToOption(opts) {
171
+ let { option: option } = opts;
172
+ let options = this.options();
173
+ let targetIndex = options.findIndex((opt)=>opt === option || opt.contains(option));
174
+ if (targetIndex === -1) throw new Error('Option provided is not in the menu');
175
+ if (document.activeElement === this.menu) await this.user.keyboard('[ArrowDown]');
176
+ let currIndex = options.indexOf(document.activeElement);
177
+ if (currIndex === -1) throw new Error('ActiveElement is not in the menu');
178
+ let direction = targetIndex > currIndex ? 'down' : 'up';
179
+ for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
180
+ }
181
+ /**
182
+ * Closes the menu.
183
+ */ async close() {
184
+ let menu = this.menu;
185
+ if (menu) {
186
+ (0, $l5sJH$testinglibraryreact.act)(()=>menu.focus());
187
+ await this.user.keyboard('[Escape]');
188
+ await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
189
+ 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}`);
190
+ else return true;
191
+ });
192
+ if (document.contains(menu)) throw new Error('Expected the menu to not be in the document after closing it.');
193
+ }
194
+ }
195
+ /**
196
+ * Returns the menu's trigger.
197
+ */ get trigger() {
198
+ if (!this._trigger) throw new Error('No trigger element found for menu.');
199
+ return this._trigger;
200
+ }
201
+ /**
202
+ * Returns the menu if present.
203
+ */ get menu() {
204
+ let menuId = this.trigger.getAttribute('aria-controls');
205
+ return menuId ? document.getElementById(menuId) : null;
206
+ }
207
+ /**
208
+ * Returns the menu's sections if any.
209
+ */ get sections() {
210
+ let menu = this.menu;
211
+ if (menu) return (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('group');
212
+ else return [];
213
+ }
214
+ /**
215
+ * Returns the menu's options if present. Can be filtered to a subsection of the menu if provided via `element`.
216
+ */ options(opts = {}) {
217
+ let { element: element = this.menu } = opts;
218
+ let options = [];
219
+ if (element) {
220
+ options = (0, $l5sJH$testinglibraryreact.within)(element).queryAllByRole('menuitem');
221
+ if (options.length === 0) {
222
+ options = (0, $l5sJH$testinglibraryreact.within)(element).queryAllByRole('menuitemradio');
223
+ if (options.length === 0) options = (0, $l5sJH$testinglibraryreact.within)(element).queryAllByRole('menuitemcheckbox');
201
224
  }
202
- };
225
+ }
226
+ return options;
227
+ }
228
+ /**
229
+ * Returns the menu's submenu triggers if any.
230
+ */ get submenuTriggers() {
231
+ let options = this.options();
232
+ if (options.length > 0) return options.filter((item)=>item.getAttribute('aria-haspopup') != null);
233
+ return [];
234
+ }
235
+ constructor(opts){
236
+ this._isSubmenu = false;
203
237
  let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer, isSubmenu: isSubmenu } = opts;
204
238
  this.user = user;
205
239
  this._interactionType = interactionType || 'mouse';
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAUM,MAAM;IAkPX,IAAI,UAAU;QACZ,IAAI,CAAC,IAAI,CAAC,QAAQ,EAChB,MAAM,IAAI,MAAM;QAElB,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,UAAyB;QAC3B,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,UAAyB,EAAE;QAC/B,IAAI,MAAM;YACR,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;YACtC,IAA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ages/@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 isSubmenu?: boolean\n}\nexport class MenuTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _trigger: HTMLElement | undefined;\n private _isSubmenu: boolean = false;\n\n constructor(opts: MenuOptions) {\n let {root, user, interactionType, advanceTimer, isSubmenu} = 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 this._isSubmenu = isSubmenu || false;\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'], direction?: 'up' | 'down'} = {}) => {\n let {\n needsLongPress,\n interactionType = this._interactionType,\n direction\n } = opts;\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 if (direction === 'up') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowUp]');\n } else if (direction === 'down') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowDown]');\n } else {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\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: {\n option?: HTMLElement,\n optionText?: string,\n menuSelectionMode?: 'single' | 'multiple',\n needsLongPress?: boolean,\n closesOnSelect?: boolean,\n interactionType?: UserOpts['interactionType'],\n keyboardActivation?: 'Space' | 'Enter'\n }) => {\n let {\n optionText,\n menuSelectionMode = 'single',\n needsLongPress,\n closesOnSelect = true,\n option,\n interactionType = this._interactionType,\n keyboardActivation = 'Enter'\n } = opts;\n let trigger = this.trigger;\n\n if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) {\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).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]'))! as HTMLElement;\n }\n if (!option) {\n throw new Error('No option found in the menu.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== menu || !menu.contains(document.activeElement)) {\n act(() => menu.focus());\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\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 act(() => {jest.runAllTimers();});\n\n if (option && option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect && keyboardActivation !== 'Space' && !this._isSubmenu) {\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\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: this._interactionType, root: submenu, isSubmenu: true});\n if (interactionType === 'mouse') {\n await this.user.pointer({target: submenu});\n act(() => {jest.runAllTimers();});\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToOption({option: submenu});\n await this.user.keyboard('[ArrowRight]');\n act(() => {jest.runAllTimers();});\n } else {\n await submenuTriggerTester.open();\n }\n\n\n return submenuTriggerTester;\n }\n }\n\n return null;\n };\n\n keyboardNavigateToOption = async (opts: {option: HTMLElement}) => {\n let {option} = opts;\n let options = this.options;\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the menu');\n }\n if (document.activeElement === this.menu) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (targetIndex === -1) {\n throw new Error('ActiveElement is not in the menu');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\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 if (!this._trigger) {\n throw new Error('No trigger element found for menu.');\n }\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[] {\n let menu = this.menu;\n let options: HTMLElement[] = [];\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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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 {MenuTesterOpts, UserOpts} from './types';\nimport {triggerLongPress} from './events';\n\ninterface MenuOpenOpts {\n /**\n * Whether the menu needs to be long pressed to open.\n */\n needsLongPress?: boolean,\n /**\n * What interaction type to use when opening the menu. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * Whether to open the menu via ArrowUp or ArrowDown if in keyboard modality.\n */\n direction?: 'up' | 'down'\n}\n\ninterface MenuSelectOpts extends MenuOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement,\n /**\n * The menu's selection mode. Will affect whether or not the menu is expected to be closed upon option selection.\n * @default 'single'\n */\n menuSelectionMode?: 'single' | 'multiple',\n /**\n * Whether or not the menu closes on select. Depends on menu implementation and configuration.\n * @default true\n */\n closesOnSelect?: boolean,\n /**\n * Whether the option should be triggered by Space or Enter in keyboard modality.\n * @default 'Enter'\n */\n keyboardActivation?: 'Space' | 'Enter'\n}\n\ninterface MenuOpenSubmenuOpts extends MenuOpenOpts {\n /**\n * The text or node of the submenu trigger to open. Available submenu trigger nodes can be sourced via `submenuTriggers`.\n */\n submenuTrigger: string | HTMLElement\n}\n\nexport class MenuTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _trigger: HTMLElement | undefined;\n private _isSubmenu: boolean = false;\n\n constructor(opts: MenuTesterOpts) {\n let {root, user, interactionType, advanceTimer, isSubmenu} = 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 this._isSubmenu = isSubmenu || false;\n }\n\n /**\n * Set the interaction type used by the menu tester.\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 /**\n * Opens the menu. Defaults to using the interaction type set on the menu tester.\n */\n async open(opts: MenuOpenOpts = {}) {\n let {\n needsLongPress,\n interactionType = this._interactionType,\n direction\n } = opts;\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 if (direction === 'up') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowUp]');\n } else if (direction === 'down') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowDown]');\n } else {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\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 /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let menu = this.menu;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && menu != null) {\n option = (within(menu!).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]'))! as HTMLElement;\n }\n\n return option;\n }\n\n // TODO: also very similar to select, barring potential long press support\n // Close on select is also kinda specific?\n /**\n * Selects the desired menu option. Defaults to using the interaction type set on the menu tester. If necessary, will open the menu dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: MenuSelectOpts) {\n let {\n menuSelectionMode = 'single',\n needsLongPress,\n closesOnSelect = true,\n option,\n interactionType = this._interactionType,\n keyboardActivation = 'Enter'\n } = opts;\n let trigger = this.trigger;\n\n if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) {\n await this.open({needsLongPress});\n }\n\n let menu = this.menu;\n\n if (!menu) {\n throw new Error('Menu not found.');\n }\n\n if (menu) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the menu.');\n }\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== menu || !menu.contains(document.activeElement)) {\n act(() => menu.focus());\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\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 act(() => {jest.runAllTimers();});\n\n if (option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect && keyboardActivation !== 'Space' && !this._isSubmenu) {\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 /**\n * 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.\n */\n async openSubmenu(opts: MenuOpenSubmenuOpts): Promise<MenuTester | null> {\n let {\n submenuTrigger,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\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 if (typeof submenuTrigger === 'string') {\n submenuTrigger = (within(menu!).getByText(submenuTrigger).closest('[role=menuitem]'))! as HTMLElement;\n }\n\n let submenuTriggerTester = new MenuTester({user: this.user, interactionType: this._interactionType, root: submenuTrigger, isSubmenu: true});\n if (interactionType === 'mouse') {\n await this.user.pointer({target: submenuTrigger});\n act(() => {jest.runAllTimers();});\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToOption({option: submenuTrigger});\n await this.user.keyboard('[ArrowRight]');\n act(() => {jest.runAllTimers();});\n } else {\n await submenuTriggerTester.open();\n }\n\n\n return submenuTriggerTester;\n }\n }\n\n return null;\n }\n\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.findIndex(opt => (opt === option) || opt.contains(option));\n\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the menu');\n }\n if (document.activeElement === this.menu) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the menu');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Closes the menu.\n */\n async close() {\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 /**\n * Returns the menu's trigger.\n */\n get trigger(): HTMLElement {\n if (!this._trigger) {\n throw new Error('No trigger element found for menu.');\n }\n\n return this._trigger;\n }\n\n /**\n * Returns the menu if present.\n */\n get menu(): HTMLElement | null {\n let menuId = this.trigger.getAttribute('aria-controls');\n return menuId ? document.getElementById(menuId) : null;\n }\n\n /**\n * Returns the menu's sections if any.\n */\n get sections(): HTMLElement[] {\n let menu = this.menu;\n if (menu) {\n return within(menu).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n /**\n * Returns the menu's options if present. Can be filtered to a subsection of the menu if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.menu} = opts;\n let options: HTMLElement[] = [];\n if (element) {\n options = within(element).queryAllByRole('menuitem');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemradio');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemcheckbox');\n }\n }\n }\n\n return options;\n }\n\n /**\n * Returns the menu's submenu triggers if any.\n */\n get submenuTriggers(): HTMLElement[] {\n let options = this.options();\n if (options.length > 0) {\n return options.filter(item => item.getAttribute('aria-haspopup') != null);\n }\n\n return [];\n }\n}\n"],"names":[],"version":3,"file":"menu.main.js.map"}