@react-aria/test-utils 1.0.0-alpha.2 → 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 (71) hide show
  1. package/LICENSE +201 -0
  2. package/dist/combobox.main.js +116 -82
  3. package/dist/combobox.main.js.map +1 -1
  4. package/dist/combobox.mjs +117 -83
  5. package/dist/combobox.module.js +117 -83
  6. package/dist/combobox.module.js.map +1 -1
  7. package/dist/events.main.js.map +1 -1
  8. package/dist/events.module.js.map +1 -1
  9. package/dist/gridlist.main.js +102 -59
  10. package/dist/gridlist.main.js.map +1 -1
  11. package/dist/gridlist.mjs +103 -60
  12. package/dist/gridlist.module.js +103 -60
  13. package/dist/gridlist.module.js.map +1 -1
  14. package/dist/listbox.main.js +135 -0
  15. package/dist/listbox.main.js.map +1 -0
  16. package/dist/listbox.mjs +130 -0
  17. package/dist/listbox.module.js +130 -0
  18. package/dist/listbox.module.js.map +1 -0
  19. package/dist/main.js.map +1 -1
  20. package/dist/menu.main.js +197 -119
  21. package/dist/menu.main.js.map +1 -1
  22. package/dist/menu.mjs +198 -120
  23. package/dist/menu.module.js +198 -120
  24. package/dist/menu.module.js.map +1 -1
  25. package/dist/module.js.map +1 -1
  26. package/dist/select.main.js +116 -70
  27. package/dist/select.main.js.map +1 -1
  28. package/dist/select.mjs +117 -71
  29. package/dist/select.module.js +117 -71
  30. package/dist/select.module.js.map +1 -1
  31. package/dist/table.main.js +170 -143
  32. package/dist/table.main.js.map +1 -1
  33. package/dist/table.mjs +171 -144
  34. package/dist/table.module.js +171 -144
  35. package/dist/table.module.js.map +1 -1
  36. package/dist/tabs.main.js +133 -0
  37. package/dist/tabs.main.js.map +1 -0
  38. package/dist/tabs.mjs +128 -0
  39. package/dist/tabs.module.js +128 -0
  40. package/dist/tabs.module.js.map +1 -0
  41. package/dist/testSetup.main.js +2 -6
  42. package/dist/testSetup.main.js.map +1 -1
  43. package/dist/testSetup.mjs +2 -6
  44. package/dist/testSetup.module.js +2 -6
  45. package/dist/testSetup.module.js.map +1 -1
  46. package/dist/tree.main.js +165 -0
  47. package/dist/tree.main.js.map +1 -0
  48. package/dist/tree.mjs +160 -0
  49. package/dist/tree.module.js +160 -0
  50. package/dist/tree.module.js.map +1 -0
  51. package/dist/types.d.ts +607 -139
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/user.main.js +16 -5
  54. package/dist/user.main.js.map +1 -1
  55. package/dist/user.mjs +16 -5
  56. package/dist/user.module.js +16 -5
  57. package/dist/user.module.js.map +1 -1
  58. package/package.json +5 -5
  59. package/src/combobox.ts +105 -36
  60. package/src/events.ts +1 -1
  61. package/src/gridlist.ts +146 -59
  62. package/src/index.ts +1 -1
  63. package/src/listbox.ts +226 -0
  64. package/src/menu.ts +207 -55
  65. package/src/select.ts +137 -44
  66. package/src/table.ts +134 -78
  67. package/src/tabs.ts +198 -0
  68. package/src/testSetup.ts +2 -6
  69. package/src/tree.ts +248 -0
  70. package/src/types.ts +133 -0
  71. package/src/user.ts +62 -37
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2019 Adobe
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -18,99 +18,133 @@ $parcel$export(module.exports, "ComboBoxTester", () => $15e4b71f2b6c4964$export$
18
18
  * governing permissions and limitations under the License.
19
19
  */
20
20
  class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
21
- get combobox() {
21
+ /**
22
+ * Set the interaction type used by the combobox tester.
23
+ */ setInteractionType(type) {
24
+ this._interactionType = type;
25
+ }
26
+ /**
27
+ * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.
28
+ */ async open(opts = {}) {
29
+ let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
30
+ let trigger = this.trigger;
31
+ let combobox = this.combobox;
32
+ let isDisabled = trigger.hasAttribute('disabled');
33
+ if (interactionType === 'mouse') {
34
+ if (triggerBehavior === 'focus') await this.user.click(combobox);
35
+ else await this.user.click(trigger);
36
+ } else if (interactionType === 'keyboard' && this._trigger != null) {
37
+ (0, $f8PS3$testinglibraryreact.act)(()=>this._trigger.focus());
38
+ if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
39
+ } else if (interactionType === 'touch') {
40
+ if (triggerBehavior === 'focus') await this.user.pointer({
41
+ target: combobox,
42
+ keys: '[TouchA]'
43
+ });
44
+ else await this.user.pointer({
45
+ target: trigger,
46
+ keys: '[TouchA]'
47
+ });
48
+ }
49
+ await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
50
+ if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
51
+ else return true;
52
+ });
53
+ let listBoxId = combobox.getAttribute('aria-controls');
54
+ await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
55
+ if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
56
+ else return true;
57
+ });
58
+ }
59
+ /**
60
+ * Returns an option matching the specified index or text content.
61
+ */ findOption(opts) {
62
+ let { optionIndexOrText: optionIndexOrText } = opts;
63
+ let option;
64
+ let options = this.options();
65
+ let listbox = this.listbox;
66
+ if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
67
+ else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $f8PS3$testinglibraryreact.within)(listbox).getByText(optionIndexOrText).closest('[role=option]');
68
+ return option;
69
+ }
70
+ /**
71
+ * Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox dropdown beforehand.
72
+ * The desired option can be targeted via the option's node, the option's text, or the option's index.
73
+ */ async selectOption(opts) {
74
+ let { option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType } = opts;
75
+ if (!this.combobox.getAttribute('aria-controls')) await this.open({
76
+ triggerBehavior: triggerBehavior
77
+ });
78
+ let listbox = this.listbox;
79
+ if (!listbox) throw new Error('Combobox\'s listbox not found.');
80
+ if (listbox) {
81
+ if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
82
+ optionIndexOrText: option
83
+ });
84
+ if (!option) throw new Error('Target option not found in the listbox.');
85
+ // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow
86
+ // the required amount of times to reach the option. For now just click the option even in keyboard mode
87
+ if (interactionType === 'mouse' || interactionType === 'keyboard') await this.user.click(option);
88
+ else await this.user.pointer({
89
+ target: option,
90
+ keys: '[TouchA]'
91
+ });
92
+ if (option.getAttribute('href') == null) await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
93
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
94
+ else return true;
95
+ });
96
+ } else throw new Error("Attempted to select a option in the combobox, but the listbox wasn't found.");
97
+ }
98
+ /**
99
+ * Closes the combobox dropdown.
100
+ */ async close() {
101
+ let listbox = this.listbox;
102
+ if (listbox) {
103
+ (0, $f8PS3$testinglibraryreact.act)(()=>this.combobox.focus());
104
+ await this.user.keyboard('[Escape]');
105
+ await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
106
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
107
+ else return true;
108
+ });
109
+ }
110
+ }
111
+ /**
112
+ * Returns the combobox.
113
+ */ get combobox() {
22
114
  return this._combobox;
23
115
  }
