@react-aria/test-utils 3.0.0-nightly-ecd229153-251022 → 3.0.0-nightly-070dfd621-251024
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/checkboxgroup.main.js +104 -0
- package/dist/checkboxgroup.main.js.map +1 -0
- package/dist/checkboxgroup.mjs +99 -0
- package/dist/checkboxgroup.module.js +99 -0
- package/dist/checkboxgroup.module.js.map +1 -0
- package/dist/dialog.main.js +105 -0
- package/dist/dialog.main.js.map +1 -0
- package/dist/dialog.mjs +100 -0
- package/dist/dialog.module.js +100 -0
- package/dist/dialog.module.js.map +1 -0
- package/dist/radiogroup.main.js +123 -0
- package/dist/radiogroup.main.js.map +1 -0
- package/dist/radiogroup.mjs +118 -0
- package/dist/radiogroup.module.js +118 -0
- package/dist/radiogroup.module.js.map +1 -0
- package/dist/tabs.main.js +5 -3
- package/dist/tabs.main.js.map +1 -1
- package/dist/tabs.mjs +5 -3
- package/dist/tabs.module.js +5 -3
- package/dist/tabs.module.js.map +1 -1
- package/dist/types.d.ts +134 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/user.main.js +12 -3
- package/dist/user.main.js.map +1 -1
- package/dist/user.mjs +12 -3
- package/dist/user.module.js +12 -3
- package/dist/user.module.js.map +1 -1
- package/package.json +1 -1
- package/src/checkboxgroup.ts +158 -0
- package/src/dialog.ts +143 -0
- package/src/radiogroup.ts +176 -0
- package/src/tabs.ts +7 -2
- package/src/types.ts +21 -0
- package/src/user.ts +25 -7
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var $5a8bfe1663b8366d$exports = require("./events.main.js");
|
|
2
|
+
var $7ADgU$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", () => $18c3478e4f4e94c5$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 $18c3478e4f4e94c5$export$f54f4bde770cc5a6 {
|
|
23
|
+
/**
|
|
24
|
+
* Set the interaction type used by the checkbox group tester.
|
|
25
|
+
*/ setInteractionType(type) {
|
|
26
|
+
this._interactionType = type;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns a checkbox matching the specified index or text content.
|
|
30
|
+
*/ findCheckbox(opts) {
|
|
31
|
+
let { checkboxIndexOrText: checkboxIndexOrText } = opts;
|
|
32
|
+
let checkbox;
|
|
33
|
+
if (typeof checkboxIndexOrText === 'number') checkbox = this.checkboxes[checkboxIndexOrText];
|
|
34
|
+
else if (typeof checkboxIndexOrText === 'string') {
|
|
35
|
+
let label = (0, $7ADgU$testinglibraryreact.within)(this.checkboxgroup).getByText(checkboxIndexOrText);
|
|
36
|
+
// Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it
|
|
37
|
+
if (label) {
|
|
38
|
+
checkbox = (0, $7ADgU$testinglibraryreact.within)(label).queryByRole('checkbox');
|
|
39
|
+
if (!checkbox) {
|
|
40
|
+
let labelWrapper = label.closest('label');
|
|
41
|
+
if (labelWrapper) checkbox = (0, $7ADgU$testinglibraryreact.within)(labelWrapper).queryByRole('checkbox');
|
|
42
|
+
else checkbox = label.closest('[role=checkbox]');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return checkbox;
|
|
47
|
+
}
|
|
48
|
+
async keyboardNavigateToCheckbox(opts) {
|
|
49
|
+
let { checkbox: checkbox } = opts;
|
|
50
|
+
let checkboxes = this.checkboxes;
|
|
51
|
+
checkboxes = checkboxes.filter((checkbox)=>!(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));
|
|
52
|
+
if (checkboxes.length === 0) throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');
|
|
53
|
+
let targetIndex = checkboxes.indexOf(checkbox);
|
|
54
|
+
if (targetIndex === -1) throw new Error('Checkbox provided is not in the checkbox group.');
|
|
55
|
+
if (!this.checkboxgroup.contains(document.activeElement)) (0, $7ADgU$testinglibraryreact.act)(()=>checkboxes[0].focus());
|
|
56
|
+
let currIndex = checkboxes.indexOf(document.activeElement);
|
|
57
|
+
if (currIndex === -1) throw new Error('Active element is not in the checkbox group.');
|
|
58
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.tab({
|
|
59
|
+
shift: targetIndex < currIndex
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.
|
|
64
|
+
*/ async toggleCheckbox(opts) {
|
|
65
|
+
let { checkbox: checkbox, interactionType: interactionType = this._interactionType } = opts;
|
|
66
|
+
if (typeof checkbox === 'string' || typeof checkbox === 'number') checkbox = this.findCheckbox({
|
|
67
|
+
checkboxIndexOrText: checkbox
|
|
68
|
+
});
|
|
69
|
+
if (!checkbox) throw new Error('Target checkbox not found in the checkboxgroup.');
|
|
70
|
+
else if (checkbox.hasAttribute('disabled')) throw new Error('Target checkbox is disabled.');
|
|
71
|
+
if (interactionType === 'keyboard') {
|
|
72
|
+
await this.keyboardNavigateToCheckbox({
|
|
73
|
+
checkbox: checkbox
|
|
74
|
+
});
|
|
75
|
+
await this.user.keyboard('[Space]');
|
|
76
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, checkbox, interactionType);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns the checkboxgroup.
|
|
80
|
+
*/ get checkboxgroup() {
|
|
81
|
+
return this._checkboxgroup;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the checkboxes.
|
|
85
|
+
*/ get checkboxes() {
|
|
86
|
+
return (0, $7ADgU$testinglibraryreact.within)(this.checkboxgroup).queryAllByRole('checkbox');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the currently selected checkboxes in the checkboxgroup if any.
|
|
90
|
+
*/ get selectedCheckboxes() {
|
|
91
|
+
return this.checkboxes.filter((checkbox)=>checkbox.checked || checkbox.getAttribute('aria-checked') === 'true');
|
|
92
|
+
}
|
|
93
|
+
constructor(opts){
|
|
94
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
95
|
+
this.user = user;
|
|
96
|
+
this._interactionType = interactionType || 'mouse';
|
|
97
|
+
this._checkboxgroup = root;
|
|
98
|
+
let checkboxgroup = (0, $7ADgU$testinglibraryreact.within)(root).queryAllByRole('group');
|
|
99
|
+
if (checkboxgroup.length > 0) this._checkboxgroup = checkboxgroup[0];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=checkboxgroup.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiBM,MAAM;IAkBX;;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,wBA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* 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.main.js.map"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.mjs";
|
|
2
|
+
import {within as $jmBF6$within, act as $jmBF6$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 $8473f5d1df4c8eb7$export$f54f4bde770cc5a6 {
|
|
17
|
+
/**
|
|
18
|
+
* Set the interaction type used by the checkbox group tester.
|
|
19
|
+
*/ setInteractionType(type) {
|
|
20
|
+
this._interactionType = type;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns a checkbox matching the specified index or text content.
|
|
24
|
+
*/ findCheckbox(opts) {
|
|
25
|
+
let { checkboxIndexOrText: checkboxIndexOrText } = opts;
|
|
26
|
+
let checkbox;
|
|
27
|
+
if (typeof checkboxIndexOrText === 'number') checkbox = this.checkboxes[checkboxIndexOrText];
|
|
28
|
+
else if (typeof checkboxIndexOrText === 'string') {
|
|
29
|
+
let label = (0, $jmBF6$within)(this.checkboxgroup).getByText(checkboxIndexOrText);
|
|
30
|
+
// Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it
|
|
31
|
+
if (label) {
|
|
32
|
+
checkbox = (0, $jmBF6$within)(label).queryByRole('checkbox');
|
|
33
|
+
if (!checkbox) {
|
|
34
|
+
let labelWrapper = label.closest('label');
|
|
35
|
+
if (labelWrapper) checkbox = (0, $jmBF6$within)(labelWrapper).queryByRole('checkbox');
|
|
36
|
+
else checkbox = label.closest('[role=checkbox]');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return checkbox;
|
|
41
|
+
}
|
|
42
|
+
async keyboardNavigateToCheckbox(opts) {
|
|
43
|
+
let { checkbox: checkbox } = opts;
|
|
44
|
+
let checkboxes = this.checkboxes;
|
|
45
|
+
checkboxes = checkboxes.filter((checkbox)=>!(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));
|
|
46
|
+
if (checkboxes.length === 0) throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');
|
|
47
|
+
let targetIndex = checkboxes.indexOf(checkbox);
|
|
48
|
+
if (targetIndex === -1) throw new Error('Checkbox provided is not in the checkbox group.');
|
|
49
|
+
if (!this.checkboxgroup.contains(document.activeElement)) (0, $jmBF6$act)(()=>checkboxes[0].focus());
|
|
50
|
+
let currIndex = checkboxes.indexOf(document.activeElement);
|
|
51
|
+
if (currIndex === -1) throw new Error('Active element is not in the checkbox group.');
|
|
52
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.tab({
|
|
53
|
+
shift: targetIndex < currIndex
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.
|
|
58
|
+
*/ async toggleCheckbox(opts) {
|
|
59
|
+
let { checkbox: checkbox, interactionType: interactionType = this._interactionType } = opts;
|
|
60
|
+
if (typeof checkbox === 'string' || typeof checkbox === 'number') checkbox = this.findCheckbox({
|
|
61
|
+
checkboxIndexOrText: checkbox
|
|
62
|
+
});
|
|
63
|
+
if (!checkbox) throw new Error('Target checkbox not found in the checkboxgroup.');
|
|
64
|
+
else if (checkbox.hasAttribute('disabled')) throw new Error('Target checkbox is disabled.');
|
|
65
|
+
if (interactionType === 'keyboard') {
|
|
66
|
+
await this.keyboardNavigateToCheckbox({
|
|
67
|
+
checkbox: checkbox
|
|
68
|
+
});
|
|
69
|
+
await this.user.keyboard('[Space]');
|
|
70
|
+
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, checkbox, interactionType);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the checkboxgroup.
|
|
74
|
+
*/ get checkboxgroup() {
|
|
75
|
+
return this._checkboxgroup;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the checkboxes.
|
|
79
|
+
*/ get checkboxes() {
|
|
80
|
+
return (0, $jmBF6$within)(this.checkboxgroup).queryAllByRole('checkbox');
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns the currently selected checkboxes in the checkboxgroup if any.
|
|
84
|
+
*/ get selectedCheckboxes() {
|
|
85
|
+
return this.checkboxes.filter((checkbox)=>checkbox.checked || checkbox.getAttribute('aria-checked') === 'true');
|
|
86
|
+
}
|
|
87
|
+
constructor(opts){
|
|
88
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
89
|
+
this.user = user;
|
|
90
|
+
this._interactionType = interactionType || 'mouse';
|
|
91
|
+
this._checkboxgroup = root;
|
|
92
|
+
let checkboxgroup = (0, $jmBF6$within)(root).queryAllByRole('group');
|
|
93
|
+
if (checkboxgroup.length > 0) this._checkboxgroup = checkboxgroup[0];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
export {$8473f5d1df4c8eb7$export$f54f4bde770cc5a6 as CheckboxGroupTester};
|
|
99
|
+
//# sourceMappingURL=checkboxgroup.module.js.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.module.js";
|
|
2
|
+
import {within as $jmBF6$within, act as $jmBF6$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 $8473f5d1df4c8eb7$export$f54f4bde770cc5a6 {
|
|
17
|
+
/**
|
|
18
|
+
* Set the interaction type used by the checkbox group tester.
|
|
19
|
+
*/ setInteractionType(type) {
|
|
20
|
+
this._interactionType = type;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns a checkbox matching the specified index or text content.
|
|
24
|
+
*/ findCheckbox(opts) {
|
|
25
|
+
let { checkboxIndexOrText: checkboxIndexOrText } = opts;
|
|
26
|
+
let checkbox;
|
|
27
|
+
if (typeof checkboxIndexOrText === 'number') checkbox = this.checkboxes[checkboxIndexOrText];
|
|
28
|
+
else if (typeof checkboxIndexOrText === 'string') {
|
|
29
|
+
let label = (0, $jmBF6$within)(this.checkboxgroup).getByText(checkboxIndexOrText);
|
|
30
|
+
// Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it
|
|
31
|
+
if (label) {
|
|
32
|
+
checkbox = (0, $jmBF6$within)(label).queryByRole('checkbox');
|
|
33
|
+
if (!checkbox) {
|
|
34
|
+
let labelWrapper = label.closest('label');
|
|
35
|
+
if (labelWrapper) checkbox = (0, $jmBF6$within)(labelWrapper).queryByRole('checkbox');
|
|
36
|
+
else checkbox = label.closest('[role=checkbox]');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return checkbox;
|
|
41
|
+
}
|
|
42
|
+
async keyboardNavigateToCheckbox(opts) {
|
|
43
|
+
let { checkbox: checkbox } = opts;
|
|
44
|
+
let checkboxes = this.checkboxes;
|
|
45
|
+
checkboxes = checkboxes.filter((checkbox)=>!(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));
|
|
46
|
+
if (checkboxes.length === 0) throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');
|
|
47
|
+
let targetIndex = checkboxes.indexOf(checkbox);
|
|
48
|
+
if (targetIndex === -1) throw new Error('Checkbox provided is not in the checkbox group.');
|
|
49
|
+
if (!this.checkboxgroup.contains(document.activeElement)) (0, $jmBF6$act)(()=>checkboxes[0].focus());
|
|
50
|
+
let currIndex = checkboxes.indexOf(document.activeElement);
|
|
51
|
+
if (currIndex === -1) throw new Error('Active element is not in the checkbox group.');
|
|
52
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.tab({
|
|
53
|
+
shift: targetIndex < currIndex
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.
|
|
58
|
+
*/ async toggleCheckbox(opts) {
|
|
59
|
+
let { checkbox: checkbox, interactionType: interactionType = this._interactionType } = opts;
|
|
60
|
+
if (typeof checkbox === 'string' || typeof checkbox === 'number') checkbox = this.findCheckbox({
|
|
61
|
+
checkboxIndexOrText: checkbox
|
|
62
|
+
});
|
|
63
|
+
if (!checkbox) throw new Error('Target checkbox not found in the checkboxgroup.');
|
|
64
|
+
else if (checkbox.hasAttribute('disabled')) throw new Error('Target checkbox is disabled.');
|
|
65
|
+
if (interactionType === 'keyboard') {
|
|
66
|
+
await this.keyboardNavigateToCheckbox({
|
|
67
|
+
checkbox: checkbox
|
|
68
|
+
});
|
|
69
|
+
await this.user.keyboard('[Space]');
|
|
70
|
+
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, checkbox, interactionType);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the checkboxgroup.
|
|
74
|
+
*/ get checkboxgroup() {
|
|
75
|
+
return this._checkboxgroup;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the checkboxes.
|
|
79
|
+
*/ get checkboxes() {
|
|
80
|
+
return (0, $jmBF6$within)(this.checkboxgroup).queryAllByRole('checkbox');
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns the currently selected checkboxes in the checkboxgroup if any.
|
|
84
|
+
*/ get selectedCheckboxes() {
|
|
85
|
+
return this.checkboxes.filter((checkbox)=>checkbox.checked || checkbox.getAttribute('aria-checked') === 'true');
|
|
86
|
+
}
|
|
87
|
+
constructor(opts){
|
|
88
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
89
|
+
this.user = user;
|
|
90
|
+
this._interactionType = interactionType || 'mouse';
|
|
91
|
+
this._checkboxgroup = root;
|
|
92
|
+
let checkboxgroup = (0, $jmBF6$within)(root).queryAllByRole('group');
|
|
93
|
+
if (checkboxgroup.length > 0) this._checkboxgroup = checkboxgroup[0];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
export {$8473f5d1df4c8eb7$export$f54f4bde770cc5a6 as CheckboxGroupTester};
|
|
99
|
+
//# sourceMappingURL=checkboxgroup.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiBM,MAAM;IAkBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB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AG,aAAa,CAAC,EAAE;IAE1C;AAkHF","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.module.js.map"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var $7D3o2$testinglibraryreact = require("@testing-library/react");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
$parcel$export(module.exports, "DialogTester", () => $fe51f406377a5335$export$e79328f5295cc2a1);
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
class $fe51f406377a5335$export$e79328f5295cc2a1 {
|
|
21
|
+
/**
|
|
22
|
+
* Set the interaction type used by the dialog tester.
|
|
23
|
+
*/ setInteractionType(type) {
|
|
24
|
+
this._interactionType = type;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Opens the dialog. Defaults to using the interaction type set on the dialog tester.
|
|
28
|
+
*/ async open(opts = {}) {
|
|
29
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
30
|
+
let trigger = this.trigger;
|
|
31
|
+
if (!trigger.hasAttribute('disabled')) {
|
|
32
|
+
if (interactionType === 'mouse') await this.user.click(trigger);
|
|
33
|
+
else if (interactionType === 'touch') await this.user.pointer({
|
|
34
|
+
target: trigger,
|
|
35
|
+
keys: '[TouchA]'
|
|
36
|
+
});
|
|
37
|
+
else if (interactionType === 'keyboard') {
|
|
38
|
+
(0, $7D3o2$testinglibraryreact.act)(()=>trigger.focus());
|
|
39
|
+
await this.user.keyboard('[Enter]');
|
|
40
|
+
}
|
|
41
|
+
if (this._overlayType === 'popover') {
|
|
42
|
+
await (0, $7D3o2$testinglibraryreact.waitFor)(()=>{
|
|
43
|
+
if (trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on dialog trigger element.');
|
|
44
|
+
else return true;
|
|
45
|
+
});
|
|
46
|
+
let dialogId = trigger.getAttribute('aria-controls');
|
|
47
|
+
await (0, $7D3o2$testinglibraryreact.waitFor)(()=>{
|
|
48
|
+
if (!dialogId || document.getElementById(dialogId) == null) throw new Error(`Dialog with id of ${dialogId} not found in document.`);
|
|
49
|
+
else {
|
|
50
|
+
this._dialog = document.getElementById(dialogId);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
let dialog;
|
|
56
|
+
await (0, $7D3o2$testinglibraryreact.waitFor)(()=>{
|
|
57
|
+
dialog = document.querySelector('[role=dialog], [role=alertdialog]');
|
|
58
|
+
if (dialog == null) throw new Error('No dialog of type role="dialog" or role="alertdialog" found after pressing the trigger.');
|
|
59
|
+
else return true;
|
|
60
|
+
});
|
|
61
|
+
if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) this._dialog = dialog;
|
|
62
|
+
else throw new Error('New modal dialog doesnt contain the active element OR the active element is still the trigger. Uncertain if the proper modal dialog was found');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Closes the dialog via the Escape key.
|
|
68
|
+
*/ async close() {
|
|
69
|
+
let dialog = this._dialog;
|
|
70
|
+
if (dialog) {
|
|
71
|
+
await this.user.keyboard('[Escape]');
|
|
72
|
+
await (0, $7D3o2$testinglibraryreact.waitFor)(()=>{
|
|
73
|
+
if (document.contains(dialog)) throw new Error('Expected the dialog to not be in the document after closing it.');
|
|
74
|
+
else {
|
|
75
|
+
this._dialog = undefined;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the dialog's trigger.
|
|
83
|
+
*/ get trigger() {
|
|
84
|
+
if (!this._trigger) throw new Error('No trigger element found for dialog.');
|
|
85
|
+
return this._trigger;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns the dialog if present.
|
|
89
|
+
*/ get dialog() {
|
|
90
|
+
return this._dialog && document.contains(this._dialog) ? this._dialog : null;
|
|
91
|
+
}
|
|
92
|
+
constructor(opts){
|
|
93
|
+
let { root: root, user: user, interactionType: interactionType, overlayType: overlayType } = opts;
|
|
94
|
+
this.user = user;
|
|
95
|
+
this._interactionType = interactionType || 'mouse';
|
|
96
|
+
this._overlayType = overlayType || 'modal';
|
|
97
|
+
// Handle case where element provided is a wrapper of the trigger button
|
|
98
|
+
let trigger = (0, $7D3o2$testinglibraryreact.within)(root).queryByRole('button');
|
|
99
|
+
if (trigger) this._trigger = trigger;
|
|
100
|
+
else this._trigger = root;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=dialog.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAYM,MAAM;IAsBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1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qBAEf,MAAM,IAAI,MAAM;YAEpB;QACF;IACF;IAEA;;GAEC,GACD,MAAM,QAAuB;QAC3B,IAAI,SAAS,IAAI,CAAC,OAAO;QACzB,IAAI,QAAQ;YACV,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YACzB,MAAM,CAAA,GAAA,kCAAM,EAAE;gBACZ,IAAI,SAAS,QAAQ,CAAC,SACpB,MAAM,IAAI,MAAM;qBACX;oBACL,IAAI,CAAC,OAAO,GAAG;oBACf,OAAO;gBACT;YACF;QACF;IACF;IAEA;;GAEC,GACD,IAAI,UAAuB;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAChB,MAAM,IAAI,MAAM;QAGlB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA;;GAEC,GACD,IAAI,SAA6B;QAC/B,OAAO,IAAI,CAAC,OAAO,IAAI,SAAS,QAAQ,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG;IAC1E;IAhHA,YAAY,IAAsB,CAAE;QAClC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,eAAE,WAAW,EAAC,GAAG;QACjD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,YAAY,GAAG,eAAe;QAEnC,wEAAwE;QACxE,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,WAAW,CAAC;QACvC,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;aAEhB,IAAI,CAAC,QAAQ,GAAG;IAEpB;AAoGF","sources":["packages/@react-aria/test-utils/src/dialog.ts"],"sourcesContent":["/*\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {DialogTesterOpts, UserOpts} from './types';\n\ninterface DialogOpenOpts {\n /**\n * What interaction type to use when opening the dialog. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\nexport class DialogTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement | undefined;\n private _dialog: HTMLElement | undefined;\n private _overlayType: DialogTesterOpts['overlayType'];\n\n constructor(opts: DialogTesterOpts) {\n let {root, user, interactionType, overlayType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._overlayType = overlayType || 'modal';\n\n // Handle case where element provided is a wrapper of the trigger button\n let trigger = within(root).queryByRole('button');\n if (trigger) {\n this._trigger = trigger;\n } else {\n this._trigger = root;\n }\n }\n\n /**\n * Set the interaction type used by the dialog tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the dialog. Defaults to using the interaction type set on the dialog tester.\n */\n async open(opts: DialogOpenOpts = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n if (!trigger.hasAttribute('disabled')) {\n if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n\n if (this._overlayType === 'popover') {\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on dialog trigger element.');\n } else {\n return true;\n }\n });\n\n let dialogId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!dialogId || document.getElementById(dialogId) == null) {\n throw new Error(`Dialog with id of ${dialogId} not found in document.`);\n } else {\n this._dialog = document.getElementById(dialogId)!;\n return true;\n }\n });\n } else {\n let dialog;\n await waitFor(() => {\n dialog = document.querySelector('[role=dialog], [role=alertdialog]');\n if (dialog == null) {\n throw new Error('No dialog of type role=\"dialog\" or role=\"alertdialog\" found after pressing the trigger.');\n } else {\n return true;\n }\n });\n\n if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) {\n this._dialog = dialog;\n } else {\n throw new Error('New modal dialog doesnt contain the active element OR the active element is still the trigger. Uncertain if the proper modal dialog was found');\n }\n }\n }\n }\n\n /**\n * Closes the dialog via the Escape key.\n */\n async close(): Promise<void> {\n let dialog = this._dialog;\n if (dialog) {\n await this.user.keyboard('[Escape]');\n await waitFor(() => {\n if (document.contains(dialog)) {\n throw new Error('Expected the dialog to not be in the document after closing it.');\n } else {\n this._dialog = undefined;\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the dialog's trigger.\n */\n get trigger(): HTMLElement {\n if (!this._trigger) {\n throw new Error('No trigger element found for dialog.');\n }\n\n return this._trigger;\n }\n\n /**\n * Returns the dialog if present.\n */\n get dialog(): HTMLElement | null {\n return this._dialog && document.contains(this._dialog) ? this._dialog : null;\n }\n}\n"],"names":[],"version":3,"file":"dialog.main.js.map"}
|
package/dist/dialog.mjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {act as $ikD9Y$act, waitFor as $ikD9Y$waitFor, within as $ikD9Y$within} from "@testing-library/react";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
class $5bce5d4037467b58$export$e79328f5295cc2a1 {
|
|
15
|
+
/**
|
|
16
|
+
* Set the interaction type used by the dialog tester.
|
|
17
|
+
*/ setInteractionType(type) {
|
|
18
|
+
this._interactionType = type;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Opens the dialog. Defaults to using the interaction type set on the dialog tester.
|
|
22
|
+
*/ async open(opts = {}) {
|
|
23
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
24
|
+
let trigger = this.trigger;
|
|
25
|
+
if (!trigger.hasAttribute('disabled')) {
|
|
26
|
+
if (interactionType === 'mouse') await this.user.click(trigger);
|
|
27
|
+
else if (interactionType === 'touch') await this.user.pointer({
|
|
28
|
+
target: trigger,
|
|
29
|
+
keys: '[TouchA]'
|
|
30
|
+
});
|
|
31
|
+
else if (interactionType === 'keyboard') {
|
|
32
|
+
(0, $ikD9Y$act)(()=>trigger.focus());
|
|
33
|
+
await this.user.keyboard('[Enter]');
|
|
34
|
+
}
|
|
35
|
+
if (this._overlayType === 'popover') {
|
|
36
|
+
await (0, $ikD9Y$waitFor)(()=>{
|
|
37
|
+
if (trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on dialog trigger element.');
|
|
38
|
+
else return true;
|
|
39
|
+
});
|
|
40
|
+
let dialogId = trigger.getAttribute('aria-controls');
|
|
41
|
+
await (0, $ikD9Y$waitFor)(()=>{
|
|
42
|
+
if (!dialogId || document.getElementById(dialogId) == null) throw new Error(`Dialog with id of ${dialogId} not found in document.`);
|
|
43
|
+
else {
|
|
44
|
+
this._dialog = document.getElementById(dialogId);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
let dialog;
|
|
50
|
+
await (0, $ikD9Y$waitFor)(()=>{
|
|
51
|
+
dialog = document.querySelector('[role=dialog], [role=alertdialog]');
|
|
52
|
+
if (dialog == null) throw new Error('No dialog of type role="dialog" or role="alertdialog" found after pressing the trigger.');
|
|
53
|
+
else return true;
|
|
54
|
+
});
|
|
55
|
+
if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) this._dialog = dialog;
|
|
56
|
+
else throw new Error('New modal dialog doesnt contain the active element OR the active element is still the trigger. Uncertain if the proper modal dialog was found');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Closes the dialog via the Escape key.
|
|
62
|
+
*/ async close() {
|
|
63
|
+
let dialog = this._dialog;
|
|
64
|
+
if (dialog) {
|
|
65
|
+
await this.user.keyboard('[Escape]');
|
|
66
|
+
await (0, $ikD9Y$waitFor)(()=>{
|
|
67
|
+
if (document.contains(dialog)) throw new Error('Expected the dialog to not be in the document after closing it.');
|
|
68
|
+
else {
|
|
69
|
+
this._dialog = undefined;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns the dialog's trigger.
|
|
77
|
+
*/ get trigger() {
|
|
78
|
+
if (!this._trigger) throw new Error('No trigger element found for dialog.');
|
|
79
|
+
return this._trigger;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the dialog if present.
|
|
83
|
+
*/ get dialog() {
|
|
84
|
+
return this._dialog && document.contains(this._dialog) ? this._dialog : null;
|
|
85
|
+
}
|
|
86
|
+
constructor(opts){
|
|
87
|
+
let { root: root, user: user, interactionType: interactionType, overlayType: overlayType } = opts;
|
|
88
|
+
this.user = user;
|
|
89
|
+
this._interactionType = interactionType || 'mouse';
|
|
90
|
+
this._overlayType = overlayType || 'modal';
|
|
91
|
+
// Handle case where element provided is a wrapper of the trigger button
|
|
92
|
+
let trigger = (0, $ikD9Y$within)(root).queryByRole('button');
|
|
93
|
+
if (trigger) this._trigger = trigger;
|
|
94
|
+
else this._trigger = root;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
export {$5bce5d4037467b58$export$e79328f5295cc2a1 as DialogTester};
|
|
100
|
+
//# sourceMappingURL=dialog.module.js.map
|