@react-aria/test-utils 1.0.0-alpha.0 → 1.0.0-alpha.2

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.
Files changed (58) hide show
  1. package/dist/combobox.main.js +137 -0
  2. package/dist/combobox.main.js.map +1 -0
  3. package/dist/combobox.mjs +132 -0
  4. package/dist/combobox.module.js +132 -0
  5. package/dist/combobox.module.js.map +1 -0
  6. package/dist/events.main.js +25 -10
  7. package/dist/events.main.js.map +1 -1
  8. package/dist/events.mjs +26 -11
  9. package/dist/events.module.js +25 -10
  10. package/dist/events.module.js.map +1 -1
  11. package/dist/gridlist.main.js +97 -0
  12. package/dist/gridlist.main.js.map +1 -0
  13. package/dist/gridlist.mjs +92 -0
  14. package/dist/gridlist.module.js +92 -0
  15. package/dist/gridlist.module.js.map +1 -0
  16. package/dist/import.mjs +4 -2
  17. package/dist/main.js +10 -18
  18. package/dist/main.js.map +1 -1
  19. package/dist/menu.main.js +176 -0
  20. package/dist/menu.main.js.map +1 -0
  21. package/dist/menu.mjs +171 -0
  22. package/dist/menu.module.js +171 -0
  23. package/dist/menu.module.js.map +1 -0
  24. package/dist/module.js +4 -2
  25. package/dist/module.js.map +1 -1
  26. package/dist/select.main.js +113 -0
  27. package/dist/select.main.js.map +1 -0
  28. package/dist/select.mjs +108 -0
  29. package/dist/select.module.js +108 -0
  30. package/dist/select.module.js.map +1 -0
  31. package/dist/table.main.js +191 -0
  32. package/dist/table.main.js.map +1 -0
  33. package/dist/table.mjs +186 -0
  34. package/dist/table.module.js +186 -0
  35. package/dist/table.module.js.map +1 -0
  36. package/dist/testSetup.main.js +1 -1
  37. package/dist/testSetup.mjs +2 -2
  38. package/dist/testSetup.module.js +1 -1
  39. package/dist/types.d.ts +180 -4
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/user.main.js +65 -0
  42. package/dist/user.main.js.map +1 -0
  43. package/dist/user.mjs +56 -0
  44. package/dist/user.module.js +56 -0
  45. package/dist/user.module.js.map +1 -0
  46. package/dist/userEventMaps.main.js +15 -15
  47. package/dist/userEventMaps.mjs +16 -16
  48. package/dist/userEventMaps.module.js +15 -15
  49. package/package.json +6 -7
  50. package/src/combobox.ts +188 -0
  51. package/src/events.ts +28 -8
  52. package/src/gridlist.ts +116 -0
  53. package/src/index.ts +6 -3
  54. package/src/menu.ts +246 -0
  55. package/src/select.ts +158 -0
  56. package/src/table.ts +282 -0
  57. package/src/user.ts +73 -0
  58. package/LICENSE +0 -201