24
- get trigger() {
116
+ /**
117
+ * Returns the combobox trigger button.
118
+ */ get trigger() {
25
119
  return this._trigger;
26
120
  }
27
- get listbox() {
121
+ /**
122
+ * Returns the combobox's listbox if present.
123
+ */ get listbox() {
28
124
  let listBoxId = this.combobox.getAttribute('aria-controls');
29
- return listBoxId ? document.getElementById(listBoxId) || undefined : undefined;
125
+ return listBoxId ? document.getElementById(listBoxId) || null : null;
30
126
  }
31
- get sections() {
127
+ /**
128
+ * Returns the combobox's sections if present.
129
+ */ get sections() {
32
130
  let listbox = this.listbox;
33
- if (listbox) return (0, $f8PS3$testinglibraryreact.within)(listbox).queryAllByRole('group');
34
- else return [];
131
+ return listbox ? (0, $f8PS3$testinglibraryreact.within)(listbox).queryAllByRole('group') : [];
132
+ }
133
+ /**
134
+ * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.
135
+ */ options(opts = {}) {
136
+ let { element: element = this.listbox } = opts;
137
+ let options = [];
138
+ if (element) options = (0, $f8PS3$testinglibraryreact.within)(element).queryAllByRole('option');
139
+ return options;
35
140
  }
36
- get focusedOption() {
141
+ /**
142
+ * Returns the currently focused option in the combobox's dropdown if any.
143
+ */ get focusedOption() {
37
144
  let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');
38
- return focusedOptionId ? document.getElementById(focusedOptionId) : undefined;
145
+ return focusedOptionId ? document.getElementById(focusedOptionId) : null;
39
146
  }
40
147
  constructor(opts){
41
- this.setInteractionType = (type)=>{
42
- this._interactionType = type;
43
- };
44
- this.open = async (opts = {})=>{
45
- let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
46
- let trigger = this.trigger;
47
- let combobox = this.combobox;
48
- let isDisabled = trigger.hasAttribute('disabled');
49
- if (interactionType === 'mouse') {
50
- if (triggerBehavior === 'focus') await this.user.click(combobox);
51
- else await this.user.click(trigger);
52
- } else if (interactionType === 'keyboard' && this._trigger != null) {
53
- (0, $f8PS3$testinglibraryreact.act)(()=>this._trigger.focus());
54
- if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
55
- } else if (interactionType === 'touch') {
56
- if (triggerBehavior === 'focus') await this.user.pointer({
57
- target: combobox,
58
- keys: '[TouchA]'
59
- });
60
- else await this.user.pointer({
61
- target: trigger,
62
- keys: '[TouchA]'
63
- });
64
- }
65
- await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
66
- if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
67
- else return true;
68
- });
69
- let listBoxId = combobox.getAttribute('aria-controls');
70
- await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
71
- if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
72
- else return true;
73
- });
74
- };
75
- this.selectOption = async (opts = {})=>{
76
- let { optionText: optionText, option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType } = opts;
77
- if (!this.combobox.getAttribute('aria-controls')) await this.open({
78
- triggerBehavior: triggerBehavior
79
- });
80
- let listbox = this.listbox;
81
- if (listbox) {
82
- if (!option && optionText) option = (0, $f8PS3$testinglibraryreact.within)(listbox).getByText(optionText);
83
- // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow
84
- // the required amount of times to reach the option. For now just click the option even in keyboard mode
85
- if (interactionType === 'mouse' || interactionType === 'keyboard') await this.user.click(option);
86
- else await this.user.pointer({
87
- target: option,
88
- keys: '[TouchA]'
89
- });
90
- if (option && option.getAttribute('href') == null) await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
91
- if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
92
- else return true;
93
- });
94
- } else throw new Error("Attempted to select a option in the combobox, but the listbox wasn't found.");
95
- };
96
- this.close = async ()=>{
97
- let listbox = this.listbox;
98
- if (listbox) {
99
- (0, $f8PS3$testinglibraryreact.act)(()=>this.combobox.focus());
100
- await this.user.keyboard('[Escape]');
101
- await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
102
- if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
103
- else return true;
104
- });
105
- }
106
- };
107
- this.options = (opts = {})=>{
108
- let { element: element } = opts;
109
- element = element || this.listbox;
110
- let options = [];
111
- if (element) options = (0, $f8PS3$testinglibraryreact.within)(element).queryAllByRole('option');
112
- return options;
113
- };
114
148
  let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
