@react-aria/test-utils 1.0.0-nightly.5041 → 1.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +70 -0
  2. package/dist/import.mjs +6 -4
  3. package/dist/main.js +15 -23
  4. package/dist/main.js.map +1 -1
  5. package/dist/module.js +6 -4
  6. package/dist/module.js.map +1 -1
  7. package/dist/private/act.cjs +33 -0
  8. package/dist/private/act.cjs.map +1 -0
  9. package/dist/private/act.js +28 -0
  10. package/dist/private/act.js.map +1 -0
  11. package/dist/private/checkboxgroup.cjs +107 -0
  12. package/dist/private/checkboxgroup.cjs.map +1 -0
  13. package/dist/private/checkboxgroup.js +102 -0
  14. package/dist/private/checkboxgroup.js.map +1 -0
  15. package/dist/private/combobox.cjs +199 -0
  16. package/dist/private/combobox.cjs.map +1 -0
  17. package/dist/private/combobox.js +194 -0
  18. package/dist/private/combobox.js.map +1 -0
  19. package/dist/private/dialog.cjs +110 -0
  20. package/dist/private/dialog.cjs.map +1 -0
  21. package/dist/private/dialog.js +105 -0
  22. package/dist/private/dialog.js.map +1 -0
  23. package/dist/private/gridlist.cjs +173 -0
  24. package/dist/private/gridlist.cjs.map +1 -0
  25. package/dist/private/gridlist.js +168 -0
  26. package/dist/private/gridlist.js.map +1 -0
  27. package/dist/private/listbox.cjs +163 -0
  28. package/dist/private/listbox.cjs.map +1 -0
  29. package/dist/private/listbox.js +158 -0
  30. package/dist/private/listbox.js.map +1 -0
  31. package/dist/private/menu.cjs +265 -0
  32. package/dist/private/menu.cjs.map +1 -0
  33. package/dist/private/menu.js +260 -0
  34. package/dist/private/menu.js.map +1 -0
  35. package/dist/private/radiogroup.cjs +122 -0
  36. package/dist/private/radiogroup.cjs.map +1 -0
  37. package/dist/private/radiogroup.js +117 -0
  38. package/dist/private/radiogroup.js.map +1 -0
  39. package/dist/private/select.cjs +169 -0
  40. package/dist/private/select.cjs.map +1 -0
  41. package/dist/private/select.js +164 -0
  42. package/dist/private/select.js.map +1 -0
  43. package/dist/private/table.cjs +346 -0
  44. package/dist/private/table.cjs.map +1 -0
  45. package/dist/private/table.js +341 -0
  46. package/dist/private/table.js.map +1 -0
  47. package/dist/private/tabs.cjs +131 -0
  48. package/dist/private/tabs.cjs.map +1 -0
  49. package/dist/private/tabs.js +126 -0
  50. package/dist/private/tabs.js.map +1 -0
  51. package/dist/private/testSetup.cjs +87 -0
  52. package/dist/private/testSetup.cjs.map +1 -0
  53. package/dist/private/testSetup.js +81 -0
  54. package/dist/private/testSetup.js.map +1 -0
  55. package/dist/private/tree.cjs +181 -0
  56. package/dist/private/tree.cjs.map +1 -0
  57. package/dist/private/tree.js +176 -0
  58. package/dist/private/tree.js.map +1 -0
  59. package/dist/private/user.cjs +85 -0
  60. package/dist/private/user.cjs.map +1 -0
  61. package/dist/private/user.js +76 -0
  62. package/dist/private/user.js.map +1 -0
  63. package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
  64. package/dist/private/userEventMaps.cjs.map +1 -0
  65. package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
  66. package/dist/private/userEventMaps.js.map +1 -0
  67. package/dist/private/utils.cjs +136 -0
  68. package/dist/private/utils.cjs.map +1 -0
  69. package/dist/private/utils.js +127 -0
  70. package/dist/private/utils.js.map +1 -0
  71. package/dist/types/src/act.d.ts +4 -0
  72. package/dist/types/src/checkboxgroup.d.ts +47 -0
  73. package/dist/types/src/combobox.d.ts +87 -0
  74. package/dist/types/src/dialog.d.ts +37 -0
  75. package/dist/types/src/events.d.ts +25 -0
  76. package/dist/types/src/gridlist.d.ts +56 -0
  77. package/dist/types/src/index.d.ts +16 -0
  78. package/dist/types/src/listbox.d.ts +91 -0
  79. package/dist/types/src/menu.d.ts +112 -0
  80. package/dist/types/src/radiogroup.d.ts +47 -0
  81. package/dist/types/src/select.d.ts +74 -0
  82. package/dist/types/src/table.d.ts +120 -0
  83. package/dist/types/src/tabs.d.ts +59 -0
  84. package/dist/types/src/testSetup.d.ts +6 -0
  85. package/dist/types/src/tree.d.ts +62 -0
  86. package/dist/types/src/types.d.ts +143 -0
  87. package/dist/types/src/user.d.ts +49 -0
  88. package/dist/types/src/userEventMaps.d.ts +2 -0
  89. package/dist/types/src/utils.d.ts +29 -0
  90. package/package.json +26 -18
  91. package/src/act.ts +35 -0
  92. package/src/checkboxgroup.ts +165 -0
  93. package/src/combobox.ts +307 -0
  94. package/src/dialog.ts +155 -0
  95. package/src/gridlist.ts +278 -0
  96. package/src/index.ts +17 -3
  97. package/src/listbox.ts +300 -0
  98. package/src/menu.ts +479 -0
  99. package/src/radiogroup.ts +179 -0
  100. package/src/select.ts +273 -0
  101. package/src/table.ts +589 -0
  102. package/src/tabs.ts +204 -0
  103. package/src/testSetup.ts +41 -36
  104. package/src/tree.ts +290 -0
  105. package/src/types.ts +171 -0
  106. package/src/user.ts +153 -0
  107. package/src/userEventMaps.ts +1 -1
  108. package/src/utils.ts +155 -0
  109. package/dist/events.main.js +0 -37
  110. package/dist/events.main.js.map +0 -1
  111. package/dist/events.mjs +0 -31
  112. package/dist/events.module.js +0 -31
  113. package/dist/events.module.js.map +0 -1
  114. package/dist/testSetup.main.js +0 -82
  115. package/dist/testSetup.main.js.map +0 -1
  116. package/dist/testSetup.mjs +0 -76
  117. package/dist/testSetup.module.js +0 -76
  118. package/dist/testSetup.module.js.map +0 -1
  119. package/dist/types.d.ts +0 -16
  120. package/dist/types.d.ts.map +0 -1
  121. package/dist/userEventMaps.main.js.map +0 -1
  122. package/dist/userEventMaps.module.js +0 -38
  123. package/dist/userEventMaps.module.js.map +0 -1
  124. package/src/events.ts +0 -28
