@react-aria/test-utils 1.0.0-nightly.5041 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/dist/import.mjs +6 -4
- package/dist/main.js +15 -23
- package/dist/main.js.map +1 -1
- package/dist/module.js +6 -4
- package/dist/module.js.map +1 -1
- package/dist/private/act.cjs +33 -0
- package/dist/private/act.cjs.map +1 -0
- package/dist/private/act.js +28 -0
- package/dist/private/act.js.map +1 -0
- package/dist/private/checkboxgroup.cjs +107 -0
- package/dist/private/checkboxgroup.cjs.map +1 -0
- package/dist/private/checkboxgroup.js +102 -0
- package/dist/private/checkboxgroup.js.map +1 -0
- package/dist/private/combobox.cjs +199 -0
- package/dist/private/combobox.cjs.map +1 -0
- package/dist/private/combobox.js +194 -0
- package/dist/private/combobox.js.map +1 -0
- package/dist/private/dialog.cjs +110 -0
- package/dist/private/dialog.cjs.map +1 -0
- package/dist/private/dialog.js +105 -0
- package/dist/private/dialog.js.map +1 -0
- package/dist/private/gridlist.cjs +173 -0
- package/dist/private/gridlist.cjs.map +1 -0
- package/dist/private/gridlist.js +168 -0
- package/dist/private/gridlist.js.map +1 -0
- package/dist/private/listbox.cjs +163 -0
- package/dist/private/listbox.cjs.map +1 -0
- package/dist/private/listbox.js +158 -0
- package/dist/private/listbox.js.map +1 -0
- package/dist/private/menu.cjs +265 -0
- package/dist/private/menu.cjs.map +1 -0
- package/dist/private/menu.js +260 -0
- package/dist/private/menu.js.map +1 -0
- package/dist/private/radiogroup.cjs +122 -0
- package/dist/private/radiogroup.cjs.map +1 -0
- package/dist/private/radiogroup.js +117 -0
- package/dist/private/radiogroup.js.map +1 -0
- package/dist/private/select.cjs +169 -0
- package/dist/private/select.cjs.map +1 -0
- package/dist/private/select.js +164 -0
- package/dist/private/select.js.map +1 -0
- package/dist/private/table.cjs +346 -0
- package/dist/private/table.cjs.map +1 -0
- package/dist/private/table.js +341 -0
- package/dist/private/table.js.map +1 -0
- package/dist/private/tabs.cjs +131 -0
- package/dist/private/tabs.cjs.map +1 -0
- package/dist/private/tabs.js +126 -0
- 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/private/tree.cjs +181 -0
- package/dist/private/tree.cjs.map +1 -0
- package/dist/private/tree.js +176 -0
- 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/private/userEventMaps.cjs.map +1 -0
- package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
- package/dist/private/userEventMaps.js.map +1 -0
- package/dist/private/utils.cjs +136 -0
- package/dist/private/utils.cjs.map +1 -0
- package/dist/private/utils.js +127 -0
- package/dist/private/utils.js.map +1 -0
- package/dist/types/src/act.d.ts +4 -0
- package/dist/types/src/checkboxgroup.d.ts +47 -0
- package/dist/types/src/combobox.d.ts +87 -0
- package/dist/types/src/dialog.d.ts +37 -0
- package/dist/types/src/events.d.ts +25 -0
- package/dist/types/src/gridlist.d.ts +56 -0
- package/dist/types/src/index.d.ts +16 -0
- package/dist/types/src/listbox.d.ts +91 -0
- package/dist/types/src/menu.d.ts +112 -0
- package/dist/types/src/radiogroup.d.ts +47 -0
- package/dist/types/src/select.d.ts +74 -0
- package/dist/types/src/table.d.ts +120 -0
- package/dist/types/src/tabs.d.ts +59 -0
- package/dist/types/src/testSetup.d.ts +6 -0
- package/dist/types/src/tree.d.ts +62 -0
- package/dist/types/src/types.d.ts +143 -0
- package/dist/types/src/user.d.ts +49 -0
- package/dist/types/src/userEventMaps.d.ts +2 -0
- package/dist/types/src/utils.d.ts +29 -0
- package/package.json +26 -18
- package/src/act.ts +35 -0
- package/src/checkboxgroup.ts +165 -0
- package/src/combobox.ts +307 -0
- package/src/dialog.ts +155 -0
- package/src/gridlist.ts +278 -0
- package/src/index.ts +17 -3
- package/src/listbox.ts +300 -0
- package/src/menu.ts +479 -0
- package/src/radiogroup.ts +179 -0
- package/src/select.ts +273 -0
- package/src/table.ts +589 -0
- package/src/tabs.ts +204 -0
- package/src/testSetup.ts +41 -36
- package/src/tree.ts +290 -0
- package/src/types.ts +171 -0
- package/src/user.ts +153 -0
- package/src/userEventMaps.ts +1 -1
- package/src/utils.ts +155 -0
- package/dist/events.main.js +0 -37
- package/dist/events.main.js.map +0 -1
- package/dist/events.mjs +0 -31
- package/dist/events.module.js +0 -31
- package/dist/events.module.js.map +0 -1
- package/dist/testSetup.main.js +0 -82
- package/dist/testSetup.main.js.map +0 -1
- package/dist/testSetup.mjs +0 -76
- package/dist/testSetup.module.js +0 -76
- package/dist/testSetup.module.js.map +0 -1
- package/dist/types.d.ts +0 -16
- package/dist/types.d.ts.map +0 -1
- package/dist/userEventMaps.main.js.map +0 -1
- package/dist/userEventMaps.module.js +0 -38
- package/dist/userEventMaps.module.js.map +0 -1
- package/src/events.ts +0 -28
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
1
|
# @react-aria/test-utils
|
|
2
2
|
|
|
3
3
|
This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
|
|
4
|
+
|
|
5
|
+
See the [React Aria testing docs](https://react-aria.adobe.com/testing#react-aria-test-utils) for usage.
|
|
6
|
+
|
|
7
|
+
`@react-aria/test-utils` is a set of testing utilities that aims to make writing unit tests easier for consumers of React Aria or for users who have built their own components following the respective ARIA pattern specification.
|
|
8
|
+
|
|
9
|
+
> **Requirements:** This library uses [@testing-library/dom@10](https://www.npmjs.com/package/@testing-library/dom) and [@testing-library/user-event@14](https://www.npmjs.com/package/@testing-library/user-event). You need to be on React 18+ for these utilities to work.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm install @react-aria/test-utils --dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
Initialize a `User` object at the top of your test file, and use it to create an ARIA pattern tester in your test cases. The tester has methods that you can call within your test to query for specific subcomponents or simulate common interactions.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// YourTest.test.ts
|
|
23
|
+
import {screen} from '@testing-library/react';
|
|
24
|
+
import {User} from '@react-aria/test-utils';
|
|
25
|
+
|
|
26
|
+
// Provide whatever method of advancing timers you use in your test, this example assumes Jest with fake timers.
|
|
27
|
+
// 'interactionType' specifies what mode of interaction should be simulated by the tester
|
|
28
|
+
// 'advanceTimer' is used by the tester to advance the timers in the tests for specific interactions (e.g. long press)
|
|
29
|
+
let testUtilUser = new User({interactionType: 'mouse', advanceTimer: jest.advanceTimersByTime});
|
|
30
|
+
// ...
|
|
31
|
+
|
|
32
|
+
it('my test case', async function () {
|
|
33
|
+
// Render your test component/app
|
|
34
|
+
render();
|
|
35
|
+
// Initialize the table tester via providing the 'Table' pattern name and the root element of said table
|
|
36
|
+
let table = testUtilUser.createTester('Table', {root: screen.getByTestId('test_table')});
|
|
37
|
+
|
|
38
|
+
// ...
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## User API
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
class User {
|
|
46
|
+
constructor(opts?: {
|
|
47
|
+
interactionType?: 'mouse' | 'keyboard' | 'touch',
|
|
48
|
+
advanceTimer?: (time?: number) => void | Promise<unknown>
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
createTester(patternName, opts): PatternTester;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- `interactionType` — default modality used by testers created from this `User`. Individual testers can override this via `setInteractionType` or per-method options.
|
|
56
|
+
- `advanceTimer` — used by testers to advance timers for interactions like long press. Pass `jest.advanceTimersByTime` (or your test framework's equivalent) when using fake timers.
|
|
57
|
+
- `createTester(patternName, opts)` — returns a tester for the given ARIA pattern. `opts.root` is the root element of the component under test.
|
|
58
|
+
|
|
59
|
+
## Patterns
|
|
60
|
+
|
|
61
|
+
Below is a list of the ARIA patterns supported by `createTester`. See the accompanying component testing docs pages on the [React Aria docs site](https://react-aria.adobe.com/testing#react-aria-test-utils) for sample usage of each tester in a test suite.
|
|
62
|
+
|
|
63
|
+
- [CheckboxGroup](https://react-aria.adobe.com/CheckboxGroup/testing)
|
|
64
|
+
- [ComboBox](https://react-aria.adobe.com/ComboBox/testing)
|
|
65
|
+
- Dialog via [Modal](https://react-aria.adobe.com/Modal/testing) / [Popover](https://react-aria.adobe.com/Popover/testing)
|
|
66
|
+
- [GridList](https://react-aria.adobe.com/GridList/testing)
|
|
67
|
+
- [ListBox](https://react-aria.adobe.com/ListBox/testing)
|
|
68
|
+
- [Menu](https://react-aria.adobe.com/Menu/testing)
|
|
69
|
+
- [RadioGroup](https://react-aria.adobe.com/RadioGroup/testing)
|
|
70
|
+
- [Select](https://react-aria.adobe.com/Select/testing)
|
|
71
|
+
- [Table](https://react-aria.adobe.com/Table/testing)
|
|
72
|
+
- [Tabs](https://react-aria.adobe.com/Tabs/testing)
|
|
73
|
+
- [Tree](https://react-aria.adobe.com/Tree/testing)
|
package/dist/import.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {installMouseEvent as $
|
|
3
|
-
import {pointerMap as $
|
|
1
|
+
import {triggerLongPress as $b4e037a2907521c6$export$3a22a5a9bc0fd3b} from "./private/utils.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";
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
* Copyright 2023 Adobe. All rights reserved.
|
|
@@ -17,5 +18,6 @@ import {pointerMap as $50ecfb18069ec897$export$7dbde2c4caaa8d35} from "./userEve
|
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
export {$b4e037a2907521c6$export$3a22a5a9bc0fd3b as triggerLongPress, $448e93e3748c7958$export$de31e3987c917741 as installMouseEvent, $448e93e3748c7958$export$82f0b04c1d69a901 as installPointerEvent, $759f061d800cf446$export$7dbde2c4caaa8d35 as pointerMap, $4ab48216ddc89c32$export$1f44aaf2ec115b54 as User};
|
|
21
23
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(dest, key, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return source[key];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return dest;
|
|
1
|
+
var $022fcf8e360befed$exports = require("./private/utils.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
|
+
|
|
6
|
+
|
|
7
|
+
function $parcel$export(e, n, v, s) {
|
|
8
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
21
9
|
}
|
|
10
|
+
|
|
11
|
+
$parcel$export(module.exports, "triggerLongPress", function () { return $022fcf8e360befed$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; });
|
|
22
16
|
/*
|
|
23
17
|
* Copyright 2023 Adobe. All rights reserved.
|
|
24
18
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -32,9 +26,7 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
32
26
|
*/
|
|
33
27
|
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
$parcel$exportWildcard(module.exports, $b53408e40e8d56d0$exports);
|
|
37
|
-
$parcel$exportWildcard(module.exports, $0e568517a25183a7$exports);
|
|
29
|
+
|
|
38
30
|
|
|
39
31
|
|
|
40
32
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
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 './utils';\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,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {installMouseEvent as $
|
|
3
|
-
import {pointerMap as $
|
|
1
|
+
import {triggerLongPress as $b4e037a2907521c6$export$3a22a5a9bc0fd3b} from "./private/utils.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";
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
* Copyright 2023 Adobe. All rights reserved.
|
|
@@ -17,5 +18,6 @@ import {pointerMap as $50ecfb18069ec897$export$7dbde2c4caaa8d35} from "./userEve
|
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
export {$b4e037a2907521c6$export$3a22a5a9bc0fd3b as triggerLongPress, $448e93e3748c7958$export$de31e3987c917741 as installMouseEvent, $448e93e3748c7958$export$82f0b04c1d69a901 as installPointerEvent, $759f061d800cf446$export$7dbde2c4caaa8d35 as pointerMap, $4ab48216ddc89c32$export$1f44aaf2ec115b54 as User};
|
|
21
23
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
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 './utils';\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,33 @@
|
|
|
1
|
+
var $5POqM$react = require("react");
|
|
2
|
+
var $5POqM$reactdomtestutils = require("react-dom/test-utils");
|
|
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, "act", function () { return $a84d573878cc1e5e$export$3ba232387fd5d6dd; });
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2026 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
|
+
let $a84d573878cc1e5e$var$actImpl;
|
|
23
|
+
if (typeof $5POqM$react.act === 'function') $a84d573878cc1e5e$var$actImpl = $5POqM$react.act;
|
|
24
|
+
else $a84d573878cc1e5e$var$actImpl = $5POqM$reactdomtestutils.act;
|
|
25
|
+
const $a84d573878cc1e5e$export$3ba232387fd5d6dd = (fn)=>{
|
|
26
|
+
// only wrap in act if in test environment, breaks vite browser test if test utils are used otherwise
|
|
27
|
+
if (// @ts-ignore
|
|
28
|
+
typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined') return $a84d573878cc1e5e$var$actImpl(fn);
|
|
29
|
+
return fn();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=act.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAKD,IAAI;AACJ,IAAI,OAAO,qBAAc,YACvB,gCAAU;KAEV,gCAAU;AAGL,MAAM,4CAAsB,CAAA;IACjC,qGAAqG;IACrG,IACE,aAAa;IACb,OAAO,6BAA6B,YAEhC,2BACA,OAAO,SAAS,aAEpB,OAAO,8BAAQ;IAEjB,OAAO;AACT","sources":["packages/@react-aria/test-utils/src/act.ts"],"sourcesContent":["/*\n * Copyright 2026 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 * as React from 'react';\nimport * as ReactDOMTestUtils from 'react-dom/test-utils';\n\nlet actImpl: typeof ReactDOMTestUtils.act;\nif (typeof React.act === 'function') {\n actImpl = React.act;\n} else {\n actImpl = ReactDOMTestUtils.act;\n}\n\nexport const act: typeof actImpl = fn => {\n // only wrap in act if in test environment, breaks vite browser test if test utils are used otherwise\n if (\n // @ts-ignore\n typeof IS_REACT_ACT_ENVIRONMENT === 'boolean'\n ? // @ts-ignore\n IS_REACT_ACT_ENVIRONMENT\n : typeof jest !== 'undefined'\n ) {\n return actImpl(fn);\n }\n return fn();\n};\n"],"names":[],"version":3,"file":"act.cjs.map"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {act as $1k33P$act} from "react";
|
|
2
|
+
import {act as $1k33P$act1} from "react-dom/test-utils";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2026 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
|
+
let $1350703ef3ac1acc$var$actImpl;
|
|
17
|
+
if (typeof $1k33P$act === 'function') $1350703ef3ac1acc$var$actImpl = $1k33P$act;
|
|
18
|
+
else $1350703ef3ac1acc$var$actImpl = $1k33P$act1;
|
|
19
|
+
const $1350703ef3ac1acc$export$3ba232387fd5d6dd = (fn)=>{
|
|
20
|
+
// only wrap in act if in test environment, breaks vite browser test if test utils are used otherwise
|
|
21
|
+
if (// @ts-ignore
|
|
22
|
+
typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined') return $1350703ef3ac1acc$var$actImpl(fn);
|
|
23
|
+
return fn();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export {$1350703ef3ac1acc$export$3ba232387fd5d6dd as act};
|
|
28
|
+
//# sourceMappingURL=act.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAKD,IAAI;AACJ,IAAI,OAAO,eAAc,YACvB,gCAAU;KAEV,gCAAU;AAGL,MAAM,4CAAsB,CAAA;IACjC,qGAAqG;IACrG,IACE,aAAa;IACb,OAAO,6BAA6B,YAEhC,2BACA,OAAO,SAAS,aAEpB,OAAO,8BAAQ;IAEjB,OAAO;AACT","sources":["packages/@react-aria/test-utils/src/act.ts"],"sourcesContent":["/*\n * Copyright 2026 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 * as React from 'react';\nimport * as ReactDOMTestUtils from 'react-dom/test-utils';\n\nlet actImpl: typeof ReactDOMTestUtils.act;\nif (typeof React.act === 'function') {\n actImpl = React.act;\n} else {\n actImpl = ReactDOMTestUtils.act;\n}\n\nexport const act: typeof actImpl = fn => {\n // only wrap in act if in test environment, breaks vite browser test if test utils are used otherwise\n if (\n // @ts-ignore\n typeof IS_REACT_ACT_ENVIRONMENT === 'boolean'\n ? // @ts-ignore\n IS_REACT_ACT_ENVIRONMENT\n : typeof jest !== 'undefined'\n ) {\n return actImpl(fn);\n }\n return fn();\n};\n"],"names":[],"version":3,"file":"act.js.map"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var $a84d573878cc1e5e$exports = require("./act.cjs");
|
|
2
|
+
var $022fcf8e360befed$exports = require("./utils.cjs");
|
|
3
|
+
var $aZ766$testinglibrarydom = require("@testing-library/dom");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
function $parcel$export(e, n, v, s) {
|
|
7
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
$parcel$export(module.exports, "CheckboxGroupTester", function () { return $2c71bb2c1e5033f0$export$f54f4bde770cc5a6; });
|
|
11
|
+
/*
|
|
12
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
13
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
+
* governing permissions and limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class $2c71bb2c1e5033f0$export$f54f4bde770cc5a6 {
|
|
25
|
+
constructor(opts){
|
|
26
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
27
|
+
this.user = user;
|
|
28
|
+
this._interactionType = interactionType || 'mouse';
|
|
29
|
+
this._checkboxgroup = root;
|
|
30
|
+
let checkboxgroup = (0, $aZ766$testinglibrarydom.within)(root).queryAllByRole('group');
|
|
31
|
+
if (checkboxgroup.length > 0) this._checkboxgroup = checkboxgroup[0];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set the interaction type used by the checkbox group tester.
|
|
35
|
+
*/ setInteractionType(type) {
|
|
36
|
+
this._interactionType = type;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns a checkbox matching the specified index or text content.
|
|
40
|
+
*/ findCheckbox(opts) {
|
|
41
|
+
let { indexOrText: indexOrText } = opts;
|
|
42
|
+
let checkbox;
|
|
43
|
+
if (typeof indexOrText === 'number') checkbox = this.getCheckboxes()[indexOrText];
|
|
44
|
+
else if (typeof indexOrText === 'string') {
|
|
45
|
+
let label = (0, $aZ766$testinglibrarydom.within)(this.getCheckboxGroup()).getByText(indexOrText);
|
|
46
|
+
// Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it
|
|
47
|
+
if (label) {
|
|
48
|
+
checkbox = (0, $aZ766$testinglibrarydom.within)(label).queryByRole('checkbox');
|
|
49
|
+
if (!checkbox) {
|
|
50
|
+
let labelWrapper = label.closest('label');
|
|
51
|
+
if (labelWrapper) checkbox = (0, $aZ766$testinglibrarydom.within)(labelWrapper).queryByRole('checkbox');
|
|
52
|
+
else checkbox = label.closest('[role=checkbox]');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return checkbox;
|
|
57
|
+
}
|
|
58
|
+
async keyboardNavigateToCheckbox(opts) {
|
|
59
|
+
let { checkbox: checkbox } = opts;
|
|
60
|
+
let checkboxes = this.getCheckboxes();
|
|
61
|
+
checkboxes = checkboxes.filter((checkbox)=>!(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));
|
|
62
|
+
if (checkboxes.length === 0) throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');
|
|
63
|
+
let targetIndex = checkboxes.indexOf(checkbox);
|
|
64
|
+
if (targetIndex === -1) throw new Error('Checkbox provided is not in the checkbox group.');
|
|
65
|
+
if (!this.getCheckboxGroup().contains(document.activeElement)) (0, $a84d573878cc1e5e$exports.act)(()=>checkboxes[0].focus());
|
|
66
|
+
let currIndex = checkboxes.indexOf(document.activeElement);
|
|
67
|
+
if (currIndex === -1) throw new Error('Active element is not in the checkbox group.');
|
|
68
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.tab({
|
|
69
|
+
shift: targetIndex < currIndex
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox
|
|
74
|
+
* tester.
|
|
75
|
+
*/ async toggleCheckbox(opts) {
|
|
76
|
+
let { checkbox: checkbox, interactionType: interactionType = this._interactionType } = opts;
|
|
77
|
+
if (typeof checkbox === 'string' || typeof checkbox === 'number') checkbox = this.findCheckbox({
|
|
78
|
+
indexOrText: checkbox
|
|
79
|
+
});
|
|
80
|
+
if (!checkbox) throw new Error(`Target checkbox "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.checkbox)}" not found in the checkboxgroup.`);
|
|
81
|
+
else if (checkbox.hasAttribute('disabled')) throw new Error(`Target checkbox "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.checkbox)}" is disabled.`);
|
|
82
|
+
if (interactionType === 'keyboard') {
|
|
83
|
+
await this.keyboardNavigateToCheckbox({
|
|
84
|
+
checkbox: checkbox
|
|
85
|
+
});
|
|
86
|
+
await this.user.keyboard('[Space]');
|
|
87
|
+
} else await (0, $022fcf8e360befed$exports.pressElement)(this.user, checkbox, interactionType);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns the checkboxgroup.
|
|
91
|
+
*/ getCheckboxGroup() {
|
|
92
|
+
return this._checkboxgroup;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns the checkboxes.
|
|
96
|
+
*/ getCheckboxes() {
|
|
97
|
+
return (0, $aZ766$testinglibrarydom.within)(this.getCheckboxGroup()).queryAllByRole('checkbox');
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns the currently selected checkboxes in the checkboxgroup if any.
|
|
101
|
+
*/ getSelectedCheckboxes() {
|
|
102
|
+
return this.getCheckboxes().filter((checkbox)=>checkbox.checked || checkbox.getAttribute('aria-checked') === 'true');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=checkboxgroup.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAmBM,MAAM;IAKX,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,+BAAK,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,IAAoC,EAAe;QAC9D,IAAI,eAAC,WAAW,EAAC,GAAG;QAEpB,IAAI;QACJ,IAAI,OAAO,gBAAgB,UACzB,WAAW,IAAI,CAAC,aAAa,EAAE,CAAC,YAAY;aACvC,IAAI,OAAO,gBAAgB,UAAU;YAC1C,IAAI,QAAQ,CAAA,GAAA,+BAAK,EAAE,IAAI,CAAC,gBAAgB,IAAI,SAAS,CAAC;YAEtD,6HAA6H;YAC7H,IAAI,OAAO;gBACT,WAAW,CAAA,GAAA,+BAAK,EAAE,OAAO,WAAW,CAAC;gBACrC,IAAI,CAAC,UAAU;oBACb,IAAI,eAAe,MAAM,OAAO,CAAC;o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C,aAC/B,MAAM,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAA,GAAA,0CAAe,EAAE,KAAK,QAAQ,EAAE,cAAc,CAAC;QAGrF,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,mBAAgC;QAC9B,OAAO,IAAI,CAAC,cAAc;IAC5B;IAEA;;GAEC,GACD,gBAA+B;QAC7B,OAAO,CAAA,GAAA,+BAAK,EAAE,IAAI,CAAC,gBAAgB,IAAI,cAAc,CAAC;IACxD;IAEA;;GAEC,GACD,wBAAuC;QACrC,OAAO,IAAI,CAAC,aAAa,GAAG,MAAM,CAChC,CAAA,WACE,AAAC,SAA8B,OAAO,IAAI,SAAS,YAAY,CAAC,oBAAoB;IAE1F;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} from './act';\nimport {CheckboxGroupTesterOpts, UserOpts} from './types';\nimport {formatTargetNode, pressElement} from './utils';\nimport {within} from '@testing-library/dom';\n\ninterface TriggerCheckboxOptions {\n /**\n * What interaction type to use when triggering a checkbox. Defaults to the interaction type set\n * 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 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: {indexOrText: number | string}): HTMLElement {\n let {indexOrText} = opts;\n\n let checkbox;\n if (typeof indexOrText === 'number') {\n checkbox = this.getCheckboxes()[indexOrText];\n } else if (typeof indexOrText === 'string') {\n let label = within(this.getCheckboxGroup()).getByText(indexOrText);\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.getCheckboxes();\n checkboxes = checkboxes.filter(\n checkbox =>\n !(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true')\n );\n if (checkboxes.length === 0) {\n throw new Error(\n 'Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.'\n );\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.getCheckboxGroup().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\n * tester.\n */\n async toggleCheckbox(opts: TriggerCheckboxOptions): Promise<void> {\n let {checkbox, interactionType = this._interactionType} = opts;\n\n if (typeof checkbox === 'string' || typeof checkbox === 'number') {\n checkbox = this.findCheckbox({indexOrText: checkbox});\n }\n\n if (!checkbox) {\n throw new Error(\n `Target checkbox \"${formatTargetNode(opts.checkbox)}\" not found in the checkboxgroup.`\n );\n } else if (checkbox.hasAttribute('disabled')) {\n throw new Error(`Target checkbox \"${formatTargetNode(opts.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 getCheckboxGroup(): HTMLElement {\n return this._checkboxgroup;\n }\n\n /**\n * Returns the checkboxes.\n */\n getCheckboxes(): HTMLElement[] {\n return within(this.getCheckboxGroup()).queryAllByRole('checkbox');\n }\n\n /**\n * Returns the currently selected checkboxes in the checkboxgroup if any.\n */\n getSelectedCheckboxes(): HTMLElement[] {\n return this.getCheckboxes().filter(\n checkbox =>\n (checkbox as HTMLInputElement).checked || checkbox.getAttribute('aria-checked') === 'true'\n );\n }\n}\n"],"names":[],"version":3,"file":"checkboxgroup.cjs.map"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {act as $1350703ef3ac1acc$export$3ba232387fd5d6dd} from "./act.js";
|
|
2
|
+
import {formatTargetNode as $b4e037a2907521c6$export$bc3bc4a9206bf789, pressElement as $b4e037a2907521c6$export$6ffa3eb717517feb} from "./utils.js";
|
|
3
|
+
import {within as $g4drr$within} from "@testing-library/dom";
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
7
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
* governing permissions and limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class $e7160b4be83b4967$export$f54f4bde770cc5a6 {
|
|
19
|
+
constructor(opts){
|
|
20
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
21
|
+
this.user = user;
|
|
22
|
+
this._interactionType = interactionType || 'mouse';
|
|
23
|
+
this._checkboxgroup = root;
|
|
24
|
+
let checkboxgroup = (0, $g4drr$within)(root).queryAllByRole('group');
|
|
25
|
+
if (checkboxgroup.length > 0) this._checkboxgroup = checkboxgroup[0];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Set the interaction type used by the checkbox group tester.
|
|
29
|
+
*/ setInteractionType(type) {
|
|
30
|
+
this._interactionType = type;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns a checkbox matching the specified index or text content.
|
|
34
|
+
*/ findCheckbox(opts) {
|
|
35
|
+
let { indexOrText: indexOrText } = opts;
|
|
36
|
+
let checkbox;
|
|
37
|
+
if (typeof indexOrText === 'number') checkbox = this.getCheckboxes()[indexOrText];
|
|
38
|
+
else if (typeof indexOrText === 'string') {
|
|
39
|
+
let label = (0, $g4drr$within)(this.getCheckboxGroup()).getByText(indexOrText);
|
|
40
|
+
// Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it
|
|
41
|
+
if (label) {
|
|
42
|
+
checkbox = (0, $g4drr$within)(label).queryByRole('checkbox');
|
|
43
|
+
if (!checkbox) {
|
|
44
|
+
let labelWrapper = label.closest('label');
|
|
45
|
+
if (labelWrapper) checkbox = (0, $g4drr$within)(labelWrapper).queryByRole('checkbox');
|
|
46
|
+
else checkbox = label.closest('[role=checkbox]');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return checkbox;
|
|
51
|
+
}
|
|
52
|
+
async keyboardNavigateToCheckbox(opts) {
|
|
53
|
+
let { checkbox: checkbox } = opts;
|
|
54
|
+
let checkboxes = this.getCheckboxes();
|
|
55
|
+
checkboxes = checkboxes.filter((checkbox)=>!(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));
|
|
56
|
+
if (checkboxes.length === 0) throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');
|
|
57
|
+
let targetIndex = checkboxes.indexOf(checkbox);
|
|
58
|
+
if (targetIndex === -1) throw new Error('Checkbox provided is not in the checkbox group.');
|
|
59
|
+
if (!this.getCheckboxGroup().contains(document.activeElement)) (0, $1350703ef3ac1acc$export$3ba232387fd5d6dd)(()=>checkboxes[0].focus());
|
|
60
|
+
let currIndex = checkboxes.indexOf(document.activeElement);
|
|
61
|
+
if (currIndex === -1) throw new Error('Active element is not in the checkbox group.');
|
|
62
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.tab({
|
|
63
|
+
shift: targetIndex < currIndex
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox
|
|
68
|
+
* tester.
|
|
69
|
+
*/ async toggleCheckbox(opts) {
|
|
70
|
+
let { checkbox: checkbox, interactionType: interactionType = this._interactionType } = opts;
|
|
71
|
+
if (typeof checkbox === 'string' || typeof checkbox === 'number') checkbox = this.findCheckbox({
|
|
72
|
+
indexOrText: checkbox
|
|
73
|
+
});
|
|
74
|
+
if (!checkbox) throw new Error(`Target checkbox "${(0, $b4e037a2907521c6$export$bc3bc4a9206bf789)(opts.checkbox)}" not found in the checkboxgroup.`);
|
|
75
|
+
else if (checkbox.hasAttribute('disabled')) throw new Error(`Target checkbox "${(0, $b4e037a2907521c6$export$bc3bc4a9206bf789)(opts.checkbox)}" is disabled.`);
|
|
76
|
+
if (interactionType === 'keyboard') {
|
|
77
|
+
await this.keyboardNavigateToCheckbox({
|
|
78
|
+
checkbox: checkbox
|
|
79
|
+
});
|
|
80
|
+
await this.user.keyboard('[Space]');
|
|
81
|
+
} else await (0, $b4e037a2907521c6$export$6ffa3eb717517feb)(this.user, checkbox, interactionType);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the checkboxgroup.
|
|
85
|
+
*/ getCheckboxGroup() {
|
|
86
|
+
return this._checkboxgroup;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the checkboxes.
|
|
90
|
+
*/ getCheckboxes() {
|
|
91
|
+
return (0, $g4drr$within)(this.getCheckboxGroup()).queryAllByRole('checkbox');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns the currently selected checkboxes in the checkboxgroup if any.
|
|
95
|
+
*/ getSelectedCheckboxes() {
|
|
96
|
+
return this.getCheckboxes().filter((checkbox)=>checkbox.checked || checkbox.getAttribute('aria-checked') === 'true');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
export {$e7160b4be83b4967$export$f54f4bde770cc5a6 as CheckboxGroupTester};
|
|
102
|
+
//# sourceMappingURL=checkboxgroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAmBM,MAAM;IAKX,YAAY,IAA6B,CAAE;QACzC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,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wBAAuC;QACrC,OAAO,IAAI,CAAC,aAAa,GAAG,MAAM,CAChC,CAAA,WACE,AAAC,SAA8B,OAAO,IAAI,SAAS,YAAY,CAAC,oBAAoB;IAE1F;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} from './act';\nimport {CheckboxGroupTesterOpts, UserOpts} from './types';\nimport {formatTargetNode, pressElement} from './utils';\nimport {within} from '@testing-library/dom';\n\ninterface TriggerCheckboxOptions {\n /**\n * What interaction type to use when triggering a checkbox. Defaults to the interaction type set\n * 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 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: {indexOrText: number | string}): HTMLElement {\n let {indexOrText} = opts;\n\n let checkbox;\n if (typeof indexOrText === 'number') {\n checkbox = this.getCheckboxes()[indexOrText];\n } else if (typeof indexOrText === 'string') {\n let label = within(this.getCheckboxGroup()).getByText(indexOrText);\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.getCheckboxes();\n checkboxes = checkboxes.filter(\n checkbox =>\n !(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true')\n );\n if (checkboxes.length === 0) {\n throw new Error(\n 'Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.'\n );\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.getCheckboxGroup().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\n * tester.\n */\n async toggleCheckbox(opts: TriggerCheckboxOptions): Promise<void> {\n let {checkbox, interactionType = this._interactionType} = opts;\n\n if (typeof checkbox === 'string' || typeof checkbox === 'number') {\n checkbox = this.findCheckbox({indexOrText: checkbox});\n }\n\n if (!checkbox) {\n throw new Error(\n `Target checkbox \"${formatTargetNode(opts.checkbox)}\" not found in the checkboxgroup.`\n );\n } else if (checkbox.hasAttribute('disabled')) {\n throw new Error(`Target checkbox \"${formatTargetNode(opts.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 getCheckboxGroup(): HTMLElement {\n return this._checkboxgroup;\n }\n\n /**\n * Returns the checkboxes.\n */\n getCheckboxes(): HTMLElement[] {\n return within(this.getCheckboxGroup()).queryAllByRole('checkbox');\n }\n\n /**\n * Returns the currently selected checkboxes in the checkboxgroup if any.\n */\n getSelectedCheckboxes(): HTMLElement[] {\n return this.getCheckboxes().filter(\n checkbox =>\n (checkbox as HTMLInputElement).checked || checkbox.getAttribute('aria-checked') === 'true'\n );\n }\n}\n"],"names":[],"version":3,"file":"checkboxgroup.js.map"}
|