115
149
  this.user = user;
116
150
  this._interactionType = interactionType || 'mouse';
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;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;QAElC;IACF;AAuIF","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, waitFor, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\n\nexport interface ComboBoxOptions extends UserOpts, BaseTesterOpts {\n user: any,\n trigger?: HTMLElement\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement | undefined;\n\n constructor(opts: ComboBoxOptions) {\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 trigger = within(root).queryByRole('button', {hidden: true});\n if (trigger) {\n this._trigger = trigger;\n } else {\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 = this._combobox;\n }\n }\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n open = async (opts: {triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\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' && this._trigger != null) {\n act(() => this._trigger!.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 selectOption = async (opts: {option?: HTMLElement, optionText?: string, triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {\n let {optionText, option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (listbox) {\n if (!option && optionText) {\n option = within(listbox).getByText(optionText);\n }\n\n // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option && option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n };\n\n close = async () => {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n };\n\n get combobox() {\n return this._combobox;\n }\n\n get trigger() {\n return this._trigger;\n }\n\n get listbox() {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || undefined : undefined;\n }\n\n options = (opts: {element?: HTMLElement} = {}): HTMLElement[] | never[] => {\n let {element} = opts;\n element = element || this.listbox;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n };\n\n get sections() {\n let listbox = this.listbox;\n if (listbox) {\n return within(listbox).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n get focusedOption() {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : undefined;\n }\n}\n"],"names":[],"version":3,"file":"combobox.main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAkCX;;GAEC,GACD,mBAAmB,IAAiC,EAAE;QACpD,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAyB,CAAC,CAAC,EAAE;QACtC,IAAI,mBAAC,kBAAkB,2BAAU,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;QAC5E,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,WAAW,IAAI,CAAC,QAAQ;QAC5B,IAAI,aAAa,QAAS,YAAY,CAAC;QAEvC,IAAI,oBAAoB;YACtB,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBAEtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;eAEnB,IAAI,oBAAoB,cAAc,IAAI,CAAC,QAAQ,IAAI,M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A8LF","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, waitFor, within} from '@testing-library/react';\nimport {ComboBoxTesterOpts, UserOpts} from './types';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\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 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 `options()`.\n */\n option: number | string | HTMLElement\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 trigger = within(root).queryByRole('button', {hidden: true});\n if (trigger) {\n this._trigger = trigger;\n } else {\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 = this._combobox;\n }\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']) {\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 = {}) {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\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' && this._trigger != null) {\n act(() => this._trigger!.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: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let listbox = this.listbox;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && listbox != null) {\n option = (within(listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n /**\n * Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox 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: ComboBoxSelectOpts) {\n let {option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Combobox\\'s listbox not found.');\n }\n\n if (listbox) {\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 listbox.');\n }\n\n // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close() {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n get combobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\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 provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.listbox} = 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 get focusedOption(): HTMLElement | null {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.main.js.map"}