@@ -0,0 +1,97 @@
1
+ var $5a8bfe1663b8366d$exports = require("./events.main.js");
2
+ var $cgwRb$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, "GridListTester", () => $30ee8e379774bea4$export$93a85aaed9fabd83);
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 $30ee8e379774bea4$export$93a85aaed9fabd83 {
23
+ // TODO: do we really need this getter? Theoretically the user already has the reference to the gridlist
24
+ get gridlist() {
25
+ return this._gridlist;
26
+ }
27
+ get rows() {
28
+ var _this;
29
+ return (0, $cgwRb$testinglibraryreact.within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).queryAllByRole('row');
30
+ }
31
+ get selectedRows() {
32
+ return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
33
+ }
34
+ constructor(opts){
35
+ this.setInteractionType = (type)=>{
36
+ this._interactionType = type;
37
+ };
38
+ // TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share
39
+ // For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common
40
+ // If the current way of passing in the user specified advance timers is ok, then I'd be find including long press
41
+ // Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way
42
+ // the user can test a specific type of interaction?
43
+ this.toggleRowSelection = async (opts = {})=>{
44
+ let { index: index, text: text, interactionType: interactionType = this._interactionType } = opts;
45
+ let row = this.findRow({
46
+ index: index,
47
+ text: text
48
+ });
49
+ let rowCheckbox = (0, $cgwRb$testinglibraryreact.within)(row).queryByRole('checkbox');
50
+ if (rowCheckbox) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
51
+ else {
52
+ let cell = (0, $cgwRb$testinglibraryreact.within)(row).getAllByRole('gridcell')[0];
53
+ await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, cell, interactionType);
54
+ }
55
+ };
56
+ // TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for
57
+ // an element?
58
+ this.findRow = (opts)=>{
59
+ let { index: index, text: text } = opts;
60
+ let row;
61
+ if (index != null) row = this.rows[index];
62
+ else if (text != null) {
63
+ var _this;
64
+ row = (0, $cgwRb$testinglibraryreact.within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).getByText(text);
65
+ while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
66
+ }
67
+ return row;
68
+ };
69
+ // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
70
+ // user specificlly tells us
71
+ this.triggerRowAction = async (opts)=>{
72
+ let { index: index, text: text, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
73
+ let row = this.findRow({
74
+ index: index,
75
+ text: text
76
+ });
77
+ if (row) {
78
+ if (needsDoubleClick) await this.user.dblClick(row);
79
+ else if (interactionType === 'keyboard') {
80
+ (0, $cgwRb$testinglibraryreact.act)(()=>row.focus());
81
+ await this.user.keyboard('[Enter]');
82
+ } else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
83
+ }
84
+ };
85
+ this.cells = (opts = {})=>{
86
+ let { element: element } = opts;
87
+ return (0, $cgwRb$testinglibraryreact.within)(element || this.gridlist).queryAllByRole('gridcell');
88
+ };
89
+ let { root: root, user: user, interactionType: interactionType } = opts;
90
+ this.user = user;
91
+ this._interactionType = interactionType || 'mouse';
92
+ this._gridlist = root;
93
+ }
94
+ }
95
+
96
+
97
+ //# sourceMappingURL=gridlist.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IA+EX,wGAAwG;IACxG,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,SAAS;IACvB;IAEA,IAAI,OAAO;YACK;QAAd,OAAO,CAAA,GAAA,iCAAK,GAAE,QAAA,IAAI,cAAJ,4BAAA,MAAM,QAAQ,EAAE,cAAc,CAAC;IAC/C;IAEA,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IApFA,YAAY,IAAqB,CAAE;aAOnC,qBAAqB,CAAC;YACpB,IAAI,CAAC,gBAAgB,GAAG;QAC1B;QAEA,+GAA+G;QAC/G,6IAA6I;QAC7I,kHAAkH;QAClH,0HAA0H;QAC1H,oDAAoD;aACpD,qBAAqB,OAAO,OAAuF,CAAC,CAAC;YACnH,IAAI,SAAC,KAAK,QAAE,IAAI,mBAAE,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;YAE7D,IAAI,MAAM,IAAI,CAAC,OAAO,CAAC;uBAAC;sBAAO;YAAI;YACnC,IAAI,cAAc,CAAA,GAAA,iCAAK,EAAE,KAAK,WAAW,CAAC;YAC1C,IAAI,aACF,MAAM,CAAA,GAAA,sCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,aAAa;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C,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,SAAS,GAAG;IACnB;AAqFF","sources":["packages/@react-aria/test-utils/src/gridlist.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\nimport {pressElement} from './events';\n\nexport interface GridListOptions extends UserOpts, BaseTesterOpts {\n user: any\n}\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _gridlist: HTMLElement;\n\n\n constructor(opts: GridListOptions) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._gridlist = root;\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n // TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share\n // For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common\n // If the current way of passing in the user specified advance timers is ok, then I'd be find including long press\n // Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way\n // the user can test a specific type of interaction?\n toggleRowSelection = async (opts: {index?: number, text?: string, interactionType?: UserOpts['interactionType']} = {}) => {\n let {index, text, interactionType = this._interactionType} = opts;\n\n let row = this.findRow({index, text});\n let rowCheckbox = within(row).queryByRole('checkbox');\n if (rowCheckbox) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n await pressElement(this.user, cell, interactionType);\n }\n };\n\n // TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for\n // an element?\n findRow = (opts: {index?: number, text?: string}) => {\n let {\n index,\n text\n } = opts;\n\n let row;\n if (index != null) {\n row = this.rows[index];\n } else if (text != null) {\n row = within(this?.gridlist).getByText(text);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n };\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n triggerRowAction = async (opts: {index?: number, text?: string, needsDoubleClick?: boolean, interactionType?: UserOpts['interactionType']}) => {\n let {\n index,\n text,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n let row = this.findRow({index, text});\n if (row) {\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n act(() => row.focus());\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n };\n\n // TODO: do we really need this getter? Theoretically the user already has the reference to the gridlist\n get gridlist() {\n return this._gridlist;\n }\n\n get rows() {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n get selectedRows() {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n cells = (opts: {element?: HTMLElement} = {}) => {\n let {element} = opts;\n return within(element || this.gridlist).queryAllByRole('gridcell');\n };\n}\n"],"names":[],"version":3,"file":"gridlist.main.js.map"}
@@ -0,0 +1,92 @@
1
+ import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.mjs";
2
+ import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react";
3
+
4
+ /*
5
+ * Copyright 2024 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
17
+ // TODO: do we really need this getter? Theoretically the user already has the reference to the gridlist
18
+ get gridlist() {
19
+ return this._gridlist;
20
+ }
21
+ get rows() {
22
+ var _this;
23
+ return (0, $haOzD$within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).queryAllByRole('row');
24
+ }
25
+ get selectedRows() {
26
+ return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
27
+ }
28
+ constructor(opts){
29
+ this.setInteractionType = (type)=>{
30
+ this._interactionType = type;
31
+ };
32
+ // TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share
33
+ // For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common
34
+ // If the current way of passing in the user specified advance timers is ok, then I'd be find including long press
35
+ // Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way
36
+ // the user can test a specific type of interaction?
37
+ this.toggleRowSelection = async (opts = {})=>{
38
+ let { index: index, text: text, interactionType: interactionType = this._interactionType } = opts;
39
+ let row = this.findRow({
40
+ index: index,
41
+ text: text
42
+ });
43
+ let rowCheckbox = (0, $haOzD$within)(row).queryByRole('checkbox');
44
+ if (rowCheckbox) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
45
+ else {
46
+ let cell = (0, $haOzD$within)(row).getAllByRole('gridcell')[0];
47
+ await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
48
+ }
49
+ };
50
+ // TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for
51
+ // an element?
52
+ this.findRow = (opts)=>{
53
+ let { index: index, text: text } = opts;
54
+ let row;
55
+ if (index != null) row = this.rows[index];
56
+ else if (text != null) {
57
+ var _this;
58
+ row = (0, $haOzD$within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).getByText(text);
59
+ while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
60
+ }
61
+ return row;
62
+ };
63
+ // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
64
+ // user specificlly tells us
65
+ this.triggerRowAction = async (opts)=>{
66
+ let { index: index, text: text, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
67
+ let row = this.findRow({
68
+ index: index,
69
+ text: text
70
+ });
71
+ if (row) {
72
+ if (needsDoubleClick) await this.user.dblClick(row);
73
+ else if (interactionType === 'keyboard') {
74
+ (0, $haOzD$act)(()=>row.focus());
75
+ await this.user.keyboard('[Enter]');
76
+ } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
77
+ }
78
+ };
79
+ this.cells = (opts = {})=>{
80
+ let { element: element } = opts;
81
+ return (0, $haOzD$within)(element || this.gridlist).queryAllByRole('gridcell');
82
+ };
83
+ let { root: root, user: user, interactionType: interactionType } = opts;
84
+ this.user = user;
85
+ this._interactionType = interactionType || 'mouse';
86
+ this._gridlist = root;
87
+ }
88
+ }
89
+
90
+
91
+ export {$5ca9e9228f508f75$export$93a85aaed9fabd83 as GridListTester};
92
+ //# sourceMappingURL=gridlist.module.js.map
@@ -0,0 +1,92 @@
1
+ import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.module.js";
2
+ import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react";
3
+
4
+ /*
5
+ * Copyright 2024 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
17
+ // TODO: do we really need this getter? Theoretically the user already has the reference to the gridlist
18
+ get gridlist() {
19
+ return this._gridlist;
20
+ }
21
+ get rows() {
22
+ var _this;
23
+ return (0, $haOzD$within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).queryAllByRole('row');
24
+ }
25
+ get selectedRows() {
26
+ return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
27
+ }
28
+ constructor(opts){
29
+ this.setInteractionType = (type)=>{
30
+ this._interactionType = type;
31
+ };
32
+ // TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share
33
+ // For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common
34
+ // If the current way of passing in the user specified advance timers is ok, then I'd be find including long press
35
+ // Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way
36
+ // the user can test a specific type of interaction?
37
+ this.toggleRowSelection = async (opts = {})=>{
38
+ let { index: index, text: text, interactionType: interactionType = this._interactionType } = opts;
39
+ let row = this.findRow({
40
+ index: index,
41
+ text: text
42
+ });
43
+ let rowCheckbox = (0, $haOzD$within)(row).queryByRole('checkbox');
44
+ if (rowCheckbox) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
45
+ else {
46
+ let cell = (0, $haOzD$within)(row).getAllByRole('gridcell')[0];
47
+ await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
48
+ }
49
+ };
50
+ // TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for
51
+ // an element?
52
+ this.findRow = (opts)=>{
53
+ let { index: index, text: text } = opts;
54
+ let row;
55
+ if (index != null) row = this.rows[index];
56
+ else if (text != null) {
57
+ var _this;
58
+ row = (0, $haOzD$within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).getByText(text);
59
+ while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
60
+ }
61
+ return row;
62
+ };
63
+ // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
64
+ // user specificlly tells us
65
+ this.triggerRowAction = async (opts)=>{
66
+ let { index: index, text: text, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
67
+ let row = this.findRow({
68
+ index: index,
69
+ text: text
70
+ });
71
+ if (row) {
72
+ if (needsDoubleClick) await this.user.dblClick(row);
73
+ else if (interactionType === 'keyboard') {
74
+ (0, $haOzD$act)(()=>row.focus());
75
+ await this.user.keyboard('[Enter]');
76
+ } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
77
+ }
78
+ };
79
+ this.cells = (opts = {})=>{
80
+ let { element: element } = opts;
81
+ return (0, $haOzD$within)(element || this.gridlist).queryAllByRole('gridcell');
82
+ };
83
+ let { root: root, user: user, interactionType: interactionType } = opts;
84
+ this.user = user;
85
+ this._interactionType = interactionType || 'mouse';
86
+ this._gridlist = root;
87
+ }
88
+ }
89
+
90
+
91
+ export {$5ca9e9228f508f75$export$93a85aaed9fabd83 as GridListTester};
92
+ //# sourceMappingURL=gridlist.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IA+EX,wGAAwG;IACxG,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,SAAS;IACvB;IAEA,IAAI,OAAO;YACK;QAAd,OAAO,CAAA,GAAA,aAAK,GAAE,QAAA,IAAI,cAAJ,4BAAA,MAAM,QAAQ,EAAE,cAAc,CAAC;IAC/C;IAEA,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IApFA,YAAY,IAAqB,CAAE;aAOnC,qBAAqB,CAAC;YACpB,IAAI,CAAC,gBAAgB,GAAG;QAC1B;QAE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AC;qBACpB,IAAI,oBAAoB,YAAY;oBACzC,CAAA,GAAA,UAAE,EAAE,IAAM,IAAI,KAAK;oBACnB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAC3B,OACE,MAAM,CAAA,GAAA,yCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK;YAEvC;QACF;aAeA,QAAQ,CAAC,OAAgC,CAAC,CAAC;YACzC,IAAI,WAAC,OAAO,EAAC,GAAG;YAChB,OAAO,CAAA,GAAA,aAAK,EAAE,WAAW,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;QACzD;QAxFE,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,SAAS,GAAG;IACnB;AAqFF","sources":["packages/@react-aria/test-utils/src/gridlist.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\nimport {pressElement} from './events';\n\nexport interface GridListOptions extends UserOpts, BaseTesterOpts {\n user: any\n}\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _gridlist: HTMLElement;\n\n\n constructor(opts: GridListOptions) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._gridlist = root;\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n // TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share\n // For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common\n // If the current way of passing in the user specified advance timers is ok, then I'd be find including long press\n // Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way\n // the user can test a specific type of interaction?\n toggleRowSelection = async (opts: {index?: number, text?: string, interactionType?: UserOpts['interactionType']} = {}) => {\n let {index, text, interactionType = this._interactionType} = opts;\n\n let row = this.findRow({index, text});\n let rowCheckbox = within(row).queryByRole('checkbox');\n if (rowCheckbox) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n await pressElement(this.user, cell, interactionType);\n }\n };\n\n // TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for\n // an element?\n findRow = (opts: {index?: number, text?: string}) => {\n let {\n index,\n text\n } = opts;\n\n let row;\n if (index != null) {\n row = this.rows[index];\n } else if (text != null) {\n row = within(this?.gridlist).getByText(text);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n };\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n triggerRowAction = async (opts: {index?: number, text?: string, needsDoubleClick?: boolean, interactionType?: UserOpts['interactionType']}) => {\n let {\n index,\n text,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n let row = this.findRow({index, text});\n if (row) {\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n act(() => row.focus());\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n };\n\n // TODO: do we really need this getter? Theoretically the user already has the reference to the gridlist\n get gridlist() {\n return this._gridlist;\n }\n\n get rows() {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n get selectedRows() {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n cells = (opts: {element?: HTMLElement} = {}) => {\n let {element} = opts;\n return within(element || this.gridlist).queryAllByRole('gridcell');\n };\n}\n"],"names":[],"version":3,"file":"gridlist.module.js.map"}
package/dist/import.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import {DEFAULT_LONG_PRESS_TIME as $5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
1
+ import {triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
2
2
  import {installMouseEvent as $68df97871cfb5e33$export$de31e3987c917741, installPointerEvent as $68df97871cfb5e33$export$82f0b04c1d69a901} from "./testSetup.mjs";
3
3
  import {pointerMap as $50ecfb18069ec897$export$7dbde2c4caaa8d35} from "./userEventMaps.mjs";
4
+ import {User as $0d71b4e9cc4df40a$export$1f44aaf2ec115b54} from "./user.mjs";
4
5
 
5
6
  /*
6
7
  * Copyright 2023 Adobe. All rights reserved.
@@ -17,5 +18,6 @@ import {pointerMap as $50ecfb18069ec897$export$7dbde2c4caaa8d35} from "./userEve
17
18
 
18
19
 
19
20
 
20
- export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $68df97871cfb5e33$export$de31e3987c917741 as installMouseEvent, $68df97871cfb5e33$export$82f0b04c1d69a901 as installPointerEvent, $50ecfb18069ec897$export$7dbde2c4caaa8d35 as pointerMap};
21
+
22
+ export {$5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $68df97871cfb5e33$export$de31e3987c917741 as installMouseEvent, $68df97871cfb5e33$export$82f0b04c1d69a901 as installPointerEvent, $50ecfb18069ec897$export$7dbde2c4caaa8d35 as pointerMap, $0d71b4e9cc4df40a$export$1f44aaf2ec115b54 as User};
21
23
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,24 +1,18 @@
1
1
  var $5a8bfe1663b8366d$exports = require("./events.main.js");
2
2
  var $b53408e40e8d56d0$exports = require("./testSetup.main.js");
3
3
  var $0e568517a25183a7$exports = require("./userEventMaps.main.js");
4
+ var $4168d511756883ff$exports = require("./user.main.js");
4
5
 
5
6
 
6
- function $parcel$exportWildcard(dest, source) {
7
- Object.keys(source).forEach(function(key) {
8
- if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
9
- return;
10
- }
11
-
12
- Object.defineProperty(dest, key, {
13
- enumerable: true,
14
- get: function get() {
15
- return source[key];
16
- }
17
- });
18
- });
19
-
20
- return dest;
7
+ function $parcel$export(e, n, v, s) {
8
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
21
9
  }
10
+
11
+ $parcel$export(module.exports, "triggerLongPress", () => $5a8bfe1663b8366d$exports.triggerLongPress);
12
+ $parcel$export(module.exports, "installMouseEvent", () => $b53408e40e8d56d0$exports.installMouseEvent);
13
+ $parcel$export(module.exports, "installPointerEvent", () => $b53408e40e8d56d0$exports.installPointerEvent);
14
+ $parcel$export(module.exports, "pointerMap", () => $0e568517a25183a7$exports.pointerMap);
15
+ $parcel$export(module.exports, "User", () => $4168d511756883ff$exports.User);
22
16
  /*
23
17
  * Copyright 2023 Adobe. All rights reserved.
24
18
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -32,9 +26,7 @@ function $parcel$exportWildcard(dest, source) {
32
26
  */
