@react-aria/test-utils 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +5 -5
- package/dist/main.js +9 -9
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -5
- package/dist/module.js.map +1 -1
- package/dist/private/checkboxgroup.cjs +104 -0
- package/dist/private/checkboxgroup.cjs.map +1 -0
- package/dist/private/checkboxgroup.js +99 -0
- package/dist/private/checkboxgroup.js.map +1 -0
- package/dist/{combobox.main.js → private/combobox.cjs} +35 -35
- package/dist/private/combobox.cjs.map +1 -0
- package/dist/{combobox.mjs → private/combobox.js} +35 -35
- package/dist/private/combobox.js.map +1 -0
- package/dist/private/dialog.cjs +105 -0
- package/dist/private/dialog.cjs.map +1 -0
- package/dist/private/dialog.js +100 -0
- package/dist/private/dialog.js.map +1 -0
- package/dist/{events.main.js → private/events.cjs} +32 -34
- package/dist/private/events.cjs.map +1 -0
- package/dist/{events.mjs → private/events.js} +29 -31
- package/dist/private/events.js.map +1 -0
- package/dist/{gridlist.main.js → private/gridlist.cjs} +27 -28
- package/dist/private/gridlist.cjs.map +1 -0
- package/dist/{gridlist.mjs → private/gridlist.js} +27 -28
- package/dist/private/gridlist.js.map +1 -0
- package/dist/{listbox.main.js → private/listbox.cjs} +24 -24
- package/dist/private/listbox.cjs.map +1 -0
- package/dist/{listbox.mjs → private/listbox.js} +24 -24
- package/dist/private/listbox.js.map +1 -0
- package/dist/{menu.main.js → private/menu.cjs} +46 -48
- package/dist/private/menu.cjs.map +1 -0
- package/dist/{menu.mjs → private/menu.js} +46 -48
- package/dist/private/menu.js.map +1 -0
- package/dist/private/radiogroup.cjs +120 -0
- package/dist/private/radiogroup.cjs.map +1 -0
- package/dist/private/radiogroup.js +115 -0
- package/dist/private/radiogroup.js.map +1 -0
- package/dist/{select.main.js → private/select.cjs} +31 -29
- package/dist/private/select.cjs.map +1 -0
- package/dist/{select.mjs → private/select.js} +31 -29
- package/dist/private/select.js.map +1 -0
- package/dist/{table.main.js → private/table.cjs} +82 -57
- package/dist/private/table.cjs.map +1 -0
- package/dist/{table.module.js → private/table.js} +82 -57
- package/dist/private/table.js.map +1 -0
- package/dist/{tabs.main.js → private/tabs.cjs} +24 -26
- package/dist/private/tabs.cjs.map +1 -0
- package/dist/{tabs.mjs → private/tabs.js} +24 -26
- package/dist/private/tabs.js.map +1 -0
- package/dist/private/testSetup.cjs +87 -0
- package/dist/private/testSetup.cjs.map +1 -0
- package/dist/private/testSetup.js +81 -0
- package/dist/private/testSetup.js.map +1 -0
- package/dist/{tree.main.js → private/tree.cjs} +34 -35
- package/dist/private/tree.cjs.map +1 -0
- package/dist/{tree.mjs → private/tree.js} +34 -35
- package/dist/private/tree.js.map +1 -0
- package/dist/private/user.cjs +85 -0
- package/dist/private/user.cjs.map +1 -0
- package/dist/private/user.js +76 -0
- package/dist/private/user.js.map +1 -0
- package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
- package/dist/{userEventMaps.main.js.map → private/userEventMaps.cjs.map} +1 -1
- package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
- package/dist/{userEventMaps.module.js.map → private/userEventMaps.js.map} +1 -1
- package/dist/types/src/checkboxgroup.d.ts +45 -0
- package/dist/types/src/combobox.d.ts +75 -0
- package/dist/types/src/dialog.d.ts +36 -0
- package/dist/types/src/events.d.ts +25 -0
- package/dist/types/src/gridlist.d.ts +51 -0
- package/dist/types/src/index.d.ts +16 -0
- package/dist/types/src/listbox.d.ts +80 -0
- package/dist/types/src/menu.d.ts +102 -0
- package/dist/types/src/radiogroup.d.ts +46 -0
- package/dist/types/src/select.d.ts +67 -0
- package/dist/types/src/table.d.ts +104 -0
- package/dist/types/src/tabs.d.ts +58 -0
- package/dist/types/src/testSetup.d.ts +6 -0
- package/dist/types/src/tree.d.ts +57 -0
- package/dist/types/src/types.d.ts +136 -0
- package/dist/types/src/user.d.ts +47 -0
- package/dist/types/src/userEventMaps.d.ts +2 -0
- package/package.json +7 -7
- package/src/checkboxgroup.ts +158 -0
- package/src/dialog.ts +143 -0
- package/src/index.ts +11 -0
- package/src/radiogroup.ts +176 -0
- package/src/select.ts +10 -2
- package/src/table.ts +46 -1
- package/src/tabs.ts +7 -2
- package/src/testSetup.ts +30 -28
- package/src/types.ts +21 -0
- package/src/user.ts +25 -7
- package/dist/combobox.main.js.map +0 -1
- package/dist/combobox.module.js +0 -167
- package/dist/combobox.module.js.map +0 -1
- package/dist/events.main.js.map +0 -1
- package/dist/events.module.js +0 -112
- package/dist/events.module.js.map +0 -1
- package/dist/gridlist.main.js.map +0 -1
- package/dist/gridlist.module.js +0 -149
- package/dist/gridlist.module.js.map +0 -1
- package/dist/listbox.main.js.map +0 -1
- package/dist/listbox.module.js +0 -138
- package/dist/listbox.module.js.map +0 -1
- package/dist/menu.main.js.map +0 -1
- package/dist/menu.module.js +0 -269
- package/dist/menu.module.js.map +0 -1
- package/dist/select.main.js.map +0 -1
- package/dist/select.module.js +0 -158
- package/dist/select.module.js.map +0 -1
- package/dist/table.main.js.map +0 -1
- package/dist/table.mjs +0 -290
- package/dist/table.module.js.map +0 -1
- package/dist/tabs.main.js.map +0 -1
- package/dist/tabs.module.js +0 -128
- package/dist/tabs.module.js.map +0 -1
- package/dist/testSetup.main.js +0 -78
- package/dist/testSetup.main.js.map +0 -1
- package/dist/testSetup.mjs +0 -72
- package/dist/testSetup.module.js +0 -72
- package/dist/testSetup.module.js.map +0 -1
- package/dist/tree.main.js.map +0 -1
- package/dist/tree.module.js +0 -179
- package/dist/tree.module.js.map +0 -1
- package/dist/types.d.ts +0 -694
- package/dist/types.d.ts.map +0 -1
- package/dist/user.main.js +0 -76
- package/dist/user.main.js.map +0 -1
- package/dist/user.mjs +0 -67
- package/dist/user.module.js +0 -67
- package/dist/user.module.js.map +0 -1
- package/dist/userEventMaps.module.js +0 -38
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {within as $d5vWN$within, act as $d5vWN$act, waitFor as $d5vWN$waitFor} from "@testing-library/react";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2024 Adobe. All rights reserved.
|
|
@@ -11,7 +11,29 @@ import {act as $1n52X$act, waitFor as $1n52X$waitFor, within as $1n52X$within} f
|
|
|
11
11
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
|
-
class $
|
|
14
|
+
class $a2202d8b369e6a8a$export$f97e14e96d71ab3b {
|
|
15
|
+
constructor(opts){
|
|
16
|
+
let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
|
|
17
|
+
this.user = user;
|
|
18
|
+
this._interactionType = interactionType || 'mouse';
|
|
19
|
+
// Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to
|
|
20
|
+
// query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
|
|
21
|
+
this._combobox = root;
|
|
22
|
+
let combobox = (0, $d5vWN$within)(root).queryByRole('combobox');
|
|
23
|
+
if (combobox) this._combobox = combobox;
|
|
24
|
+
// This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)
|
|
25
|
+
if (trigger) this._trigger = trigger;
|
|
26
|
+
else {
|
|
27
|
+
let buttons = (0, $d5vWN$within)(root).queryAllByRole('button', {
|
|
28
|
+
hidden: true
|
|
29
|
+
});
|
|
30
|
+
if (buttons.length === 1) trigger = buttons[0];
|
|
31
|
+
else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
32
|
+
// For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
|
|
33
|
+
// is also the trigger button
|
|
34
|
+
this._trigger = trigger || this._combobox;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
15
37
|
/**
|
|
16
38
|
* Set the interaction type used by the combobox tester.
|
|
17
39
|
*/ setInteractionType(type) {
|
|
@@ -28,7 +50,7 @@ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
|
|
|
28
50
|
if (triggerBehavior === 'focus') await this.user.click(combobox);
|
|
29
51
|
else await this.user.click(trigger);
|
|
30
52
|
} else if (interactionType === 'keyboard' && this._trigger != null) {
|
|
31
|
-
(0, $
|
|
53
|
+
(0, $d5vWN$act)(()=>this._trigger.focus());
|
|
32
54
|
if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
|
|
33
55
|
} else if (interactionType === 'touch') {
|
|
34
56
|
if (triggerBehavior === 'focus') await this.user.pointer({
|
|
@@ -40,12 +62,12 @@ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
|
|
|
40
62
|
keys: '[TouchA]'
|
|
41
63
|
});
|
|
42
64
|
}
|
|
43
|
-
await (0, $
|
|
65
|
+
await (0, $d5vWN$waitFor)(()=>{
|
|
44
66
|
if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
|
|
45
67
|
else return true;
|
|
46
68
|
});
|
|
47
69
|
let listBoxId = combobox.getAttribute('aria-controls');
|
|
48
|
-
await (0, $
|
|
70
|
+
await (0, $d5vWN$waitFor)(()=>{
|
|
49
71
|
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
|
|
50
72
|
else return true;
|
|
51
73
|
});
|
|
@@ -58,7 +80,7 @@ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
|
|
|
58
80
|
let options = this.options();
|
|
59
81
|
let listbox = this.listbox;
|
|
60
82
|
if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
|
|
61
|
-
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $
|
|
83
|
+
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $d5vWN$within)(listbox).getByText(optionIndexOrText).closest('[role=option]');
|
|
62
84
|
return option;
|
|
63
85
|
}
|
|
64
86
|
/**
|
|
@@ -83,7 +105,7 @@ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
|
|
|
83
105
|
target: option,
|
|
84
106
|
keys: '[TouchA]'
|
|
85
107
|
});
|
|
86
|
-
if (option.getAttribute('href') == null) await (0, $
|
|
108
|
+
if (option.getAttribute('href') == null) await (0, $d5vWN$waitFor)(()=>{
|
|
87
109
|
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
88
110
|
else return true;
|
|
89
111
|
});
|
|
@@ -94,9 +116,9 @@ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
|
|
|
94
116
|
*/ async close() {
|
|
95
117
|
let listbox = this.listbox;
|
|
96
118
|
if (listbox) {
|
|
97
|
-
(0, $
|
|
119
|
+
(0, $d5vWN$act)(()=>this.combobox.focus());
|
|
98
120
|
await this.user.keyboard('[Escape]');
|
|
99
|
-
await (0, $
|
|
121
|
+
await (0, $d5vWN$waitFor)(()=>{
|
|
100
122
|
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
101
123
|
else return true;
|
|
102
124
|
});
|
|
@@ -122,14 +144,14 @@ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
|
|
|
122
144
|
* Returns the combobox's sections if present.
|
|
123
145
|
*/ get sections() {
|
|
124
146
|
let listbox = this.listbox;
|
|
125
|
-
return listbox ? (0, $
|
|
147
|
+
return listbox ? (0, $d5vWN$within)(listbox).queryAllByRole('group') : [];
|
|
126
148
|
}
|
|
127
149
|
/**
|
|
128
150
|
* Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.
|
|
129
151
|
*/ options(opts = {}) {
|
|
130
152
|
let { element: element = this.listbox } = opts;
|
|
131
153
|
let options = [];
|
|
132
|
-
if (element) options = (0, $
|
|
154
|
+
if (element) options = (0, $d5vWN$within)(element).queryAllByRole('option');
|
|
133
155
|
return options;
|
|
134
156
|
}
|
|
135
157
|
/**
|
|
@@ -138,30 +160,8 @@ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
|
|
|
138
160
|
let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');
|
|
139
161
|
return focusedOptionId ? document.getElementById(focusedOptionId) : null;
|
|
140
162
|
}
|
|
141
|
-
constructor(opts){
|
|
142
|
-
let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
|
|
143
|
-
this.user = user;
|
|
144
|
-
this._interactionType = interactionType || 'mouse';
|
|
145
|
-
// Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to
|
|
146
|
-
// query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
|
|
147
|
-
this._combobox = root;
|
|
148
|
-
let combobox = (0, $1n52X$within)(root).queryByRole('combobox');
|
|
149
|
-
if (combobox) this._combobox = combobox;
|
|
150
|
-
// This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)
|
|
151
|
-
if (trigger) this._trigger = trigger;
|
|
152
|
-
else {
|
|
153
|
-
let buttons = (0, $1n52X$within)(root).queryAllByRole('button', {
|
|
154
|
-
hidden: true
|
|
155
|
-
});
|
|
156
|
-
if (buttons.length === 1) trigger = buttons[0];
|
|
157
|
-
else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
158
|
-
// For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
|
|
159
|
-
// is also the trigger button
|
|
160
|
-
this._trigger = trigger || this._combobox;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
|
|
166
|
-
export {$
|
|
167
|
-
//# sourceMappingURL=combobox.
|
|
166
|
+
export {$a2202d8b369e6a8a$export$f97e14e96d71ab3b as ComboBoxTester};
|
|
167
|
+
//# sourceMappingURL=combobox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IA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,UAA8B;QAChC,IAAI,YAAY,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QAC3C,OAAO,YAAY,SAAS,cAAc,CAAC,cAAc,OAAO;IAClE;IAEA;;GAEC,GACD,IAAI,WAA0B;QAC5B,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC,WAAW,EAAE;IAC/D;IAEA;;GAEC,GACD,QAAQ,OAAgC,CAAC,CAAC,EAAiB;QACzD,IAAI,WAAC,UAAU,IAAI,CAAC,OAAO,EAAC,GAAG;QAC/B,IAAI,UAAU,EAAE;QAChB,IAAI,SACF,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;QAG3C,OAAO;IACT;IAEA;;GAEC,GACD,IAAI,gBAAoC;QACtC,IAAI,kBAAkB,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QACjD,OAAO,kBAAkB,SAAS,cAAc,CAAC,mBAAmB;IACtE;AACF","sources":["packages/@react-aria/test-utils/src/combobox.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {ComboBoxTesterOpts, UserOpts} from './types';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\n * @default 'manual'\n */\n triggerBehavior?: 'focus' | 'manual',\n /**\n * What interaction type to use when opening the combobox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface ComboBoxSelectOpts extends ComboBoxOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement;\n\n constructor(opts: ComboBoxTesterOpts) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let buttons = within(root).queryAllByRole('button', {hidden: true});\n\n if (buttons.length === 1) {\n trigger = buttons[0];\n } else if (buttons.length > 1) {\n trigger = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = trigger || this._combobox;\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.\n */\n async open(opts: ComboBoxOpenOpts = {}): Promise<void> {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard' && this._trigger != null) {\n act(() => this._trigger!.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`Listbox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Returns an option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let listbox = this.listbox;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && listbox != null) {\n option = (within(listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n /**\n * Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: ComboBoxSelectOpts): Promise<void> {\n let {option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Combobox\\'s listbox not found.');\n }\n\n if (listbox) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n get combobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n\n /**\n * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.listbox} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the currently focused option in the combobox's dropdown if any.\n */\n get focusedOption(): HTMLElement | null {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.js.map"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var $4WTiJ$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", function () { return $cde1dbf8bdfa11d9$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 $cde1dbf8bdfa11d9$export$e79328f5295cc2a1 {
|
|
21
|
+
constructor(opts){
|
|
22
|
+
let { root: root, user: user, interactionType: interactionType, overlayType: overlayType } = opts;
|
|
23
|
+
this.user = user;
|
|
24
|
+
this._interactionType = interactionType || 'mouse';
|
|
25
|
+
this._overlayType = overlayType || 'modal';
|
|
26
|
+
// Handle case where element provided is a wrapper of the trigger button
|
|
27
|
+
let trigger = (0, $4WTiJ$testinglibraryreact.within)(root).queryByRole('button');
|
|
28
|
+
if (trigger) this._trigger = trigger;
|
|
29
|
+
else this._trigger = root;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Set the interaction type used by the dialog tester.
|
|
33
|
+
*/ setInteractionType(type) {
|
|
34
|
+
this._interactionType = type;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Opens the dialog. Defaults to using the interaction type set on the dialog tester.
|
|
38
|
+
*/ async open(opts = {}) {
|
|
39
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
40
|
+
let trigger = this.trigger;
|
|
41
|
+
if (!trigger.hasAttribute('disabled')) {
|
|
42
|
+
if (interactionType === 'mouse') await this.user.click(trigger);
|
|
43
|
+
else if (interactionType === 'touch') await this.user.pointer({
|
|
44
|
+
target: trigger,
|
|
45
|
+
keys: '[TouchA]'
|
|
46
|
+
});
|
|
47
|
+
else if (interactionType === 'keyboard') {
|
|
48
|
+
(0, $4WTiJ$testinglibraryreact.act)(()=>trigger.focus());
|
|
49
|
+
await this.user.keyboard('[Enter]');
|
|
50
|
+
}
|
|
51
|
+
if (this._overlayType === 'popover') {
|
|
52
|
+
await (0, $4WTiJ$testinglibraryreact.waitFor)(()=>{
|
|
53
|
+
if (trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on dialog trigger element.');
|
|
54
|
+
else return true;
|
|
55
|
+
});
|
|
56
|
+
let dialogId = trigger.getAttribute('aria-controls');
|
|
57
|
+
await (0, $4WTiJ$testinglibraryreact.waitFor)(()=>{
|
|
58
|
+
if (!dialogId || document.getElementById(dialogId) == null) throw new Error(`Dialog with id of ${dialogId} not found in document.`);
|
|
59
|
+
else {
|
|
60
|
+
this._dialog = document.getElementById(dialogId);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
let dialog;
|
|
66
|
+
await (0, $4WTiJ$testinglibraryreact.waitFor)(()=>{
|
|
67
|
+
dialog = document.querySelector('[role=dialog], [role=alertdialog]');
|
|
68
|
+
if (dialog == null) throw new Error('No dialog of type role="dialog" or role="alertdialog" found after pressing the trigger.');
|
|
69
|
+
else return true;
|
|
70
|
+
});
|
|
71
|
+
if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) this._dialog = dialog;
|
|
72
|
+
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');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Closes the dialog via the Escape key.
|
|
78
|
+
*/ async close() {
|
|
79
|
+
let dialog = this._dialog;
|
|
80
|
+
if (dialog) {
|
|
81
|
+
await this.user.keyboard('[Escape]');
|
|
82
|
+
await (0, $4WTiJ$testinglibraryreact.waitFor)(()=>{
|
|
83
|
+
if (document.contains(dialog)) throw new Error('Expected the dialog to not be in the document after closing it.');
|
|
84
|
+
else {
|
|
85
|
+
this._dialog = undefined;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the dialog's trigger.
|
|
93
|
+
*/ get trigger() {
|
|
94
|
+
if (!this._trigger) throw new Error('No trigger element found for dialog.');
|
|
95
|
+
return this._trigger;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns the dialog if present.
|
|
99
|
+
*/ get dialog() {
|
|
100
|
+
return this._dialog && document.contains(this._dialog) ? this._dialog : null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=dialog.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAYM,MAAM;IAOX,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;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;QACnD,IAAI,mBACF,kBAAkB,IAA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AS,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;AACF","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.cjs.map"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {within as $Hdzb6$within, act as $Hdzb6$act, waitFor as $Hdzb6$waitFor} 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 $1bad24930969e309$export$e79328f5295cc2a1 {
|
|
15
|
+
constructor(opts){
|
|
16
|
+
let { root: root, user: user, interactionType: interactionType, overlayType: overlayType } = opts;
|
|
17
|
+
this.user = user;
|
|
18
|
+
this._interactionType = interactionType || 'mouse';
|
|
19
|
+
this._overlayType = overlayType || 'modal';
|
|
20
|
+
// Handle case where element provided is a wrapper of the trigger button
|
|
21
|
+
let trigger = (0, $Hdzb6$within)(root).queryByRole('button');
|
|
22
|
+
if (trigger) this._trigger = trigger;
|
|
23
|
+
else this._trigger = root;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Set the interaction type used by the dialog tester.
|
|
27
|
+
*/ setInteractionType(type) {
|
|
28
|
+
this._interactionType = type;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Opens the dialog. Defaults to using the interaction type set on the dialog tester.
|
|
32
|
+
*/ async open(opts = {}) {
|
|
33
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
34
|
+
let trigger = this.trigger;
|
|
35
|
+
if (!trigger.hasAttribute('disabled')) {
|
|
36
|
+
if (interactionType === 'mouse') await this.user.click(trigger);
|
|
37
|
+
else if (interactionType === 'touch') await this.user.pointer({
|
|
38
|
+
target: trigger,
|
|
39
|
+
keys: '[TouchA]'
|
|
40
|
+
});
|
|
41
|
+
else if (interactionType === 'keyboard') {
|
|
42
|
+
(0, $Hdzb6$act)(()=>trigger.focus());
|
|
43
|
+
await this.user.keyboard('[Enter]');
|
|
44
|
+
}
|
|
45
|
+
if (this._overlayType === 'popover') {
|
|
46
|
+
await (0, $Hdzb6$waitFor)(()=>{
|
|
47
|
+
if (trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on dialog trigger element.');
|
|
48
|
+
else return true;
|
|
49
|
+
});
|
|
50
|
+
let dialogId = trigger.getAttribute('aria-controls');
|
|
51
|
+
await (0, $Hdzb6$waitFor)(()=>{
|
|
52
|
+
if (!dialogId || document.getElementById(dialogId) == null) throw new Error(`Dialog with id of ${dialogId} not found in document.`);
|
|
53
|
+
else {
|
|
54
|
+
this._dialog = document.getElementById(dialogId);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
let dialog;
|
|
60
|
+
await (0, $Hdzb6$waitFor)(()=>{
|
|
61
|
+
dialog = document.querySelector('[role=dialog], [role=alertdialog]');
|
|
62
|
+
if (dialog == null) throw new Error('No dialog of type role="dialog" or role="alertdialog" found after pressing the trigger.');
|
|
63
|
+
else return true;
|
|
64
|
+
});
|
|
65
|
+
if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) this._dialog = dialog;
|
|
66
|
+
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');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Closes the dialog via the Escape key.
|
|
72
|
+
*/ async close() {
|
|
73
|
+
let dialog = this._dialog;
|
|
74
|
+
if (dialog) {
|
|
75
|
+
await this.user.keyboard('[Escape]');
|
|
76
|
+
await (0, $Hdzb6$waitFor)(()=>{
|
|
77
|
+
if (document.contains(dialog)) throw new Error('Expected the dialog to not be in the document after closing it.');
|
|
78
|
+
else {
|
|
79
|
+
this._dialog = undefined;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns the dialog's trigger.
|
|
87
|
+
*/ get trigger() {
|
|
88
|
+
if (!this._trigger) throw new Error('No trigger element found for dialog.');
|
|
89
|
+
return this._trigger;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the dialog if present.
|
|
93
|
+
*/ get dialog() {
|
|
94
|
+
return this._dialog && document.contains(this._dialog) ? this._dialog : null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
export {$1bad24930969e309$export$e79328f5295cc2a1 as DialogTester};
|
|
100
|
+
//# sourceMappingURL=dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAYM,MAAM;IAOX,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,aAAK,EAAE,MAAM,WAAW,CAAC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AAI,MAAM;yBAEhB,OAAO;gBAEX;gBAEA,IAAI,UAAU,SAAS,aAAa,KAAK,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,CAAC,SAAS,aAAa,GAC9F,IAAI,CAAC,OAAO,GAAG;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,cAAM,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;AACF","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.js.map"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var $
|
|
1
|
+
var $dJoEb$testinglibraryreact = require("@testing-library/react");
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
function $parcel$export(e, n, v, s) {
|
|
5
5
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
$parcel$export(module.exports, "getAltKey", ()
|
|
9
|
-
$parcel$export(module.exports, "getMetaKey", ()
|
|
10
|
-
$parcel$export(module.exports, "triggerLongPress", ()
|
|
11
|
-
$parcel$export(module.exports, "pressElement", ()
|
|
8
|
+
$parcel$export(module.exports, "getAltKey", function () { return $01a4eeee86094c77$export$6fc0ccaebd758b9d; });
|
|
9
|
+
$parcel$export(module.exports, "getMetaKey", function () { return $01a4eeee86094c77$export$7943c508934e27ce; });
|
|
10
|
+
$parcel$export(module.exports, "triggerLongPress", function () { return $01a4eeee86094c77$export$3a22a5a9bc0fd3b; });
|
|
11
|
+
$parcel$export(module.exports, "pressElement", function () { return $01a4eeee86094c77$export$6ffa3eb717517feb; });
|
|
12
12
|
/*
|
|
13
13
|
* Copyright 2023 Adobe. All rights reserved.
|
|
14
14
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -20,12 +20,11 @@ $parcel$export(module.exports, "pressElement", () => $5a8bfe1663b8366d$export$6f
|
|
|
20
20
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
21
|
* governing permissions and limitations under the License.
|
|
22
22
|
*/
|
|
23
|
-
const $
|
|
24
|
-
function $
|
|
25
|
-
|
|
26
|
-
return typeof window !== 'undefined' && window.navigator != null ? re.test(((_window_navigator_userAgentData = window.navigator['userAgentData']) === null || _window_navigator_userAgentData === void 0 ? void 0 : _window_navigator_userAgentData.platform) || window.navigator.platform) : false;
|
|
23
|
+
const $01a4eeee86094c77$export$4bd1d2d5ba6f5eaf = 500;
|
|
24
|
+
function $01a4eeee86094c77$var$testPlatform(re) {
|
|
25
|
+
return typeof window !== 'undefined' && window.navigator != null ? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform) : false;
|
|
27
26
|
}
|
|
28
|
-
function $
|
|
27
|
+
function $01a4eeee86094c77$var$cached(fn) {
|
|
29
28
|
if (process.env.NODE_ENV === 'test') return fn;
|
|
30
29
|
let res = null;
|
|
31
30
|
return ()=>{
|
|
@@ -33,29 +32,28 @@ function $5a8bfe1663b8366d$var$cached(fn) {
|
|
|
33
32
|
return res;
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
|
-
const $
|
|
37
|
-
return $
|
|
35
|
+
const $01a4eeee86094c77$var$isMac = $01a4eeee86094c77$var$cached(function() {
|
|
36
|
+
return $01a4eeee86094c77$var$testPlatform(/^Mac/i);
|
|
38
37
|
});
|
|
39
|
-
function $
|
|
40
|
-
return $
|
|
38
|
+
function $01a4eeee86094c77$export$6fc0ccaebd758b9d() {
|
|
39
|
+
return $01a4eeee86094c77$var$isMac() ? 'Alt' : 'ControlLeft';
|
|
41
40
|
}
|
|
42
|
-
function $
|
|
43
|
-
return $
|
|
41
|
+
function $01a4eeee86094c77$export$7943c508934e27ce() {
|
|
42
|
+
return $01a4eeee86094c77$var$isMac() ? 'MetaLeft' : 'ControlLeft';
|
|
44
43
|
}
|
|
45
|
-
async function $
|
|
44
|
+
async function $01a4eeee86094c77$export$3a22a5a9bc0fd3b(opts) {
|
|
46
45
|
// TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the
|
|
47
46
|
// render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the
|
|
48
47
|
// util before first render. Will need to document it well
|
|
49
48
|
let { element: element, advanceTimer: advanceTimer, pointerOpts: pointerOpts = {} } = opts;
|
|
50
|
-
|
|
51
|
-
let
|
|
52
|
-
let shouldFireCompatibilityEvents = (0, $jxdbS$testinglibraryreact.fireEvent).pointerDown(element, {
|
|
49
|
+
let pointerType = pointerOpts.pointerType ?? 'mouse';
|
|
50
|
+
let shouldFireCompatibilityEvents = (0, $dJoEb$testinglibraryreact.fireEvent).pointerDown(element, {
|
|
53
51
|
pointerType: pointerType,
|
|
54
52
|
...pointerOpts
|
|
55
53
|
});
|
|
56
54
|
let shouldFocus = true;
|
|
57
55
|
if (shouldFireCompatibilityEvents) {
|
|
58
|
-
if (pointerType === 'touch') shouldFocus = shouldFireCompatibilityEvents = (0, $
|
|
56
|
+
if (pointerType === 'touch') shouldFocus = shouldFireCompatibilityEvents = (0, $dJoEb$testinglibraryreact.fireEvent).touchStart(element, {
|
|
59
57
|
targetTouches: [
|
|
60
58
|
{
|
|
61
59
|
identifier: pointerOpts.pointerId,
|
|
@@ -65,18 +63,18 @@ async function $5a8bfe1663b8366d$export$3a22a5a9bc0fd3b(opts) {
|
|
|
65
63
|
]
|
|
66
64
|
});
|
|
67
65
|
else if (pointerType === 'mouse') {
|
|
68
|
-
shouldFocus = (0, $
|
|
69
|
-
if (shouldFocus) (0, $
|
|
66
|
+
shouldFocus = (0, $dJoEb$testinglibraryreact.fireEvent).mouseDown(element, pointerOpts);
|
|
67
|
+
if (shouldFocus) (0, $dJoEb$testinglibraryreact.act)(()=>element.focus());
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
|
-
await (0, $
|
|
73
|
-
(0, $
|
|
70
|
+
await (0, $dJoEb$testinglibraryreact.act)(async ()=>await advanceTimer($01a4eeee86094c77$export$4bd1d2d5ba6f5eaf));
|
|
71
|
+
(0, $dJoEb$testinglibraryreact.fireEvent).pointerUp(element, {
|
|
74
72
|
pointerType: pointerType,
|
|
75
73
|
...pointerOpts
|
|
76
74
|
});
|
|
77
75
|
if (shouldFireCompatibilityEvents) {
|
|
78
76
|
if (pointerType === 'touch') {
|
|
79
|
-
shouldFocus = (0, $
|
|
77
|
+
shouldFocus = (0, $dJoEb$testinglibraryreact.fireEvent).touchEnd(element, {
|
|
80
78
|
targetTouches: [
|
|
81
79
|
{
|
|
82
80
|
identifier: pointerOpts.pointerId,
|
|
@@ -85,17 +83,17 @@ async function $5a8bfe1663b8366d$export$3a22a5a9bc0fd3b(opts) {
|
|
|
85
83
|
}
|
|
86
84
|
]
|
|
87
85
|
});
|
|
88
|
-
shouldFocus = (0, $
|
|
89
|
-
if (shouldFocus) (0, $
|
|
90
|
-
(0, $
|
|
91
|
-
} else if (pointerType === 'mouse') (0, $
|
|
86
|
+
shouldFocus = (0, $dJoEb$testinglibraryreact.fireEvent).mouseDown(element, pointerOpts);
|
|
87
|
+
if (shouldFocus) (0, $dJoEb$testinglibraryreact.act)(()=>element.focus());
|
|
88
|
+
(0, $dJoEb$testinglibraryreact.fireEvent).mouseUp(element, pointerOpts);
|
|
89
|
+
} else if (pointerType === 'mouse') (0, $dJoEb$testinglibraryreact.fireEvent).mouseUp(element, pointerOpts);
|
|
92
90
|
}
|
|
93
|
-
(0, $
|
|
91
|
+
(0, $dJoEb$testinglibraryreact.fireEvent).click(element, {
|
|
94
92
|
detail: 1,
|
|
95
93
|
...pointerOpts
|
|
96
94
|
});
|
|
97
95
|
}
|
|
98
|
-
async function $
|
|
96
|
+
async function $01a4eeee86094c77$export$6ffa3eb717517feb(user, element, interactionType) {
|
|
99
97
|
if (interactionType === 'mouse') // Add coords with pressure so this isn't detected as a virtual click
|
|
100
98
|
await user.pointer({
|
|
101
99
|
target: element,
|
|
@@ -108,7 +106,7 @@ async function $5a8bfe1663b8366d$export$6ffa3eb717517feb(user, element, interact
|
|
|
108
106
|
// TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should
|
|
109
107
|
// stick to simulting an actual user's keyboard operations as closely as possible
|
|
110
108
|
// There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.
|
|
111
|
-
(0, $
|
|
109
|
+
(0, $dJoEb$testinglibraryreact.act)(()=>element.focus());
|
|
112
110
|
await user.keyboard('[Space]');
|
|
113
111
|
} else if (interactionType === 'touch') await user.pointer({
|
|
114
112
|
target: element,
|
|
@@ -117,4 +115,4 @@ async function $5a8bfe1663b8366d$export$6ffa3eb717517feb(user, element, interact
|
|
|
117
115
|
}
|
|
118
116
|
|
|
119
117
|
|
|
120
|
-
//# sourceMappingURL=events.
|
|
118
|
+
//# sourceMappingURL=events.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AACvC,SAAS,mCAAa,EAAU;IAC9B,OAAO,OAAO,WAAW,eAAe,OAAO,SAAS,IAAI,OACxD,GAAG,IAAI,CAAC,OAAO,SAAS,CAAC,gBAAgB,EAAE,YAAY,OAAO,SAAS,CAAC,QAAQ,IAChF;AACN;AAEA,SAAS,6BAAO,EAAiB;IAC/B,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAC3B,OAAO;IAGT,IAAI,MAAsB;IAC1B,OAAO;QACL,IAAI,OAAO,MACT,MAAM;QAER,OAAO;IACT;AACF;AAEA,MAAM,8BAAQ,6BAAO;IACnB,OAAO,mCAAa;AACtB;AAEO,SAAS;IACd,OAAO,gCAAU,QAAQ;AAC3B;AAEO,SAAS;IACd,OAAO,gCAAU,aAAa;AAChC;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,CAAA,GAAA,oCAAQ,EAAE,OAAO,CAAC,SAAS;IAE/B;IACA,CAAA,GAAA,oCAAQ,EAAE,KAAK,CAAC,SAAS;QAAC,QAAQ;QAAG,GAAG,WAAW;IAAA;AACrD;AAGO,eAAe,0CAAa,IAA8K,EAAE,OAAoB,EAAE,eAA4C;IACnR,IAAI,oBAAoB,SACtB,qEAAqE;IACrE,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;QAAe,QAAQ;YAAC,UAAU;QAAE;IAAC;SAC3E,IAAI,oBAAoB,YAAY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,KAAK;QACvB,MAAM,KAAK,QAAQ,CAAC;IACtB,OAAO,IAAI,oBAAoB,SAC7B,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;IAAU;AAEzD","sources":["packages/@react-aria/test-utils/src/events.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\nimport {act, fireEvent} from '@testing-library/react';\nimport {UserOpts} from './types';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\nfunction testPlatform(re: RegExp) {\n return typeof window !== 'undefined' && window.navigator != null\n ? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform)\n : false;\n}\n\nfunction cached(fn: () => boolean) {\n if (process.env.NODE_ENV === 'test') {\n return fn;\n }\n\n let res: boolean | null = null;\n return () => {\n if (res == null) {\n res = fn();\n }\n return res;\n };\n}\n\nconst isMac = cached(function () {\n return testPlatform(/^Mac/i);\n});\n\nexport function getAltKey(): 'Alt' | 'ControlLeft' {\n return isMac() ? 'Alt' : 'ControlLeft';\n}\n\nexport function getMetaKey(): 'MetaLeft' | 'ControlLeft' {\n return isMac() ? 'MetaLeft' : 'ControlLeft';\n}\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param opts - Options for the long press.\n * @param opts.element - Element to long press.\n * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).\n * @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.\n */\nexport async function triggerLongPress(opts: {element: HTMLElement, advanceTimer: (time: number) => unknown | Promise<unknown>, pointerOpts?: Record<string, any>}): Promise<void> {\n // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the\n // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the\n // util before first render. Will need to document it well\n let {element, advanceTimer, pointerOpts = {}} = opts;\n let pointerType = pointerOpts.pointerType ?? 'mouse';\n let shouldFireCompatibilityEvents = fireEvent.pointerDown(element, {pointerType, ...pointerOpts});\n let shouldFocus = true;\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = shouldFireCompatibilityEvents = fireEvent.touchStart(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n } else if (pointerType === 'mouse') {\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n }\n }\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n fireEvent.pointerUp(element, {pointerType, ...pointerOpts});\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = fireEvent.touchEnd(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n fireEvent.mouseUp(element, pointerOpts);\n } else if (pointerType === 'mouse') {\n fireEvent.mouseUp(element, pointerOpts);\n }\n }\n fireEvent.click(element, {detail: 1, ...pointerOpts});\n}\n\n// Docs cannot handle the types that userEvent actually declares, so hopefully this sub set is okay\nexport async function pressElement(user: {click: (element: Element) => Promise<void>, keyboard: (keys: string) => Promise<void>, pointer: (opts: {target: Element, keys: string, coords?: any}) => Promise<void>}, element: HTMLElement, interactionType: UserOpts['interactionType']): Promise<void> {\n if (interactionType === 'mouse') {\n // Add coords with pressure so this isn't detected as a virtual click\n await user.pointer({target: element, keys: '[MouseLeft]', coords: {pressure: .5}});\n } else if (interactionType === 'keyboard') {\n // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should\n // stick to simulting an actual user's keyboard operations as closely as possible\n // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.\n act(() => element.focus());\n await user.keyboard('[Space]');\n } else if (interactionType === 'touch') {\n await user.pointer({target: element, keys: '[TouchA]'});\n }\n}\n"],"names":[],"version":3,"file":"events.cjs.map"}
|