@react-aria/test-utils 1.0.0-alpha.3 → 1.0.0-alpha.4
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/combobox.main.js +116 -82
- package/dist/combobox.main.js.map +1 -1
- package/dist/combobox.mjs +117 -83
- package/dist/combobox.module.js +117 -83
- package/dist/combobox.module.js.map +1 -1
- package/dist/events.main.js.map +1 -1
- package/dist/events.module.js.map +1 -1
- package/dist/gridlist.main.js +102 -59
- package/dist/gridlist.main.js.map +1 -1
- package/dist/gridlist.mjs +103 -60
- package/dist/gridlist.module.js +103 -60
- package/dist/gridlist.module.js.map +1 -1
- package/dist/listbox.main.js +135 -0
- package/dist/listbox.main.js.map +1 -0
- package/dist/listbox.mjs +130 -0
- package/dist/listbox.module.js +130 -0
- package/dist/listbox.module.js.map +1 -0
- package/dist/main.js.map +1 -1
- package/dist/menu.main.js +195 -161
- package/dist/menu.main.js.map +1 -1
- package/dist/menu.mjs +196 -162
- package/dist/menu.module.js +196 -162
- package/dist/menu.module.js.map +1 -1
- package/dist/module.js.map +1 -1
- package/dist/select.main.js +116 -70
- package/dist/select.main.js.map +1 -1
- package/dist/select.mjs +117 -71
- package/dist/select.module.js +117 -71
- package/dist/select.module.js.map +1 -1
- package/dist/table.main.js +170 -139
- package/dist/table.main.js.map +1 -1
- package/dist/table.mjs +171 -140
- package/dist/table.module.js +171 -140
- package/dist/table.module.js.map +1 -1
- package/dist/tabs.main.js +133 -0
- package/dist/tabs.main.js.map +1 -0
- package/dist/tabs.mjs +128 -0
- package/dist/tabs.module.js +128 -0
- package/dist/tabs.module.js.map +1 -0
- package/dist/tree.main.js +165 -0
- package/dist/tree.main.js.map +1 -0
- package/dist/tree.mjs +160 -0
- package/dist/tree.module.js +160 -0
- package/dist/tree.module.js.map +1 -0
- package/dist/types.d.ts +607 -145
- package/dist/types.d.ts.map +1 -1
- package/dist/user.main.js +15 -4
- package/dist/user.main.js.map +1 -1
- package/dist/user.mjs +15 -4
- package/dist/user.module.js +15 -4
- package/dist/user.module.js.map +1 -1
- package/package.json +2 -3
- package/src/combobox.ts +105 -36
- package/src/events.ts +1 -1
- package/src/gridlist.ts +146 -59
- package/src/index.ts +1 -1
- package/src/listbox.ts +226 -0
- package/src/menu.ts +152 -62
- package/src/select.ts +137 -44
- package/src/table.ts +129 -64
- package/src/tabs.ts +198 -0
- package/src/tree.ts +248 -0
- package/src/types.ts +133 -0
- package/src/user.ts +62 -37
package/dist/combobox.module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {act as $1n52X$act, waitFor as $1n52X$waitFor, within as $1n52X$within} from "@testing-library/react";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2024 Adobe. All rights reserved.
|
|
@@ -12,99 +12,133 @@ import {within as $1n52X$within, act as $1n52X$act, waitFor as $1n52X$waitFor} f
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
class $dab75f394483aa9c$export$f97e14e96d71ab3b {
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Set the interaction type used by the combobox tester.
|
|
17
|
+
*/ setInteractionType(type) {
|
|
18
|
+
this._interactionType = type;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.
|
|
22
|
+
*/ async open(opts = {}) {
|
|
23
|
+
let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
|
|
24
|
+
let trigger = this.trigger;
|
|
25
|
+
let combobox = this.combobox;
|
|
26
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
27
|
+
if (interactionType === 'mouse') {
|
|
28
|
+
if (triggerBehavior === 'focus') await this.user.click(combobox);
|
|
29
|
+
else await this.user.click(trigger);
|
|
30
|
+
} else if (interactionType === 'keyboard' && this._trigger != null) {
|
|
31
|
+
(0, $1n52X$act)(()=>this._trigger.focus());
|
|
32
|
+
if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
|
|
33
|
+
} else if (interactionType === 'touch') {
|
|
34
|
+
if (triggerBehavior === 'focus') await this.user.pointer({
|
|
35
|
+
target: combobox,
|
|
36
|
+
keys: '[TouchA]'
|
|
37
|
+
});
|
|
38
|
+
else await this.user.pointer({
|
|
39
|
+
target: trigger,
|
|
40
|
+
keys: '[TouchA]'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
await (0, $1n52X$waitFor)(()=>{
|
|
44
|
+
if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
|
|
45
|
+
else return true;
|
|
46
|
+
});
|
|
47
|
+
let listBoxId = combobox.getAttribute('aria-controls');
|
|
48
|
+
await (0, $1n52X$waitFor)(()=>{
|
|
49
|
+
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
|
|
50
|
+
else return true;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns an option matching the specified index or text content.
|
|
55
|
+
*/ findOption(opts) {
|
|
56
|
+
let { optionIndexOrText: optionIndexOrText } = opts;
|
|
57
|
+
let option;
|
|
58
|
+
let options = this.options();
|
|
59
|
+
let listbox = this.listbox;
|
|
60
|
+
if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
|
|
61
|
+
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $1n52X$within)(listbox).getByText(optionIndexOrText).closest('[role=option]');
|
|
62
|
+
return option;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox dropdown beforehand.
|
|
66
|
+
* The desired option can be targeted via the option's node, the option's text, or the option's index.
|
|
67
|
+
*/ async selectOption(opts) {
|
|
68
|
+
let { option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType } = opts;
|
|
69
|
+
if (!this.combobox.getAttribute('aria-controls')) await this.open({
|
|
70
|
+
triggerBehavior: triggerBehavior
|
|
71
|
+
});
|
|
72
|
+
let listbox = this.listbox;
|
|
73
|
+
if (!listbox) throw new Error('Combobox\'s listbox not found.');
|
|
74
|
+
if (listbox) {
|
|
75
|
+
if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
|
|
76
|
+
optionIndexOrText: option
|
|
77
|
+
});
|
|
78
|
+
if (!option) throw new Error('Target option not found in the listbox.');
|
|
79
|
+
// TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow
|
|
80
|
+
// the required amount of times to reach the option. For now just click the option even in keyboard mode
|
|
81
|
+
if (interactionType === 'mouse' || interactionType === 'keyboard') await this.user.click(option);
|
|
82
|
+
else await this.user.pointer({
|
|
83
|
+
target: option,
|
|
84
|
+
keys: '[TouchA]'
|
|
85
|
+
});
|
|
86
|
+
if (option.getAttribute('href') == null) await (0, $1n52X$waitFor)(()=>{
|
|
87
|
+
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
88
|
+
else return true;
|
|
89
|
+
});
|
|
90
|
+
} else throw new Error("Attempted to select a option in the combobox, but the listbox wasn't found.");
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Closes the combobox dropdown.
|
|
94
|
+
*/ async close() {
|
|
95
|
+
let listbox = this.listbox;
|
|
96
|
+
if (listbox) {
|
|
97
|
+
(0, $1n52X$act)(()=>this.combobox.focus());
|
|
98
|
+
await this.user.keyboard('[Escape]');
|
|
99
|
+
await (0, $1n52X$waitFor)(()=>{
|
|
100
|
+
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
101
|
+
else return true;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns the combobox.
|
|
107
|
+
*/ get combobox() {
|
|
16
108
|
return this._combobox;
|
|
17
109
|
}
|
|
18
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Returns the combobox trigger button.
|
|
112
|
+
*/ get trigger() {
|
|
19
113
|
return this._trigger;
|
|
20
114
|
}
|
|
21
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Returns the combobox's listbox if present.
|
|
117
|
+
*/ get listbox() {
|
|
22
118
|
let listBoxId = this.combobox.getAttribute('aria-controls');
|
|
23
|
-
return listBoxId ? document.getElementById(listBoxId) ||
|
|
119
|
+
return listBoxId ? document.getElementById(listBoxId) || null : null;
|
|
24
120
|
}
|
|
25
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Returns the combobox's sections if present.
|
|
123
|
+
*/ get sections() {
|
|
26
124
|
let listbox = this.listbox;
|
|
27
|
-
|
|
28
|
-
|
|
125
|
+
return listbox ? (0, $1n52X$within)(listbox).queryAllByRole('group') : [];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.
|
|
129
|
+
*/ options(opts = {}) {
|
|
130
|
+
let { element: element = this.listbox } = opts;
|
|
131
|
+
let options = [];
|
|
132
|
+
if (element) options = (0, $1n52X$within)(element).queryAllByRole('option');
|
|
133
|
+
return options;
|
|
29
134
|
}
|
|
30
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Returns the currently focused option in the combobox's dropdown if any.
|
|
137
|
+
*/ get focusedOption() {
|
|
31
138
|
let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');
|
|
32
|
-
return focusedOptionId ? document.getElementById(focusedOptionId) :
|
|
139
|
+
return focusedOptionId ? document.getElementById(focusedOptionId) : null;
|
|
33
140
|
}
|
|
34
141
|
constructor(opts){
|
|
35
|
-
this.setInteractionType = (type)=>{
|
|
36
|
-
this._interactionType = type;
|
|
37
|
-
};
|
|
38
|
-
this.open = async (opts = {})=>{
|
|
39
|
-
let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
|
|
40
|
-
let trigger = this.trigger;
|
|
41
|
-
let combobox = this.combobox;
|
|
42
|
-
let isDisabled = trigger.hasAttribute('disabled');
|
|
43
|
-
if (interactionType === 'mouse') {
|
|
44
|
-
if (triggerBehavior === 'focus') await this.user.click(combobox);
|
|
45
|
-
else await this.user.click(trigger);
|
|
46
|
-
} else if (interactionType === 'keyboard' && this._trigger != null) {
|
|
47
|
-
(0, $1n52X$act)(()=>this._trigger.focus());
|
|
48
|
-
if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
|
|
49
|
-
} else if (interactionType === 'touch') {
|
|
50
|
-
if (triggerBehavior === 'focus') await this.user.pointer({
|
|
51
|
-
target: combobox,
|
|
52
|
-
keys: '[TouchA]'
|
|
53
|
-
});
|
|
54
|
-
else await this.user.pointer({
|
|
55
|
-
target: trigger,
|
|
56
|
-
keys: '[TouchA]'
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
await (0, $1n52X$waitFor)(()=>{
|
|
60
|
-
if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
|
|
61
|
-
else return true;
|
|
62
|
-
});
|
|
63
|
-
let listBoxId = combobox.getAttribute('aria-controls');
|
|
64
|
-
await (0, $1n52X$waitFor)(()=>{
|
|
65
|
-
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
|
|
66
|
-
else return true;
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
this.selectOption = async (opts = {})=>{
|
|
70
|
-
let { optionText: optionText, option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType } = opts;
|
|
71
|
-
if (!this.combobox.getAttribute('aria-controls')) await this.open({
|
|
72
|
-
triggerBehavior: triggerBehavior
|
|
73
|
-
});
|
|
74
|
-
let listbox = this.listbox;
|
|
75
|
-
if (listbox) {
|
|
76
|
-
if (!option && optionText) option = (0, $1n52X$within)(listbox).getByText(optionText);
|
|
77
|
-
// TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow
|
|
78
|
-
// the required amount of times to reach the option. For now just click the option even in keyboard mode
|
|
79
|
-
if (interactionType === 'mouse' || interactionType === 'keyboard') await this.user.click(option);
|
|
80
|
-
else await this.user.pointer({
|
|
81
|
-
target: option,
|
|
82
|
-
keys: '[TouchA]'
|
|
83
|
-
});
|
|
84
|
-
if (option && option.getAttribute('href') == null) await (0, $1n52X$waitFor)(()=>{
|
|
85
|
-
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
86
|
-
else return true;
|
|
87
|
-
});
|
|
88
|
-
} else throw new Error("Attempted to select a option in the combobox, but the listbox wasn't found.");
|
|
89
|
-
};
|
|
90
|
-
this.close = async ()=>{
|
|
91
|
-
let listbox = this.listbox;
|
|
92
|
-
if (listbox) {
|
|
93
|
-
(0, $1n52X$act)(()=>this.combobox.focus());
|
|
94
|
-
await this.user.keyboard('[Escape]');
|
|
95
|
-
await (0, $1n52X$waitFor)(()=>{
|
|
96
|
-
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
97
|
-
else return true;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
this.options = (opts = {})=>{
|
|
102
|
-
let { element: element } = opts;
|
|
103
|
-
element = element || this.listbox;
|
|
104
|
-
let options = [];
|
|
105
|
-
if (element) options = (0, $1n52X$within)(element).queryAllByRole('option');
|
|
106
|
-
return options;
|
|
107
|
-
};
|
|
108
142
|
let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
|
|
109
143
|
this.user = user;
|
|
110
144
|
this._interactionType = interactionType || 'mouse';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAUM,MAAM;IAkIX,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,SAAS;IACvB;IAEA,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ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AAU,IAAI,CAAC,OAAO;YAC1B,IAAI,SAAS;gBACX,CAAA,GAAA,UAAE,EAAE,IAAM,IAAI,CAAC,QAAQ,CAAC,KAAK;gBAC7B,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAEzB,MAAM,CAAA,GAAA,cAAM,EAAE;oBACZ,IAAI,SAAS,QAAQ,CAAC,UACpB,MAAM,IAAI,MAAM;yBAEhB,OAAO;gBAEX;YACF;QACF;aAeA,UAAU,CAAC,OAAgC,CAAC,CAAC;YAC3C,IAAI,WAAC,OAAO,EAAC,GAAG;YAChB,UAAU,WAAW,IAAI,CAAC,OAAO;YACjC,IAAI,UAAU,EAAE;YAChB,IAAI,SACF,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;YAG3C,OAAO;QACT;QAjJE,IAAI,QAAC,IAAI,WAAE,OAAO,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QAC7C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAE3C,8IAA8I;QAC9I,2FAA2F;QAC3F,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,WAAW,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC;QACxC,IAAI,UACF,IAAI,CAAC,SAAS,GAAG;QAGnB,6KAA6K;QAC7K,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC,UAAU;gBAAC,QAAQ;YAAI;YAC9D,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;iBAEhB,qHAAqH;YACrH,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;QAElC;IACF;AAuIF","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 {BaseTesterOpts, UserOpts} from './user';\n\nexport interface ComboBoxOptions extends UserOpts, BaseTesterOpts {\n user?: any,\n trigger?: HTMLElement\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement | undefined;\n\n constructor(opts: ComboBoxOptions) {\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 trigger = within(root).queryByRole('button', {hidden: true});\n if (trigger) {\n this._trigger = trigger;\n } else {\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 = this._combobox;\n }\n }\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n open = async (opts: {triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {\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 selectOption = async (opts: {option?: HTMLElement, optionText?: string, triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {\n let {optionText, 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 if (!option && optionText) {\n option = within(listbox).getByText(optionText);\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 && 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 close = async () => {\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 get combobox() {\n return this._combobox;\n }\n\n get trigger() {\n return this._trigger;\n }\n\n get listbox() {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || undefined : undefined;\n }\n\n options = (opts: {element?: HTMLElement} = {}): HTMLElement[] | never[] => {\n let {element} = opts;\n element = element || this.listbox;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n };\n\n get sections() {\n let listbox = this.listbox;\n if (listbox) {\n return within(listbox).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n get focusedOption() {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : undefined;\n }\n}\n"],"names":[],"version":3,"file":"combobox.module.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAkCX;;GAEC,GACD,mBAAmB,IAAiC,EAAE;QACpD,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAyB,CAAC,CAAC,EAAE;QACtC,IAAI,mBAAC,kBAAkB,2BAAU,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;QAC5E,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,WAAW,IAAI,CAAC,QAAQ;QAC5B,IAAI,aAAa,QAAS,YAAY,CAAC;QAEvC,IAAI,oBAAoB;YACtB,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBAEtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;eAEnB,IAAI,oBAAoB,cAAc,IAAI,CAAC,QAAQ,IAAI,MAAM;YAClE,CAAA,GAAA,UAAE,EAAE,IAAM,IAAI,CAAC,QAAQ,CAAE,KAAK;YAC9B,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC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AAI,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;IAvNA,YAAY,IAAwB,CAAE;QACpC,IAAI,QAAC,IAAI,WAAE,OAAO,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QAC7C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAE3C,8IAA8I;QAC9I,2FAA2F;QAC3F,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,WAAW,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC;QACxC,IAAI,UACF,IAAI,CAAC,SAAS,GAAG;QAGnB,6KAA6K;QAC7K,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC,UAAU;gBAAC,QAAQ;YAAI;YAC9D,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;iBAEhB,qHAAqH;YACrH,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;QAElC;IACF;AA8LF","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 trigger = within(root).queryByRole('button', {hidden: true});\n if (trigger) {\n this._trigger = trigger;\n } else {\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 = this._combobox;\n }\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']) {\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 = {}) {\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) {\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() {\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.module.js.map"}
|
package/dist/events.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AAShC,eAAe,yCAAiB,IAAwG;IAC7I,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;IAChD,MAAM,CAAA,GAAA,oCAAQ,EAAE,WAAW,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;IAC1E,MAAM,CAAA,GAAA,8BAAE,EAAE,UAAY,MAAM,aAAa;IACzC,MAAM,CAAA,GAAA,oCAAQ,EAAE,SAAS,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;AAC1E;AAGO,eAAe,0CAAa,IAAI,EAAE,OAAoB,EAAE,eAA4C;IACzG,IAAI,oBAAoB,SACtB,MAAM,KAAK,KAAK,CAAC;SACZ,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 './
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AAShC,eAAe,yCAAiB,IAAwG;IAC7I,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;IAChD,MAAM,CAAA,GAAA,oCAAQ,EAAE,WAAW,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;IAC1E,MAAM,CAAA,GAAA,8BAAE,EAAE,UAAY,MAAM,aAAa;IACzC,MAAM,CAAA,GAAA,oCAAQ,EAAE,SAAS,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;AAC1E;AAGO,eAAe,0CAAa,IAAI,EAAE,OAAoB,EAAE,eAA4C;IACzG,IAAI,oBAAoB,SACtB,MAAM,KAAK,KAAK,CAAC;SACZ,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;\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) => void | Promise<unknown>, pointerOpts?: {}}) {\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 await fireEvent.pointerDown(element, {pointerType: 'mouse', ...pointerOpts});\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n await fireEvent.pointerUp(element, {pointerType: 'mouse', ...pointerOpts});\n}\n\n\nexport async function pressElement(user, element: HTMLElement, interactionType: UserOpts['interactionType']) {\n if (interactionType === 'mouse') {\n await user.click(element);\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.main.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AAShC,eAAe,yCAAiB,IAAwG;IAC7I,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;IAChD,MAAM,CAAA,GAAA,gBAAQ,EAAE,WAAW,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;IAC1E,MAAM,CAAA,GAAA,UAAE,EAAE,UAAY,MAAM,aAAa;IACzC,MAAM,CAAA,GAAA,gBAAQ,EAAE,SAAS,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;AAC1E;AAGO,eAAe,0CAAa,IAAI,EAAE,OAAoB,EAAE,eAA4C;IACzG,IAAI,oBAAoB,SACtB,MAAM,KAAK,KAAK,CAAC;SACZ,IAAI,oBAAoB,YAAY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,UAAE,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 './
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AAShC,eAAe,yCAAiB,IAAwG;IAC7I,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;IAChD,MAAM,CAAA,GAAA,gBAAQ,EAAE,WAAW,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;IAC1E,MAAM,CAAA,GAAA,UAAE,EAAE,UAAY,MAAM,aAAa;IACzC,MAAM,CAAA,GAAA,gBAAQ,EAAE,SAAS,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;AAC1E;AAGO,eAAe,0CAAa,IAAI,EAAE,OAAoB,EAAE,eAA4C;IACzG,IAAI,oBAAoB,SACtB,MAAM,KAAK,KAAK,CAAC;SACZ,IAAI,oBAAoB,YAAY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,UAAE,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;\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) => void | Promise<unknown>, pointerOpts?: {}}) {\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 await fireEvent.pointerDown(element, {pointerType: 'mouse', ...pointerOpts});\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n await fireEvent.pointerUp(element, {pointerType: 'mouse', ...pointerOpts});\n}\n\n\nexport async function pressElement(user, element: HTMLElement, interactionType: UserOpts['interactionType']) {\n if (interactionType === 'mouse') {\n await user.click(element);\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.module.js.map"}
|
package/dist/gridlist.main.js
CHANGED
|
@@ -20,75 +20,118 @@ $parcel$export(module.exports, "GridListTester", () => $30ee8e379774bea4$export$
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
class $30ee8e379774bea4$export$93a85aaed9fabd83 {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Set the interaction type used by the gridlist tester.
|
|
25
|
+
*/ setInteractionType(type) {
|
|
26
|
+
this._interactionType = type;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns a row matching the specified index or text content.
|
|
30
|
+
*/ findRow(opts) {
|
|
31
|
+
let { rowIndexOrText: rowIndexOrText } = opts;
|
|
32
|
+
let row;
|
|
33
|
+
if (typeof rowIndexOrText === 'number') row = this.rows[rowIndexOrText];
|
|
34
|
+
else if (typeof rowIndexOrText === 'string') row = (0, $cgwRb$testinglibraryreact.within)(this.gridlist).getByText(rowIndexOrText).closest('[role=row]');
|
|
35
|
+
return row;
|
|
36
|
+
}
|
|
37
|
+
// TODO: RTL
|
|
38
|
+
async keyboardNavigateToRow(opts) {
|
|
39
|
+
let { row: row } = opts;
|
|
40
|
+
let rows = this.rows;
|
|
41
|
+
let targetIndex = rows.indexOf(row);
|
|
42
|
+
if (targetIndex === -1) throw new Error('Option provided is not in the gridlist');
|
|
43
|
+
if (document.activeElement === this._gridlist) await this.user.keyboard('[ArrowDown]');
|
|
44
|
+
else if (this._gridlist.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
|
|
45
|
+
while (document.activeElement.getAttribute('role') !== 'row');
|
|
46
|
+
let currIndex = rows.indexOf(document.activeElement);
|
|
47
|
+
if (currIndex === -1) throw new Error('ActiveElement is not in the gridlist');
|
|
48
|
+
let direction = targetIndex > currIndex ? 'down' : 'up';
|
|
49
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
|
|
53
|
+
*/ async toggleRowSelection(opts) {
|
|
54
|
+
let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
|
|
55
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
56
|
+
rowIndexOrText: row
|
|
57
|
+
});
|
|
58
|
+
if (!row) throw new Error('Target row not found in the gridlist.');
|
|
59
|
+
let rowCheckbox = (0, $cgwRb$testinglibraryreact.within)(row).queryByRole('checkbox');
|
|
60
|
+
// TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually
|
|
61
|
+
// but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)
|
|
62
|
+
if (interactionType === 'keyboard' && ((rowCheckbox === null || rowCheckbox === void 0 ? void 0 : rowCheckbox.getAttribute('disabled')) === '' || (row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true')) return;
|
|
63
|
+
// this would be better than the check to do nothing in events.ts
|
|
64
|
+
// also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly
|
|
65
|
+
if (interactionType === 'keyboard' && !checkboxSelection) {
|
|
66
|
+
await this.keyboardNavigateToRow({
|
|
67
|
+
row: row
|
|
68
|
+
});
|
|
69
|
+
await this.user.keyboard('{Space}');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (rowCheckbox && checkboxSelection) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
|
|
73
|
+
else {
|
|
74
|
+
let cell = (0, $cgwRb$testinglibraryreact.within)(row).getAllByRole('gridcell')[0];
|
|
75
|
+
if (needsLongPress && interactionType === 'touch') {
|
|
76
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
77
|
+
// Note that long press interactions with rows is strictly touch only for grid rows
|
|
78
|
+
await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
|
|
79
|
+
element: cell,
|
|
80
|
+
advanceTimer: this._advanceTimer,
|
|
81
|
+
pointerOpts: {
|
|
82
|
+
pointerType: 'touch'
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, cell, interactionType);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
|
|
89
|
+
// user specificlly tells us
|
|
90
|
+
/**
|
|
91
|
+
* Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
|
|
92
|
+
*/ async triggerRowAction(opts) {
|
|
93
|
+
let { row: row, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
94
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
95
|
+
rowIndexOrText: row
|
|
96
|
+
});
|
|
97
|
+
if (!row) throw new Error('Target row not found in the gridlist.');
|
|
98
|
+
if (needsDoubleClick) await this.user.dblClick(row);
|
|
99
|
+
else if (interactionType === 'keyboard') {
|
|
100
|
+
if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
|
|
101
|
+
if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) (0, $cgwRb$testinglibraryreact.act)(()=>this._gridlist.focus());
|
|
102
|
+
await this.keyboardNavigateToRow({
|
|
103
|
+
row: row
|
|
104
|
+
});
|
|
105
|
+
await this.user.keyboard('[Enter]');
|
|
106
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns the gridlist.
|
|
110
|
+
*/ get gridlist() {
|
|
25
111
|
return this._gridlist;
|
|
26
112
|
}
|
|
27
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Returns the gridlist's rows if any.
|
|
115
|
+
*/ get rows() {
|
|
28
116
|
var _this;
|
|
29
117
|
return (0, $cgwRb$testinglibraryreact.within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).queryAllByRole('row');
|
|
30
118
|
}
|
|
31
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Returns the gridlist's selected rows if any.
|
|
121
|
+
*/ get selectedRows() {
|
|
32
122
|
return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
|
|
33
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.
|
|
126
|
+
*/ cells(opts = {}) {
|
|
127
|
+
let { element: element = this.gridlist } = opts;
|
|
128
|
+
return (0, $cgwRb$testinglibraryreact.within)(element).queryAllByRole('gridcell');
|
|
129
|
+
}
|
|
34
130
|
constructor(opts){
|
|
35
|
-
|
|
36
|
-
this._interactionType = type;
|
|
37
|
-
};
|
|
38
|
-
// TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share
|
|
39
|
-
// For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common
|
|
40
|
-
// If the current way of passing in the user specified advance timers is ok, then I'd be find including long press
|
|
41
|
-
// Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way
|
|
42
|
-
// the user can test a specific type of interaction?
|
|
43
|
-
this.toggleRowSelection = async (opts = {})=>{
|
|
44
|
-
let { index: index, text: text, interactionType: interactionType = this._interactionType } = opts;
|
|
45
|
-
let row = this.findRow({
|
|
46
|
-
index: index,
|
|
47
|
-
text: text
|
|
48
|
-
});
|
|
49
|
-
let rowCheckbox = (0, $cgwRb$testinglibraryreact.within)(row).queryByRole('checkbox');
|
|
50
|
-
if (rowCheckbox) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
|
|
51
|
-
else {
|
|
52
|
-
let cell = (0, $cgwRb$testinglibraryreact.within)(row).getAllByRole('gridcell')[0];
|
|
53
|
-
await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, cell, interactionType);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
// TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for
|
|
57
|
-
// an element?
|
|
58
|
-
this.findRow = (opts)=>{
|
|
59
|
-
let { index: index, text: text } = opts;
|
|
60
|
-
let row;
|
|
61
|
-
if (index != null) row = this.rows[index];
|
|
62
|
-
else if (text != null) {
|
|
63
|
-
var _this;
|
|
64
|
-
row = (0, $cgwRb$testinglibraryreact.within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).getByText(text);
|
|
65
|
-
while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
|
|
66
|
-
}
|
|
67
|
-
return row;
|
|
68
|
-
};
|
|
69
|
-
// TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
|
|
70
|
-
// user specificlly tells us
|
|
71
|
-
this.triggerRowAction = async (opts)=>{
|
|
72
|
-
let { index: index, text: text, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
73
|
-
let row = this.findRow({
|
|
74
|
-
index: index,
|
|
75
|
-
text: text
|
|
76
|
-
});
|
|
77
|
-
if (row) {
|
|
78
|
-
if (needsDoubleClick) await this.user.dblClick(row);
|
|
79
|
-
else if (interactionType === 'keyboard') {
|
|
80
|
-
(0, $cgwRb$testinglibraryreact.act)(()=>row.focus());
|
|
81
|
-
await this.user.keyboard('[Enter]');
|
|
82
|
-
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
this.cells = (opts = {})=>{
|
|
86
|
-
let { element: element } = opts;
|
|
87
|
-
return (0, $cgwRb$testinglibraryreact.within)(element || this.gridlist).queryAllByRole('gridcell');
|
|
88
|
-
};
|
|
89
|
-
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
131
|
+
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
90
132
|
this.user = user;
|
|
91
133
|
this._interactionType = interactionType || 'mouse';
|
|
134
|
+
this._advanceTimer = advanceTimer;
|
|
92
135
|
this._gridlist = root;
|
|
93
136
|
}
|
|
94
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IA+EX,wGAAwG;IACxG,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,SAAS;IACvB;IAEA,IAAI,OAAO;YACK;QAAd,OAAO,CAAA,GAAA,iCAAK,GAAE,QAAA,IAAI,cAAJ,4BAAA,MAAM,QAAQ,EAAE,cAAc,CAAC;IAC/C;IAEA,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CA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G;YAEJ,IAAI,MAAM,IAAI,CAAC,OAAO,CAAC;uBAAC;sBAAO;YAAI;YACnC,IAAI,KAAK;gBACP,IAAI,kBACF,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;qBACpB,IAAI,oBAAoB,YAAY;oBACzC,CAAA,GAAA,8BAAE,EAAE,IAAM,IAAI,KAAK;oBACnB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAC3B,OACE,MAAM,CAAA,GAAA,sCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK;YAEvC;QACF;aAeA,QAAQ,CAAC,OAAgC,CAAC,CAAC;YACzC,IAAI,WAAC,OAAO,EAAC,GAAG;YAChB,OAAO,CAAA,GAAA,iCAAK,EAAE,WAAW,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;QACzD;QAxFE,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,SAAS,GAAG;IACnB;AAqFF","sources":["packages/@react-aria/test-utils/src/gridlist.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, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\nimport {pressElement} from './events';\n\nexport interface GridListOptions extends UserOpts, BaseTesterOpts {\n user?: any\n}\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _gridlist: HTMLElement;\n\n\n constructor(opts: GridListOptions) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._gridlist = root;\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n // TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share\n // For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common\n // If the current way of passing in the user specified advance timers is ok, then I'd be find including long press\n // Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way\n // the user can test a specific type of interaction?\n toggleRowSelection = async (opts: {index?: number, text?: string, interactionType?: UserOpts['interactionType']} = {}) => {\n let {index, text, interactionType = this._interactionType} = opts;\n\n let row = this.findRow({index, text});\n let rowCheckbox = within(row).queryByRole('checkbox');\n if (rowCheckbox) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n await pressElement(this.user, cell, interactionType);\n }\n };\n\n // TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for\n // an element?\n findRow = (opts: {index?: number, text?: string}) => {\n let {\n index,\n text\n } = opts;\n\n let row;\n if (index != null) {\n row = this.rows[index];\n } else if (text != null) {\n row = within(this?.gridlist).getByText(text);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n };\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n triggerRowAction = async (opts: {index?: number, text?: string, needsDoubleClick?: boolean, interactionType?: UserOpts['interactionType']}) => {\n let {\n index,\n text,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n let row = this.findRow({index, text});\n if (row) {\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n act(() => row.focus());\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n };\n\n // TODO: do we really need this getter? Theoretically the user already has the reference to the gridlist\n get gridlist() {\n return this._gridlist;\n }\n\n get rows() {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n get selectedRows() {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n cells = (opts: {element?: HTMLElement} = {}) => {\n let {element} = opts;\n return within(element || this.gridlist).queryAllByRole('gridcell');\n };\n}\n"],"names":[],"version":3,"file":"gridlist.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAE;QACpD,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe;aAC1B,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,QAAQ,EAAG,SAAS,CAAC,gBAAgB,OAAO,CAAC;QAGlE,OAAO;IACT;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAAwB,EAAE;QAC5D,IAAI,OAAC,GAAG,EAAC,GAAG;QACZ,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAElB,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,SAAS,EAC3C,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;aACpB,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,aAAa,KAAK,SAAS,aAAa,CAAE,YAAY,CAAC,YAAY,OAC7G,GACE,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;eAClB,SAAS,aAAa,CAAE,YAAY,CAAC,YAAY,OAAO;QAEnE,IAAI,YAAY,KAAK,OAAO,CAAC,SAAS,aAAa;QACnD,IAA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C;IAC/C;IAEA;;GAEC,GACD,IAAI,eAA8B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,QAAQ,EAAC,GAAG;QAChC,OAAO,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;IACxC;IAhLA,YAAY,IAAwB,CAAE;QACpC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,SAAS,GAAG;IACnB;AA2KF","sources":["packages/@react-aria/test-utils/src/gridlist.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, within} from '@testing-library/react';\nimport {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\n\ninterface GridListToggleRowOpts extends ToggleGridRowOpts {}\ninterface GridListRowActionOpts extends GridRowActionOpts {}\n\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _gridlist: HTMLElement;\n\n constructor(opts: GridListTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._gridlist = root;\n }\n\n /**\n * Set the interaction type used by the gridlist tester.\n */\n setInteractionType(type: UserOpts['interactionType']) {\n this._interactionType = type;\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n if (typeof rowIndexOrText === 'number') {\n row = this.rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = (within(this.gridlist!).getByText(rowIndexOrText).closest('[role=row]'))! as HTMLElement;\n }\n\n return row;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement}) {\n let {row} = opts;\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the gridlist');\n }\n if (document.activeElement === this._gridlist) {\n await this.user.keyboard('[ArrowDown]');\n } else if (this._gridlist.contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the gridlist');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async toggleRowSelection(opts: GridListToggleRowOpts) {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n // TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually\n // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)\n if (interactionType === 'keyboard' && (rowCheckbox?.getAttribute('disabled') === '' || row?.getAttribute('aria-disabled') === 'true')) {\n return;\n }\n\n // this would be better than the check to do nothing in events.ts\n // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly\n if (interactionType === 'keyboard' && !checkboxSelection) {\n await this.keyboardNavigateToRow({row});\n await this.user.keyboard('{Space}');\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n\n } else {\n await pressElement(this.user, cell, interactionType);\n }\n }\n }\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n /**\n * Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async triggerRowAction(opts: GridListRowActionOpts) {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) {\n act(() => this._gridlist.focus());\n }\n\n await this.keyboardNavigateToRow({row});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n /**\n * Returns the gridlist.\n */\n get gridlist(): HTMLElement {\n return this._gridlist;\n }\n\n /**\n * Returns the gridlist's rows if any.\n */\n get rows(): HTMLElement[] {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n /**\n * Returns the gridlist's selected rows if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.gridlist} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"gridlist.main.js.map"}
|