@react-aria/test-utils 1.0.0-alpha.3 → 1.0.0-alpha.5
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 +42 -4
- package/dist/events.main.js.map +1 -1
- package/dist/events.mjs +42 -4
- package/dist/events.module.js +42 -4
- 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 +166 -139
- package/dist/table.main.js.map +1 -1
- package/dist/table.mjs +167 -140
- package/dist/table.module.js +167 -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 +3 -4
- package/src/combobox.ts +105 -36
- package/src/events.ts +29 -4
- 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 +130 -69
- 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/select.module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {act as $7v0pZ$act, waitFor as $7v0pZ$waitFor, within as $7v0pZ$within} from "@testing-library/react";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2024 Adobe. All rights reserved.
|
|
@@ -12,87 +12,133 @@ import {within as $7v0pZ$within, act as $7v0pZ$act, waitFor as $7v0pZ$waitFor} f
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Set the interaction type used by the select tester.
|
|
17
|
+
*/ setInteractionType(type) {
|
|
18
|
+
this._interactionType = type;
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
});
|
|
21
43
|
}
|
|
22
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Closes the select.
|
|
46
|
+
*/ async close() {
|
|
23
47
|
let listbox = this.listbox;
|
|
24
|
-
|
|
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.');
|
|
25
57
|
}
|
|
26
|
-
|
|
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();
|
|
27
64
|
let listbox = this.listbox;
|
|
28
|
-
|
|
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;
|
|
29
68
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
if (interactionType === 'keyboard') {
|
|
95
|
+
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
96
|
+
if (document.activeElement !== listbox || !listbox.contains(document.activeElement)) (0, $7v0pZ$act)(()=>listbox.focus());
|
|
97
|
+
await this.keyboardNavigateToOption({
|
|
98
|
+
option: option
|
|
99
|
+
});
|
|
41
100
|
await this.user.keyboard('[Enter]');
|
|
42
|
-
} else if (
|
|
43
|
-
|
|
101
|
+
} 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)
|
|
102
|
+
if (interactionType === 'mouse') await this.user.click(option);
|
|
103
|
+
else await this.user.pointer({
|
|
104
|
+
target: option,
|
|
44
105
|
keys: '[TouchA]'
|
|
45
106
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let listBoxId = trigger.getAttribute('aria-controls');
|
|
51
|
-
await (0, $7v0pZ$waitFor)(()=>{
|
|
52
|
-
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`ListBox with id of ${listBoxId} not found in document.`);
|
|
53
|
-
else return true;
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
this.selectOption = async (opts)=>{
|
|
57
|
-
let { optionText: optionText, interactionType: interactionType = this._interactionType } = opts || {};
|
|
58
|
-
let trigger = this.trigger;
|
|
59
|
-
if (!trigger.getAttribute('aria-controls')) await this.open();
|
|
60
|
-
let listbox = this.listbox;
|
|
61
|
-
if (listbox) {
|
|
62
|
-
let option = (0, $7v0pZ$within)(listbox).getByText(optionText);
|
|
63
|
-
if (interactionType === 'keyboard') {
|
|
64
|
-
if (document.activeElement !== listbox || !listbox.contains(document.activeElement)) (0, $7v0pZ$act)(()=>listbox.focus());
|
|
65
|
-
// TODO: this simulates typeahead, do we want to add a helper util for that? Not sure if users would really need that for
|
|
66
|
-
// their test
|
|
67
|
-
await this.user.keyboard(optionText);
|
|
68
|
-
await this.user.keyboard('[Enter]');
|
|
69
|
-
} 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)
|
|
70
|
-
if (interactionType === 'mouse') await this.user.click(option);
|
|
71
|
-
else await this.user.pointer({
|
|
72
|
-
target: option,
|
|
73
|
-
keys: '[TouchA]'
|
|
107
|
+
if ((option === null || option === void 0 ? void 0 : option.getAttribute('href')) == null) {
|
|
108
|
+
await (0, $7v0pZ$waitFor)(()=>{
|
|
109
|
+
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}`);
|
|
110
|
+
else return true;
|
|
74
111
|
});
|
|
75
|
-
if (
|
|
76
|
-
await (0, $7v0pZ$waitFor)(()=>{
|
|
77
|
-
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}`);
|
|
78
|
-
else return true;
|
|
79
|
-
});
|
|
80
|
-
if (document.contains(listbox)) throw new Error('Expected select element listbox to not be in the document after selecting an option');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
this.close = async ()=>{
|
|
85
|
-
let listbox = this.listbox;
|
|
86
|
-
if (listbox) {
|
|
87
|
-
(0, $7v0pZ$act)(()=>listbox.focus());
|
|
88
|
-
await this.user.keyboard('[Escape]');
|
|
112
|
+
if (document.contains(listbox)) throw new Error('Expected select element listbox to not be in the document after selecting an option');
|
|
89
113
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Returns the select's options if present. Can be filtered to a subsection of the listbox if provided via `element`.
|
|
118
|
+
*/ options(opts = {}) {
|
|
119
|
+
let { element: element = this.listbox } = opts;
|
|
120
|
+
let options = [];
|
|
121
|
+
if (element) options = (0, $7v0pZ$within)(element).queryAllByRole('option');
|
|
122
|
+
return options;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns the select's trigger.
|
|
126
|
+
*/ get trigger() {
|
|
127
|
+
return this._trigger;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns the select's listbox if present.
|
|
131
|
+
*/ get listbox() {
|
|
132
|
+
let listBoxId = this.trigger.getAttribute('aria-controls');
|
|
133
|
+
return listBoxId ? document.getElementById(listBoxId) : null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns the select's sections if present.
|
|
137
|
+
*/ get sections() {
|
|
138
|
+
let listbox = this.listbox;
|
|
139
|
+
return listbox ? (0, $7v0pZ$within)(listbox).queryAllByRole('group') : [];
|
|
140
|
+
}
|
|
141
|
+
constructor(opts){
|
|
96
142
|
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
97
143
|
this.user = user;
|
|
98
144
|
this._interactionType = interactionType || 'mouse';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AASM,MAAM;IAwHX,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QAC1C,OAAO,YAAY,SAAS,cAAc,CAAC,aAAa;IAC1D;IAEA,IAAI,UAAU;QACZ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC,YAAY,EAAE;IAChE;IAEA,IAAI,WAAW;QACb,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC,WAAW,EAAE;IAC/D;IApIA,YAAY,IAAmB,CAAE;aAYjC,qBAAqB,CAAC;YACpB,IAAI,CAAC,gBAAgB,GAAG;QAC1B;aAEA,OAAO,OAAO,OAAwD,CAAC,CAAC;YACtE,IAAI,mBACF,kBAAkB,IAAI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AC9F,IAAI,gBAAgB,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC;QAC7C,IAAI,iBAAiB,MACnB,gBAAgB;QAElB,IAAI,CAAC,QAAQ,GAAG;IAClB;AA2HF","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 {BaseTesterOpts, UserOpts} from './user';\n\nexport interface SelectOptions extends UserOpts, BaseTesterOpts {\n // TODO: I think the type grabbed from the testing library dist for UserEvent is breaking the build, will need to figure out a better place to grab from\n user?: any\n}\nexport class SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectOptions) {\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 triggerButton = within(root).queryByRole('button');\n if (triggerButton == null) {\n triggerButton = root;\n }\n this._trigger = triggerButton;\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n open = async (opts: {interactionType?: UserOpts['interactionType']} = {}) => {\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 selectOption = async (opts: {optionText: string, interactionType?: UserOpts['interactionType']}) => {\n let {\n optionText,\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 let option = within(listbox).getByText(optionText);\n if (interactionType === 'keyboard') {\n if (document.activeElement !== listbox || !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n\n // TODO: this simulates typeahead, do we want to add a helper util for that? Not sure if users would really need that for\n // their test\n await this.user.keyboard(optionText);\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 (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 close = async () => {\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 get trigger() {\n return this._trigger;\n }\n\n get listbox() {\n let listBoxId = this.trigger.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : undefined;\n }\n\n get options() {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('option') : [];\n }\n\n get sections() {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.module.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAmBM,MAAM;IAgBX;;GAEC,GACD,mBAAmB,IAAiC,EAAE;QACpD,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAE;QACpC,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,QAAQ,YAAY,CAAC;QACrC,MAAM,CAAA,GAAA,cAAM,EAAE;YACZ,IAAI,CAAC,cAAe,CAAA,CAAC,aAAa,SAAS,cAAc,CAAC,cAAc,IAAG,GACzE,MAAM,IAAI,MAA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This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, 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 triggerButton = within(root).queryByRole('button');\n if (triggerButton == null) {\n triggerButton = root;\n }\n this._trigger = triggerButton;\n }\n /**\n * Set the interaction type used by the select tester.\n */\n setInteractionType(type: UserOpts['interactionType']) {\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 = {}) {\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() {\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) {\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 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 (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
CHANGED
|
@@ -20,161 +20,188 @@ $parcel$export(module.exports, "TableTester", () => $80a9def682ac1297$export$4c6
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
class $80a9def682ac1297$export$4c6a9d6ae3b0086 {
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Set the interaction type used by the table tester.
|
|
25
|
+
*/ setInteractionType(type) {
|
|
26
|
+
this._interactionType = type;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.
|
|
30
|
+
*/ async toggleRowSelection(opts) {
|
|
31
|
+
let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
|
|
32
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
33
|
+
rowIndexOrText: row
|
|
34
|
+
});
|
|
35
|
+
if (!row) throw new Error('Target row not found in the table.');
|
|
36
|
+
let rowCheckbox = (0, $2auAU$testinglibraryreact.within)(row).queryByRole('checkbox');
|
|
37
|
+
if (interactionType === 'keyboard' && !checkboxSelection) {
|
|
38
|
+
// TODO: for now focus the row directly until I add keyboard navigation
|
|
39
|
+
await (0, $2auAU$testinglibraryreact.act)(async ()=>{
|
|
40
|
+
row.focus();
|
|
41
|
+
});
|
|
42
|
+
await this.user.keyboard('{Space}');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (rowCheckbox && checkboxSelection) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
|
|
46
|
+
else {
|
|
47
|
+
let cell = (0, $2auAU$testinglibraryreact.within)(row).getAllByRole('gridcell')[0];
|
|
48
|
+
if (needsLongPress && interactionType === 'touch') {
|
|
49
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
50
|
+
// Note that long press interactions with rows is strictly touch only for grid rows
|
|
51
|
+
await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
|
|
52
|
+
element: cell,
|
|
53
|
+
advanceTimer: this._advanceTimer,
|
|
54
|
+
pointerOpts: {
|
|
55
|
+
pointerType: 'touch'
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, cell, interactionType);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.
|
|
63
|
+
*/ async toggleSort(opts) {
|
|
64
|
+
let { column: column, interactionType: interactionType = this._interactionType } = opts;
|
|
65
|
+
let columnheader;
|
|
66
|
+
if (typeof column === 'number') columnheader = this.columns[column];
|
|
67
|
+
else if (typeof column === 'string') {
|
|
68
|
+
columnheader = (0, $2auAU$testinglibraryreact.within)(this.rowGroups[0]).getByText(column);
|
|
69
|
+
while(columnheader && !/columnheader/.test(columnheader.getAttribute('role')))columnheader = columnheader.parentElement;
|
|
70
|
+
} else columnheader = column;
|
|
71
|
+
let menuButton = (0, $2auAU$testinglibraryreact.within)(columnheader).queryByRole('button');
|
|
72
|
+
if (menuButton) {
|
|
73
|
+
let currentSort = columnheader.getAttribute('aria-sort');
|
|
74
|
+
// TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like
|
|
75
|
+
// the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the
|
|
76
|
+
// column header except if the active element is already the menu button within the column header
|
|
77
|
+
if (interactionType === 'keyboard' && document.activeElement !== menuButton) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, columnheader, interactionType);
|
|
78
|
+
else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, menuButton, interactionType);
|
|
79
|
+
await (0, $2auAU$testinglibraryreact.waitFor)(()=>{
|
|
80
|
+
if (menuButton.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on table column dropdown menu trigger element.');
|
|
81
|
+
else return true;
|
|
82
|
+
});
|
|
83
|
+
let menuId = menuButton.getAttribute('aria-controls');
|
|
84
|
+
await (0, $2auAU$testinglibraryreact.waitFor)(()=>{
|
|
85
|
+
if (!menuId || document.getElementById(menuId) == null) throw new Error(`Table column header menu with id of ${menuId} not found in document.`);
|
|
86
|
+
else return true;
|
|
87
|
+
});
|
|
88
|
+
if (menuId) {
|
|
89
|
+
let menu = document.getElementById(menuId);
|
|
90
|
+
if (menu) {
|
|
91
|
+
if (currentSort === 'ascending') await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, (0, $2auAU$testinglibraryreact.within)(menu).getAllByRole('menuitem')[1], interactionType);
|
|
92
|
+
else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, (0, $2auAU$testinglibraryreact.within)(menu).getAllByRole('menuitem')[0], interactionType);
|
|
93
|
+
await (0, $2auAU$testinglibraryreact.waitFor)(()=>{
|
|
94
|
+
if (document.contains(menu)) throw new Error('Expected table column menu listbox to not be in the document after selecting an option');
|
|
95
|
+
else return true;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Handle cases where the table may transition in response to the row selection/deselection
|
|
100
|
+
if (!this._advanceTimer) throw new Error('No advanceTimers provided for table transition.');
|
|
101
|
+
await (0, $2auAU$testinglibraryreact.act)(async ()=>{
|
|
102
|
+
var _this__advanceTimer, _this;
|
|
103
|
+
await ((_this__advanceTimer = (_this = this)._advanceTimer) === null || _this__advanceTimer === void 0 ? void 0 : _this__advanceTimer.call(_this, 200));
|
|
104
|
+
});
|
|
105
|
+
await (0, $2auAU$testinglibraryreact.waitFor)(()=>{
|
|
106
|
+
if (document.activeElement !== menuButton) throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);
|
|
107
|
+
else return true;
|
|
108
|
+
});
|
|
109
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, columnheader, interactionType);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.
|
|
113
|
+
*/ async triggerRowAction(opts) {
|
|
114
|
+
let { row: row, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
115
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
116
|
+
rowIndexOrText: row
|
|
117
|
+
});
|
|
118
|
+
if (!row) throw new Error('Target row not found in the table.');
|
|
119
|
+
if (needsDoubleClick) await this.user.dblClick(row);
|
|
120
|
+
else if (interactionType === 'keyboard') {
|
|
121
|
+
// TODO: add keyboard navigation instead of focusing the row directly. Will need to consider if the focus in in the columns
|
|
122
|
+
(0, $2auAU$testinglibraryreact.act)(()=>row.focus());
|
|
123
|
+
await this.user.keyboard('[Enter]');
|
|
124
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
|
|
125
|
+
}
|
|
126
|
+
// 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.
|
|
127
|
+
// 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
|
|
128
|
+
// on the mocks the user sets up for their row height/etc.
|
|
129
|
+
// 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
|
|
130
|
+
// add much value if we provide that to them
|
|
131
|
+
/**
|
|
132
|
+
* Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.
|
|
133
|
+
*/ async toggleSelectAll(opts = {}) {
|
|
134
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
135
|
+
let checkbox = (0, $2auAU$testinglibraryreact.within)(this.table).getByLabelText('Select All');
|
|
136
|
+
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.
|
|
137
|
+
await this.user.click(checkbox);
|
|
138
|
+
else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, checkbox, interactionType);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns a row matching the specified index or text content.
|
|
142
|
+
*/ findRow(opts) {
|
|
143
|
+
let { rowIndexOrText: rowIndexOrText } = opts;
|
|
144
|
+
let row;
|
|
145
|
+
let rows = this.rows;
|
|
146
|
+
let bodyRowGroup = this.rowGroups[1];
|
|
147
|
+
if (typeof rowIndexOrText === 'number') row = rows[rowIndexOrText];
|
|
148
|
+
else if (typeof rowIndexOrText === 'string') {
|
|
149
|
+
row = (0, $2auAU$testinglibraryreact.within)(bodyRowGroup).getByText(rowIndexOrText);
|
|
150
|
+
while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
|
|
151
|
+
}
|
|
152
|
+
return row;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Returns a cell matching the specified text content.
|
|
156
|
+
*/ findCell(opts) {
|
|
157
|
+
let { text: text } = opts;
|
|
158
|
+
let cell = (0, $2auAU$testinglibraryreact.within)(this.table).getByText(text);
|
|
159
|
+
if (cell) while(cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')){
|
|
160
|
+
if (cell.parentElement) cell = cell.parentElement;
|
|
161
|
+
else break;
|
|
162
|
+
}
|
|
163
|
+
return cell;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns the table.
|
|
167
|
+
*/ get table() {
|
|
24
168
|
return this._table;
|
|
25
169
|
}
|
|
26
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Returns the row groups within the table.
|
|
172
|
+
*/ get rowGroups() {
|
|
27
173
|
let table = this._table;
|
|
28
174
|
return table ? (0, $2auAU$testinglibraryreact.within)(table).queryAllByRole('rowgroup') : [];
|
|
29
175
|
}
|
|
30
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Returns the columns within the table.
|
|
178
|
+
*/ get columns() {
|
|
31
179
|
let headerRowGroup = this.rowGroups[0];
|
|
32
180
|
return headerRowGroup ? (0, $2auAU$testinglibraryreact.within)(headerRowGroup).queryAllByRole('columnheader') : [];
|
|
33
181
|
}
|
|
34
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Returns the rows within the table if any.
|
|
184
|
+
*/ get rows() {
|
|
35
185
|
let bodyRowGroup = this.rowGroups[1];
|
|
36
186
|
return bodyRowGroup ? (0, $2auAU$testinglibraryreact.within)(bodyRowGroup).queryAllByRole('row') : [];
|
|
37
187
|
}
|
|
38
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Returns the currently selected rows within the table if any.
|
|
190
|
+
*/ get selectedRows() {
|
|
39
191
|
return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
|
|
40
192
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Returns the row headers within the table if any.
|
|
195
|
+
*/ get rowHeaders() {
|
|
196
|
+
return (0, $2auAU$testinglibraryreact.within)(this.table).queryAllByRole('rowheader');
|
|
44
197
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.
|
|
200
|
+
*/ cells(opts = {}) {
|
|
201
|
+
let { element: element = this.table } = opts;
|
|
202
|
+
return (0, $2auAU$testinglibraryreact.within)(element).queryAllByRole('gridcell');
|
|
48
203
|
}
|
|
49
204
|
constructor(opts){
|
|
50
|
-
this.setInteractionType = (type)=>{
|
|
51
|
-
this._interactionType = type;
|
|
52
|
-
};
|
|
53
|
-
this.toggleRowSelection = async (opts = {})=>{
|
|
54
|
-
let { index: index, text: text, needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
|
|
55
|
-
let row = this.findRow({
|
|
56
|
-
index: index,
|
|
57
|
-
text: text
|
|
58
|
-
});
|
|
59
|
-
let rowCheckbox = (0, $2auAU$testinglibraryreact.within)(row).queryByRole('checkbox');
|
|
60
|
-
if (rowCheckbox) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
|
|
61
|
-
else {
|
|
62
|
-
let cell = (0, $2auAU$testinglibraryreact.within)(row).getAllByRole('gridcell')[0];
|
|
63
|
-
if (needsLongPress && interactionType === 'touch') {
|
|
64
|
-
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
65
|
-
// Note that long press interactions with rows is strictly touch only for grid rows
|
|
66
|
-
await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
|
|
67
|
-
element: cell,
|
|
68
|
-
advanceTimer: this._advanceTimer,
|
|
69
|
-
pointerOpts: {
|
|
70
|
-
pointerType: 'touch'
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
// TODO: interestingly enough, we need to do a followup click otherwise future row selections may not fire properly?
|
|
74
|
-
// To reproduce, try removing this, forcing toggleRowSelection to hit "needsLongPress ? await triggerLongPress(cell) : await action(cell);" and
|
|
75
|
-
// run Table.test's "should support long press to enter selection mode on touch" test to see what happens
|
|
76
|
-
await (0, $2auAU$testinglibraryreact.fireEvent).click(cell);
|
|
77
|
-
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, cell, interactionType);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
this.toggleSort = async (opts = {})=>{
|
|
81
|
-
let { index: index, text: text, interactionType: interactionType = this._interactionType } = opts;
|
|
82
|
-
let columnheader;
|
|
83
|
-
if (index != null) columnheader = this.columns[index];
|
|
84
|
-
else if (text != null) {
|
|
85
|
-
columnheader = (0, $2auAU$testinglibraryreact.within)(this.rowGroups[0]).getByText(text);
|
|
86
|
-
while(columnheader && !/columnheader/.test(columnheader.getAttribute('role')))columnheader = columnheader.parentElement;
|
|
87
|
-
}
|
|
88
|
-
let menuButton = (0, $2auAU$testinglibraryreact.within)(columnheader).queryByRole('button');
|
|
89
|
-
if (menuButton) {
|
|
90
|
-
let currentSort = columnheader.getAttribute('aria-sort');
|
|
91
|
-
// TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like
|
|
92
|
-
// the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the
|
|
93
|
-
// column header except if the active element is already the menu button within the column header
|
|
94
|
-
if (interactionType === 'keyboard' && document.activeElement !== menuButton) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, columnheader, interactionType);
|
|
95
|
-
else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, menuButton, interactionType);
|
|
96
|
-
await (0, $2auAU$testinglibraryreact.waitFor)(()=>{
|
|
97
|
-
if (menuButton.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on table column dropdown menu trigger element.');
|
|
98
|
-
else return true;
|
|
99
|
-
});
|
|
100
|
-
let menuId = menuButton.getAttribute('aria-controls');
|
|
101
|
-
await (0, $2auAU$testinglibraryreact.waitFor)(()=>{
|
|
102
|
-
if (!menuId || document.getElementById(menuId) == null) throw new Error(`Table column header menu with id of ${menuId} not found in document.`);
|
|
103
|
-
else return true;
|
|
104
|
-
});
|
|
105
|
-
if (menuId) {
|
|
106
|
-
let menu = document.getElementById(menuId);
|
|
107
|
-
if (menu) {
|
|
108
|
-
if (currentSort === 'ascending') await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, (0, $2auAU$testinglibraryreact.within)(menu).getAllByRole('menuitem')[1], interactionType);
|
|
109
|
-
else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, (0, $2auAU$testinglibraryreact.within)(menu).getAllByRole('menuitem')[0], interactionType);
|
|
110
|
-
await (0, $2auAU$testinglibraryreact.waitFor)(()=>{
|
|
111
|
-
if (document.contains(menu)) throw new Error('Expected table column menu listbox to not be in the document after selecting an option');
|
|
112
|
-
else return true;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
// Handle cases where the table may transition in response to the row selection/deselection
|
|
117
|
-
if (!this._advanceTimer) throw new Error('No advanceTimers provided for table transition.');
|
|
118
|
-
await (0, $2auAU$testinglibraryreact.act)(async ()=>{
|
|
119
|
-
var _this__advanceTimer, _this;
|
|
120
|
-
await ((_this__advanceTimer = (_this = this)._advanceTimer) === null || _this__advanceTimer === void 0 ? void 0 : _this__advanceTimer.call(_this, 200));
|
|
121
|
-
});
|
|
122
|
-
await (0, $2auAU$testinglibraryreact.waitFor)(()=>{
|
|
123
|
-
if (document.activeElement !== menuButton) throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);
|
|
124
|
-
else return true;
|
|
125
|
-
});
|
|
126
|
-
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, columnheader, interactionType);
|
|
127
|
-
};
|
|
128
|
-
// TODO: should there be a util for triggering a row action? Perhaps there should be but it would rely on the user teling us the config of the
|
|
129
|
-
// table. Maybe we could rely on the user knowing to trigger a press/double click? We could have the user pass in "needsDoubleClick"
|
|
130
|
-
// It is also iffy if there is any row selected because then the table is in selectionMode and the below actions will simply toggle row selection
|
|
131
|
-
this.triggerRowAction = async (opts = {})=>{
|
|
132
|
-
let { index: index, text: text, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
133
|
-
let row = this.findRow({
|
|
134
|
-
index: index,
|
|
135
|
-
text: text
|
|
136
|
-
});
|
|
137
|
-
if (row) {
|
|
138
|
-
if (needsDoubleClick) await this.user.dblClick(row);
|
|
139
|
-
else if (interactionType === 'keyboard') {
|
|
140
|
-
(0, $2auAU$testinglibraryreact.act)(()=>row.focus());
|
|
141
|
-
await this.user.keyboard('[Enter]');
|
|
142
|
-
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
// 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.
|
|
146
|
-
// 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
|
|
147
|
-
// on the mocks the user sets up for their row height/etc.
|
|
148
|
-
// 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
|
|
149
|
-
// add much value if we provide that to them
|
|
150
|
-
this.toggleSelectAll = async (opts = {})=>{
|
|
151
|
-
let { interactionType: interactionType = this._interactionType } = opts;
|
|
152
|
-
let checkbox = (0, $2auAU$testinglibraryreact.within)(this.table).getByLabelText('Select All');
|
|
153
|
-
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.
|
|
154
|
-
await this.user.click(checkbox);
|
|
155
|
-
else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, checkbox, interactionType);
|
|
156
|
-
};
|
|
157
|
-
this.findRow = (opts = {})=>{
|
|
158
|
-
let { index: index, text: text } = opts;
|
|
159
|
-
let row;
|
|
160
|
-
let rows = this.rows;
|
|
161
|
-
let bodyRowGroup = this.rowGroups[1];
|
|
162
|
-
if (index != null) row = rows[index];
|
|
163
|
-
else if (text != null) {
|
|
164
|
-
row = (0, $2auAU$testinglibraryreact.within)(bodyRowGroup).getByText(text);
|
|
165
|
-
while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
|
|
166
|
-
}
|
|
167
|
-
return row;
|
|
168
|
-
};
|
|
169
|
-
this.findCell = (opts)=>{
|
|
170
|
-
let { text: text } = opts;
|
|
171
|
-
let cell = (0, $2auAU$testinglibraryreact.within)(this.table).getByText(text);
|
|
172
|
-
if (cell) while(cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')){
|
|
173
|
-
if (cell.parentElement) cell = cell.parentElement;
|
|
174
|
-
else break;
|
|
175
|
-
}
|
|
176
|
-
return cell;
|
|
177
|
-
};
|
|
178
205
|
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
179
206
|
this.user = user;
|
|
180
207
|
this._interactionType = interactionType || 'mouse';
|