@react-aria/test-utils 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +5 -5
- package/dist/main.js +9 -9
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -5
- package/dist/module.js.map +1 -1
- package/dist/private/checkboxgroup.cjs +104 -0
- package/dist/private/checkboxgroup.cjs.map +1 -0
- package/dist/private/checkboxgroup.js +99 -0
- package/dist/private/checkboxgroup.js.map +1 -0
- package/dist/{combobox.main.js → private/combobox.cjs} +35 -35
- package/dist/private/combobox.cjs.map +1 -0
- package/dist/{combobox.mjs → private/combobox.js} +35 -35
- package/dist/private/combobox.js.map +1 -0
- package/dist/private/dialog.cjs +105 -0
- package/dist/private/dialog.cjs.map +1 -0
- package/dist/private/dialog.js +100 -0
- package/dist/private/dialog.js.map +1 -0
- package/dist/{events.main.js → private/events.cjs} +32 -34
- package/dist/private/events.cjs.map +1 -0
- package/dist/{events.mjs → private/events.js} +29 -31
- package/dist/private/events.js.map +1 -0
- package/dist/{gridlist.main.js → private/gridlist.cjs} +27 -28
- package/dist/private/gridlist.cjs.map +1 -0
- package/dist/{gridlist.mjs → private/gridlist.js} +27 -28
- package/dist/private/gridlist.js.map +1 -0
- package/dist/{listbox.main.js → private/listbox.cjs} +24 -24
- package/dist/private/listbox.cjs.map +1 -0
- package/dist/{listbox.mjs → private/listbox.js} +24 -24
- package/dist/private/listbox.js.map +1 -0
- package/dist/{menu.main.js → private/menu.cjs} +46 -48
- package/dist/private/menu.cjs.map +1 -0
- package/dist/{menu.mjs → private/menu.js} +46 -48
- package/dist/private/menu.js.map +1 -0
- package/dist/private/radiogroup.cjs +120 -0
- package/dist/private/radiogroup.cjs.map +1 -0
- package/dist/private/radiogroup.js +115 -0
- package/dist/private/radiogroup.js.map +1 -0
- package/dist/{select.main.js → private/select.cjs} +31 -29
- package/dist/private/select.cjs.map +1 -0
- package/dist/{select.mjs → private/select.js} +31 -29
- package/dist/private/select.js.map +1 -0
- package/dist/{table.main.js → private/table.cjs} +82 -57
- package/dist/private/table.cjs.map +1 -0
- package/dist/{table.module.js → private/table.js} +82 -57
- package/dist/private/table.js.map +1 -0
- package/dist/{tabs.main.js → private/tabs.cjs} +24 -26
- package/dist/private/tabs.cjs.map +1 -0
- package/dist/{tabs.mjs → private/tabs.js} +24 -26
- package/dist/private/tabs.js.map +1 -0
- package/dist/private/testSetup.cjs +87 -0
- package/dist/private/testSetup.cjs.map +1 -0
- package/dist/private/testSetup.js +81 -0
- package/dist/private/testSetup.js.map +1 -0
- package/dist/{tree.main.js → private/tree.cjs} +34 -35
- package/dist/private/tree.cjs.map +1 -0
- package/dist/{tree.mjs → private/tree.js} +34 -35
- package/dist/private/tree.js.map +1 -0
- package/dist/private/user.cjs +85 -0
- package/dist/private/user.cjs.map +1 -0
- package/dist/private/user.js +76 -0
- package/dist/private/user.js.map +1 -0
- package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
- package/dist/{userEventMaps.main.js.map → private/userEventMaps.cjs.map} +1 -1
- package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
- package/dist/{userEventMaps.module.js.map → private/userEventMaps.js.map} +1 -1
- package/dist/types/src/checkboxgroup.d.ts +45 -0
- package/dist/types/src/combobox.d.ts +75 -0
- package/dist/types/src/dialog.d.ts +36 -0
- package/dist/types/src/events.d.ts +25 -0
- package/dist/types/src/gridlist.d.ts +51 -0
- package/dist/types/src/index.d.ts +16 -0
- package/dist/types/src/listbox.d.ts +80 -0
- package/dist/types/src/menu.d.ts +102 -0
- package/dist/types/src/radiogroup.d.ts +46 -0
- package/dist/types/src/select.d.ts +67 -0
- package/dist/types/src/table.d.ts +104 -0
- package/dist/types/src/tabs.d.ts +58 -0
- package/dist/types/src/testSetup.d.ts +6 -0
- package/dist/types/src/tree.d.ts +57 -0
- package/dist/types/src/types.d.ts +136 -0
- package/dist/types/src/user.d.ts +47 -0
- package/dist/types/src/userEventMaps.d.ts +2 -0
- package/package.json +7 -7
- package/src/checkboxgroup.ts +158 -0
- package/src/dialog.ts +143 -0
- package/src/index.ts +11 -0
- package/src/radiogroup.ts +176 -0
- package/src/select.ts +10 -2
- package/src/table.ts +46 -1
- package/src/tabs.ts +7 -2
- package/src/testSetup.ts +30 -28
- package/src/types.ts +21 -0
- package/src/user.ts +25 -7
- package/dist/combobox.main.js.map +0 -1
- package/dist/combobox.module.js +0 -167
- package/dist/combobox.module.js.map +0 -1
- package/dist/events.main.js.map +0 -1
- package/dist/events.module.js +0 -112
- package/dist/events.module.js.map +0 -1
- package/dist/gridlist.main.js.map +0 -1
- package/dist/gridlist.module.js +0 -149
- package/dist/gridlist.module.js.map +0 -1
- package/dist/listbox.main.js.map +0 -1
- package/dist/listbox.module.js +0 -138
- package/dist/listbox.module.js.map +0 -1
- package/dist/menu.main.js.map +0 -1
- package/dist/menu.module.js +0 -269
- package/dist/menu.module.js.map +0 -1
- package/dist/select.main.js.map +0 -1
- package/dist/select.module.js +0 -158
- package/dist/select.module.js.map +0 -1
- package/dist/table.main.js.map +0 -1
- package/dist/table.mjs +0 -290
- package/dist/table.module.js.map +0 -1
- package/dist/tabs.main.js.map +0 -1
- package/dist/tabs.module.js +0 -128
- package/dist/tabs.module.js.map +0 -1
- package/dist/testSetup.main.js +0 -78
- package/dist/testSetup.main.js.map +0 -1
- package/dist/testSetup.mjs +0 -72
- package/dist/testSetup.module.js +0 -72
- package/dist/testSetup.module.js.map +0 -1
- package/dist/tree.main.js.map +0 -1
- package/dist/tree.module.js +0 -179
- package/dist/tree.module.js.map +0 -1
- package/dist/types.d.ts +0 -694
- package/dist/types.d.ts.map +0 -1
- package/dist/user.main.js +0 -76
- package/dist/user.main.js.map +0 -1
- package/dist/user.mjs +0 -67
- package/dist/user.module.js +0 -67
- package/dist/user.module.js.map +0 -1
- package/dist/userEventMaps.module.js +0 -38
package/dist/select.module.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import {act as $7v0pZ$act, waitFor as $7v0pZ$waitFor, within as $7v0pZ$within} from "@testing-library/react";
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright 2024 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 $4350df3e19e40e36$export$d1859707465446a9 {
|
|
15
|
-
/**
|
|
16
|
-
* Set the interaction type used by the select tester.
|
|
17
|
-
*/ setInteractionType(type) {
|
|
18
|
-
this._interactionType = type;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Opens the select. Defaults to using the interaction type set on the select tester.
|
|
22
|
-
*/ async open(opts = {}) {
|
|
23
|
-
let { interactionType: interactionType = this._interactionType } = opts;
|
|
24
|
-
let trigger = this.trigger;
|
|
25
|
-
let isDisabled = trigger.hasAttribute('disabled');
|
|
26
|
-
if (interactionType === 'mouse') await this.user.click(this._trigger);
|
|
27
|
-
else if (interactionType === 'keyboard') {
|
|
28
|
-
(0, $7v0pZ$act)(()=>trigger.focus());
|
|
29
|
-
await this.user.keyboard('[Enter]');
|
|
30
|
-
} else if (interactionType === 'touch') await this.user.pointer({
|
|
31
|
-
target: this._trigger,
|
|
32
|
-
keys: '[TouchA]'
|
|
33
|
-
});
|
|
34
|
-
await (0, $7v0pZ$waitFor)(()=>{
|
|
35
|
-
if (!isDisabled && trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on select element trigger.');
|
|
36
|
-
else return true;
|
|
37
|
-
});
|
|
38
|
-
let listBoxId = trigger.getAttribute('aria-controls');
|
|
39
|
-
await (0, $7v0pZ$waitFor)(()=>{
|
|
40
|
-
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`ListBox with id of ${listBoxId} not found in document.`);
|
|
41
|
-
else return true;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Closes the select.
|
|
46
|
-
*/ async close() {
|
|
47
|
-
let listbox = this.listbox;
|
|
48
|
-
if (listbox) {
|
|
49
|
-
(0, $7v0pZ$act)(()=>listbox.focus());
|
|
50
|
-
await this.user.keyboard('[Escape]');
|
|
51
|
-
}
|
|
52
|
-
await (0, $7v0pZ$waitFor)(()=>{
|
|
53
|
-
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);
|
|
54
|
-
else return true;
|
|
55
|
-
});
|
|
56
|
-
if (listbox && document.contains(listbox)) throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Returns a option matching the specified index or text content.
|
|
60
|
-
*/ findOption(opts) {
|
|
61
|
-
let { optionIndexOrText: optionIndexOrText } = opts;
|
|
62
|
-
let option;
|
|
63
|
-
let options = this.options();
|
|
64
|
-
let listbox = this.listbox;
|
|
65
|
-
if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
|
|
66
|
-
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $7v0pZ$within)(listbox).getByText(optionIndexOrText).closest('[role=option]');
|
|
67
|
-
return option;
|
|
68
|
-
}
|
|
69
|
-
async keyboardNavigateToOption(opts) {
|
|
70
|
-
let { option: option } = opts;
|
|
71
|
-
let options = this.options();
|
|
72
|
-
let targetIndex = options.indexOf(option);
|
|
73
|
-
if (targetIndex === -1) throw new Error('Option provided is not in the listbox');
|
|
74
|
-
if (document.activeElement === this.listbox) await this.user.keyboard('[ArrowDown]');
|
|
75
|
-
let currIndex = options.indexOf(document.activeElement);
|
|
76
|
-
if (currIndex === -1) throw new Error('ActiveElement is not in the listbox');
|
|
77
|
-
let direction = targetIndex > currIndex ? 'down' : 'up';
|
|
78
|
-
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select dropdown beforehand.
|
|
82
|
-
* The desired option can be targeted via the option's node, the option's text, or the option's index.
|
|
83
|
-
*/ async selectOption(opts) {
|
|
84
|
-
let { option: option, interactionType: interactionType = this._interactionType } = opts || {};
|
|
85
|
-
let trigger = this.trigger;
|
|
86
|
-
if (!trigger.getAttribute('aria-controls')) await this.open();
|
|
87
|
-
let listbox = this.listbox;
|
|
88
|
-
if (!listbox) throw new Error('Select\'s listbox not found.');
|
|
89
|
-
if (listbox) {
|
|
90
|
-
if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
|
|
91
|
-
optionIndexOrText: option
|
|
92
|
-
});
|
|
93
|
-
if (!option) throw new Error('Target option not found in the listbox.');
|
|
94
|
-
let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';
|
|
95
|
-
if (interactionType === 'keyboard') {
|
|
96
|
-
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
97
|
-
if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) (0, $7v0pZ$act)(()=>listbox.focus());
|
|
98
|
-
await this.keyboardNavigateToOption({
|
|
99
|
-
option: option
|
|
100
|
-
});
|
|
101
|
-
await this.user.keyboard('[Enter]');
|
|
102
|
-
} else // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)
|
|
103
|
-
if (interactionType === 'mouse') await this.user.click(option);
|
|
104
|
-
else await this.user.pointer({
|
|
105
|
-
target: option,
|
|
106
|
-
keys: '[TouchA]'
|
|
107
|
-
});
|
|
108
|
-
if (!isMultiSelect && (option === null || option === void 0 ? void 0 : option.getAttribute('href')) == null) {
|
|
109
|
-
await (0, $7v0pZ$waitFor)(()=>{
|
|
110
|
-
if (document.activeElement !== this._trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);
|
|
111
|
-
else return true;
|
|
112
|
-
});
|
|
113
|
-
if (document.contains(listbox)) throw new Error('Expected select element listbox to not be in the document after selecting an option');
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Returns the select's options if present. Can be filtered to a subsection of the listbox if provided via `element`.
|
|
119
|
-
*/ options(opts = {}) {
|
|
120
|
-
let { element: element = this.listbox } = opts;
|
|
121
|
-
let options = [];
|
|
122
|
-
if (element) options = (0, $7v0pZ$within)(element).queryAllByRole('option');
|
|
123
|
-
return options;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Returns the select's trigger.
|
|
127
|
-
*/ get trigger() {
|
|
128
|
-
return this._trigger;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Returns the select's listbox if present.
|
|
132
|
-
*/ get listbox() {
|
|
133
|
-
let listBoxId = this.trigger.getAttribute('aria-controls');
|
|
134
|
-
return listBoxId ? document.getElementById(listBoxId) : null;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Returns the select's sections if present.
|
|
138
|
-
*/ get sections() {
|
|
139
|
-
let listbox = this.listbox;
|
|
140
|
-
return listbox ? (0, $7v0pZ$within)(listbox).queryAllByRole('group') : [];
|
|
141
|
-
}
|
|
142
|
-
constructor(opts){
|
|
143
|
-
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
144
|
-
this.user = user;
|
|
145
|
-
this._interactionType = interactionType || 'mouse';
|
|
146
|
-
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
147
|
-
let buttons = (0, $7v0pZ$within)(root).queryAllByRole('button');
|
|
148
|
-
let triggerButton;
|
|
149
|
-
if (buttons.length === 0) triggerButton = root;
|
|
150
|
-
else if (buttons.length === 1) triggerButton = buttons[0];
|
|
151
|
-
else triggerButton = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
152
|
-
this._trigger = triggerButton !== null && triggerButton !== void 0 ? triggerButton : root;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
export {$4350df3e19e40e36$export$d1859707465446a9 as SelectTester};
|
|
158
|
-
//# sourceMappingURL=select.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAmBM,MAAM;IAsBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;QACnD,IAAI,mBACF,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,aAAa,QAAQ,YAAY,CAAC;QAEtC,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ;aAC9B,IAAI,oBAAoB,YAAY;YACzC,CAAA,GAAA,UAAE,EAAE,IAAM,QAAQ,KAAK;YACvB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OAAO,IAAI,oBAAoB,SAC7B,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;YAAC,QAAQ,IAAI,CAAC,QAAQ;YAAE,MAAM;QAAU;QAGlE,MAAM,CAAA,GAAA,cAAM,EAAE;YACZ,IAAI,CAAC,cAAc,QAAQ,YAAY,CAAC,oBAAoB,MAC1D,MAAM,IAAI,MAAM;iBAEhB,OAAO;QAEX;QACA,IAAI,YAAY,QA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,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI;QACJ,IAAI,QAAQ,MAAM,KAAK,GACrB,gBAAgB;aACX,IAAI,QAAQ,MAAM,KAAK,GAC5B,gBAAgB,OAAO,CAAC,EAAE;aAE1B,gBAAgB,QAAQ,IAAI,CAAC,CAAA,SAAU,OAAO,YAAY,CAAC;QAG7D,IAAI,CAAC,QAAQ,GAAG,0BAAA,2BAAA,gBAAiB;IACnC;AAgNF","sources":["packages/@react-aria/test-utils/src/select.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 {SelectTesterOpts, UserOpts} from './types';\n\ninterface SelectOpenOpts {\n /**\n * What interaction type to use when opening the select. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface SelectTriggerOptionOpts extends SelectOpenOpts {\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 SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n // Handle case where the wrapper element is provided rather than the Select's button (aka RAC)\n let buttons = within(root).queryAllByRole('button');\n let triggerButton;\n if (buttons.length === 0) {\n triggerButton = root;\n } else if (buttons.length === 1) {\n triggerButton = buttons[0];\n } else {\n triggerButton = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n this._trigger = triggerButton ?? root;\n }\n /**\n * Set the interaction type used by the select tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the select. Defaults to using the interaction type set on the select tester.\n */\n async open(opts: SelectOpenOpts = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n await this.user.click(this._trigger);\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: this._trigger, keys: '[TouchA]'});\n }\n\n await waitFor(() => {\n if (!isDisabled && trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on select element trigger.');\n } else {\n return true;\n }\n });\n let listBoxId = trigger.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 * Closes the select.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => listbox.focus());\n await this.user.keyboard('[Escape]');\n }\n\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (listbox && document.contains(listbox)) {\n throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');\n }\n }\n\n /**\n * Returns a 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 private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n if (document.activeElement === this.listbox) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\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 * Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select 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: SelectTriggerOptionOpts): Promise<void> {\n let {\n option,\n interactionType = this._interactionType\n } = opts || {};\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open();\n }\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Select\\'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 let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else {\n // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n if (!isMultiSelect && option?.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(listbox)) {\n throw new Error('Expected select element listbox to not be in the document after selecting an option');\n }\n }\n }\n }\n\n /**\n * Returns the select'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 select's trigger.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the select's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.trigger.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : null;\n }\n\n /**\n * Returns the select's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.module.js.map"}
|
package/dist/table.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAyBM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAA6D,EAAE;QACjG,IAAI,OAAC,GAAG,kBAAE,iBAAiB,WAAU,GAAG;QACxC,IAAI,SAAS,CAAA,GAAA,mCAAQ;QACrB,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,4BAA4B;QAC5B,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,aAAa,GACxF,CAAA,GAAA,8BAAE,EAAE,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EAAE,gBAAgB,cAAc,CAAC,kBAAkB,EAAE;IACpF;IAEA;;GAEC,GACD,IAAI,OAAsB;QACxB,IAAI,eAAe,IAAI,CAAC,SAAS,CAAC,EAAE;QACpC,OAAO,eAAe,CAAA,GAAA,iCAAK,EAAE,cAAc,cAAc,CAAC,SAAS,EAAE;IACvE;IAEA;;GAEC,GACD,IAAI,eAA8B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA;;GAEC,GACD,IAAI,aAA4B;QAC9B,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,KAAK,EAAE,cAAc,CAAC;IAC3C;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,KAAK,EAAC,GAAG;QAC7B,OAAO,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;IACxC;IA5bA,YAAY,IAAqB,CAAE;QACjC,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,MAAM,GAAG;IAChB;AAubF","sources":["packages/@react-aria/test-utils/src/table.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 {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\nimport {GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\n\ninterface TableToggleRowOpts extends ToggleGridRowOpts {}\ninterface TableToggleSortOpts {\n /**\n * The index, text, or node of the column to toggle selection for.\n */\n column: number | string | HTMLElement,\n /**\n * What interaction type to use when sorting the column. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Row provided is not in the table');\n }\n\n // Move focus into the table\n if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) {\n act(() => this._table.focus());\n }\n\n if (document.activeElement === this._table) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n // If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows\n if (this.rowGroups[0].contains(document.activeElement)) {\n do {\n await this.user.keyboard('[ArrowDown]');\n } while (!this.rowGroups[1].contains(document.activeElement));\n }\n\n // Move focus onto the row itself\n if (this.rowGroups[1].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('Current active element is not on any of the table rows');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getMetaKey();\n let metaKey = getMetaKey();\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 table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\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 } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, cell, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\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 table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\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 let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.main.js.map"}
|
package/dist/table.mjs
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import {getAltKey as $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d, getMetaKey as $5d1eca18f92ad0e6$export$7943c508934e27ce, pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
|
|
2
|
-
import {act as $2KUjE$act, within as $2KUjE$within, waitFor as $2KUjE$waitFor} from "@testing-library/react";
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
-
* governing permissions and limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
class $6d1e4cf220920c37$export$4c6a9d6ae3b0086 {
|
|
17
|
-
/**
|
|
18
|
-
* Set the interaction type used by the table tester.
|
|
19
|
-
*/ setInteractionType(type) {
|
|
20
|
-
this._interactionType = type;
|
|
21
|
-
}
|
|
22
|
-
// TODO: RTL
|
|
23
|
-
async keyboardNavigateToRow(opts) {
|
|
24
|
-
let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
|
|
25
|
-
let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
|
|
26
|
-
let rows = this.rows;
|
|
27
|
-
let targetIndex = rows.indexOf(row);
|
|
28
|
-
if (targetIndex === -1) throw new Error('Row provided is not in the table');
|
|
29
|
-
// Move focus into the table
|
|
30
|
-
if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) (0, $2KUjE$act)(()=>this._table.focus());
|
|
31
|
-
if (document.activeElement === this._table) await this.user.keyboard('[ArrowDown]');
|
|
32
|
-
// If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows
|
|
33
|
-
if (this.rowGroups[0].contains(document.activeElement)) do await this.user.keyboard('[ArrowDown]');
|
|
34
|
-
while (!this.rowGroups[1].contains(document.activeElement));
|
|
35
|
-
// Move focus onto the row itself
|
|
36
|
-
if (this.rowGroups[1].contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
|
|
37
|
-
while (document.activeElement.getAttribute('role') !== 'row');
|
|
38
|
-
let currIndex = rows.indexOf(document.activeElement);
|
|
39
|
-
if (currIndex === -1) throw new Error('Current active element is not on any of the table rows');
|
|
40
|
-
let direction = targetIndex > currIndex ? 'down' : 'up';
|
|
41
|
-
if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
|
|
42
|
-
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
|
|
43
|
-
if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.
|
|
47
|
-
*/ async toggleRowSelection(opts) {
|
|
48
|
-
let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
|
|
49
|
-
let altKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
|
|
50
|
-
let metaKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
|
|
51
|
-
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
52
|
-
rowIndexOrText: row
|
|
53
|
-
});
|
|
54
|
-
if (!row) throw new Error('Target row not found in the table.');
|
|
55
|
-
let rowCheckbox = (0, $2KUjE$within)(row).queryByRole('checkbox');
|
|
56
|
-
if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
|
|
57
|
-
await this.keyboardNavigateToRow({
|
|
58
|
-
row: row,
|
|
59
|
-
selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
|
|
60
|
-
});
|
|
61
|
-
if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
|
|
62
|
-
await this.user.keyboard('[Space]');
|
|
63
|
-
if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
|
|
67
|
-
else {
|
|
68
|
-
let cell = (0, $2KUjE$within)(row).getAllByRole('gridcell')[0];
|
|
69
|
-
if (needsLongPress && interactionType === 'touch') {
|
|
70
|
-
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
71
|
-
// Note that long press interactions with rows is strictly touch only for grid rows
|
|
72
|
-
await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
|
|
73
|
-
element: cell,
|
|
74
|
-
advanceTimer: this._advanceTimer,
|
|
75
|
-
pointerOpts: {
|
|
76
|
-
pointerType: 'touch'
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
} else {
|
|
80
|
-
if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
|
|
81
|
-
await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
|
|
82
|
-
if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.
|
|
88
|
-
*/ async toggleSort(opts) {
|
|
89
|
-
let { column: column, interactionType: interactionType = this._interactionType } = opts;
|
|
90
|
-
let columnheader;
|
|
91
|
-
if (typeof column === 'number') columnheader = this.columns[column];
|
|
92
|
-
else if (typeof column === 'string') {
|
|
93
|
-
columnheader = (0, $2KUjE$within)(this.rowGroups[0]).getByText(column);
|
|
94
|
-
while(columnheader && !/columnheader/.test(columnheader.getAttribute('role')))columnheader = columnheader.parentElement;
|
|
95
|
-
} else columnheader = column;
|
|
96
|
-
let menuButton = (0, $2KUjE$within)(columnheader).queryByRole('button');
|
|
97
|
-
if (menuButton) {
|
|
98
|
-
let currentSort = columnheader.getAttribute('aria-sort');
|
|
99
|
-
// TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like
|
|
100
|
-
// the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the
|
|
101
|
-
// column header except if the active element is already the menu button within the column header
|
|
102
|
-
if (interactionType === 'keyboard' && document.activeElement !== menuButton) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, columnheader, interactionType);
|
|
103
|
-
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, menuButton, interactionType);
|
|
104
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
105
|
-
if (menuButton.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on table column dropdown menu trigger element.');
|
|
106
|
-
else return true;
|
|
107
|
-
});
|
|
108
|
-
let menuId = menuButton.getAttribute('aria-controls');
|
|
109
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
110
|
-
if (!menuId || document.getElementById(menuId) == null) throw new Error(`Table column header menu with id of ${menuId} not found in document.`);
|
|
111
|
-
else return true;
|
|
112
|
-
});
|
|
113
|
-
if (menuId) {
|
|
114
|
-
let menu = document.getElementById(menuId);
|
|
115
|
-
if (menu) {
|
|
116
|
-
if (currentSort === 'ascending') await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, (0, $2KUjE$within)(menu).getAllByRole('menuitem')[1], interactionType);
|
|
117
|
-
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, (0, $2KUjE$within)(menu).getAllByRole('menuitem')[0], interactionType);
|
|
118
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
119
|
-
if (document.contains(menu)) throw new Error('Expected table column menu listbox to not be in the document after selecting an option');
|
|
120
|
-
else return true;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// Handle cases where the table may transition in response to the row selection/deselection
|
|
125
|
-
if (!this._advanceTimer) throw new Error('No advanceTimers provided for table transition.');
|
|
126
|
-
await (0, $2KUjE$act)(async ()=>{
|
|
127
|
-
var _this__advanceTimer, _this;
|
|
128
|
-
await ((_this__advanceTimer = (_this = this)._advanceTimer) === null || _this__advanceTimer === void 0 ? void 0 : _this__advanceTimer.call(_this, 200));
|
|
129
|
-
});
|
|
130
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
131
|
-
if (document.activeElement !== menuButton) throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);
|
|
132
|
-
else return true;
|
|
133
|
-
});
|
|
134
|
-
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, columnheader, interactionType);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.
|
|
138
|
-
*/ async triggerColumnHeaderAction(opts) {
|
|
139
|
-
let { column: column, interactionType: interactionType = this._interactionType, action: action } = opts;
|
|
140
|
-
let columnheader;
|
|
141
|
-
if (typeof column === 'number') columnheader = this.columns[column];
|
|
142
|
-
else if (typeof column === 'string') {
|
|
143
|
-
columnheader = (0, $2KUjE$within)(this.rowGroups[0]).getByText(column);
|
|
144
|
-
while(columnheader && !/columnheader/.test(columnheader.getAttribute('role')))columnheader = columnheader.parentElement;
|
|
145
|
-
} else columnheader = column;
|
|
146
|
-
let menuButton = (0, $2KUjE$within)(columnheader).queryByRole('button');
|
|
147
|
-
if (menuButton) {
|
|
148
|
-
// TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like
|
|
149
|
-
// the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the
|
|
150
|
-
// column header except if the active element is already the menu button within the column header
|
|
151
|
-
if (interactionType === 'keyboard' && document.activeElement !== menuButton) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, columnheader, interactionType);
|
|
152
|
-
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, menuButton, interactionType);
|
|
153
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
154
|
-
if (menuButton.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on table column dropdown menu trigger element.');
|
|
155
|
-
else return true;
|
|
156
|
-
});
|
|
157
|
-
let menuId = menuButton.getAttribute('aria-controls');
|
|
158
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
159
|
-
if (!menuId || document.getElementById(menuId) == null) throw new Error(`Table column header menu with id of ${menuId} not found in document.`);
|
|
160
|
-
else return true;
|
|
161
|
-
});
|
|
162
|
-
if (menuId) {
|
|
163
|
-
let menu = document.getElementById(menuId);
|
|
164
|
-
if (menu) {
|
|
165
|
-
await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, (0, $2KUjE$within)(menu).getAllByRole('menuitem')[action], interactionType);
|
|
166
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
167
|
-
if (document.contains(menu)) throw new Error('Expected table column menu listbox to not be in the document after selecting an option');
|
|
168
|
-
else return true;
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
// Handle cases where the table may transition in response to the row selection/deselection
|
|
173
|
-
if (!this._advanceTimer) throw new Error('No advanceTimers provided for table transition.');
|
|
174
|
-
await (0, $2KUjE$act)(async ()=>{
|
|
175
|
-
var _this__advanceTimer, _this;
|
|
176
|
-
await ((_this__advanceTimer = (_this = this)._advanceTimer) === null || _this__advanceTimer === void 0 ? void 0 : _this__advanceTimer.call(_this, 200));
|
|
177
|
-
});
|
|
178
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
179
|
-
if (document.activeElement !== menuButton) throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);
|
|
180
|
-
else return true;
|
|
181
|
-
});
|
|
182
|
-
} else throw new Error('No menu button found on table column header.');
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.
|
|
186
|
-
*/ async triggerRowAction(opts) {
|
|
187
|
-
let { row: row, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
188
|
-
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
189
|
-
rowIndexOrText: row
|
|
190
|
-
});
|
|
191
|
-
if (!row) throw new Error('Target row not found in the table.');
|
|
192
|
-
if (needsDoubleClick) await this.user.dblClick(row);
|
|
193
|
-
else if (interactionType === 'keyboard') {
|
|
194
|
-
await this.keyboardNavigateToRow({
|
|
195
|
-
row: row,
|
|
196
|
-
selectionOnNav: 'none'
|
|
197
|
-
});
|
|
198
|
-
await this.user.keyboard('[Enter]');
|
|
199
|
-
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
|
|
200
|
-
}
|
|
201
|
-
// TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.
|
|
202
|
-
// For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend
|
|
203
|
-
// on the mocks the user sets up for their row height/etc.
|
|
204
|
-
// Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really
|
|
205
|
-
// add much value if we provide that to them
|
|
206
|
-
/**
|
|
207
|
-
* Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.
|
|
208
|
-
*/ async toggleSelectAll(opts = {}) {
|
|
209
|
-
let { interactionType: interactionType = this._interactionType } = opts;
|
|
210
|
-
let checkbox = (0, $2KUjE$within)(this.table).getByLabelText('Select All');
|
|
211
|
-
if (interactionType === 'keyboard') // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.
|
|
212
|
-
await this.user.click(checkbox);
|
|
213
|
-
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, checkbox, interactionType);
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Returns a row matching the specified index or text content.
|
|
217
|
-
*/ findRow(opts) {
|
|
218
|
-
let { rowIndexOrText: rowIndexOrText } = opts;
|
|
219
|
-
let row;
|
|
220
|
-
let rows = this.rows;
|
|
221
|
-
let bodyRowGroup = this.rowGroups[1];
|
|
222
|
-
if (typeof rowIndexOrText === 'number') row = rows[rowIndexOrText];
|
|
223
|
-
else if (typeof rowIndexOrText === 'string') {
|
|
224
|
-
row = (0, $2KUjE$within)(bodyRowGroup).getByText(rowIndexOrText);
|
|
225
|
-
while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
|
|
226
|
-
}
|
|
227
|
-
return row;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Returns a cell matching the specified text content.
|
|
231
|
-
*/ findCell(opts) {
|
|
232
|
-
let { text: text } = opts;
|
|
233
|
-
let cell = (0, $2KUjE$within)(this.table).getByText(text);
|
|
234
|
-
if (cell) while(cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')){
|
|
235
|
-
if (cell.parentElement) cell = cell.parentElement;
|
|
236
|
-
else break;
|
|
237
|
-
}
|
|
238
|
-
return cell;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Returns the table.
|
|
242
|
-
*/ get table() {
|
|
243
|
-
return this._table;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Returns the row groups within the table.
|
|
247
|
-
*/ get rowGroups() {
|
|
248
|
-
let table = this._table;
|
|
249
|
-
return table ? (0, $2KUjE$within)(table).queryAllByRole('rowgroup') : [];
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Returns the columns within the table.
|
|
253
|
-
*/ get columns() {
|
|
254
|
-
let headerRowGroup = this.rowGroups[0];
|
|
255
|
-
return headerRowGroup ? (0, $2KUjE$within)(headerRowGroup).queryAllByRole('columnheader') : [];
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Returns the rows within the table if any.
|
|
259
|
-
*/ get rows() {
|
|
260
|
-
let bodyRowGroup = this.rowGroups[1];
|
|
261
|
-
return bodyRowGroup ? (0, $2KUjE$within)(bodyRowGroup).queryAllByRole('row') : [];
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Returns the currently selected rows within the table if any.
|
|
265
|
-
*/ get selectedRows() {
|
|
266
|
-
return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Returns the row headers within the table if any.
|
|
270
|
-
*/ get rowHeaders() {
|
|
271
|
-
return (0, $2KUjE$within)(this.table).queryAllByRole('rowheader');
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.
|
|
275
|
-
*/ cells(opts = {}) {
|
|
276
|
-
let { element: element = this.table } = opts;
|
|
277
|
-
return (0, $2KUjE$within)(element).queryAllByRole('gridcell');
|
|
278
|
-
}
|
|
279
|
-
constructor(opts){
|
|
280
|
-
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
281
|
-
this.user = user;
|
|
282
|
-
this._interactionType = interactionType || 'mouse';
|
|
283
|
-
this._advanceTimer = advanceTimer;
|
|
284
|
-
this._table = root;
|
|
285
|
-
}
|
|
286
|
-
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;QAC7B,OAAO,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;IACxC;IA5bA,YAAY,IAAqB,CAAE;QACjC,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,MAAM,GAAG;IAChB;AAubF","sources":["packages/@react-aria/test-utils/src/table.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 {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\nimport {GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\n\ninterface TableToggleRowOpts extends ToggleGridRowOpts {}\ninterface TableToggleSortOpts {\n /**\n * The index, text, or node of the column to toggle selection for.\n */\n column: number | string | HTMLElement,\n /**\n * What interaction type to use when sorting the column. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Row provided is not in the table');\n }\n\n // Move focus into the table\n if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) {\n act(() => this._table.focus());\n }\n\n if (document.activeElement === this._table) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n // If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows\n if (this.rowGroups[0].contains(document.activeElement)) {\n do {\n await this.user.keyboard('[ArrowDown]');\n } while (!this.rowGroups[1].contains(document.activeElement));\n }\n\n // Move focus onto the row itself\n if (this.rowGroups[1].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('Current active element is not on any of the table rows');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getMetaKey();\n let metaKey = getMetaKey();\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 table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\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 } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, cell, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\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 table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\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 let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.module.js.map"}
|