@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
package/dist/import.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {triggerLongPress as $
|
|
2
|
-
import {installMouseEvent as $
|
|
3
|
-
import {pointerMap as $
|
|
4
|
-
import {User as $
|
|
1
|
+
import {triggerLongPress as $22d7d9b763402afa$export$3a22a5a9bc0fd3b} from "./private/events.js";
|
|
2
|
+
import {installMouseEvent as $448e93e3748c7958$export$de31e3987c917741, installPointerEvent as $448e93e3748c7958$export$82f0b04c1d69a901} from "./private/testSetup.js";
|
|
3
|
+
import {pointerMap as $759f061d800cf446$export$7dbde2c4caaa8d35} from "./private/userEventMaps.js";
|
|
4
|
+
import {User as $4ab48216ddc89c32$export$1f44aaf2ec115b54} from "./private/user.js";
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* Copyright 2023 Adobe. All rights reserved.
|
|
@@ -19,5 +19,5 @@ import {User as $0d71b4e9cc4df40a$export$1f44aaf2ec115b54} from "./user.mjs";
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
export {$
|
|
22
|
+
export {$22d7d9b763402afa$export$3a22a5a9bc0fd3b as triggerLongPress, $448e93e3748c7958$export$de31e3987c917741 as installMouseEvent, $448e93e3748c7958$export$82f0b04c1d69a901 as installPointerEvent, $759f061d800cf446$export$7dbde2c4caaa8d35 as pointerMap, $4ab48216ddc89c32$export$1f44aaf2ec115b54 as User};
|
|
23
23
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
4
|
-
var $
|
|
1
|
+
var $01a4eeee86094c77$exports = require("./private/events.cjs");
|
|
2
|
+
var $5e3c75beb0dad42b$exports = require("./private/testSetup.cjs");
|
|
3
|
+
var $b3fc8c302673b35d$exports = require("./private/userEventMaps.cjs");
|
|
4
|
+
var $3117e6a7fac3686b$exports = require("./private/user.cjs");
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
function $parcel$export(e, n, v, s) {
|
|
8
8
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
$parcel$export(module.exports, "triggerLongPress", ()
|
|
12
|
-
$parcel$export(module.exports, "installMouseEvent", ()
|
|
13
|
-
$parcel$export(module.exports, "installPointerEvent", ()
|
|
14
|
-
$parcel$export(module.exports, "pointerMap", ()
|
|
15
|
-
$parcel$export(module.exports, "User", ()
|
|
11
|
+
$parcel$export(module.exports, "triggerLongPress", function () { return $01a4eeee86094c77$exports.triggerLongPress; });
|
|
12
|
+
$parcel$export(module.exports, "installMouseEvent", function () { return $5e3c75beb0dad42b$exports.installMouseEvent; });
|
|
13
|
+
$parcel$export(module.exports, "installPointerEvent", function () { return $5e3c75beb0dad42b$exports.installPointerEvent; });
|
|
14
|
+
$parcel$export(module.exports, "pointerMap", function () { return $b3fc8c302673b35d$exports.pointerMap; });
|
|
15
|
+
$parcel$export(module.exports, "User", function () { return $3117e6a7fac3686b$exports.User; });
|
|
16
16
|
/*
|
|
17
17
|
* Copyright 2023 Adobe. All rights reserved.
|
|
18
18
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\n\nexport type {UserOpts} from './types';\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\nexport type {CheckboxGroupTester} from './checkboxgroup';\nexport type {ComboBoxTester} from './combobox';\nexport type {DialogTester} from './dialog';\nexport type {GridListTester} from './gridlist';\nexport type {ListBoxTester} from './listbox';\nexport type {MenuTester} from './menu';\nexport type {RadioGroupTester} from './radiogroup';\nexport type {SelectTester} from './select';\nexport type {TableTester} from './table';\nexport type {TabsTester} from './tabs';\nexport type {TreeTester} from './tree';\n\nexport type {UserOpts} from './types';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {triggerLongPress as $
|
|
2
|
-
import {installMouseEvent as $
|
|
3
|
-
import {pointerMap as $
|
|
4
|
-
import {User as $
|
|
1
|
+
import {triggerLongPress as $22d7d9b763402afa$export$3a22a5a9bc0fd3b} from "./private/events.js";
|
|
2
|
+
import {installMouseEvent as $448e93e3748c7958$export$de31e3987c917741, installPointerEvent as $448e93e3748c7958$export$82f0b04c1d69a901} from "./private/testSetup.js";
|
|
3
|
+
import {pointerMap as $759f061d800cf446$export$7dbde2c4caaa8d35} from "./private/userEventMaps.js";
|
|
4
|
+
import {User as $4ab48216ddc89c32$export$1f44aaf2ec115b54} from "./private/user.js";
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* Copyright 2023 Adobe. All rights reserved.
|
|
@@ -19,5 +19,5 @@ import {User as $0d71b4e9cc4df40a$export$1f44aaf2ec115b54} from "./user.module.j
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
export {$
|
|
22
|
+
export {$22d7d9b763402afa$export$3a22a5a9bc0fd3b as triggerLongPress, $448e93e3748c7958$export$de31e3987c917741 as installMouseEvent, $448e93e3748c7958$export$82f0b04c1d69a901 as installPointerEvent, $759f061d800cf446$export$7dbde2c4caaa8d35 as pointerMap, $4ab48216ddc89c32$export$1f44aaf2ec115b54 as User};
|
|
23
23
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\n\nexport type {UserOpts} from './types';\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\nexport type {CheckboxGroupTester} from './checkboxgroup';\nexport type {ComboBoxTester} from './combobox';\nexport type {DialogTester} from './dialog';\nexport type {GridListTester} from './gridlist';\nexport type {ListBoxTester} from './listbox';\nexport type {MenuTester} from './menu';\nexport type {RadioGroupTester} from './radiogroup';\nexport type {SelectTester} from './select';\nexport type {TableTester} from './table';\nexport type {TabsTester} from './tabs';\nexport type {TreeTester} from './tree';\n\nexport type {UserOpts} from './types';\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var $01a4eeee86094c77$exports = require("./events.cjs");
|
|
2
|
+
var $aZ766$testinglibraryreact = require("@testing-library/react");
|
|
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, "CheckboxGroupTester", function () { return $2c71bb2c1e5033f0$export$f54f4bde770cc5a6; });
|
|
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 $2c71bb2c1e5033f0$export$f54f4bde770cc5a6 {
|
|
23
|
+
constructor(opts){
|
|
24
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
25
|
+
this.user = user;
|
|
26
|
+
this._interactionType = interactionType || 'mouse';
|
|
27
|
+
this._checkboxgroup = root;
|
|
28
|
+
let checkboxgroup = (0, $aZ766$testinglibraryreact.within)(root).queryAllByRole('group');
|
|
29
|
+
if (checkboxgroup.length > 0) this._checkboxgroup = checkboxgroup[0];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Set the interaction type used by the checkbox group tester.
|
|
33
|
+
*/ setInteractionType(type) {
|
|
34
|
+
this._interactionType = type;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns a checkbox matching the specified index or text content.
|
|
38
|
+
*/ findCheckbox(opts) {
|
|
39
|
+
let { checkboxIndexOrText: checkboxIndexOrText } = opts;
|
|
40
|
+
let checkbox;
|
|
41
|
+
if (typeof checkboxIndexOrText === 'number') checkbox = this.checkboxes[checkboxIndexOrText];
|
|
42
|
+
else if (typeof checkboxIndexOrText === 'string') {
|
|
43
|
+
let label = (0, $aZ766$testinglibraryreact.within)(this.checkboxgroup).getByText(checkboxIndexOrText);
|
|
44
|
+
// Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it
|
|
45
|
+
if (label) {
|
|
46
|
+
checkbox = (0, $aZ766$testinglibraryreact.within)(label).queryByRole('checkbox');
|
|
47
|
+
if (!checkbox) {
|
|
48
|
+
let labelWrapper = label.closest('label');
|
|
49
|
+
if (labelWrapper) checkbox = (0, $aZ766$testinglibraryreact.within)(labelWrapper).queryByRole('checkbox');
|
|
50
|
+
else checkbox = label.closest('[role=checkbox]');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return checkbox;
|
|
55
|
+
}
|
|
56
|
+
async keyboardNavigateToCheckbox(opts) {
|
|
57
|
+
let { checkbox: checkbox } = opts;
|
|
58
|
+
let checkboxes = this.checkboxes;
|
|
59
|
+
checkboxes = checkboxes.filter((checkbox)=>!(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));
|
|
60
|
+
if (checkboxes.length === 0) throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');
|
|
61
|
+
let targetIndex = checkboxes.indexOf(checkbox);
|
|
62
|
+
if (targetIndex === -1) throw new Error('Checkbox provided is not in the checkbox group.');
|
|
63
|
+
if (!this.checkboxgroup.contains(document.activeElement)) (0, $aZ766$testinglibraryreact.act)(()=>checkboxes[0].focus());
|
|
64
|
+
let currIndex = checkboxes.indexOf(document.activeElement);
|
|
65
|
+
if (currIndex === -1) throw new Error('Active element is not in the checkbox group.');
|
|
66
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.tab({
|
|
67
|
+
shift: targetIndex < currIndex
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.
|
|
72
|
+
*/ async toggleCheckbox(opts) {
|
|
73
|
+
let { checkbox: checkbox, interactionType: interactionType = this._interactionType } = opts;
|
|
74
|
+
if (typeof checkbox === 'string' || typeof checkbox === 'number') checkbox = this.findCheckbox({
|
|
75
|
+
checkboxIndexOrText: checkbox
|
|
76
|
+
});
|
|
77
|
+
if (!checkbox) throw new Error('Target checkbox not found in the checkboxgroup.');
|
|
78
|
+
else if (checkbox.hasAttribute('disabled')) throw new Error('Target checkbox is disabled.');
|
|
79
|
+
if (interactionType === 'keyboard') {
|
|
80
|
+
await this.keyboardNavigateToCheckbox({
|
|
81
|
+
checkbox: checkbox
|
|
82
|
+
});
|
|
83
|
+
await this.user.keyboard('[Space]');
|
|
84
|
+
} else await (0, $01a4eeee86094c77$exports.pressElement)(this.user, checkbox, interactionType);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the checkboxgroup.
|
|
88
|
+
*/ get checkboxgroup() {
|
|
89
|
+
return this._checkboxgroup;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the checkboxes.
|
|
93
|
+
*/ get checkboxes() {
|
|
94
|
+
return (0, $aZ766$testinglibraryreact.within)(this.checkboxgroup).queryAllByRole('checkbox');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns the currently selected checkboxes in the checkboxgroup if any.
|
|
98
|
+
*/ get selectedCheckboxes() {
|
|
99
|
+
return this.checkboxes.filter((checkbox)=>checkbox.checked || checkbox.getAttribute('aria-checked') === 'true');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=checkboxgroup.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiBM,MAAM;IAMX,YAAY,IAA6B,CAAE;QACzC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAE3C,IAAI,CAAC,cAAc,GAAG;QACtB,IAAI,gBAAgB,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAChD,IAAI,cAAc,MAAM,GAAG,GACzB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC,EAAE;IAE1C;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,aAAa,IAA4C,EAAe;QACtE,IAAI,uBACF,mBAAmB,EACpB,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,wBAAwB,UACjC,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Q,mBACR,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QAEJ,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,UACtD,WAAW,IAAI,CAAC,YAAY,CAAC;YAAC,qBAAqB;QAAQ;QAG7D,IAAI,CAAC,UACH,MAAM,IAAI,MAAM;aACX,IAAI,SAAS,YAAY,CAAC,aAC/B,MAAM,IAAI,MAAM;QAGlB,IAAI,oBAAoB,YAAY;YAClC,MAAM,IAAI,CAAC,0BAA0B,CAAC;0BAAC;YAAQ;YAC/C,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OACE,MAAM,CAAA,GAAA,sCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU;IAE5C;IAEA;;GAEC,GACD,IAAI,gBAA6B;QAC/B,OAAO,IAAI,CAAC,cAAc;IAC5B;IAEA;;GAEC,GACD,IAAI,aAA4B;QAC9B,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC;IACnD;IAEA;;GAEC,GACD,IAAI,qBAAoC;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA,WAAY,AAAC,SAA8B,OAAO,IAAI,SAAS,YAAY,CAAC,oBAAoB;IAChI;AACF","sources":["packages/@react-aria/test-utils/src/checkboxgroup.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, within} from '@testing-library/react';\nimport {CheckboxGroupTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerCheckboxOptions {\n /**\n * What interaction type to use when triggering a checkbox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the checkbox to toggle selection for.\n */\n checkbox: number | string | HTMLElement\n}\n\nexport class CheckboxGroupTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _checkboxgroup: HTMLElement;\n\n\n constructor(opts: CheckboxGroupTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n this._checkboxgroup = root;\n let checkboxgroup = within(root).queryAllByRole('group');\n if (checkboxgroup.length > 0) {\n this._checkboxgroup = checkboxgroup[0];\n }\n }\n\n /**\n * Set the interaction type used by the checkbox group tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a checkbox matching the specified index or text content.\n */\n findCheckbox(opts: {checkboxIndexOrText: number | string}): HTMLElement {\n let {\n checkboxIndexOrText\n } = opts;\n\n let checkbox;\n if (typeof checkboxIndexOrText === 'number') {\n checkbox = this.checkboxes[checkboxIndexOrText];\n } else if (typeof checkboxIndexOrText === 'string') {\n let label = within(this.checkboxgroup).getByText(checkboxIndexOrText);\n\n // Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it\n if (label) {\n checkbox = within(label).queryByRole('checkbox');\n if (!checkbox) {\n let labelWrapper = label.closest('label');\n if (labelWrapper) {\n checkbox = within(labelWrapper).queryByRole('checkbox');\n } else {\n checkbox = label.closest('[role=checkbox]');\n }\n }\n }\n }\n\n return checkbox;\n }\n\n private async keyboardNavigateToCheckbox(opts: {checkbox: HTMLElement}) {\n let {checkbox} = opts;\n let checkboxes = this.checkboxes;\n checkboxes = checkboxes.filter(checkbox => !(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));\n if (checkboxes.length === 0) {\n throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');\n }\n\n let targetIndex = checkboxes.indexOf(checkbox);\n if (targetIndex === -1) {\n throw new Error('Checkbox provided is not in the checkbox group.');\n }\n\n if (!this.checkboxgroup.contains(document.activeElement)) {\n act(() => checkboxes[0].focus());\n }\n\n let currIndex = checkboxes.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Active element is not in the checkbox group.');\n }\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.tab({shift: targetIndex < currIndex});\n }\n };\n\n /**\n * Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.\n */\n async toggleCheckbox(opts: TriggerCheckboxOptions): Promise<void> {\n let {\n checkbox,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof checkbox === 'string' || typeof checkbox === 'number') {\n checkbox = this.findCheckbox({checkboxIndexOrText: checkbox});\n }\n\n if (!checkbox) {\n throw new Error('Target checkbox not found in the checkboxgroup.');\n } else if (checkbox.hasAttribute('disabled')) {\n throw new Error('Target checkbox is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n await this.keyboardNavigateToCheckbox({checkbox});\n await this.user.keyboard('[Space]');\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns the checkboxgroup.\n */\n get checkboxgroup(): HTMLElement {\n return this._checkboxgroup;\n }\n\n /**\n * Returns the checkboxes.\n */\n get checkboxes(): HTMLElement[] {\n return within(this.checkboxgroup).queryAllByRole('checkbox');\n }\n\n /**\n * Returns the currently selected checkboxes in the checkboxgroup if any.\n */\n get selectedCheckboxes(): HTMLElement[] {\n return this.checkboxes.filter(checkbox => (checkbox as HTMLInputElement).checked || checkbox.getAttribute('aria-checked') === 'true');\n }\n}\n"],"names":[],"version":3,"file":"checkboxgroup.cjs.map"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {pressElement as $22d7d9b763402afa$export$6ffa3eb717517feb} from "./events.js";
|
|
2
|
+
import {within as $g4drr$within, act as $g4drr$act} from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
class $e7160b4be83b4967$export$f54f4bde770cc5a6 {
|
|
17
|
+
constructor(opts){
|
|
18
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
19
|
+
this.user = user;
|
|
20
|
+
this._interactionType = interactionType || 'mouse';
|
|
21
|
+
this._checkboxgroup = root;
|
|
22
|
+
let checkboxgroup = (0, $g4drr$within)(root).queryAllByRole('group');
|
|
23
|
+
if (checkboxgroup.length > 0) this._checkboxgroup = checkboxgroup[0];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Set the interaction type used by the checkbox group tester.
|
|
27
|
+
*/ setInteractionType(type) {
|
|
28
|
+
this._interactionType = type;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns a checkbox matching the specified index or text content.
|
|
32
|
+
*/ findCheckbox(opts) {
|
|
33
|
+
let { checkboxIndexOrText: checkboxIndexOrText } = opts;
|
|
34
|
+
let checkbox;
|
|
35
|
+
if (typeof checkboxIndexOrText === 'number') checkbox = this.checkboxes[checkboxIndexOrText];
|
|
36
|
+
else if (typeof checkboxIndexOrText === 'string') {
|
|
37
|
+
let label = (0, $g4drr$within)(this.checkboxgroup).getByText(checkboxIndexOrText);
|
|
38
|
+
// Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it
|
|
39
|
+
if (label) {
|
|
40
|
+
checkbox = (0, $g4drr$within)(label).queryByRole('checkbox');
|
|
41
|
+
if (!checkbox) {
|
|
42
|
+
let labelWrapper = label.closest('label');
|
|
43
|
+
if (labelWrapper) checkbox = (0, $g4drr$within)(labelWrapper).queryByRole('checkbox');
|
|
44
|
+
else checkbox = label.closest('[role=checkbox]');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return checkbox;
|
|
49
|
+
}
|
|
50
|
+
async keyboardNavigateToCheckbox(opts) {
|
|
51
|
+
let { checkbox: checkbox } = opts;
|
|
52
|
+
let checkboxes = this.checkboxes;
|
|
53
|
+
checkboxes = checkboxes.filter((checkbox)=>!(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));
|
|
54
|
+
if (checkboxes.length === 0) throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');
|
|
55
|
+
let targetIndex = checkboxes.indexOf(checkbox);
|
|
56
|
+
if (targetIndex === -1) throw new Error('Checkbox provided is not in the checkbox group.');
|
|
57
|
+
if (!this.checkboxgroup.contains(document.activeElement)) (0, $g4drr$act)(()=>checkboxes[0].focus());
|
|
58
|
+
let currIndex = checkboxes.indexOf(document.activeElement);
|
|
59
|
+
if (currIndex === -1) throw new Error('Active element is not in the checkbox group.');
|
|
60
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.tab({
|
|
61
|
+
shift: targetIndex < currIndex
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.
|
|
66
|
+
*/ async toggleCheckbox(opts) {
|
|
67
|
+
let { checkbox: checkbox, interactionType: interactionType = this._interactionType } = opts;
|
|
68
|
+
if (typeof checkbox === 'string' || typeof checkbox === 'number') checkbox = this.findCheckbox({
|
|
69
|
+
checkboxIndexOrText: checkbox
|
|
70
|
+
});
|
|
71
|
+
if (!checkbox) throw new Error('Target checkbox not found in the checkboxgroup.');
|
|
72
|
+
else if (checkbox.hasAttribute('disabled')) throw new Error('Target checkbox is disabled.');
|
|
73
|
+
if (interactionType === 'keyboard') {
|
|
74
|
+
await this.keyboardNavigateToCheckbox({
|
|
75
|
+
checkbox: checkbox
|
|
76
|
+
});
|
|
77
|
+
await this.user.keyboard('[Space]');
|
|
78
|
+
} else await (0, $22d7d9b763402afa$export$6ffa3eb717517feb)(this.user, checkbox, interactionType);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns the checkboxgroup.
|
|
82
|
+
*/ get checkboxgroup() {
|
|
83
|
+
return this._checkboxgroup;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns the checkboxes.
|
|
87
|
+
*/ get checkboxes() {
|
|
88
|
+
return (0, $g4drr$within)(this.checkboxgroup).queryAllByRole('checkbox');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns the currently selected checkboxes in the checkboxgroup if any.
|
|
92
|
+
*/ get selectedCheckboxes() {
|
|
93
|
+
return this.checkboxes.filter((checkbox)=>checkbox.checked || checkbox.getAttribute('aria-checked') === 'true');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
export {$e7160b4be83b4967$export$f54f4bde770cc5a6 as CheckboxGroupTester};
|
|
99
|
+
//# sourceMappingURL=checkboxgroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiBM,MAAM;IAMX,YAAY,IAA6B,CAAE;QACzC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAE3C,IAAI,CAAC,cAAc,GAAG;QACtB,IAAI,gBAAgB,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;QAChD,IAAI,cAAc,MAAM,GAAG,GAC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zD,IAAI,cAAc,IAChB,MAAM,IAAI,MAAM;QAGlB,IAAK,IAAI,IAAI,GAAG,IAAI,KAAK,GAAG,CAAC,cAAc,YAAY,IACrD,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;YAAC,OAAO,cAAc;QAAS;IAEvD;IAEA;;GAEC,GACD,MAAM,eAAe,IAA4B,EAAiB;QAChE,IAAI,YACF,QAAQ,mBACR,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QAEJ,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,UACtD,WAAW,IAAI,CAAC,YAAY,CAAC;YAAC,qBAAqB;QAAQ;QAG7D,IAAI,CAAC,UACH,MAAM,IAAI,MAAM;aACX,IAAI,SAAS,YAAY,CAAC,aAC/B,MAAM,IAAI,MAAM;QAGlB,IAAI,oBAAoB,YAAY;YAClC,MAAM,IAAI,CAAC,0BAA0B,CAAC;0BAAC;YAAQ;YAC/C,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OACE,MAAM,CAAA,GAAA,yCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU;IAE5C;IAEA;;GAEC,GACD,IAAI,gBAA6B;QAC/B,OAAO,IAAI,CAAC,cAAc;IAC5B;IAEA;;GAEC,GACD,IAAI,aAA4B;QAC9B,OAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC;IACnD;IAEA;;GAEC,GACD,IAAI,qBAAoC;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA,WAAY,AAAC,SAA8B,OAAO,IAAI,SAAS,YAAY,CAAC,oBAAoB;IAChI;AACF","sources":["packages/@react-aria/test-utils/src/checkboxgroup.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, within} from '@testing-library/react';\nimport {CheckboxGroupTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerCheckboxOptions {\n /**\n * What interaction type to use when triggering a checkbox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the checkbox to toggle selection for.\n */\n checkbox: number | string | HTMLElement\n}\n\nexport class CheckboxGroupTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _checkboxgroup: HTMLElement;\n\n\n constructor(opts: CheckboxGroupTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n this._checkboxgroup = root;\n let checkboxgroup = within(root).queryAllByRole('group');\n if (checkboxgroup.length > 0) {\n this._checkboxgroup = checkboxgroup[0];\n }\n }\n\n /**\n * Set the interaction type used by the checkbox group tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a checkbox matching the specified index or text content.\n */\n findCheckbox(opts: {checkboxIndexOrText: number | string}): HTMLElement {\n let {\n checkboxIndexOrText\n } = opts;\n\n let checkbox;\n if (typeof checkboxIndexOrText === 'number') {\n checkbox = this.checkboxes[checkboxIndexOrText];\n } else if (typeof checkboxIndexOrText === 'string') {\n let label = within(this.checkboxgroup).getByText(checkboxIndexOrText);\n\n // Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it\n if (label) {\n checkbox = within(label).queryByRole('checkbox');\n if (!checkbox) {\n let labelWrapper = label.closest('label');\n if (labelWrapper) {\n checkbox = within(labelWrapper).queryByRole('checkbox');\n } else {\n checkbox = label.closest('[role=checkbox]');\n }\n }\n }\n }\n\n return checkbox;\n }\n\n private async keyboardNavigateToCheckbox(opts: {checkbox: HTMLElement}) {\n let {checkbox} = opts;\n let checkboxes = this.checkboxes;\n checkboxes = checkboxes.filter(checkbox => !(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));\n if (checkboxes.length === 0) {\n throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');\n }\n\n let targetIndex = checkboxes.indexOf(checkbox);\n if (targetIndex === -1) {\n throw new Error('Checkbox provided is not in the checkbox group.');\n }\n\n if (!this.checkboxgroup.contains(document.activeElement)) {\n act(() => checkboxes[0].focus());\n }\n\n let currIndex = checkboxes.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Active element is not in the checkbox group.');\n }\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.tab({shift: targetIndex < currIndex});\n }\n };\n\n /**\n * Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.\n */\n async toggleCheckbox(opts: TriggerCheckboxOptions): Promise<void> {\n let {\n checkbox,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof checkbox === 'string' || typeof checkbox === 'number') {\n checkbox = this.findCheckbox({checkboxIndexOrText: checkbox});\n }\n\n if (!checkbox) {\n throw new Error('Target checkbox not found in the checkboxgroup.');\n } else if (checkbox.hasAttribute('disabled')) {\n throw new Error('Target checkbox is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n await this.keyboardNavigateToCheckbox({checkbox});\n await this.user.keyboard('[Space]');\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns the checkboxgroup.\n */\n get checkboxgroup(): HTMLElement {\n return this._checkboxgroup;\n }\n\n /**\n * Returns the checkboxes.\n */\n get checkboxes(): HTMLElement[] {\n return within(this.checkboxgroup).queryAllByRole('checkbox');\n }\n\n /**\n * Returns the currently selected checkboxes in the checkboxgroup if any.\n */\n get selectedCheckboxes(): HTMLElement[] {\n return this.checkboxes.filter(checkbox => (checkbox as HTMLInputElement).checked || checkbox.getAttribute('aria-checked') === 'true');\n }\n}\n"],"names":[],"version":3,"file":"checkboxgroup.js.map"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var $
|
|
1
|
+
var $btaxF$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, "ComboBoxTester", ()
|
|
8
|
+
$parcel$export(module.exports, "ComboBoxTester", function () { return $2cdddd94ee78eafe$export$f97e14e96d71ab3b; });
|
|
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,29 @@ $parcel$export(module.exports, "ComboBoxTester", () => $15e4b71f2b6c4964$export$
|
|
|
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 $2cdddd94ee78eafe$export$f97e14e96d71ab3b {
|
|
21
|
+
constructor(opts){
|
|
22
|
+
let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
|
|
23
|
+
this.user = user;
|
|
24
|
+
this._interactionType = interactionType || 'mouse';
|
|
25
|
+
// 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
|
|
26
|
+
// query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
|
|
27
|
+
this._combobox = root;
|
|
28
|
+
let combobox = (0, $btaxF$testinglibraryreact.within)(root).queryByRole('combobox');
|
|
29
|
+
if (combobox) this._combobox = combobox;
|
|
30
|
+
// 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)
|
|
31
|
+
if (trigger) this._trigger = trigger;
|
|
32
|
+
else {
|
|
33
|
+
let buttons = (0, $btaxF$testinglibraryreact.within)(root).queryAllByRole('button', {
|
|
34
|
+
hidden: true
|
|
35
|
+
});
|
|
36
|
+
if (buttons.length === 1) trigger = buttons[0];
|
|
37
|
+
else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
38
|
+
// For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
|
|
39
|
+
// is also the trigger button
|
|
40
|
+
this._trigger = trigger || this._combobox;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
21
43
|
/**
|
|
22
44
|
* Set the interaction type used by the combobox tester.
|
|
23
45
|
*/ setInteractionType(type) {
|
|
@@ -34,7 +56,7 @@ class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
|
|
|
34
56
|
if (triggerBehavior === 'focus') await this.user.click(combobox);
|
|
35
57
|
else await this.user.click(trigger);
|
|
36
58
|
} else if (interactionType === 'keyboard' && this._trigger != null) {
|
|
37
|
-
(0, $
|
|
59
|
+
(0, $btaxF$testinglibraryreact.act)(()=>this._trigger.focus());
|
|
38
60
|
if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
|
|
39
61
|
} else if (interactionType === 'touch') {
|
|
40
62
|
if (triggerBehavior === 'focus') await this.user.pointer({
|
|
@@ -46,12 +68,12 @@ class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
|
|
|
46
68
|
keys: '[TouchA]'
|
|
47
69
|
});
|
|
48
70
|
}
|
|
49
|
-
await (0, $
|
|
71
|
+
await (0, $btaxF$testinglibraryreact.waitFor)(()=>{
|
|
50
72
|
if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
|
|
51
73
|
else return true;
|
|
52
74
|
});
|
|
53
75
|
let listBoxId = combobox.getAttribute('aria-controls');
|
|
54
|
-
await (0, $
|
|
76
|
+
await (0, $btaxF$testinglibraryreact.waitFor)(()=>{
|
|
55
77
|
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
|
|
56
78
|
else return true;
|
|
57
79
|
});
|
|
@@ -64,7 +86,7 @@ class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
|
|
|
64
86
|
let options = this.options();
|
|
65
87
|
let listbox = this.listbox;
|
|
66
88
|
if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
|
|
67
|
-
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $
|
|
89
|
+
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $btaxF$testinglibraryreact.within)(listbox).getByText(optionIndexOrText).closest('[role=option]');
|
|
68
90
|
return option;
|
|
69
91
|
}
|
|
70
92
|
/**
|
|
@@ -89,7 +111,7 @@ class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
|
|
|
89
111
|
target: option,
|
|
90
112
|
keys: '[TouchA]'
|
|
91
113
|
});
|
|
92
|
-
if (option.getAttribute('href') == null) await (0, $
|
|
114
|
+
if (option.getAttribute('href') == null) await (0, $btaxF$testinglibraryreact.waitFor)(()=>{
|
|
93
115
|
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
94
116
|
else return true;
|
|
95
117
|
});
|
|
@@ -100,9 +122,9 @@ class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
|
|
|
100
122
|
*/ async close() {
|
|
101
123
|
let listbox = this.listbox;
|
|
102
124
|
if (listbox) {
|
|
103
|
-
(0, $
|
|
125
|
+
(0, $btaxF$testinglibraryreact.act)(()=>this.combobox.focus());
|
|
104
126
|
await this.user.keyboard('[Escape]');
|
|
105
|
-
await (0, $
|
|
127
|
+
await (0, $btaxF$testinglibraryreact.waitFor)(()=>{
|
|
106
128
|
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
107
129
|
else return true;
|
|
108
130
|
});
|
|
@@ -128,14 +150,14 @@ class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
|
|
|
128
150
|
* Returns the combobox's sections if present.
|
|
129
151
|
*/ get sections() {
|
|
130
152
|
let listbox = this.listbox;
|
|
131
|
-
return listbox ? (0, $
|
|
153
|
+
return listbox ? (0, $btaxF$testinglibraryreact.within)(listbox).queryAllByRole('group') : [];
|
|
132
154
|
}
|
|
133
155
|
/**
|
|
134
156
|
* Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.
|
|
135
157
|
*/ options(opts = {}) {
|
|
136
158
|
let { element: element = this.listbox } = opts;
|
|
137
159
|
let options = [];
|
|
138
|
-
if (element) options = (0, $
|
|
160
|
+
if (element) options = (0, $btaxF$testinglibraryreact.within)(element).queryAllByRole('option');
|
|
139
161
|
return options;
|
|
140
162
|
}
|
|
141
163
|
/**
|
|
@@ -144,29 +166,7 @@ class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
|
|
|
144
166
|
let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');
|
|
145
167
|
return focusedOptionId ? document.getElementById(focusedOptionId) : null;
|
|
146
168
|
}
|
|
147
|
-
constructor(opts){
|
|
148
|
-
let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
|
|
149
|
-
this.user = user;
|
|
150
|
-
this._interactionType = interactionType || 'mouse';
|
|
151
|
-
// 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
|
|
152
|
-
// query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
|
|
153
|
-
this._combobox = root;
|
|
154
|
-
let combobox = (0, $f8PS3$testinglibraryreact.within)(root).queryByRole('combobox');
|
|
155
|
-
if (combobox) this._combobox = combobox;
|
|
156
|
-
// 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)
|
|
157
|
-
if (trigger) this._trigger = trigger;
|
|
158
|
-
else {
|
|
159
|
-
let buttons = (0, $f8PS3$testinglibraryreact.within)(root).queryAllByRole('button', {
|
|
160
|
-
hidden: true
|
|
161
|
-
});
|
|
162
|
-
if (buttons.length === 1) trigger = buttons[0];
|
|
163
|
-
else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
164
|
-
// For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
|
|
165
|
-
// is also the trigger button
|
|
166
|
-
this._trigger = trigger || this._combobox;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
|
|
172
|
-
//# sourceMappingURL=combobox.
|
|
172
|
+
//# sourceMappingURL=combobox.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwBM,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,iCAAK,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,iCAAK,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,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GACD,MAAM,QAAuB;QAC3B,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,SAAS;YACX,CAAA,GAAA,8BAAE,EAAE,IAAM,IAAI,CAAC,QAAQ,CAAC,KAAK;YAC7B,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAEzB,MAAM,CAAA,GAAA,kCAAM,EAAE;gBACZ,IAAI,SAAS,QAAQ,CAAC,UACpB,MAAM,IAAI,MAAM;qBAEhB,OAAO;YAEX;QACF;IACF;IAEA;;GAEC,GACD,IAAI,WAAwB;QAC1B,OAAO,IAAI,CAAC,SAAS;IACvB;IAEA;;GAEC,GACD,IAAI,UAAuB;QACzB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA;;GAEC,GACD,IAAI,UAA8B;QAChC,IAAI,YAAY,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QAC3C,OAAO,YAAY,SAAS,cAAc,CAAC,cAAc,OAAO;IAClE;IAEA;;GAEC,GACD,IAAI,WAA0B;QAC5B,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC,WAAW,EAAE;IAC/D;IAEA;;GAEC,GACD,QAAQ,OAAgC,CAAC,CAAC,EAAiB;QACzD,IAAI,WAAC,UAAU,IAAI,CAAC,OAAO,EAAC,GAAG;QAC/B,IAAI,UAAU,EAAE;QAChB,IAAI,SACF,UAAU,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;QAG3C,OAAO;IACT;IAEA;;GAEC,GACD,IAAI,gBAAoC;QACtC,IAAI,kBAAkB,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QACjD,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, 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 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.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): Promise<void> {\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(): Promise<void> {\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.cjs.map"}
|