@react-aria/test-utils 1.0.0-alpha.1 → 1.0.0-alpha.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/combobox.main.js +137 -0
- package/dist/combobox.main.js.map +1 -0
- package/dist/combobox.mjs +132 -0
- package/dist/combobox.module.js +132 -0
- package/dist/combobox.module.js.map +1 -0
- package/dist/events.main.js +25 -10
- package/dist/events.main.js.map +1 -1
- package/dist/events.mjs +25 -10
- package/dist/events.module.js +25 -10
- package/dist/events.module.js.map +1 -1
- package/dist/gridlist.main.js +97 -0
- package/dist/gridlist.main.js.map +1 -0
- package/dist/gridlist.mjs +92 -0
- package/dist/gridlist.module.js +92 -0
- package/dist/gridlist.module.js.map +1 -0
- package/dist/import.mjs +4 -2
- package/dist/main.js +10 -18
- package/dist/main.js.map +1 -1
- package/dist/menu.main.js +220 -0
- package/dist/menu.main.js.map +1 -0
- package/dist/menu.mjs +215 -0
- package/dist/menu.module.js +215 -0
- package/dist/menu.module.js.map +1 -0
- package/dist/module.js +4 -2
- package/dist/module.js.map +1 -1
- package/dist/select.main.js +113 -0
- package/dist/select.main.js.map +1 -0
- package/dist/select.mjs +108 -0
- package/dist/select.module.js +108 -0
- package/dist/select.module.js.map +1 -0
- package/dist/table.main.js +187 -0
- package/dist/table.main.js.map +1 -0
- package/dist/table.mjs +182 -0
- package/dist/table.module.js +182 -0
- package/dist/table.module.js.map +1 -0
- package/dist/testSetup.main.js +2 -6
- package/dist/testSetup.main.js.map +1 -1
- package/dist/testSetup.mjs +2 -6
- package/dist/testSetup.module.js +2 -6
- package/dist/testSetup.module.js.map +1 -1
- package/dist/types.d.ts +186 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/user.main.js +65 -0
- package/dist/user.main.js.map +1 -0
- package/dist/user.mjs +56 -0
- package/dist/user.module.js +56 -0
- package/dist/user.module.js.map +1 -0
- package/package.json +5 -5
- package/src/combobox.ts +188 -0
- package/src/events.ts +28 -8
- package/src/gridlist.ts +116 -0
- package/src/index.ts +6 -3
- package/src/menu.ts +308 -0
- package/src/select.ts +158 -0
- package/src/table.ts +273 -0
- package/src/testSetup.ts +2 -6
- package/src/user.ts +73 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var $bBwW0$testinglibraryreact = require("@testing-library/react");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
$parcel$export(module.exports, "SelectTester", () => $b97d5a42df7c75b2$export$d1859707465446a9);
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
21
|
+
get trigger() {
|
|
22
|
+
return this._trigger;
|
|
23
|
+
}
|
|
24
|
+
get listbox() {
|
|
25
|
+
let listBoxId = this.trigger.getAttribute('aria-controls');
|
|
26
|
+
return listBoxId ? document.getElementById(listBoxId) : undefined;
|
|
27
|
+
}
|
|
28
|
+
get options() {
|
|
29
|
+
let listbox = this.listbox;
|
|
30
|
+
return listbox ? (0, $bBwW0$testinglibraryreact.within)(listbox).queryAllByRole('option') : [];
|
|
31
|
+
}
|
|
32
|
+
get sections() {
|
|
33
|
+
let listbox = this.listbox;
|
|
34
|
+
return listbox ? (0, $bBwW0$testinglibraryreact.within)(listbox).queryAllByRole('group') : [];
|
|
35
|
+
}
|
|
36
|
+
constructor(opts){
|
|
37
|
+
this.setInteractionType = (type)=>{
|
|
38
|
+
this._interactionType = type;
|
|
39
|
+
};
|
|
40
|
+
this.open = async (opts = {})=>{
|
|
41
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
42
|
+
let trigger = this.trigger;
|
|
43
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
44
|
+
if (interactionType === 'mouse') await this.user.click(this._trigger);
|
|
45
|
+
else if (interactionType === 'keyboard') {
|
|
46
|
+
(0, $bBwW0$testinglibraryreact.act)(()=>trigger.focus());
|
|
47
|
+
await this.user.keyboard('[Enter]');
|
|
48
|
+
} else if (interactionType === 'touch') await this.user.pointer({
|
|
49
|
+
target: this._trigger,
|
|
50
|
+
keys: '[TouchA]'
|
|
51
|
+
});
|
|
52
|
+
await (0, $bBwW0$testinglibraryreact.waitFor)(()=>{
|
|
53
|
+
if (!isDisabled && trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on select element trigger.');
|
|
54
|
+
else return true;
|
|
55
|
+
});
|
|
56
|
+
let listBoxId = trigger.getAttribute('aria-controls');
|
|
57
|
+
await (0, $bBwW0$testinglibraryreact.waitFor)(()=>{
|
|
58
|
+
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`ListBox with id of ${listBoxId} not found in document.`);
|
|
59
|
+
else return true;
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
this.selectOption = async (opts)=>{
|
|
63
|
+
let { optionText: optionText, interactionType: interactionType = this._interactionType } = opts || {};
|
|
64
|
+
let trigger = this.trigger;
|
|
65
|
+
if (!trigger.getAttribute('aria-controls')) await this.open();
|
|
66
|
+
let listbox = this.listbox;
|
|
67
|
+
if (listbox) {
|
|
68
|
+
let option = (0, $bBwW0$testinglibraryreact.within)(listbox).getByText(optionText);
|
|
69
|
+
if (interactionType === 'keyboard') {
|
|
70
|
+
if (document.activeElement !== listbox || !listbox.contains(document.activeElement)) (0, $bBwW0$testinglibraryreact.act)(()=>listbox.focus());
|
|
71
|
+
// TODO: this simulates typeahead, do we want to add a helper util for that? Not sure if users would really need that for
|
|
72
|
+
// their test
|
|
73
|
+
await this.user.keyboard(optionText);
|
|
74
|
+
await this.user.keyboard('[Enter]');
|
|
75
|
+
} 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)
|
|
76
|
+
if (interactionType === 'mouse') await this.user.click(option);
|
|
77
|
+
else await this.user.pointer({
|
|
78
|
+
target: option,
|
|
79
|
+
keys: '[TouchA]'
|
|
80
|
+
});
|
|
81
|
+
if (option.getAttribute('href') == null) {
|
|
82
|
+
await (0, $bBwW0$testinglibraryreact.waitFor)(()=>{
|
|
83
|
+
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}`);
|
|
84
|
+
else return true;
|
|
85
|
+
});
|
|
86
|
+
if (document.contains(listbox)) throw new Error('Expected select element listbox to not be in the document after selecting an option');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this.close = async ()=>{
|
|
91
|
+
let listbox = this.listbox;
|
|
92
|
+
if (listbox) {
|
|
93
|
+
(0, $bBwW0$testinglibraryreact.act)(()=>listbox.focus());
|
|
94
|
+
await this.user.keyboard('[Escape]');
|
|
95
|
+
}
|
|
96
|
+
await (0, $bBwW0$testinglibraryreact.waitFor)(()=>{
|
|
97
|
+
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}`);
|
|
98
|
+
else return true;
|
|
99
|
+
});
|
|
100
|
+
if (listbox && document.contains(listbox)) throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');
|
|
101
|
+
};
|
|
102
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
103
|
+
this.user = user;
|
|
104
|
+
this._interactionType = interactionType || 'mouse';
|
|
105
|
+
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
106
|
+
let triggerButton = (0, $bBwW0$testinglibraryreact.within)(root).queryByRole('button');
|
|
107
|
+
if (triggerButton == null) triggerButton = root;
|
|
108
|
+
this._trigger = triggerButton;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=select.main.js.map
|
|
@@ -0,0 +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,iCAAK,EAAE,SAAS,cAAc,CAAC,YAAY,EAAE;IAChE;IAEA,IAAI,WAAW;QACb,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,iCAAK,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,CAAC,gBAAgB,EACxC,GAAG;YACJ,IAAI,UAAU,IAAI,CAAC,OAAO;YAC1B,IAAI,aAAa,QAAQ,YAAY,CAAC;YAEtC,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ;iBAC9B,IAAI,oBAAoB,YAAY;gBACzC,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,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C,IAAI,CAAC,KAAK,CAAC;qBAEtB,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;oBAAC,QAAQ;oBAAQ,MAAM;gBAAU;gBAI7D,IAAI,OAAO,YAAY,CAAC,WAAW,MAAM;oBACvC,MAAM,CAAA,GAAA,kCAAM,EAAE;wBACZ,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,QAAQ,EAC1C,MAAM,IAAI,MAAM,CAAC,yGAAyG,EAAE,SAAS,aAAa,EAAE;6BAEpJ,OAAO;oBAEX;oBAEA,IAAI,SAAS,QAAQ,CAAC,UACpB,MAAM,IAAI,MAAM;gBAEpB;YACF;QACF;aAEA,QAAQ;YACN,IAAI,UAAU,IAAI,CAAC,OAAO;YAC1B,IAAI,SAAS;gBACX,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,KAAK;gBACvB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B;YAEA,MAAM,CAAA,GAAA,kCAAM,EAAE;gBACZ,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,QAAQ,EAC1C,MAAM,IAAI,MAAM,CAAC,iHAAiH,EAAE,SAAS,aAAa,EAAE;qBAE5J,OAAO;YAEX;YAEA,IAAI,WAAW,SAAS,QAAQ,CAAC,UAC/B,MAAM,IAAI,MAAM;QAEpB;QAhHE,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,8FAA8F;QAC9F,IAAI,gBAAgB,CAAA,GAAA,iCAAK,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.main.js.map"}
|
package/dist/select.mjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {within as $7v0pZ$within, act as $7v0pZ$act, waitFor as $7v0pZ$waitFor} 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
|
+
get trigger() {
|
|
16
|
+
return this._trigger;
|
|
17
|
+
}
|
|
18
|
+
get listbox() {
|
|
19
|
+
let listBoxId = this.trigger.getAttribute('aria-controls');
|
|
20
|
+
return listBoxId ? document.getElementById(listBoxId) : undefined;
|
|
21
|
+
}
|
|
22
|
+
get options() {
|
|
23
|
+
let listbox = this.listbox;
|
|
24
|
+
return listbox ? (0, $7v0pZ$within)(listbox).queryAllByRole('option') : [];
|
|
25
|
+
}
|
|
26
|
+
get sections() {
|
|
27
|
+
let listbox = this.listbox;
|
|
28
|
+
return listbox ? (0, $7v0pZ$within)(listbox).queryAllByRole('group') : [];
|
|
29
|
+
}
|
|
30
|
+
constructor(opts){
|
|
31
|
+
this.setInteractionType = (type)=>{
|
|
32
|
+
this._interactionType = type;
|
|
33
|
+
};
|
|
34
|
+
this.open = async (opts = {})=>{
|
|
35
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
36
|
+
let trigger = this.trigger;
|
|
37
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
38
|
+
if (interactionType === 'mouse') await this.user.click(this._trigger);
|
|
39
|
+
else if (interactionType === 'keyboard') {
|
|
40
|
+
(0, $7v0pZ$act)(()=>trigger.focus());
|
|
41
|
+
await this.user.keyboard('[Enter]');
|
|
42
|
+
} else if (interactionType === 'touch') await this.user.pointer({
|
|
43
|
+
target: this._trigger,
|
|
44
|
+
keys: '[TouchA]'
|
|
45
|
+
});
|
|
46
|
+
await (0, $7v0pZ$waitFor)(()=>{
|
|
47
|
+
if (!isDisabled && trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on select element trigger.');
|
|
48
|
+
else return true;
|
|
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]'
|
|
74
|
+
});
|
|
75
|
+
if (option.getAttribute('href') == null) {
|
|
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]');
|
|
89
|
+
}
|
|
90
|
+
await (0, $7v0pZ$waitFor)(()=>{
|
|
91
|
+
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}`);
|
|
92
|
+
else return true;
|
|
93
|
+
});
|
|
94
|
+
if (listbox && document.contains(listbox)) throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');
|
|
95
|
+
};
|
|
96
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
97
|
+
this.user = user;
|
|
98
|
+
this._interactionType = interactionType || 'mouse';
|
|
99
|
+
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
100
|
+
let triggerButton = (0, $7v0pZ$within)(root).queryByRole('button');
|
|
101
|
+
if (triggerButton == null) triggerButton = root;
|
|
102
|
+
this._trigger = triggerButton;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
export {$4350df3e19e40e36$export$d1859707465446a9 as SelectTester};
|
|
108
|
+
//# sourceMappingURL=select.module.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {within as $7v0pZ$within, act as $7v0pZ$act, waitFor as $7v0pZ$waitFor} 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
|
+
get trigger() {
|
|
16
|
+
return this._trigger;
|
|
17
|
+
}
|
|
18
|
+
get listbox() {
|
|
19
|
+
let listBoxId = this.trigger.getAttribute('aria-controls');
|
|
20
|
+
return listBoxId ? document.getElementById(listBoxId) : undefined;
|
|
21
|
+
}
|
|
22
|
+
get options() {
|
|
23
|
+
let listbox = this.listbox;
|
|
24
|
+
return listbox ? (0, $7v0pZ$within)(listbox).queryAllByRole('option') : [];
|
|
25
|
+
}
|
|
26
|
+
get sections() {
|
|
27
|
+
let listbox = this.listbox;
|
|
28
|
+
return listbox ? (0, $7v0pZ$within)(listbox).queryAllByRole('group') : [];
|
|
29
|
+
}
|
|
30
|
+
constructor(opts){
|
|
31
|
+
this.setInteractionType = (type)=>{
|
|
32
|
+
this._interactionType = type;
|
|
33
|
+
};
|
|
34
|
+
this.open = async (opts = {})=>{
|
|
35
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
36
|
+
let trigger = this.trigger;
|
|
37
|
+
let isDisabled = trigger.hasAttribute('disabled');
|
|
38
|
+
if (interactionType === 'mouse') await this.user.click(this._trigger);
|
|
39
|
+
else if (interactionType === 'keyboard') {
|
|
40
|
+
(0, $7v0pZ$act)(()=>trigger.focus());
|
|
41
|
+
await this.user.keyboard('[Enter]');
|
|
42
|
+
} else if (interactionType === 'touch') await this.user.pointer({
|
|
43
|
+
target: this._trigger,
|
|
44
|
+
keys: '[TouchA]'
|
|
45
|
+
});
|
|
46
|
+
await (0, $7v0pZ$waitFor)(()=>{
|
|
47
|
+
if (!isDisabled && trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on select element trigger.');
|
|
48
|
+
else return true;
|
|
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]'
|
|
74
|
+
});
|
|
75
|
+
if (option.getAttribute('href') == null) {
|
|
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]');
|
|
89
|
+
}
|
|
90
|
+
await (0, $7v0pZ$waitFor)(()=>{
|
|
91
|
+
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}`);
|
|
92
|
+
else return true;
|
|
93
|
+
});
|
|
94
|
+
if (listbox && document.contains(listbox)) throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');
|
|
95
|
+
};
|
|
96
|
+
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
97
|
+
this.user = user;
|
|
98
|
+
this._interactionType = interactionType || 'mouse';
|
|
99
|
+
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
100
|
+
let triggerButton = (0, $7v0pZ$within)(root).queryByRole('button');
|
|
101
|
+
if (triggerButton == null) triggerButton = root;
|
|
102
|
+
this._trigger = triggerButton;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
export {$4350df3e19e40e36$export$d1859707465446a9 as SelectTester};
|
|
108
|
+
//# sourceMappingURL=select.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AASM,MAAM;IAwHX,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ;IACt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IAAI,UAAU,IAAI,CAAC,OAAO;YAC1B,IAAI,SAAS;gBACX,CAAA,GAAA,UAAE,EAAE,IAAM,QAAQ,KAAK;gBACvB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B;YAEA,MAAM,CAAA,GAAA,cAAM,EAAE;gBACZ,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,QAAQ,EAC1C,MAAM,IAAI,MAAM,CAAC,iHAAiH,EAAE,SAAS,aAAa,EAAE;qBAE5J,OAAO;YAEX;YAEA,IAAI,WAAW,SAAS,QAAQ,CAAC,UAC/B,MAAM,IAAI,MAAM;QAEpB;QAhHE,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,8FAA8F;QAC9F,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"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
var $5a8bfe1663b8366d$exports = require("./events.main.js");
|
|
2
|
+
var $2auAU$testinglibraryreact = require("@testing-library/react");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "TableTester", () => $80a9def682ac1297$export$4c6a9d6ae3b0086);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
class $80a9def682ac1297$export$4c6a9d6ae3b0086 {
|
|
23
|
+
get table() {
|
|
24
|
+
return this._table;
|
|
25
|
+
}
|
|
26
|
+
get rowGroups() {
|
|
27
|
+
let table = this._table;
|
|
28
|
+
return table ? (0, $2auAU$testinglibraryreact.within)(table).queryAllByRole('rowgroup') : [];
|
|
29
|
+
}
|
|
30
|
+
get columns() {
|
|
31
|
+
let headerRowGroup = this.rowGroups[0];
|
|
32
|
+
return headerRowGroup ? (0, $2auAU$testinglibraryreact.within)(headerRowGroup).queryAllByRole('columnheader') : [];
|
|
33
|
+
}
|
|
34
|
+
get rows() {
|
|
35
|
+
let bodyRowGroup = this.rowGroups[1];
|
|
36
|
+
return bodyRowGroup ? (0, $2auAU$testinglibraryreact.within)(bodyRowGroup).queryAllByRole('row') : [];
|
|
37
|
+
}
|
|
38
|
+
get selectedRows() {
|
|
39
|
+
return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
|
|
40
|
+
}
|
|
41
|
+
get rowHeaders() {
|
|
42
|
+
let table = this.table;
|
|
43
|
+
return table ? (0, $2auAU$testinglibraryreact.within)(table).queryAllByRole('rowheader') : [];
|
|
44
|
+
}
|
|
45
|
+
get cells() {
|
|
46
|
+
let table = this.table;
|
|
47
|
+
return table ? (0, $2auAU$testinglibraryreact.within)(table).queryAllByRole('gridcell') : [];
|
|
48
|
+
}
|
|
49
|
+
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
|
+
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
179
|
+
this.user = user;
|
|
180
|
+
this._interactionType = interactionType || 'mouse';
|
|
181
|
+
this._advanceTimer = advanceTimer;
|
|
182
|
+
this._table = root;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=table.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAaM,MAAM;IAyNX,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM;IACpB;IAEA,IAAI,YAAY;QACd,IAAI,QAAQ,IAAI,CAAC,MAAM;QACvB,OAAO,QAAQ,CAAA,GAAA,iCAAK,EAAE,OAAO,cAAc,CAAC,cAAc,EAAE;IAC9D;IAEA,IAAI,UAAU;QACZ,IAAI,iBAAiB,IAAI,CAAC,SAAS,CAAC,EAAE;QACtC,OAAO,iBAAiB,CAAA,GAAA,iCAAK,EAAE,gBAAgB,cAAc,CAAC,kBAAkB,EAAE;IACpF;IAEA,IAAI,OAAO;QACT,IAAI,eAAe,IAAI,CAAC,SAAS,CAAC,EAAE;QACpC,OAAO,eAAe,CAAA,GAAA,iCAAK,EAAE,cAAc,cAAc,CAAC,SAAS,EAAE;IACvE;IAEA,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA,IAAI,aAAa;QACf,IAAI,QAAQ,IAAI,CAAC,KAAK;QACtB,OAAO,QAAQ,CAAA,GAAA,iCAAK,EAAE,OAAO,cAAc,CAAC,eAAe,EAAE;IAC/D;IAEA,IAAI,QAAQ;QACV,IAAI,Q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AG;IAChB;AA6OF","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, fireEvent, waitFor, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\nimport {pressElement, triggerLongPress} from './events';\nexport interface TableOptions extends UserOpts, BaseTesterOpts {\n user?: any,\n advanceTimer: UserOpts['advanceTimer']\n}\n\n// TODO: Previously used logic like https://github.com/testing-library/react-testing-library/blame/c63b873072d62c858959c2a19e68f8e2cc0b11be/src/pure.js#L16\n// but https://github.com/testing-library/dom-testing-library/issues/987#issuecomment-891901804 indicates that it may falsely indicate that fake timers are enabled\n// when they aren't\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableOptions) {\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 setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n toggleRowSelection = async (opts: {index?: number, text?: string, needsLongPress?: boolean, interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n index,\n text,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\n let row = this.findRow({index, text});\n let rowCheckbox = within(row).queryByRole('checkbox');\n if (rowCheckbox) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n 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 // TODO: interestingly enough, we need to do a followup click otherwise future row selections may not fire properly?\n // To reproduce, try removing this, forcing toggleRowSelection to hit \"needsLongPress ? await triggerLongPress(cell) : await action(cell);\" and\n // run Table.test's \"should support long press to enter selection mode on touch\" test to see what happens\n await fireEvent.click(cell);\n } else {\n await pressElement(this.user, cell, interactionType);\n }\n }\n };\n\n toggleSort = async (opts: {index?: number, text?: string, interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n index,\n text,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (index != null) {\n columnheader = this.columns[index];\n } else if (text != null) {\n columnheader = within(this.rowGroups[0]).getByText(text);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\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 // 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\n // table. Maybe we could rely on the user knowing to trigger a press/double click? We could have the user pass in \"needsDoubleClick\"\n // 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\n triggerRowAction = async (opts: {index?: number, text?: string, needsDoubleClick?: boolean, interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n index,\n text,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n let row = this.findRow({index, text});\n if (row) {\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n act(() => row.focus());\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n };\n\n // TODO: 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 toggleSelectAll = async (opts: {interactionType?: UserOpts['interactionType']} = {}) => {\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 findRow = (opts: {index?: number, text?: string} = {}) => {\n let {\n index,\n text\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (index != null) {\n row = rows[index];\n } else if (text != null) {\n row = within(bodyRowGroup).getByText(text);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n };\n\n findCell = (opts: {text: string}) => {\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 get table() {\n return this._table;\n }\n\n get rowGroups() {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n get columns() {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n get rows() {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n get selectedRows() {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n get rowHeaders() {\n let table = this.table;\n return table ? within(table).queryAllByRole('rowheader') : [];\n }\n\n get cells() {\n let table = this.table;\n return table ? within(table).queryAllByRole('gridcell') : [];\n }\n}\n"],"names":[],"version":3,"file":"table.main.js.map"}
|