@react-aria/test-utils 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +5 -5
- package/dist/main.js +9 -9
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -5
- package/dist/module.js.map +1 -1
- package/dist/private/checkboxgroup.cjs +104 -0
- package/dist/private/checkboxgroup.cjs.map +1 -0
- package/dist/private/checkboxgroup.js +99 -0
- package/dist/private/checkboxgroup.js.map +1 -0
- package/dist/{combobox.main.js → private/combobox.cjs} +35 -35
- package/dist/private/combobox.cjs.map +1 -0
- package/dist/{combobox.mjs → private/combobox.js} +35 -35
- package/dist/private/combobox.js.map +1 -0
- package/dist/private/dialog.cjs +105 -0
- package/dist/private/dialog.cjs.map +1 -0
- package/dist/private/dialog.js +100 -0
- package/dist/private/dialog.js.map +1 -0
- package/dist/{events.main.js → private/events.cjs} +32 -34
- package/dist/private/events.cjs.map +1 -0
- package/dist/{events.mjs → private/events.js} +29 -31
- package/dist/private/events.js.map +1 -0
- package/dist/{gridlist.main.js → private/gridlist.cjs} +27 -28
- package/dist/private/gridlist.cjs.map +1 -0
- package/dist/{gridlist.mjs → private/gridlist.js} +27 -28
- package/dist/private/gridlist.js.map +1 -0
- package/dist/{listbox.main.js → private/listbox.cjs} +24 -24
- package/dist/private/listbox.cjs.map +1 -0
- package/dist/{listbox.mjs → private/listbox.js} +24 -24
- package/dist/private/listbox.js.map +1 -0
- package/dist/{menu.main.js → private/menu.cjs} +46 -48
- package/dist/private/menu.cjs.map +1 -0
- package/dist/{menu.mjs → private/menu.js} +46 -48
- package/dist/private/menu.js.map +1 -0
- package/dist/private/radiogroup.cjs +120 -0
- package/dist/private/radiogroup.cjs.map +1 -0
- package/dist/private/radiogroup.js +115 -0
- package/dist/private/radiogroup.js.map +1 -0
- package/dist/{select.main.js → private/select.cjs} +31 -29
- package/dist/private/select.cjs.map +1 -0
- package/dist/{select.mjs → private/select.js} +31 -29
- package/dist/private/select.js.map +1 -0
- package/dist/{table.main.js → private/table.cjs} +82 -57
- package/dist/private/table.cjs.map +1 -0
- package/dist/{table.module.js → private/table.js} +82 -57
- package/dist/private/table.js.map +1 -0
- package/dist/{tabs.main.js → private/tabs.cjs} +24 -26
- package/dist/private/tabs.cjs.map +1 -0
- package/dist/{tabs.mjs → private/tabs.js} +24 -26
- package/dist/private/tabs.js.map +1 -0
- package/dist/private/testSetup.cjs +87 -0
- package/dist/private/testSetup.cjs.map +1 -0
- package/dist/private/testSetup.js +81 -0
- package/dist/private/testSetup.js.map +1 -0
- package/dist/{tree.main.js → private/tree.cjs} +34 -35
- package/dist/private/tree.cjs.map +1 -0
- package/dist/{tree.mjs → private/tree.js} +34 -35
- package/dist/private/tree.js.map +1 -0
- package/dist/private/user.cjs +85 -0
- package/dist/private/user.cjs.map +1 -0
- package/dist/private/user.js +76 -0
- package/dist/private/user.js.map +1 -0
- package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
- package/dist/{userEventMaps.main.js.map → private/userEventMaps.cjs.map} +1 -1
- package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
- package/dist/{userEventMaps.module.js.map → private/userEventMaps.js.map} +1 -1
- package/dist/types/src/checkboxgroup.d.ts +45 -0
- package/dist/types/src/combobox.d.ts +75 -0
- package/dist/types/src/dialog.d.ts +36 -0
- package/dist/types/src/events.d.ts +25 -0
- package/dist/types/src/gridlist.d.ts +51 -0
- package/dist/types/src/index.d.ts +16 -0
- package/dist/types/src/listbox.d.ts +80 -0
- package/dist/types/src/menu.d.ts +102 -0
- package/dist/types/src/radiogroup.d.ts +46 -0
- package/dist/types/src/select.d.ts +67 -0
- package/dist/types/src/table.d.ts +104 -0
- package/dist/types/src/tabs.d.ts +58 -0
- package/dist/types/src/testSetup.d.ts +6 -0
- package/dist/types/src/tree.d.ts +57 -0
- package/dist/types/src/types.d.ts +136 -0
- package/dist/types/src/user.d.ts +47 -0
- package/dist/types/src/userEventMaps.d.ts +2 -0
- package/package.json +7 -7
- package/src/checkboxgroup.ts +158 -0
- package/src/dialog.ts +143 -0
- package/src/index.ts +11 -0
- package/src/radiogroup.ts +176 -0
- package/src/select.ts +10 -2
- package/src/table.ts +46 -1
- package/src/tabs.ts +7 -2
- package/src/testSetup.ts +30 -28
- package/src/types.ts +21 -0
- package/src/user.ts +25 -7
- package/dist/combobox.main.js.map +0 -1
- package/dist/combobox.module.js +0 -167
- package/dist/combobox.module.js.map +0 -1
- package/dist/events.main.js.map +0 -1
- package/dist/events.module.js +0 -112
- package/dist/events.module.js.map +0 -1
- package/dist/gridlist.main.js.map +0 -1
- package/dist/gridlist.module.js +0 -149
- package/dist/gridlist.module.js.map +0 -1
- package/dist/listbox.main.js.map +0 -1
- package/dist/listbox.module.js +0 -138
- package/dist/listbox.module.js.map +0 -1
- package/dist/menu.main.js.map +0 -1
- package/dist/menu.module.js +0 -269
- package/dist/menu.module.js.map +0 -1
- package/dist/select.main.js.map +0 -1
- package/dist/select.module.js +0 -158
- package/dist/select.module.js.map +0 -1
- package/dist/table.main.js.map +0 -1
- package/dist/table.mjs +0 -290
- package/dist/table.module.js.map +0 -1
- package/dist/tabs.main.js.map +0 -1
- package/dist/tabs.module.js +0 -128
- package/dist/tabs.module.js.map +0 -1
- package/dist/testSetup.main.js +0 -78
- package/dist/testSetup.main.js.map +0 -1
- package/dist/testSetup.mjs +0 -72
- package/dist/testSetup.module.js +0 -72
- package/dist/testSetup.module.js.map +0 -1
- package/dist/tree.main.js.map +0 -1
- package/dist/tree.module.js +0 -179
- package/dist/tree.module.js.map +0 -1
- package/dist/types.d.ts +0 -694
- package/dist/types.d.ts.map +0 -1
- package/dist/user.main.js +0 -76
- package/dist/user.main.js.map +0 -1
- package/dist/user.mjs +0 -67
- package/dist/user.module.js +0 -67
- package/dist/user.module.js.map +0 -1
- package/dist/userEventMaps.module.js +0 -38
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var $
|
|
1
|
+
var $gMthZ$testinglibraryreact = require("@testing-library/react");
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
function $parcel$export(e, n, v, s) {
|
|
5
5
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
$parcel$export(module.exports, "SelectTester", ()
|
|
8
|
+
$parcel$export(module.exports, "SelectTester", function () { return $842eb702165f4e83$export$d1859707465446a9; });
|
|
9
9
|
/*
|
|
10
10
|
* Copyright 2024 Adobe. All rights reserved.
|
|
11
11
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -17,7 +17,19 @@ $parcel$export(module.exports, "SelectTester", () => $b97d5a42df7c75b2$export$d1
|
|
|
17
17
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
18
|
* governing permissions and limitations under the License.
|
|
19
19
|
*/
|
|
20
|
-
class $
|
|
20
|
+
class $842eb702165f4e83$export$d1859707465446a9 {
|
|
21
|
+
constructor(opts){
|
|
22
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
23
|
+
this.user = user;
|
|
24
|
+
this._interactionType = interactionType || 'mouse';
|
|
25
|
+
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
26
|
+
let buttons = (0, $gMthZ$testinglibraryreact.within)(root).queryAllByRole('button');
|
|
27
|
+
let triggerButton;
|
|
28
|
+
if (buttons.length === 0) triggerButton = root;
|
|
29
|
+
else if (buttons.length === 1) triggerButton = buttons[0];
|
|
30
|
+
else triggerButton = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
31
|
+
this._trigger = triggerButton ?? root;
|
|
32
|
+
}
|
|
21
33
|
/**
|
|
22
34
|
* Set the interaction type used by the select tester.
|
|
23
35
|
*/ setInteractionType(type) {
|
|
@@ -31,18 +43,18 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
31
43
|
let isDisabled = trigger.hasAttribute('disabled');
|
|
32
44
|
if (interactionType === 'mouse') await this.user.click(this._trigger);
|
|
33
45
|
else if (interactionType === 'keyboard') {
|
|
34
|
-
(0, $
|
|
46
|
+
(0, $gMthZ$testinglibraryreact.act)(()=>trigger.focus());
|
|
35
47
|
await this.user.keyboard('[Enter]');
|
|
36
48
|
} else if (interactionType === 'touch') await this.user.pointer({
|
|
37
49
|
target: this._trigger,
|
|
38
50
|
keys: '[TouchA]'
|
|
39
51
|
});
|
|
40
|
-
await (0, $
|
|
52
|
+
await (0, $gMthZ$testinglibraryreact.waitFor)(()=>{
|
|
41
53
|
if (!isDisabled && trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on select element trigger.');
|
|
42
54
|
else return true;
|
|
43
55
|
});
|
|
44
56
|
let listBoxId = trigger.getAttribute('aria-controls');
|
|
45
|
-
await (0, $
|
|
57
|
+
await (0, $gMthZ$testinglibraryreact.waitFor)(()=>{
|
|
46
58
|
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`ListBox with id of ${listBoxId} not found in document.`);
|
|
47
59
|
else return true;
|
|
48
60
|
});
|
|
@@ -52,10 +64,10 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
52
64
|
*/ async close() {
|
|
53
65
|
let listbox = this.listbox;
|
|
54
66
|
if (listbox) {
|
|
55
|
-
(0, $
|
|
67
|
+
(0, $gMthZ$testinglibraryreact.act)(()=>listbox.focus());
|
|
56
68
|
await this.user.keyboard('[Escape]');
|
|
57
69
|
}
|
|
58
|
-
await (0, $
|
|
70
|
+
await (0, $gMthZ$testinglibraryreact.waitFor)(()=>{
|
|
59
71
|
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);
|
|
60
72
|
else return true;
|
|
61
73
|
});
|
|
@@ -69,7 +81,7 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
69
81
|
let options = this.options();
|
|
70
82
|
let listbox = this.listbox;
|
|
71
83
|
if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
|
|
72
|
-
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $
|
|
84
|
+
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $gMthZ$testinglibraryreact.within)(listbox).getByText(optionIndexOrText).closest('[role=option]');
|
|
73
85
|
return option;
|
|
74
86
|
}
|
|
75
87
|
async keyboardNavigateToOption(opts) {
|
|
@@ -87,7 +99,7 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
87
99
|
* Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select dropdown beforehand.
|
|
88
100
|
* The desired option can be targeted via the option's node, the option's text, or the option's index.
|
|
89
101
|
*/ async selectOption(opts) {
|
|
90
|
-
let { option: option, interactionType: interactionType = this._interactionType } = opts || {};
|
|
102
|
+
let { option: option, closesOnSelect: closesOnSelect, interactionType: interactionType = this._interactionType } = opts || {};
|
|
91
103
|
let trigger = this.trigger;
|
|
92
104
|
if (!trigger.getAttribute('aria-controls')) await this.open();
|
|
93
105
|
let listbox = this.listbox;
|
|
@@ -98,9 +110,11 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
98
110
|
});
|
|
99
111
|
if (!option) throw new Error('Target option not found in the listbox.');
|
|
100
112
|
let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';
|
|
113
|
+
let isSingleSelect = !isMultiSelect;
|
|
114
|
+
closesOnSelect = closesOnSelect ?? isSingleSelect;
|
|
101
115
|
if (interactionType === 'keyboard') {
|
|
102
|
-
if (
|
|
103
|
-
if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) (0, $
|
|
116
|
+
if (option?.getAttribute('aria-disabled') === 'true') return;
|
|
117
|
+
if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) (0, $gMthZ$testinglibraryreact.act)(()=>listbox.focus());
|
|
104
118
|
await this.keyboardNavigateToOption({
|
|
105
119
|
option: option
|
|
106
120
|
});
|
|
@@ -111,8 +125,8 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
111
125
|
target: option,
|
|
112
126
|
keys: '[TouchA]'
|
|
113
127
|
});
|
|
114
|
-
if (
|
|
115
|
-
await (0, $
|
|
128
|
+
if (closesOnSelect && option?.getAttribute('href') == null) {
|
|
129
|
+
await (0, $gMthZ$testinglibraryreact.waitFor)(()=>{
|
|
116
130
|
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);
|
|
117
131
|
else return true;
|
|
118
132
|
});
|
|
@@ -125,7 +139,7 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
125
139
|
*/ options(opts = {}) {
|
|
126
140
|
let { element: element = this.listbox } = opts;
|
|
127
141
|
let options = [];
|
|
128
|
-
if (element) options = (0, $
|
|
142
|
+
if (element) options = (0, $gMthZ$testinglibraryreact.within)(element).queryAllByRole('option');
|
|
129
143
|
return options;
|
|
130
144
|
}
|
|
131
145
|
/**
|
|
@@ -143,21 +157,9 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
143
157
|
* Returns the select's sections if present.
|
|
144
158
|
*/ get sections() {
|
|
145
159
|
let listbox = this.listbox;
|
|
146
|
-
return listbox ? (0, $
|
|
147
|
-
}
|
|
148
|
-
constructor(opts){
|
|
149
|
-
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
150
|
-
this.user = user;
|
|
151
|
-
this._interactionType = interactionType || 'mouse';
|
|
152
|
-
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
153
|
-
let buttons = (0, $bBwW0$testinglibraryreact.within)(root).queryAllByRole('button');
|
|
154
|
-
let triggerButton;
|
|
155
|
-
if (buttons.length === 0) triggerButton = root;
|
|
156
|
-
else if (buttons.length === 1) triggerButton = buttons[0];
|
|
157
|
-
else triggerButton = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
158
|
-
this._trigger = triggerButton !== null && triggerButton !== void 0 ? triggerButton : root;
|
|
160
|
+
return listbox ? (0, $gMthZ$testinglibraryreact.within)(listbox).queryAllByRole('group') : [];
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
|
|
163
|
-
//# sourceMappingURL=select.
|
|
165
|
+
//# sourceMappingURL=select.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAKX,YAAY,IAAsB,CAAE;QAClC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,8FAA8F;QAC9F,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI;QACJ,IAAI,QAAQ,MAAM,KAAK,GACrB,gBAAgB;aACX,IAAI,QAAQ,MAAM,KAAK,GAC5B,gBAAgB,OAAO,CAAC,EAAE;aAE1B,gBAAgB,QAAQ,IAAI,CAAC,CAAA,SAAU,OAAO,YAAY,CAAC;QAG7D,IAAI,CAAC,QAAQ,GAAG,iBAAiB;IACnC;IACA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;QACnD,IAAI,mBACF,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,aAAa,QAAQ,YAAY,CAAC;QAEtC,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ;aAC9B,IAAI,oBAAoB,YAAY;YACzC,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,KAAK;YACvB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,C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;QAC5B,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC,WAAW,EAAE;IAC/D;AACF","sources":["packages/@react-aria/test-utils/src/select.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {SelectTesterOpts, UserOpts} from './types';\n\ninterface SelectOpenOpts {\n /**\n * What interaction type to use when opening the select. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface SelectTriggerOptionOpts extends SelectOpenOpts {\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 * Whether or not the select closes on selection. Depends on select implementation and configuration.\n * @default true\n */\n closesOnSelect?: boolean\n}\n\nexport class SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n // Handle case where the wrapper element is provided rather than the Select's button (aka RAC)\n let buttons = within(root).queryAllByRole('button');\n let triggerButton;\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\n this._trigger = triggerButton ?? root;\n }\n /**\n * Set the interaction type used by the select tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the select. Defaults to using the interaction type set on the select tester.\n */\n async open(opts: SelectOpenOpts = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n await this.user.click(this._trigger);\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: this._trigger, keys: '[TouchA]'});\n }\n\n await waitFor(() => {\n if (!isDisabled && trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on select element trigger.');\n } else {\n return true;\n }\n });\n let listBoxId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`ListBox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Closes the select.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => listbox.focus());\n await this.user.keyboard('[Escape]');\n }\n\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (listbox && document.contains(listbox)) {\n throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let 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 private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n if (document.activeElement === this.listbox) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select 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: SelectTriggerOptionOpts): Promise<void> {\n let {\n option,\n closesOnSelect,\n interactionType = this._interactionType\n } = opts || {};\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open();\n }\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Select\\'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 let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';\n let isSingleSelect = !isMultiSelect;\n closesOnSelect = closesOnSelect ?? isSingleSelect;\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else {\n // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n if (closesOnSelect && option?.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(listbox)) {\n throw new Error('Expected select element listbox to not be in the document after selecting an option');\n }\n }\n }\n }\n\n /**\n * Returns the select'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 select's trigger.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the select's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.trigger.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : null;\n }\n\n /**\n * Returns the select's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.cjs.map"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {within as $d0NQz$within, act as $d0NQz$act, waitFor as $d0NQz$waitFor} from "@testing-library/react";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2024 Adobe. All rights reserved.
|
|
@@ -11,7 +11,19 @@ import {act as $7v0pZ$act, waitFor as $7v0pZ$waitFor, within as $7v0pZ$within} f
|
|
|
11
11
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
|
-
class $
|
|
14
|
+
class $6acb352063615cf0$export$d1859707465446a9 {
|
|
15
|
+
constructor(opts){
|
|
16
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
17
|
+
this.user = user;
|
|
18
|
+
this._interactionType = interactionType || 'mouse';
|
|
19
|
+
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
20
|
+
let buttons = (0, $d0NQz$within)(root).queryAllByRole('button');
|
|
21
|
+
let triggerButton;
|
|
22
|
+
if (buttons.length === 0) triggerButton = root;
|
|
23
|
+
else if (buttons.length === 1) triggerButton = buttons[0];
|
|
24
|
+
else triggerButton = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
25
|
+
this._trigger = triggerButton ?? root;
|
|
26
|
+
}
|
|
15
27
|
/**
|
|
16
28
|
* Set the interaction type used by the select tester.
|
|
17
29
|
*/ setInteractionType(type) {
|
|
@@ -25,18 +37,18 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
25
37
|
let isDisabled = trigger.hasAttribute('disabled');
|
|
26
38
|
if (interactionType === 'mouse') await this.user.click(this._trigger);
|
|
27
39
|
else if (interactionType === 'keyboard') {
|
|
28
|
-
(0, $
|
|
40
|
+
(0, $d0NQz$act)(()=>trigger.focus());
|
|
29
41
|
await this.user.keyboard('[Enter]');
|
|
30
42
|
} else if (interactionType === 'touch') await this.user.pointer({
|
|
31
43
|
target: this._trigger,
|
|
32
44
|
keys: '[TouchA]'
|
|
33
45
|
});
|
|
34
|
-
await (0, $
|
|
46
|
+
await (0, $d0NQz$waitFor)(()=>{
|
|
35
47
|
if (!isDisabled && trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on select element trigger.');
|
|
36
48
|
else return true;
|
|
37
49
|
});
|
|
38
50
|
let listBoxId = trigger.getAttribute('aria-controls');
|
|
39
|
-
await (0, $
|
|
51
|
+
await (0, $d0NQz$waitFor)(()=>{
|
|
40
52
|
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`ListBox with id of ${listBoxId} not found in document.`);
|
|
41
53
|
else return true;
|
|
42
54
|
});
|
|
@@ -46,10 +58,10 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
46
58
|
*/ async close() {
|
|
47
59
|
let listbox = this.listbox;
|
|
48
60
|
if (listbox) {
|
|
49
|
-
(0, $
|
|
61
|
+
(0, $d0NQz$act)(()=>listbox.focus());
|
|
50
62
|
await this.user.keyboard('[Escape]');
|
|
51
63
|
}
|
|
52
|
-
await (0, $
|
|
64
|
+
await (0, $d0NQz$waitFor)(()=>{
|
|
53
65
|
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);
|
|
54
66
|
else return true;
|
|
55
67
|
});
|
|
@@ -63,7 +75,7 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
63
75
|
let options = this.options();
|
|
64
76
|
let listbox = this.listbox;
|
|
65
77
|
if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
|
|
66
|
-
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $
|
|
78
|
+
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $d0NQz$within)(listbox).getByText(optionIndexOrText).closest('[role=option]');
|
|
67
79
|
return option;
|
|
68
80
|
}
|
|
69
81
|
async keyboardNavigateToOption(opts) {
|
|
@@ -81,7 +93,7 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
81
93
|
* Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select dropdown beforehand.
|
|
82
94
|
* The desired option can be targeted via the option's node, the option's text, or the option's index.
|
|
83
95
|
*/ async selectOption(opts) {
|
|
84
|
-
let { option: option, interactionType: interactionType = this._interactionType } = opts || {};
|
|
96
|
+
let { option: option, closesOnSelect: closesOnSelect, interactionType: interactionType = this._interactionType } = opts || {};
|
|
85
97
|
let trigger = this.trigger;
|
|
86
98
|
if (!trigger.getAttribute('aria-controls')) await this.open();
|
|
87
99
|
let listbox = this.listbox;
|
|
@@ -92,9 +104,11 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
92
104
|
});
|
|
93
105
|
if (!option) throw new Error('Target option not found in the listbox.');
|
|
94
106
|
let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';
|
|
107
|
+
let isSingleSelect = !isMultiSelect;
|
|
108
|
+
closesOnSelect = closesOnSelect ?? isSingleSelect;
|
|
95
109
|
if (interactionType === 'keyboard') {
|
|
96
|
-
if (
|
|
97
|
-
if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) (0, $
|
|
110
|
+
if (option?.getAttribute('aria-disabled') === 'true') return;
|
|
111
|
+
if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) (0, $d0NQz$act)(()=>listbox.focus());
|
|
98
112
|
await this.keyboardNavigateToOption({
|
|
99
113
|
option: option
|
|
100
114
|
});
|
|
@@ -105,8 +119,8 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
105
119
|
target: option,
|
|
106
120
|
keys: '[TouchA]'
|
|
107
121
|
});
|
|
108
|
-
if (
|
|
109
|
-
await (0, $
|
|
122
|
+
if (closesOnSelect && option?.getAttribute('href') == null) {
|
|
123
|
+
await (0, $d0NQz$waitFor)(()=>{
|
|
110
124
|
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);
|
|
111
125
|
else return true;
|
|
112
126
|
});
|
|
@@ -119,7 +133,7 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
119
133
|
*/ options(opts = {}) {
|
|
120
134
|
let { element: element = this.listbox } = opts;
|
|
121
135
|
let options = [];
|
|
122
|
-
if (element) options = (0, $
|
|
136
|
+
if (element) options = (0, $d0NQz$within)(element).queryAllByRole('option');
|
|
123
137
|
return options;
|
|
124
138
|
}
|
|
125
139
|
/**
|
|
@@ -137,22 +151,10 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
137
151
|
* Returns the select's sections if present.
|
|
138
152
|
*/ get sections() {
|
|
139
153
|
let listbox = this.listbox;
|
|
140
|
-
return listbox ? (0, $
|
|
141
|
-
}
|
|
142
|
-
constructor(opts){
|
|
143
|
-
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
144
|
-
this.user = user;
|
|
145
|
-
this._interactionType = interactionType || 'mouse';
|
|
146
|
-
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
147
|
-
let buttons = (0, $7v0pZ$within)(root).queryAllByRole('button');
|
|
148
|
-
let triggerButton;
|
|
149
|
-
if (buttons.length === 0) triggerButton = root;
|
|
150
|
-
else if (buttons.length === 1) triggerButton = buttons[0];
|
|
151
|
-
else triggerButton = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
152
|
-
this._trigger = triggerButton !== null && triggerButton !== void 0 ? triggerButton : root;
|
|
154
|
+
return listbox ? (0, $d0NQz$within)(listbox).queryAllByRole('group') : [];
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
|
|
157
|
-
export {$
|
|
158
|
-
//# sourceMappingURL=select.
|
|
159
|
+
export {$6acb352063615cf0$export$d1859707465446a9 as SelectTester};
|
|
160
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAKX,YAAY,IAAsB,CAAE;QAClC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,8FAA8F;QAC9F,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI;QACJ,IAAI,QAAQ,MAAM,KAAK,GACrB,gBAAgB;aACX,IAAI,QAAQ,MAAM,KAAK,GAC5B,gBAAgB,OAAO,CAAC,EAAE;aAE1B,gBAAgB,QAAQ,IAAI,CAAC,CAAA,SAAU,OAAO,YAAY,CAAC;QAG7D,IAAI,CAAC,QAAQ,GAAG,iBAAiB;IACnC;IACA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;QACnD,IAAI,mBACF,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;Q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AE,SAAS,cAAc,CAAC;QAG3C,OAAO;IACT;IAEA;;GAEC,GACD,IAAI,UAAuB;QACzB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA;;GAEC,GACD,IAAI,UAA8B;QAChC,IAAI,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QAC1C,OAAO,YAAY,SAAS,cAAc,CAAC,aAAa;IAC1D;IAEA;;GAEC,GACD,IAAI,WAA0B;QAC5B,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC,WAAW,EAAE;IAC/D;AACF","sources":["packages/@react-aria/test-utils/src/select.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {SelectTesterOpts, UserOpts} from './types';\n\ninterface SelectOpenOpts {\n /**\n * What interaction type to use when opening the select. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface SelectTriggerOptionOpts extends SelectOpenOpts {\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 * Whether or not the select closes on selection. Depends on select implementation and configuration.\n * @default true\n */\n closesOnSelect?: boolean\n}\n\nexport class SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n // Handle case where the wrapper element is provided rather than the Select's button (aka RAC)\n let buttons = within(root).queryAllByRole('button');\n let triggerButton;\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\n this._trigger = triggerButton ?? root;\n }\n /**\n * Set the interaction type used by the select tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the select. Defaults to using the interaction type set on the select tester.\n */\n async open(opts: SelectOpenOpts = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n await this.user.click(this._trigger);\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: this._trigger, keys: '[TouchA]'});\n }\n\n await waitFor(() => {\n if (!isDisabled && trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on select element trigger.');\n } else {\n return true;\n }\n });\n let listBoxId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`ListBox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Closes the select.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => listbox.focus());\n await this.user.keyboard('[Escape]');\n }\n\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (listbox && document.contains(listbox)) {\n throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let 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 private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n if (document.activeElement === this.listbox) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select 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: SelectTriggerOptionOpts): Promise<void> {\n let {\n option,\n closesOnSelect,\n interactionType = this._interactionType\n } = opts || {};\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open();\n }\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Select\\'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 let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';\n let isSingleSelect = !isMultiSelect;\n closesOnSelect = closesOnSelect ?? isSingleSelect;\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else {\n // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n if (closesOnSelect && option?.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(listbox)) {\n throw new Error('Expected select element listbox to not be in the document after selecting an option');\n }\n }\n }\n }\n\n /**\n * Returns the select'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 select's trigger.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the select's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.trigger.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : null;\n }\n\n /**\n * Returns the select's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.js.map"}
|