33
27
 
34
28
 
35
- $parcel$exportWildcard(module.exports, $5a8bfe1663b8366d$exports);
36
- $parcel$exportWildcard(module.exports, $b53408e40e8d56d0$exports);
37
- $parcel$exportWildcard(module.exports, $0e568517a25183a7$exports);
29
+
38
30
 
39
31
 
40
32
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './events';\nexport * from './testSetup';\nexport * from './userEventMaps';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\n\nexport type {UserOpts} from './user';\n"],"names":[],"version":3,"file":"main.js.map"}
@@ -0,0 +1,176 @@
1
+ var $5a8bfe1663b8366d$exports = require("./events.main.js");
2
+ var $l5sJH$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, "MenuTester", () => $31965f39292c8e99$export$f73bbc9212ed861e);
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 $31965f39292c8e99$export$f73bbc9212ed861e {
23
+ get trigger() {
24
+ return this._trigger;
25
+ }
26
+ get menu() {
27
+ let menuId = this.trigger.getAttribute('aria-controls');
28
+ return menuId ? document.getElementById(menuId) : undefined;
29
+ }
30
+ get options() {
31
+ let menu = this.menu;
32
+ let options = [];
33
+ if (menu) {
34
+ options = (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('menuitem');
35
+ if (options.length === 0) {
36
+ options = (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('menuitemradio');
37
+ if (options.length === 0) options = (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('menuitemcheckbox');
38
+ }
39
+ }
40
+ return options;
41
+ }
42
+ get sections() {
43
+ let menu = this.menu;
44
+ if (menu) return (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('group');
45
+ else return [];
46
+ }
47
+ get submenuTriggers() {
48
+ let options = this.options;
49
+ if (options.length > 0) return this.options.filter((item)=>item.getAttribute('aria-haspopup') != null);
50
+ return [];
51
+ }
52
+ constructor(opts){
53
+ this.setInteractionType = (type)=>{
54
+ this._interactionType = type;
55
+ };
56
+ // TODO: this has been common to select as well, maybe make select use it? Or make a generic method. Will need to make error messages generic
57
+ // One difference will be that it supports long press as well
58
+ this.open = async (opts = {})=>{
59
+ let { needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
60
+ let trigger = this.trigger;
61
+ let isDisabled = trigger.hasAttribute('disabled');
62
+ if (interactionType === 'mouse' || interactionType === 'touch') {
63
+ if (needsLongPress) {
64
+ if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
65
+ let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';
66
+ await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
67
+ element: trigger,
68
+ advanceTimer: this._advanceTimer,
69
+ pointerOpts: {
70
+ pointerType: pointerType
71
+ }
72
+ });
73
+ } else if (interactionType === 'mouse') await this.user.click(trigger);
74
+ else await this.user.pointer({
75
+ target: trigger,
76
+ keys: '[TouchA]'
77
+ });
78
+ } else if (interactionType === 'keyboard' && !isDisabled) {
79
+ (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
80
+ await this.user.keyboard('[Enter]');
81
+ }
82
+ await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
83
+ if (trigger.getAttribute('aria-controls') == null && !isDisabled) throw new Error('No aria-controls found on menu trigger element.');
84
+ else return true;
85
+ });
86
+ if (!isDisabled) {
87
+ let menuId = trigger.getAttribute('aria-controls');
88
+ await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
89
+ if (!menuId || document.getElementById(menuId) == null) throw new Error(`Menu with id of ${menuId} not found in document.`);
90
+ else return true;
91
+ });
92
+ }
93
+ };
94
+ // TODO: also very similar to select, barring potential long press support
95
+ // Close on select is also kinda specific?
96
+ this.selectOption = async (opts)=>{
97
+ let { optionText: optionText, menuSelectionMode: menuSelectionMode = 'single', needsLongPress: needsLongPress, closesOnSelect: closesOnSelect = true, option: option, interactionType: interactionType = this._interactionType } = opts;
98
+ let trigger = this.trigger;
99
+ if (!trigger.getAttribute('aria-controls')) await this.open({
100
+ needsLongPress: needsLongPress
101
+ });
102
+ let menu = this.menu;
103
+ if (menu) {
104
+ if (!option && optionText) option = (0, $l5sJH$testinglibraryreact.within)(menu).getByText(optionText);
105
+ if (interactionType === 'keyboard') {
106
+ if (document.activeElement !== menu || !menu.contains(document.activeElement)) (0, $l5sJH$testinglibraryreact.act)(()=>menu.focus());
107
+ await this.user.keyboard(optionText);
108
+ await this.user.keyboard('[Enter]');
109
+ } else if (interactionType === 'mouse') await this.user.click(option);
110
+ else await this.user.pointer({
111
+ target: option,
112
+ keys: '[TouchA]'
113
+ });
114
+ if (option && option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect) {
115
+ await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
116
+ if (document.activeElement !== trigger) throw new Error(`Expected the document.activeElement after selecting an option to be the menu trigger but got ${document.activeElement}`);
117
+ else return true;
118
+ });
119
+ if (document.contains(menu)) throw new Error('Expected menu element to not be in the document after selecting an option');
120
+ }
121
+ } else throw new Error("Attempted to select a option in the menu, but menu wasn't found.");
122
+ };
123
+ // TODO: update this to remove needsLongPress if we wanna make the user call open first always
124
+ this.openSubmenu = async (opts)=>{
125
+ let { submenuTrigger: submenuTrigger, submenuTriggerText: submenuTriggerText, needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
126
+ let trigger = this.trigger;
127
+ let isDisabled = trigger.hasAttribute('disabled');
128
+ if (!trigger.getAttribute('aria-controls') && !isDisabled) await this.open({
129
+ needsLongPress: needsLongPress
130
+ });
131
+ if (!isDisabled) {
132
+ let menu = this.menu;
133
+ if (menu) {
134
+ let submenu;
135
+ if (submenuTrigger) submenu = submenuTrigger;
136
+ else if (submenuTriggerText) submenu = (0, $l5sJH$testinglibraryreact.within)(menu).getByText(submenuTriggerText);
137
+ let submenuTriggerTester = new $31965f39292c8e99$export$f73bbc9212ed861e({
138
+ user: this.user,
139
+ interactionType: interactionType,
140
+ root: submenu
141
+ });
142
+ await submenuTriggerTester.open();
143
+ return submenuTriggerTester;
144
+ }
145
+ }
146
+ return null;
147
+ };
148
+ this.close = async ()=>{
149
+ let menu = this.menu;
150
+ if (menu) {
151
+ (0, $l5sJH$testinglibraryreact.act)(()=>menu.focus());
152
+ await this.user.keyboard('[Escape]');
153
+ await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
154
+ if (document.activeElement !== this.trigger) throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);
155
+ else return true;
156
+ });
157
+ if (document.contains(menu)) throw new Error('Expected the menu to not be in the document after closing it.');
158
+ }
159
+ };
160
+ let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
161
+ this.user = user;
162
+ this._interactionType = interactionType || 'mouse';
163
+ this._advanceTimer = advanceTimer;
164
+ // Handle case where a submenu trigger is provided to the tester
165
+ if (root.getAttribute('role') === 'menuitem') this._trigger = root;
166
+ else {
167
+ // Handle case where element provided is a wrapper of the trigger button
168
+ let trigger = (0, $l5sJH$testinglibraryreact.within)(root).queryByRole('button');
169
+ if (trigger) this._trigger = trigger;
170
+ else this._trigger = root;
171
+ }
172
+ }
173
+ }
174
+
175
+
176
+ //# sourceMappingURL=menu.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAwLX,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAO;QACT,IAAI,SAAS,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QACvC,OAAO,SAAS,SAAS,cAAc,CAAC,UAAU;IACpD;IAEA,IAAI,UAAmC;QACrC,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,UAAU,EAAE;QAChB,IAAI,MAAM;YACR,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;YACtC,IAAI,QAAQ,MAAM,KAAK,GAAG;gBACxB,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;gBACtC,IAAI,QAAQ,MAAM,KAAK,GACrB,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;YAE1C;QACF;QAEA,OAAO;IACT;IAEA,IAAI,WAAW;QACb,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,MACF,OAAO,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;aAEnC,OAAO,EAAE;IAEb;IAEA,IAAI,kBAAkB;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AEX;gBAEA,IAAI,SAAS,QAAQ,CAAC,OACpB,MAAM,IAAI,MAAM;YAEpB;QACF;QA/KE,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QAErB,gEAAgE;QAChE,IAAI,KAAK,YAAY,CAAC,YAAY,YAChC,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,wEAAwE;YACxE,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,WAAW,CAAC;YACvC,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;iBAEhB,IAAI,CAAC,QAAQ,GAAG;QAEpB;IACF;AA0MF","sources":["packages/@react-aria/test-utils/src/menu.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';\nimport {triggerLongPress} from './events';\n\nexport interface MenuOptions extends UserOpts, BaseTesterOpts {\n user: any\n}\nexport class MenuTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _trigger: HTMLElement;\n\n constructor(opts: MenuOptions) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n\n // Handle case where a submenu trigger is provided to the tester\n if (root.getAttribute('role') === 'menuitem') {\n this._trigger = root;\n } else {\n // Handle case where element provided is a wrapper of the trigger button\n let trigger = within(root).queryByRole('button');\n if (trigger) {\n this._trigger = trigger;\n } else {\n this._trigger = root;\n }\n }\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n // TODO: this has been common to select as well, maybe make select use it? Or make a generic method. Will need to make error messages generic\n // One difference will be that it supports long press as well\n open = async (opts: {needsLongPress?: boolean, interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (interactionType === 'mouse' || interactionType === 'touch') {\n if (needsLongPress) {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';\n await triggerLongPress({element: trigger, advanceTimer: this._advanceTimer, pointerOpts: {pointerType}});\n } else if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n } else if (interactionType === 'keyboard' && !isDisabled) {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null && !isDisabled) {\n throw new Error('No aria-controls found on menu trigger element.');\n } else {\n return true;\n }\n });\n if (!isDisabled) {\n let menuId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n };\n\n // TODO: also very similar to select, barring potential long press support\n // Close on select is also kinda specific?\n selectOption = async (opts: {option?: HTMLElement, optionText?: string, menuSelectionMode?: 'single' | 'multiple', needsLongPress?: boolean, closesOnSelect?: boolean, interactionType?: UserOpts['interactionType']}) => {\n let {\n optionText,\n menuSelectionMode = 'single',\n needsLongPress,\n closesOnSelect = true,\n option,\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open({needsLongPress});\n }\n\n let menu = this.menu;\n if (menu) {\n if (!option && optionText) {\n option = within(menu).getByText(optionText);\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== menu || !menu.contains(document.activeElement)) {\n act(() => menu.focus());\n }\n\n await this.user.keyboard(optionText);\n await this.user.keyboard('[Enter]');\n } else {\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 && option.getAttribute('href') == null && option.getAttribute('aria-haspopup') == null && menuSelectionMode === 'single' && closesOnSelect) {\n await waitFor(() => {\n if (document.activeElement !== trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the menu trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(menu)) {\n throw new Error('Expected menu element to not be in the document after selecting an option');\n }\n }\n } else {\n throw new Error(\"Attempted to select a option in the menu, but menu wasn't found.\");\n }\n };\n\n // TODO: update this to remove needsLongPress if we wanna make the user call open first always\n openSubmenu = async (opts: {submenuTrigger?: HTMLElement, submenuTriggerText?: string, needsLongPress?: boolean, interactionType?: UserOpts['interactionType']}): Promise<MenuTester | null> => {\n let {\n submenuTrigger,\n submenuTriggerText,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (!trigger.getAttribute('aria-controls') && !isDisabled) {\n await this.open({needsLongPress});\n }\n if (!isDisabled) {\n let menu = this.menu;\n if (menu) {\n let submenu;\n if (submenuTrigger) {\n submenu = submenuTrigger;\n } else if (submenuTriggerText) {\n submenu = within(menu).getByText(submenuTriggerText);\n }\n\n let submenuTriggerTester = new MenuTester({user: this.user, interactionType: interactionType, root: submenu});\n await submenuTriggerTester.open();\n\n return submenuTriggerTester;\n }\n }\n\n return null;\n };\n\n close = async () => {\n let menu = this.menu;\n if (menu) {\n act(() => menu.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.activeElement !== this.trigger) {\n throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(menu)) {\n throw new Error('Expected the menu to not be in the document after closing it.');\n }\n }\n };\n\n get trigger() {\n return this._trigger;\n }\n\n get menu() {\n let menuId = this.trigger.getAttribute('aria-controls');\n return menuId ? document.getElementById(menuId) : undefined;\n }\n\n get options(): HTMLElement[] | never[] {\n let menu = this.menu;\n let options = [];\n if (menu) {\n options = within(menu).queryAllByRole('menuitem');\n if (options.length === 0) {\n options = within(menu).queryAllByRole('menuitemradio');\n if (options.length === 0) {\n options = within(menu).queryAllByRole('menuitemcheckbox');\n }\n }\n }\n\n return options;\n }\n\n get sections() {\n let menu = this.menu;\n if (menu) {\n return within(menu).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n get submenuTriggers() {\n let options = this.options;\n if (options.length > 0) {\n return this.options.filter(item => item.getAttribute('aria-haspopup') != null);\n }\n\n return [];\n }\n}\n"],"names":[],"version":3,"file":"menu.main.js.map"}