@@ -0,0 +1,199 @@
1
+ var $a84d573878cc1e5e$exports = require("./act.cjs");
2
+ var $022fcf8e360befed$exports = require("./utils.cjs");
3
+ var $btaxF$testinglibrarydom = require("@testing-library/dom");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "ComboBoxTester", function () { return $2cdddd94ee78eafe$export$f97e14e96d71ab3b; });
11
+ /*
12
+ * Copyright 2024 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ class $2cdddd94ee78eafe$export$f97e14e96d71ab3b {
25
+ constructor(opts){
26
+ let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
27
+ this.user = user;
28
+ this._interactionType = interactionType || 'mouse';
29
+ // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to
30
+ // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
31
+ this._combobox = root;
32
+ let combobox = (0, $btaxF$testinglibrarydom.within)(root).queryByRole('combobox');
33
+ if (combobox) this._combobox = combobox;
34
+ // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)
35
+ if (trigger) this._trigger = trigger;
36
+ else {
37
+ let buttons = (0, $btaxF$testinglibrarydom.within)(root).queryAllByRole('button', {
38
+ hidden: true
39
+ });
40
+ if (buttons.length === 1) trigger = buttons[0];
41
+ else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
42
+ // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
43
+ // is also the trigger button
44
+ this._trigger = trigger || this._combobox;
45
+ }
46
+ }
47
+ /**
48
+ * Set the interaction type used by the combobox tester.
49
+ */ setInteractionType(type) {
50
+ this._interactionType = type;
51
+ }
52
+ /**
53
+ * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.
54
+ */ async open(opts = {}) {
55
+ let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
56
+ let trigger = this.getTrigger();
57
+ let combobox = this.getCombobox();
58
+ let isDisabled = trigger.hasAttribute('disabled');
59
+ if (interactionType === 'mouse') {
60
+ if (triggerBehavior === 'focus') await this.user.click(combobox);
61
+ else await this.user.click(trigger);
62
+ } else if (interactionType === 'keyboard') {
63
+ (0, $a84d573878cc1e5e$exports.act)(()=>combobox.focus());
64
+ if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
65
+ } else if (interactionType === 'touch') {
66
+ if (triggerBehavior === 'focus') await this.user.pointer({
67
+ target: combobox,
68
+ keys: '[TouchA]'
69
+ });
70
+ else await this.user.pointer({
71
+ target: trigger,
72
+ keys: '[TouchA]'
73
+ });
74
+ }
75
+ await (0, $btaxF$testinglibrarydom.waitFor)(()=>{
76
+ if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
77
+ else return true;
78
+ });
79
+ let listBoxId = combobox.getAttribute('aria-controls');
80
+ await (0, $btaxF$testinglibrarydom.waitFor)(()=>{
81
+ if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
82
+ else return true;
83
+ });
84
+ }
85
+ /**
86
+ * Returns an option matching the specified index or text content.
87
+ */ findOption(opts) {
88
+ let { indexOrText: indexOrText } = opts;
89
+ let option;
90
+ let options = this.getOptions();
91
+ let listbox = this.getListbox();
92
+ if (typeof indexOrText === 'number') option = options[indexOrText];
93
+ else if (typeof indexOrText === 'string' && listbox != null) option = (0, $btaxF$testinglibrarydom.within)(listbox).getByText(indexOrText).closest('[role=option]');
94
+ return option;
95
+ }
96
+ async keyboardNavigateToOption(opts) {
97
+ let { option: option } = opts;
98
+ let combobox = this.getCombobox();
99
+ let options = this.getOptions();
100
+ let targetIndex = options.findIndex((opt)=>opt === option || opt.contains(option));
101
+ if (targetIndex === -1) throw new Error('Option provided is not in the combobox listbox.');
102
+ let getCurrentIndex = ()=>{
103
+ let id = combobox.getAttribute('aria-activedescendant');
104
+ if (!id) return -1;
105
+ return options.findIndex((opt)=>opt.id === id);
106
+ };
107
+ if (getCurrentIndex() === -1) await this.user.keyboard('[ArrowDown]');
108
+ let currIndex = getCurrentIndex();
109
+ if (currIndex === -1) throw new Error('Could not determine the current option in the combobox listbox.');
110
+ let direction = targetIndex > currIndex ? 'down' : 'up';
111
+ for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
112
+ }
113
+ /**
114
+ * Toggles the selection of the desired combobox option if possible. Defaults to using the
115
+ * interaction type set on the combobox tester. If necessary, will open the combobox dropdown
116
+ * beforehand. The desired option can be targeted via the option's node, the option's text, or the
117
+ * option's index.
118
+ */ async toggleOptionSelection(opts) {
119
+ let { option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType, closesOnSelect: closesOnSelect } = opts;
120
+ if (!this.getCombobox().getAttribute('aria-controls')) await this.open({
121
+ triggerBehavior: triggerBehavior
122
+ });
123
+ let listbox = this.getListbox();
124
+ if (!listbox) throw new Error("Combobox's listbox not found.");
125
+ if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
126
+ indexOrText: option
127
+ });
128
+ if (!option) throw new Error(`Target option "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.option)}" not found in the listbox.`);
129
+ let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';
130
+ closesOnSelect = closesOnSelect ?? !isMultiSelect;
131
+ if (interactionType === 'keyboard') {
132
+ await this.keyboardNavigateToOption({
133
+ option: option
134
+ });
135
+ await this.user.keyboard('[Enter]');
136
+ } else if (interactionType === 'mouse') await this.user.click(option);
137
+ else await this.user.pointer({
138
+ target: option,
139
+ keys: '[TouchA]'
140
+ });
141
+ if (closesOnSelect && option.getAttribute('href') == null) await (0, $btaxF$testinglibrarydom.waitFor)(()=>{
142
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
143
+ else return true;
144
+ });
145
+ }
146
+ /**
147
+ * Closes the combobox dropdown.
148
+ */ async close() {
149
+ let listbox = this.getListbox();
150
+ if (listbox) {
151
+ (0, $a84d573878cc1e5e$exports.act)(()=>this.getCombobox().focus());
152
+ await this.user.keyboard('[Escape]');
153
+ await (0, $btaxF$testinglibrarydom.waitFor)(()=>{
154
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
155
+ else return true;
156
+ });
157
+ }
158
+ }
159
+ /**
160
+ * Returns the combobox.
161
+ */ getCombobox() {
162
+ return this._combobox;
163
+ }
164
+ /**
165
+ * Returns the combobox trigger button.
166
+ */ getTrigger() {
167
+ return this._trigger;
168
+ }
169
+ /**
170
+ * Returns the combobox's listbox if present.
171
+ */ getListbox() {
172
+ let listBoxId = this.getCombobox().getAttribute('aria-controls');
173
+ return listBoxId ? document.getElementById(listBoxId) || null : null;
174
+ }
175
+ /**
176
+ * Returns the combobox's sections if present.
177
+ */ getSections() {
178
+ let listbox = this.getListbox();
179
+ return listbox ? (0, $btaxF$testinglibrarydom.within)(listbox).queryAllByRole('group') : [];
180
+ }
181
+ /**
182
+ * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if
183
+ * provided via `element`.
184
+ */ getOptions(opts = {}) {
185
+ let { element: element = this.getListbox() } = opts;
186
+ let options = [];
187
+ if (element) options = (0, $btaxF$testinglibrarydom.within)(element).queryAllByRole('option');
188
+ return options;
189
+ }
190
+ /**
191
+ * Returns the currently focused option in the combobox's dropdown if any.
192
+ */ getFocusedOption() {
193
+ let focusedOptionId = this.getCombobox().getAttribute('aria-activedescendant');
194
+ return focusedOptionId ? document.getElementById(focusedOptionId) : null;
195
+ }
196
+ }
197
+
198
+
199
+ //# sourceMappingURL=combobox.cjs.map
@@ -0,0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E;IAC/D;IAEA;;;GAGC,GACD,WAAW,OAAgC,CAAC,CAAC,EAAiB;QAC5D,IAAI,WAAC,UAAU,IAAI,CAAC,UAAU,IAAG,GAAG;QACpC,IAAI,UAAU,EAAE;QAChB,IAAI,SACF,UAAU,CAAA,GAAA,+BAAK,EAAE,SAAS,cAAc,CAAC;QAG3C,OAAO;IACT;IAEA;;GAEC,GACD,mBAAuC;QACrC,IAAI,kBAAkB,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC;QACtD,OAAO,kBAAkB,SAAS,cAAc,CAAC,mBAAmB;IACtE;AACF","sources":["packages/@react-aria/test-utils/src/combobox.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} from './act';\nimport {ComboBoxTesterOpts, UserOpts} from './types';\nimport {formatTargetNode} from './utils';\nimport {waitFor, within} from '@testing-library/dom';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\n *\n * @default 'manual'\n */\n triggerBehavior?: 'focus' | 'manual';\n /**\n * What interaction type to use when opening the combobox. Defaults to the interaction type set on\n * the tester.\n */\n interactionType?: UserOpts['interactionType'];\n}\n\ninterface ComboBoxSelectOpts extends ComboBoxOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via\n * `getOptions()`.\n */\n option: number | string | HTMLElement;\n /**\n * Whether or not the combobox closes on selection. Defaults to `true` for single select\n * comboboxes and `false` for multi-select comboboxes.\n */\n closesOnSelect?: boolean;\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement;\n\n constructor(opts: ComboBoxTesterOpts) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let buttons = within(root).queryAllByRole('button', {hidden: true});\n\n if (buttons.length === 1) {\n trigger = buttons[0];\n } else if (buttons.length > 1) {\n trigger = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = trigger || this._combobox;\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.\n */\n async open(opts: ComboBoxOpenOpts = {}): Promise<void> {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.getTrigger();\n let combobox = this.getCombobox();\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard') {\n act(() => combobox.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.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 /**\n * Returns an option matching the specified index or text content.\n */\n findOption(opts: {indexOrText: number | string}): HTMLElement {\n let {indexOrText} = opts;\n\n let option;\n let options = this.getOptions();\n let listbox = this.getListbox();\n\n if (typeof indexOrText === 'number') {\n option = options[indexOrText];\n } else if (typeof indexOrText === 'string' && listbox != null) {\n option = within(listbox!).getByText(indexOrText).closest('[role=option]')! as HTMLElement;\n }\n\n return option;\n }\n\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let combobox = this.getCombobox();\n let options = this.getOptions();\n let targetIndex = options.findIndex(opt => opt === option || opt.contains(option));\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the combobox listbox.');\n }\n\n let getCurrentIndex = () => {\n let id = combobox.getAttribute('aria-activedescendant');\n if (!id) {\n return -1;\n }\n return options.findIndex(opt => opt.id === id);\n };\n\n if (getCurrentIndex() === -1) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n let currIndex = getCurrentIndex();\n if (currIndex === -1) {\n throw new Error('Could not determine the current option in the combobox listbox.');\n }\n\n let direction = targetIndex > currIndex ? 'down' : 'up';\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 * Toggles the selection of the desired combobox option if possible. Defaults to using the\n * interaction type set on the combobox tester. If necessary, will open the combobox dropdown\n * beforehand. The desired option can be targeted via the option's node, the option's text, or the\n * option's index.\n */\n async toggleOptionSelection(opts: ComboBoxSelectOpts): Promise<void> {\n let {option, triggerBehavior, interactionType = this._interactionType, closesOnSelect} = opts;\n if (!this.getCombobox().getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.getListbox();\n if (!listbox) {\n throw new Error(\"Combobox's listbox not found.\");\n }\n\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({indexOrText: option});\n }\n\n if (!option) {\n throw new Error(`Target option \"${formatTargetNode(opts.option)}\" not found in the listbox.`);\n }\n\n let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';\n closesOnSelect = closesOnSelect ?? !isMultiSelect;\n\n if (interactionType === 'keyboard') {\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (closesOnSelect && option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error(\n 'Expected listbox element to not be in the document after selecting an option'\n );\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close(): Promise<void> {\n let listbox = this.getListbox();\n if (listbox) {\n act(() => this.getCombobox().focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error(\n 'Expected listbox element to not be in the document after selecting an option'\n );\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n getCombobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n getTrigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n getListbox(): HTMLElement | null {\n let listBoxId = this.getCombobox().getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n getSections(): HTMLElement[] {\n let listbox = this.getListbox();\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n\n /**\n * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if\n * provided via `element`.\n */\n getOptions(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.getListbox()} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the currently focused option in the combobox's dropdown if any.\n */\n getFocusedOption(): HTMLElement | null {\n let focusedOptionId = this.getCombobox().getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.cjs.map"}
@@ -0,0 +1,194 @@
1
+ import {act as $1350703ef3ac1acc$export$3ba232387fd5d6dd} from "./act.js";
2
+ import {formatTargetNode as $b4e037a2907521c6$export$bc3bc4a9206bf789} from "./utils.js";
3
+ import {within as $d5vWN$within, waitFor as $d5vWN$waitFor} from "@testing-library/dom";
4
+
5
+ /*
6
+ * Copyright 2024 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ class $a2202d8b369e6a8a$export$f97e14e96d71ab3b {
19
+ constructor(opts){
20
+ let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
21
+ this.user = user;
22
+ this._interactionType = interactionType || 'mouse';
23
+ // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to
24
+ // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
25
+ this._combobox = root;
26
+ let combobox = (0, $d5vWN$within)(root).queryByRole('combobox');
27
+ if (combobox) this._combobox = combobox;
28
+ // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)
29
+ if (trigger) this._trigger = trigger;
30
+ else {
31
+ let buttons = (0, $d5vWN$within)(root).queryAllByRole('button', {
32
+ hidden: true
33
+ });
34
+ if (buttons.length === 1) trigger = buttons[0];
35
+ else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
36
+ // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
37
+ // is also the trigger button
38
+ this._trigger = trigger || this._combobox;
39
+ }
40
+ }
41
+ /**
42
+ * Set the interaction type used by the combobox tester.
43
+ */ setInteractionType(type) {
44
+ this._interactionType = type;
45
+ }
46
+ /**
47
+ * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.
48
+ */ async open(opts = {}) {
49
+ let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
50
+ let trigger = this.getTrigger();
51
+ let combobox = this.getCombobox();
52
+ let isDisabled = trigger.hasAttribute('disabled');
53
+ if (interactionType === 'mouse') {
54
+ if (triggerBehavior === 'focus') await this.user.click(combobox);
55
+ else await this.user.click(trigger);
56
+ } else if (interactionType === 'keyboard') {
57
+ (0, $1350703ef3ac1acc$export$3ba232387fd5d6dd)(()=>combobox.focus());
58
+ if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
59
+ } else if (interactionType === 'touch') {
60
+ if (triggerBehavior === 'focus') await this.user.pointer({
61
+ target: combobox,
62
+ keys: '[TouchA]'
63
+ });
64
+ else await this.user.pointer({
65
+ target: trigger,
66
+ keys: '[TouchA]'
67
+ });
68
+ }
69
+ await (0, $d5vWN$waitFor)(()=>{
70
+ if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
71
+ else return true;
72
+ });
73
+ let listBoxId = combobox.getAttribute('aria-controls');
74
+ await (0, $d5vWN$waitFor)(()=>{
75
+ if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
76
+ else return true;
77
+ });
78
+ }
79
+ /**
80
+ * Returns an option matching the specified index or text content.
81
+ */ findOption(opts) {
82
+ let { indexOrText: indexOrText } = opts;
83
+ let option;
84
+ let options = this.getOptions();
85
+ let listbox = this.getListbox();
86
+ if (typeof indexOrText === 'number') option = options[indexOrText];
87
+ else if (typeof indexOrText === 'string' && listbox != null) option = (0, $d5vWN$within)(listbox).getByText(indexOrText).closest('[role=option]');
88
+ return option;
89
+ }
90
+ async keyboardNavigateToOption(opts) {
91
+ let { option: option } = opts;
92
+ let combobox = this.getCombobox();
93
+ let options = this.getOptions();
94
+ let targetIndex = options.findIndex((opt)=>opt === option || opt.contains(option));
95
+ if (targetIndex === -1) throw new Error('Option provided is not in the combobox listbox.');
96
+ let getCurrentIndex = ()=>{
97
+ let id = combobox.getAttribute('aria-activedescendant');
98
+ if (!id) return -1;
99
+ return options.findIndex((opt)=>opt.id === id);
100
+ };
101
+ if (getCurrentIndex() === -1) await this.user.keyboard('[ArrowDown]');
102
+ let currIndex = getCurrentIndex();
103
+ if (currIndex === -1) throw new Error('Could not determine the current option in the combobox listbox.');
104
+ let direction = targetIndex > currIndex ? 'down' : 'up';
105
+ for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
106
+ }
107
+ /**
108
+ * Toggles the selection of the desired combobox option if possible. Defaults to using the
109
+ * interaction type set on the combobox tester. If necessary, will open the combobox dropdown
110
+ * beforehand. The desired option can be targeted via the option's node, the option's text, or the
111
+ * option's index.
112
+ */ async toggleOptionSelection(opts) {
113
+ let { option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType, closesOnSelect: closesOnSelect } = opts;
114
+ if (!this.getCombobox().getAttribute('aria-controls')) await this.open({
115
+ triggerBehavior: triggerBehavior
116
+ });
117
+ let listbox = this.getListbox();
118
+ if (!listbox) throw new Error("Combobox's listbox not found.");
119
+ if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
120
+ indexOrText: option
121
+ });
122
+ if (!option) throw new Error(`Target option "${(0, $b4e037a2907521c6$export$bc3bc4a9206bf789)(opts.option)}" not found in the listbox.`);
123
+ let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';
124
+ closesOnSelect = closesOnSelect ?? !isMultiSelect;
125
+ if (interactionType === 'keyboard') {
126
+ await this.keyboardNavigateToOption({
127
+ option: option
128
+ });
129
+ await this.user.keyboard('[Enter]');
130
+ } else if (interactionType === 'mouse') await this.user.click(option);
131
+ else await this.user.pointer({
132
+ target: option,
133
+ keys: '[TouchA]'
134
+ });
135
+ if (closesOnSelect && option.getAttribute('href') == null) await (0, $d5vWN$waitFor)(()=>{
136
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
137
+ else return true;
138
+ });
139
+ }
140
+ /**
141
+ * Closes the combobox dropdown.
142
+ */ async close() {
143
+ let listbox = this.getListbox();
144
+ if (listbox) {
145
+ (0, $1350703ef3ac1acc$export$3ba232387fd5d6dd)(()=>this.getCombobox().focus());
146
+ await this.user.keyboard('[Escape]');
147
+ await (0, $d5vWN$waitFor)(()=>{
148
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
149
+ else return true;
150
+ });
151
+ }
152
+ }
153
+ /**
154
+ * Returns the combobox.
155
+ */ getCombobox() {
156
+ return this._combobox;
157
+ }
158
+ /**
159
+ * Returns the combobox trigger button.
160
+ */ getTrigger() {
161
+ return this._trigger;
162
+ }
163
+ /**
164
+ * Returns the combobox's listbox if present.
165
+ */ getListbox() {
166
+ let listBoxId = this.getCombobox().getAttribute('aria-controls');
167
+ return listBoxId ? document.getElementById(listBoxId) || null : null;
168
+ }
169
+ /**
170
+ * Returns the combobox's sections if present.
171
+ */ getSections() {
172
+ let listbox = this.getListbox();
173
+ return listbox ? (0, $d5vWN$within)(listbox).queryAllByRole('group') : [];
174
+ }
175
+ /**
176
+ * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if
177
+ * provided via `element`.
178
+ */ getOptions(opts = {}) {
179
+ let { element: element = this.getListbox() } = opts;
180
+ let options = [];
181
+ if (element) options = (0, $d5vWN$within)(element).queryAllByRole('option');
182
+ return options;
183
+ }
184
+ /**
185
+ * Returns the currently focused option in the combobox's dropdown if any.
186
+ */ getFocusedOption() {
187
+ let focusedOptionId = this.getCombobox().getAttribute('aria-activedescendant');
188
+ return focusedOptionId ? document.getElementById(focusedOptionId) : null;
189
+ }
190
+ }
191
+
192
+
193
+ export {$a2202d8b369e6a8a$export$f97e14e96d71ab3b as ComboBoxTester};
194
+ //# sourceMappingURL=combobox.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAkCM,MAAM;IAMX,YAAY,IAAwB,CAAE;QACpC,IAAI,QAAC,IAAI,WAAE,OAAO,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QAC7C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAE3C,8IAA8I;QAC9I,2FAA2F;QAC3F,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,WAAW,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC;QACxC,IAAI,UACF,IAAI,CAAC,SAAS,GAAG;QAGnB,6KAA6K;QAC7K,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC,UAAU;gBAAC,QAAQ;YAAI;YAEjE,IAAI,QAAQ,MAAM,KAAK,GACrB,UAAU,OAAO,CAAC,EAAE;iBACf,IAAI,QAAQ,MAAM,GAAG,GAC1B,UAAU,QAAQ,IAAI,CAAC,CAAA,SAAU,OAAO,YAAY,CAAC;YAGvD,qHAAqH;YACrH,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,GAAG,WAAW,IAAI,CAAC,SAAS;QAC3C;IACF;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gB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,CAAC,SAAS;IACvB;IAEA;;GAEC,GACD,aAA0B;QACxB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA;;GAEC,GACD,aAAiC;QAC/B,IAAI,YAAY,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC;QAChD,OAAO,YAAY,SAAS,cAAc,CAAC,cAAc,OAAO;IAClE;IAEA;;GAEC,GACD,cAA6B;QAC3B,IAAI,UAAU,IAAI,CAAC,UAAU;QAC7B,OAAO,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC,WAAW,EAAE;IAC/D;IAEA;;;GAGC,GACD,WAAW,OAAgC,CAAC,CAAC,EAAiB;QAC5D,IAAI,WAAC,UAAU,IAAI,CAAC,UAAU,IAAG,GAAG;QACpC,IAAI,UAAU,EAAE;QAChB,IAAI,SACF,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;QAG3C,OAAO;IACT;IAEA;;GAEC,GACD,mBAAuC;QACrC,IAAI,kBAAkB,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC;QACtD,OAAO,kBAAkB,SAAS,cAAc,CAAC,mBAAmB;IACtE;AACF","sources":["packages/@react-aria/test-utils/src/combobox.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} from './act';\nimport {ComboBoxTesterOpts, UserOpts} from './types';\nimport {formatTargetNode} from './utils';\nimport {waitFor, within} from '@testing-library/dom';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\n *\n * @default 'manual'\n */\n triggerBehavior?: 'focus' | 'manual';\n /**\n * What interaction type to use when opening the combobox. Defaults to the interaction type set on\n * the tester.\n */\n interactionType?: UserOpts['interactionType'];\n}\n\ninterface ComboBoxSelectOpts extends ComboBoxOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via\n * `getOptions()`.\n */\n option: number | string | HTMLElement;\n /**\n * Whether or not the combobox closes on selection. Defaults to `true` for single select\n * comboboxes and `false` for multi-select comboboxes.\n */\n closesOnSelect?: boolean;\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement;\n\n constructor(opts: ComboBoxTesterOpts) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let buttons = within(root).queryAllByRole('button', {hidden: true});\n\n if (buttons.length === 1) {\n trigger = buttons[0];\n } else if (buttons.length > 1) {\n trigger = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = trigger || this._combobox;\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.\n */\n async open(opts: ComboBoxOpenOpts = {}): Promise<void> {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.getTrigger();\n let combobox = this.getCombobox();\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard') {\n act(() => combobox.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.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 /**\n * Returns an option matching the specified index or text content.\n */\n findOption(opts: {indexOrText: number | string}): HTMLElement {\n let {indexOrText} = opts;\n\n let option;\n let options = this.getOptions();\n let listbox = this.getListbox();\n\n if (typeof indexOrText === 'number') {\n option = options[indexOrText];\n } else if (typeof indexOrText === 'string' && listbox != null) {\n option = within(listbox!).getByText(indexOrText).closest('[role=option]')! as HTMLElement;\n }\n\n return option;\n }\n\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let combobox = this.getCombobox();\n let options = this.getOptions();\n let targetIndex = options.findIndex(opt => opt === option || opt.contains(option));\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the combobox listbox.');\n }\n\n let getCurrentIndex = () => {\n let id = combobox.getAttribute('aria-activedescendant');\n if (!id) {\n return -1;\n }\n return options.findIndex(opt => opt.id === id);\n };\n\n if (getCurrentIndex() === -1) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n let currIndex = getCurrentIndex();\n if (currIndex === -1) {\n throw new Error('Could not determine the current option in the combobox listbox.');\n }\n\n let direction = targetIndex > currIndex ? 'down' : 'up';\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 * Toggles the selection of the desired combobox option if possible. Defaults to using the\n * interaction type set on the combobox tester. If necessary, will open the combobox dropdown\n * beforehand. The desired option can be targeted via the option's node, the option's text, or the\n * option's index.\n */\n async toggleOptionSelection(opts: ComboBoxSelectOpts): Promise<void> {\n let {option, triggerBehavior, interactionType = this._interactionType, closesOnSelect} = opts;\n if (!this.getCombobox().getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.getListbox();\n if (!listbox) {\n throw new Error(\"Combobox's listbox not found.\");\n }\n\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({indexOrText: option});\n }\n\n if (!option) {\n throw new Error(`Target option \"${formatTargetNode(opts.option)}\" not found in the listbox.`);\n }\n\n let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';\n closesOnSelect = closesOnSelect ?? !isMultiSelect;\n\n if (interactionType === 'keyboard') {\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (closesOnSelect && option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error(\n 'Expected listbox element to not be in the document after selecting an option'\n );\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close(): Promise<void> {\n let listbox = this.getListbox();\n if (listbox) {\n act(() => this.getCombobox().focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error(\n 'Expected listbox element to not be in the document after selecting an option'\n );\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n getCombobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n getTrigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n getListbox(): HTMLElement | null {\n let listBoxId = this.getCombobox().getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n getSections(): HTMLElement[] {\n let listbox = this.getListbox();\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n\n /**\n * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if\n * provided via `element`.\n */\n getOptions(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.getListbox()} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the currently focused option in the combobox's dropdown if any.\n */\n getFocusedOption(): HTMLElement | null {\n let focusedOptionId = this.getCombobox().getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.js.map"}
@@ -0,0 +1,110 @@
1
+ var $a84d573878cc1e5e$exports = require("./act.cjs");
2
+ var $4WTiJ$testinglibrarydom = require("@testing-library/dom");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "DialogTester", function () { return $cde1dbf8bdfa11d9$export$e79328f5295cc2a1; });
10
+ /*
11
+ * Copyright 2025 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+ class $cde1dbf8bdfa11d9$export$e79328f5295cc2a1 {
23
+ constructor(opts){
24
+ let { root: root, user: user, interactionType: interactionType, overlayType: overlayType } = opts;
25
+ this.user = user;
26
+ this._interactionType = interactionType || 'mouse';
27
+ this._overlayType = overlayType || 'modal';
28
+ // Handle case where element provided is a wrapper of the trigger button.
29
+ let buttons = (0, $4WTiJ$testinglibrarydom.within)(root).queryAllByRole('button');
30
+ let triggerButton;
31
+ if (buttons.length === 0) triggerButton = root;
32
+ else if (buttons.length === 1) triggerButton = buttons[0];
33
+ else triggerButton = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
34
+ this._trigger = triggerButton ?? root;
35
+ }
36
+ /**
37
+ * Set the interaction type used by the dialog tester.
38
+ */ setInteractionType(type) {
39
+ this._interactionType = type;
40
+ }
41
+ /**
42
+ * Opens the dialog. Defaults to using the interaction type set on the dialog tester.
43
+ */ async open(opts = {}) {
44
+ let { interactionType: interactionType = this._interactionType } = opts;
45
+ let trigger = this.getTrigger();
46
+ if (!trigger.hasAttribute('disabled')) {
47
+ if (interactionType === 'mouse') await this.user.click(trigger);
48
+ else if (interactionType === 'touch') await this.user.pointer({
49
+ target: trigger,
50
+ keys: '[TouchA]'
51
+ });
52
+ else if (interactionType === 'keyboard') {
53
+ (0, $a84d573878cc1e5e$exports.act)(()=>trigger.focus());
54
+ await this.user.keyboard('[Enter]');
55
+ }
56
+ if (this._overlayType === 'popover') {
57
+ await (0, $4WTiJ$testinglibrarydom.waitFor)(()=>{
58
+ if (trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on dialog trigger element.');
59
+ else return true;
60
+ });
61
+ let dialogId = trigger.getAttribute('aria-controls');
62
+ await (0, $4WTiJ$testinglibrarydom.waitFor)(()=>{
63
+ if (!dialogId || document.getElementById(dialogId) == null) throw new Error(`Dialog with id of ${dialogId} not found in document.`);
64
+ else {
65
+ this._dialog = document.getElementById(dialogId);
66
+ return true;
67
+ }
68
+ });
69
+ } else {
70
+ let dialog;
71
+ await (0, $4WTiJ$testinglibrarydom.waitFor)(()=>{
72
+ dialog = document.querySelector('[role=dialog], [role=alertdialog]');
73
+ if (dialog == null) throw new Error('No dialog of type role="dialog" or role="alertdialog" found after pressing the trigger.');
74
+ else return true;
75
+ });
76
+ if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) this._dialog = dialog;
77
+ else throw new Error('New modal dialog doesnt contain the active element OR the active element is still the trigger. Uncertain if the proper modal dialog was found');
78
+ }
79
+ }
80
+ }
81
+ /**
82
+ * Closes the dialog via the Escape key.
83
+ */ async close() {
84
+ let dialog = this._dialog;
85
+ if (dialog) {
86
+ await this.user.keyboard('[Escape]');
87
+ await (0, $4WTiJ$testinglibrarydom.waitFor)(()=>{
88
+ if (document.contains(dialog)) throw new Error('Expected the dialog to not be in the document after closing it.');
89
+ else {
90
+ this._dialog = undefined;
91
+ return true;
92
+ }
93
+ });
94
+ }
95
+ }
96
+ /**
97
+ * Returns the dialog's trigger.
98
+ */ getTrigger() {
99
+ if (!this._trigger) throw new Error('No trigger element found for dialog.');
100
+ return this._trigger;
101
+ }
102
+ /**
103
+ * Returns the dialog if present.
104
+ */ getDialog() {
105
+ return this._dialog && document.contains(this._dialog) ? this._dialog : null;
106
+ }
107
+ }
108
+
109
+
110
+ //# sourceMappingURL=dialog.cjs.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAcM,MAAM;IAOX,YAAY,IAAsB,CAAE;QAClC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,eAAE,WAAW,EAAC,GAAG;QACjD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,YAAY,GAAG,eAAe;QAEnC,yEAAyE;QACzE,IAAI,UAAU,CAAA,GAAA,+BAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI;QACJ,IAAI,QAAQ,MAAM,KAAK,GACrB,gBAAgB;aACX,IA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M,CAAA,GAAA,gCAAM,EAAE;oBACZ,SAAS,SAAS,aAAa,CAAC;oBAChC,IAAI,UAAU,MACZ,MAAM,IAAI,MACR;yBAGF,OAAO;gBAEX;gBAEA,IACE,UACA,SAAS,aAAa,KAAK,IAAI,CAAC,QAAQ,IACxC,OAAO,QAAQ,CAAC,SAAS,aAAa,GAEtC,IAAI,CAAC,OAAO,GAAG;qBAEf,MAAM,IAAI,MACR;YAGN;QACF;IACF;IAEA;;GAEC,GACD,MAAM,QAAuB;QAC3B,IAAI,SAAS,IAAI,CAAC,OAAO;QACzB,IAAI,QAAQ;YACV,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YACzB,MAAM,CAAA,GAAA,gCAAM,EAAE;gBACZ,IAAI,SAAS,QAAQ,CAAC,SACpB,MAAM,IAAI,MAAM;qBACX;oBACL,IAAI,CAAC,OAAO,GAAG;oBACf,OAAO;gBACT;YACF;QACF;IACF;IAEA;;GAEC,GACD,aAA0B;QACxB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAChB,MAAM,IAAI,MAAM;QAGlB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA;;GAEC,GACD,YAAgC;QAC9B,OAAO,IAAI,CAAC,OAAO,IAAI,SAAS,QAAQ,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG;IAC1E;AACF","sources":["packages/@react-aria/test-utils/src/dialog.ts"],"sourcesContent":["/*\n * Copyright 2025 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} from './act';\nimport {DialogTesterOpts, UserOpts} from './types';\nimport {waitFor, within} from '@testing-library/dom';\n\ninterface DialogOpenOpts {\n /**\n * What interaction type to use when opening the dialog. Defaults to the interaction type set on\n * the tester.\n */\n interactionType?: UserOpts['interactionType'];\n}\n\nexport class DialogTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement | undefined;\n private _dialog: HTMLElement | undefined;\n private _overlayType: DialogTesterOpts['overlayType'];\n\n constructor(opts: DialogTesterOpts) {\n let {root, user, interactionType, overlayType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._overlayType = overlayType || 'modal';\n\n // Handle case where element provided is a wrapper of the trigger button.\n let buttons = within(root).queryAllByRole('button');\n let triggerButton: HTMLElement | undefined;\n if (buttons.length === 0) {\n triggerButton = root;\n } else if (buttons.length === 1) {\n triggerButton = buttons[0];\n } else {\n triggerButton = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n this._trigger = triggerButton ?? root;\n }\n\n /**\n * Set the interaction type used by the dialog tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the dialog. Defaults to using the interaction type set on the dialog tester.\n */\n async open(opts: DialogOpenOpts = {}): Promise<void> {\n let {interactionType = this._interactionType} = opts;\n let trigger = this.getTrigger();\n if (!trigger.hasAttribute('disabled')) {\n if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n\n if (this._overlayType === 'popover') {\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on dialog trigger element.');\n } else {\n return true;\n }\n });\n\n let dialogId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!dialogId || document.getElementById(dialogId) == null) {\n throw new Error(`Dialog with id of ${dialogId} not found in document.`);\n } else {\n this._dialog = document.getElementById(dialogId)!;\n return true;\n }\n });\n } else {\n let dialog;\n await waitFor(() => {\n dialog = document.querySelector('[role=dialog], [role=alertdialog]');\n if (dialog == null) {\n throw new Error(\n 'No dialog of type role=\"dialog\" or role=\"alertdialog\" found after pressing the trigger.'\n );\n } else {\n return true;\n }\n });\n\n if (\n dialog &&\n document.activeElement !== this._trigger &&\n dialog.contains(document.activeElement)\n ) {\n this._dialog = dialog;\n } else {\n throw new Error(\n 'New modal dialog doesnt contain the active element OR the active element is still the trigger. Uncertain if the proper modal dialog was found'\n );\n }\n }\n }\n }\n\n /**\n * Closes the dialog via the Escape key.\n */\n async close(): Promise<void> {\n let dialog = this._dialog;\n if (dialog) {\n await this.user.keyboard('[Escape]');\n await waitFor(() => {\n if (document.contains(dialog)) {\n throw new Error('Expected the dialog to not be in the document after closing it.');\n } else {\n this._dialog = undefined;\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the dialog's trigger.\n */\n getTrigger(): HTMLElement {\n if (!this._trigger) {\n throw new Error('No trigger element found for dialog.');\n }\n\n return this._trigger;\n }\n\n /**\n * Returns the dialog if present.\n */\n getDialog(): HTMLElement | null {\n return this._dialog && document.contains(this._dialog) ? this._dialog : null;\n }\n}\n"],"names":[],"version":3,"file":"dialog.cjs.map"}