@react-aria/test-utils 1.0.0-nightly.5041 → 1.0.0-rc.0

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 (124) hide show
  1. package/README.md +70 -0
  2. package/dist/import.mjs +6 -4
  3. package/dist/main.js +15 -23
  4. package/dist/main.js.map +1 -1
  5. package/dist/module.js +6 -4
  6. package/dist/module.js.map +1 -1
  7. package/dist/private/act.cjs +33 -0
  8. package/dist/private/act.cjs.map +1 -0
  9. package/dist/private/act.js +28 -0
  10. package/dist/private/act.js.map +1 -0
  11. package/dist/private/checkboxgroup.cjs +107 -0
  12. package/dist/private/checkboxgroup.cjs.map +1 -0
  13. package/dist/private/checkboxgroup.js +102 -0
  14. package/dist/private/checkboxgroup.js.map +1 -0
  15. package/dist/private/combobox.cjs +199 -0
  16. package/dist/private/combobox.cjs.map +1 -0
  17. package/dist/private/combobox.js +194 -0
  18. package/dist/private/combobox.js.map +1 -0
  19. package/dist/private/dialog.cjs +110 -0
  20. package/dist/private/dialog.cjs.map +1 -0
  21. package/dist/private/dialog.js +105 -0
  22. package/dist/private/dialog.js.map +1 -0
  23. package/dist/private/gridlist.cjs +173 -0
  24. package/dist/private/gridlist.cjs.map +1 -0
  25. package/dist/private/gridlist.js +168 -0
  26. package/dist/private/gridlist.js.map +1 -0
  27. package/dist/private/listbox.cjs +163 -0
  28. package/dist/private/listbox.cjs.map +1 -0
  29. package/dist/private/listbox.js +158 -0
  30. package/dist/private/listbox.js.map +1 -0
  31. package/dist/private/menu.cjs +265 -0
  32. package/dist/private/menu.cjs.map +1 -0
  33. package/dist/private/menu.js +260 -0
  34. package/dist/private/menu.js.map +1 -0
  35. package/dist/private/radiogroup.cjs +122 -0
  36. package/dist/private/radiogroup.cjs.map +1 -0
  37. package/dist/private/radiogroup.js +117 -0
  38. package/dist/private/radiogroup.js.map +1 -0
  39. package/dist/private/select.cjs +169 -0
  40. package/dist/private/select.cjs.map +1 -0
  41. package/dist/private/select.js +164 -0
  42. package/dist/private/select.js.map +1 -0
  43. package/dist/private/table.cjs +346 -0
  44. package/dist/private/table.cjs.map +1 -0
  45. package/dist/private/table.js +341 -0
  46. package/dist/private/table.js.map +1 -0
  47. package/dist/private/tabs.cjs +131 -0
  48. package/dist/private/tabs.cjs.map +1 -0
  49. package/dist/private/tabs.js +126 -0
  50. package/dist/private/tabs.js.map +1 -0
  51. package/dist/private/testSetup.cjs +87 -0
  52. package/dist/private/testSetup.cjs.map +1 -0
  53. package/dist/private/testSetup.js +81 -0
  54. package/dist/private/testSetup.js.map +1 -0
  55. package/dist/private/tree.cjs +181 -0
  56. package/dist/private/tree.cjs.map +1 -0
  57. package/dist/private/tree.js +176 -0
  58. package/dist/private/tree.js.map +1 -0
  59. package/dist/private/user.cjs +85 -0
  60. package/dist/private/user.cjs.map +1 -0
  61. package/dist/private/user.js +76 -0
  62. package/dist/private/user.js.map +1 -0
  63. package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
  64. package/dist/private/userEventMaps.cjs.map +1 -0
  65. package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
  66. package/dist/private/userEventMaps.js.map +1 -0
  67. package/dist/private/utils.cjs +136 -0
  68. package/dist/private/utils.cjs.map +1 -0
  69. package/dist/private/utils.js +127 -0
  70. package/dist/private/utils.js.map +1 -0
  71. package/dist/types/src/act.d.ts +4 -0
  72. package/dist/types/src/checkboxgroup.d.ts +47 -0
  73. package/dist/types/src/combobox.d.ts +87 -0
  74. package/dist/types/src/dialog.d.ts +37 -0
  75. package/dist/types/src/events.d.ts +25 -0
  76. package/dist/types/src/gridlist.d.ts +56 -0
  77. package/dist/types/src/index.d.ts +16 -0
  78. package/dist/types/src/listbox.d.ts +91 -0
  79. package/dist/types/src/menu.d.ts +112 -0
  80. package/dist/types/src/radiogroup.d.ts +47 -0
  81. package/dist/types/src/select.d.ts +74 -0
  82. package/dist/types/src/table.d.ts +120 -0
  83. package/dist/types/src/tabs.d.ts +59 -0
  84. package/dist/types/src/testSetup.d.ts +6 -0
  85. package/dist/types/src/tree.d.ts +62 -0
  86. package/dist/types/src/types.d.ts +143 -0
  87. package/dist/types/src/user.d.ts +49 -0
  88. package/dist/types/src/userEventMaps.d.ts +2 -0
  89. package/dist/types/src/utils.d.ts +29 -0
  90. package/package.json +26 -18
  91. package/src/act.ts +35 -0
  92. package/src/checkboxgroup.ts +165 -0
  93. package/src/combobox.ts +307 -0
  94. package/src/dialog.ts +155 -0
  95. package/src/gridlist.ts +278 -0
  96. package/src/index.ts +17 -3
  97. package/src/listbox.ts +300 -0
  98. package/src/menu.ts +479 -0
  99. package/src/radiogroup.ts +179 -0
  100. package/src/select.ts +273 -0
  101. package/src/table.ts +589 -0
  102. package/src/tabs.ts +204 -0
  103. package/src/testSetup.ts +41 -36
  104. package/src/tree.ts +290 -0
  105. package/src/types.ts +171 -0
  106. package/src/user.ts +153 -0
  107. package/src/userEventMaps.ts +1 -1
  108. package/src/utils.ts +155 -0
  109. package/dist/events.main.js +0 -37
  110. package/dist/events.main.js.map +0 -1
  111. package/dist/events.mjs +0 -31
  112. package/dist/events.module.js +0 -31
  113. package/dist/events.module.js.map +0 -1
  114. package/dist/testSetup.main.js +0 -82
  115. package/dist/testSetup.main.js.map +0 -1
  116. package/dist/testSetup.mjs +0 -76
  117. package/dist/testSetup.module.js +0 -76
  118. package/dist/testSetup.module.js.map +0 -1
  119. package/dist/types.d.ts +0 -16
  120. package/dist/types.d.ts.map +0 -1
  121. package/dist/userEventMaps.main.js.map +0 -1
  122. package/dist/userEventMaps.module.js +0 -38
  123. package/dist/userEventMaps.module.js.map +0 -1
  124. package/src/events.ts +0 -28
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA8BM,MAAM;IAKX,YAAY,IAAsB,CAAE;QAClC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IA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AAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OACE,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;aAEtB,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;YAAC,QAAQ;YAAQ,MAAM;QAAU;QAI7D,IAAI,kBAAkB,QAAQ,aAAa,WAAW,MAAM;YAC1D,MAAM,CAAA,GAAA,cAAM,EAAE;gBACZ,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,QAAQ,EAC1C,MAAM,IAAI,MACR,CAAC,yGAAyG,EAAE,SAAS,aAAa,EAAE;qBAGtI,OAAO;YAEX;YAEA,IAAI,SAAS,QAAQ,CAAC,UACpB,MAAM,IAAI,MACR;QAGN;IACF;IAEA;;;GAGC,GACD,WAAW,OAAgC,CAAC,CAAC,EAAiB;QAC5D,IAAI,WAAC,UAAU,IAAI,CAAC,UAAU,IAAG,GAAG;QACpC,IAAI,UAAU,EAAE;QAChB,IAAI,SACF,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;QAG3C,OAAO;IACT;IAEA;;GAEC,GACD,aAA0B;QACxB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA;;GAEC,GACD,aAAiC;QAC/B,IAAI,YAAY,IAAI,CAAC,UAAU,GAAG,YAAY,CAAC;QAC/C,OAAO,YAAY,SAAS,cAAc,CAAC,aAAa;IAC1D;IAEA;;GAEC,GACD,cAA6B;QAC3B,IAAI,UAAU,IAAI,CAAC,UAAU;QAC7B,OAAO,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC,WAAW,EAAE;IAC/D;AACF","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} from './act';\nimport {formatTargetNode} from './utils';\nimport {SelectTesterOpts, UserOpts} from './types';\nimport {waitFor, within} from '@testing-library/dom';\n\ninterface SelectOpenOpts {\n /**\n * What interaction type to use when opening the select. Defaults to the interaction type set on\n * the tester.\n */\n interactionType?: UserOpts['interactionType'];\n}\n\ninterface SelectTriggerOptionOpts extends SelectOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via\n * `getOptions()`.\n */\n option: number | string | HTMLElement;\n /**\n * Whether or not the select closes on selection. Depends on select implementation and\n * configuration.\n *\n * @default true\n */\n closesOnSelect?: boolean;\n}\n\nexport class SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n // Handle case where the wrapper element is provided rather than the Select's button (aka RAC)\n let buttons = within(root).queryAllByRole('button');\n let triggerButton;\n if (buttons.length === 0) {\n triggerButton = root;\n } else if (buttons.length === 1) {\n triggerButton = buttons[0];\n } else {\n triggerButton = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n this._trigger = triggerButton ?? root;\n }\n /**\n * Set the interaction type used by the select tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the select. Defaults to using the interaction type set on the select tester.\n */\n async open(opts: SelectOpenOpts = {}): Promise<void> {\n let {interactionType = this._interactionType} = opts;\n let trigger = this.getTrigger();\n let isDisabled = trigger.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n await this.user.click(this._trigger);\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: this._trigger, keys: '[TouchA]'});\n }\n\n await waitFor(() => {\n if (!isDisabled && trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on select element trigger.');\n } else {\n return true;\n }\n });\n let listBoxId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`ListBox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Closes the select.\n */\n async close(): Promise<void> {\n let listbox = this.getListbox();\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(\n `Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`\n );\n } else {\n return true;\n }\n });\n\n if (listbox && document.contains(listbox)) {\n throw new Error(\n 'Expected the select element listbox to not be in the document after closing the dropdown.'\n );\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {indexOrText: number | string}): HTMLElement {\n let {indexOrText} = opts;\n\n let option;\n let options = this.getOptions();\n let listbox = this.getListbox();\n\n if (typeof indexOrText === 'number') {\n option = options[indexOrText];\n } else if (typeof indexOrText === 'string' && listbox != null) {\n option = within(listbox!).getByText(indexOrText).closest('[role=option]')! as HTMLElement;\n }\n\n return option;\n }\n\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.getOptions();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n if (document.activeElement === this.getListbox()) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n }\n\n /**\n * Toggles the selection of the desired select option if possible. Defaults to using the\n * interaction type set on the select tester. If necessary, will open the select dropdown\n * beforehand. The desired option can be targeted via the option's node, the option's text, or the\n * option's index.\n */\n async toggleOptionSelection(opts: SelectTriggerOptionOpts): Promise<void> {\n let {option, closesOnSelect, interactionType = this._interactionType} = opts || {};\n let trigger = this.getTrigger();\n if (!trigger.getAttribute('aria-controls')) {\n await this.open();\n }\n let listbox = this.getListbox();\n if (!listbox) {\n throw new Error(\"Select's listbox not found.\");\n }\n\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({indexOrText: option});\n }\n\n if (!option) {\n throw new Error(`Target option \"${formatTargetNode(opts.option)}\" not found in the listbox.`);\n }\n\n let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';\n let isSingleSelect = !isMultiSelect;\n closesOnSelect = closesOnSelect ?? isSingleSelect;\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n throw new Error(`Cannot select disabled option \"${formatTargetNode(opts.option)}\".`);\n }\n\n if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else {\n 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 (closesOnSelect && option?.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(\n `Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`\n );\n } else {\n return true;\n }\n });\n\n if (document.contains(listbox)) {\n throw new Error(\n 'Expected select element listbox to not be in the document after selecting an option'\n );\n }\n }\n }\n\n /**\n * Returns the select's options if present. Can be filtered to a subsection of the listbox if\n * provided via `element`.\n */\n getOptions(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.getListbox()} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the select's trigger.\n */\n getTrigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the select's listbox if present.\n */\n getListbox(): HTMLElement | null {\n let listBoxId = this.getTrigger().getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : null;\n }\n\n /**\n * Returns the select's sections if present.\n */\n getSections(): HTMLElement[] {\n let listbox = this.getListbox();\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.js.map"}
@@ -0,0 +1,346 @@
1
+ var $a84d573878cc1e5e$exports = require("./act.cjs");
2
+ var $022fcf8e360befed$exports = require("./utils.cjs");
3
+ var $kIP0K$testinglibrarydom = require("@testing-library/dom");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "TableTester", function () { return $b9d4e4f005cd9015$export$4c6a9d6ae3b0086; });
11
+ /*
12
+ * Copyright 2024 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ class $b9d4e4f005cd9015$export$4c6a9d6ae3b0086 {
25
+ constructor(opts){
26
+ let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer, direction: direction } = opts;
27
+ this.user = user;
28
+ this._interactionType = interactionType || 'mouse';
29
+ this._advanceTimer = advanceTimer;
30
+ this._direction = direction || 'ltr';
31
+ this._table = root;
32
+ let role = root.getAttribute('role');
33
+ if (role !== 'grid' && role !== 'treegrid') {
34
+ let table = (0, $kIP0K$testinglibrarydom.within)(root).queryByRole('grid') || (0, $kIP0K$testinglibrarydom.within)(root).queryByRole('treegrid');
35
+ if (table) this._table = table;
36
+ }
37
+ }
38
+ /**
39
+ * Set the interaction type used by the table tester.
40
+ */ setInteractionType(type) {
41
+ this._interactionType = type;
42
+ }
43
+ async keyboardNavigateToRow(opts) {
44
+ let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
45
+ let altKey = (0, $022fcf8e360befed$exports.getAltKey)();
46
+ let rows = this.getRows();
47
+ let targetIndex = rows.indexOf(row);
48
+ if (targetIndex === -1) throw new Error('Row provided is not in the table');
49
+ // Move focus into the table
50
+ if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) (0, $a84d573878cc1e5e$exports.act)(()=>this._table.focus());
51
+ if (document.activeElement === this._table) await this.user.keyboard('[ArrowDown]');
52
+ let rowGroups = this.getRowGroups();
53
+ // If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows
54
+ if (rowGroups[0].contains(document.activeElement)) do await this.user.keyboard('[ArrowDown]');
55
+ while (!rowGroups[1].contains(document.activeElement));
56
+ // Move focus onto the row itself
57
+ let focusPrevKey = this._direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
58
+ if (rowGroups[1].contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard(`[${focusPrevKey}]`);
59
+ while (document.activeElement.getAttribute('role') !== 'row');
60
+ let currIndex = rows.indexOf(document.activeElement);
61
+ if (currIndex === -1) throw new Error('Current active element is not on any of the table rows');
62
+ let direction = targetIndex > currIndex ? 'down' : 'up';
63
+ if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
64
+ for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
65
+ if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
66
+ }
67
+ /**
68
+ * Toggles the selection for the specified table row. Defaults to using the interaction type set
69
+ * on the table tester.
70
+ */ async toggleRowSelection(opts) {
71
+ let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
72
+ let altKey = (0, $022fcf8e360befed$exports.getAltKey)();
73
+ let metaKey = (0, $022fcf8e360befed$exports.getMetaKey)();
74
+ if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
75
+ indexOrText: row
76
+ });
77
+ if (!row) throw new Error(`Target row "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.row)}" not found in the table.`);
78
+ let rowCheckbox = (0, $kIP0K$testinglibrarydom.within)(row).queryByRole('checkbox');
79
+ if (rowCheckbox?.getAttribute('disabled') === '' || row.getAttribute('aria-disabled') === 'true') throw new Error(`Cannot toggle selection on disabled row "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.row)}".`);
80
+ if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
81
+ await this.keyboardNavigateToRow({
82
+ row: row,
83
+ selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
84
+ });
85
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
86
+ await this.user.keyboard('[Space]');
87
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
88
+ return;
89
+ }
90
+ if (rowCheckbox && checkboxSelection) await (0, $022fcf8e360befed$exports.pressElement)(this.user, rowCheckbox, interactionType);
91
+ else {
92
+ let cell = (0, $kIP0K$testinglibrarydom.within)(row).getAllByRole('gridcell')[0];
93
+ if (needsLongPress && interactionType === 'touch') // Note that long press interactions with rows is strictly touch only for grid rows
94
+ await (0, $022fcf8e360befed$exports.triggerLongPress)({
95
+ element: cell,
96
+ advanceTimer: this._advanceTimer,
97
+ pointerOpts: {
98
+ pointerType: 'touch'
99
+ }
100
+ });
101
+ else {
102
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
103
+ await (0, $022fcf8e360befed$exports.pressElement)(this.user, cell, interactionType);
104
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ * Toggles the expansion for the specified tree row. Defaults to using the interaction type set on
110
+ * the tree tester.
111
+ */ async toggleRowExpansion(opts) {
112
+ let { row: row, interactionType: interactionType = this._interactionType } = opts;
113
+ if (!this.getTable().contains(document.activeElement)) await (0, $a84d573878cc1e5e$exports.act)(async ()=>{
114
+ this.getTable().focus();
115
+ });
116
+ if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
117
+ indexOrText: row
118
+ });
119
+ if (!row) throw new Error(`Target row "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.row)}" not found in the table.`);
120
+ else if (row.getAttribute('aria-expanded') == null) throw new Error(`Target row "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.row)}" is not expandable.`);
121
+ if (row.getAttribute('aria-disabled') === 'true') throw new Error(`Cannot toggle expansion on disabled row "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.row)}".`);
122
+ if (interactionType === 'mouse' || interactionType === 'touch') {
123
+ let rowExpander = (0, $kIP0K$testinglibrarydom.within)(row).getAllByRole('button')[0]; // what happens if the button is not first? how can we differentiate?
124
+ await (0, $022fcf8e360befed$exports.pressElement)(this.user, rowExpander, interactionType);
125
+ } else if (interactionType === 'keyboard') {
126
+ // note that our keyboard navigation makes sure selection isn't changes
127
+ await this.keyboardNavigateToRow({
128
+ row: row
129
+ });
130
+ let collapseKey = this._direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
131
+ let expandKey = this._direction === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
132
+ if (row.getAttribute('aria-expanded') === 'true') await this.user.keyboard(`[${collapseKey}]`);
133
+ else await this.user.keyboard(`[${expandKey}]`);
134
+ }
135
+ }
136
+ /**
137
+ * Toggles the sort order for the specified table column. Defaults to using the interaction type
138
+ * set on the table tester.
139
+ */ async toggleSort(opts) {
140
+ let { column: column, interactionType: interactionType = this._interactionType } = opts;
141
+ let columnheader;
142
+ if (typeof column === 'number') columnheader = this.getColumns()[column];
143
+ else if (typeof column === 'string') {
144
+ columnheader = (0, $kIP0K$testinglibrarydom.within)(this.getRowGroups()[0]).getByText(column);
145
+ while(columnheader && !/columnheader/.test(columnheader.getAttribute('role')))columnheader = columnheader.parentElement;
146
+ } else columnheader = column;
147
+ let menuButton = (0, $kIP0K$testinglibrarydom.within)(columnheader).queryByRole('button');
148
+ if (menuButton) {
149
+ let currentSort = columnheader.getAttribute('aria-sort');
150
+ // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like
151
+ // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the
152
+ // column header except if the active element is already the menu button within the column header
153
+ if (interactionType === 'keyboard' && document.activeElement !== menuButton) await (0, $022fcf8e360befed$exports.pressElement)(this.user, columnheader, interactionType);
154
+ else await (0, $022fcf8e360befed$exports.pressElement)(this.user, menuButton, interactionType);
155
+ await (0, $kIP0K$testinglibrarydom.waitFor)(()=>{
156
+ if (menuButton.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on table column dropdown menu trigger element.');
157
+ else return true;
158
+ });
159
+ let menuId = menuButton.getAttribute('aria-controls');
160
+ await (0, $kIP0K$testinglibrarydom.waitFor)(()=>{
161
+ if (!menuId || document.getElementById(menuId) == null) throw new Error(`Table column header menu with id of ${menuId} not found in document.`);
162
+ else return true;
163
+ });
164
+ if (menuId) {
165
+ let menu = document.getElementById(menuId);
166
+ if (menu) {
167
+ if (currentSort === 'ascending') await (0, $022fcf8e360befed$exports.pressElement)(this.user, (0, $kIP0K$testinglibrarydom.within)(menu).getAllByRole('menuitem')[1], interactionType);
168
+ else await (0, $022fcf8e360befed$exports.pressElement)(this.user, (0, $kIP0K$testinglibrarydom.within)(menu).getAllByRole('menuitem')[0], interactionType);
169
+ await (0, $kIP0K$testinglibrarydom.waitFor)(()=>{
170
+ if (document.contains(menu)) throw new Error('Expected table column menu listbox to not be in the document after selecting an option');
171
+ else return true;
172
+ });
173
+ }
174
+ }
175
+ // Handle cases where the table may transition in response to the row selection/deselection
176
+ await (0, $a84d573878cc1e5e$exports.act)(async ()=>{
177
+ await this._advanceTimer(200);
178
+ });
179
+ await (0, $kIP0K$testinglibrarydom.waitFor)(()=>{
180
+ if (document.activeElement !== menuButton) throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);
181
+ else return true;
182
+ });
183
+ } else await (0, $022fcf8e360befed$exports.pressElement)(this.user, columnheader, interactionType);
184
+ }
185
+ /**
186
+ * Triggers an action for the specified table column menu. Defaults to using the interaction type
187
+ * set on the table tester.
188
+ */ async triggerColumnHeaderAction(opts) {
189
+ let { column: column, interactionType: interactionType = this._interactionType, action: action } = opts;
190
+ let columnheader;
191
+ if (typeof column === 'number') columnheader = this.getColumns()[column];
192
+ else if (typeof column === 'string') {
193
+ columnheader = (0, $kIP0K$testinglibrarydom.within)(this.getRowGroups()[0]).getByText(column);
194
+ while(columnheader && !/columnheader/.test(columnheader.getAttribute('role')))columnheader = columnheader.parentElement;
195
+ } else columnheader = column;
196
+ let menuButton = (0, $kIP0K$testinglibrarydom.within)(columnheader).queryByRole('button');
197
+ if (menuButton) {
198
+ // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like
199
+ // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the
200
+ // column header except if the active element is already the menu button within the column header
201
+ if (interactionType === 'keyboard' && document.activeElement !== menuButton) await (0, $022fcf8e360befed$exports.pressElement)(this.user, columnheader, interactionType);
202
+ else await (0, $022fcf8e360befed$exports.pressElement)(this.user, menuButton, interactionType);
203
+ await (0, $kIP0K$testinglibrarydom.waitFor)(()=>{
204
+ if (menuButton.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on table column dropdown menu trigger element.');
205
+ else return true;
206
+ });
207
+ let menuId = menuButton.getAttribute('aria-controls');
208
+ await (0, $kIP0K$testinglibrarydom.waitFor)(()=>{
209
+ if (!menuId || document.getElementById(menuId) == null) throw new Error(`Table column header menu with id of ${menuId} not found in document.`);
210
+ else return true;
211
+ });
212
+ if (menuId) {
213
+ let menu = document.getElementById(menuId);
214
+ if (menu) {
215
+ await (0, $022fcf8e360befed$exports.pressElement)(this.user, (0, $kIP0K$testinglibrarydom.within)(menu).getAllByRole('menuitem')[action], interactionType);
216
+ await (0, $kIP0K$testinglibrarydom.waitFor)(()=>{
217
+ if (document.contains(menu)) throw new Error('Expected table column menu listbox to not be in the document after selecting an option');
218
+ else return true;
219
+ });
220
+ }
221
+ }
222
+ // Handle cases where the table may transition in response to the row selection/deselection
223
+ await (0, $a84d573878cc1e5e$exports.act)(async ()=>{
224
+ await this._advanceTimer(200);
225
+ });
226
+ await (0, $kIP0K$testinglibrarydom.waitFor)(()=>{
227
+ if (document.activeElement !== menuButton) throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);
228
+ else return true;
229
+ });
230
+ } else throw new Error('No menu button found on table column header.');
231
+ }
232
+ /**
233
+ * Triggers the action for the specified table row. Defaults to using the interaction type set on
234
+ * the table tester.
235
+ */ async triggerRowAction(opts) {
236
+ let { row: row, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
237
+ if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
238
+ indexOrText: row
239
+ });
240
+ if (!row) throw new Error(`Target row "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.row)}" not found in the table.`);
241
+ if (row.getAttribute('aria-disabled') === 'true') throw new Error(`Cannot trigger row action on disabled row "${(0, $022fcf8e360befed$exports.formatTargetNode)(opts.row)}".`);
242
+ if (needsDoubleClick) await this.user.dblClick(row);
243
+ else if (interactionType === 'keyboard') {
244
+ await this.keyboardNavigateToRow({
245
+ row: row,
246
+ selectionOnNav: 'none'
247
+ });
248
+ await this.user.keyboard('[Enter]');
249
+ } else await (0, $022fcf8e360befed$exports.pressElement)(this.user, row, interactionType);
250
+ }
251
+ // 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
252
+ // add much value if we provide that to them
253
+ /**
254
+ * Toggle selection for all rows in the table. Defaults to using the interaction type set on the
255
+ * table tester.
256
+ */ async toggleSelectAll(opts = {}) {
257
+ let { interactionType: interactionType = this._interactionType } = opts;
258
+ if (interactionType === 'keyboard') {
259
+ let metaKey = (0, $022fcf8e360befed$exports.getMetaKey)();
260
+ let table = this.getTable();
261
+ if (document.activeElement !== table && !table.contains(document.activeElement)) (0, $a84d573878cc1e5e$exports.act)(()=>table.focus());
262
+ await this.user.keyboard(`[${metaKey}>]a[/${metaKey}]`);
263
+ } else {
264
+ let checkbox = (0, $kIP0K$testinglibrarydom.within)(this.getTable()).getByLabelText('Select All');
265
+ await (0, $022fcf8e360befed$exports.pressElement)(this.user, checkbox, interactionType);
266
+ }
267
+ }
268
+ /**
269
+ * Returns a row matching the specified index or text content.
270
+ */ findRow(opts) {
271
+ let { indexOrText: indexOrText } = opts;
272
+ let row;
273
+ let rows = this.getRows();
274
+ let bodyRowGroup = this.getRowGroups()[1];
275
+ if (typeof indexOrText === 'number') row = rows[indexOrText];
276
+ else if (typeof indexOrText === 'string') {
277
+ row = (0, $kIP0K$testinglibrarydom.within)(bodyRowGroup).getByText(indexOrText);
278
+ while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
279
+ }
280
+ return row;
281
+ }
282
+ /**
283
+ * Returns a cell matching the specified text content.
284
+ */ findCell(opts) {
285
+ let { text: text } = opts;
286
+ let cell = (0, $kIP0K$testinglibrarydom.within)(this.getTable()).getByText(text);
287
+ if (cell) while(cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')){
288
+ if (cell.parentElement) cell = cell.parentElement;
289
+ else break;
290
+ }
291
+ return cell;
292
+ }
293
+ /**
294
+ * Returns the table.
295
+ */ getTable() {
296
+ return this._table;
297
+ }
298
+ /**
299
+ * Returns the row groups within the table.
300
+ */ getRowGroups() {
301
+ let table = this._table;
302
+ return table ? (0, $kIP0K$testinglibrarydom.within)(table).queryAllByRole('rowgroup') : [];
303
+ }
304
+ /**
305
+ * Returns the columns within the table.
306
+ */ getColumns() {
307
+ let headerRowGroup = this.getRowGroups()[0];
308
+ return headerRowGroup ? (0, $kIP0K$testinglibrarydom.within)(headerRowGroup).queryAllByRole('columnheader') : [];
309
+ }
310
+ /**
311
+ * Returns the rows within the table if any. Can be filtered to a specific row group if provided
312
+ * via `element`.
313
+ */ getRows(opts = {}) {
314
+ let { element: element } = opts;
315
+ if (element != null) return (0, $kIP0K$testinglibrarydom.within)(element).queryAllByRole('row');
316
+ return this.getRowGroups().slice(1).flatMap((rowGroup)=>(0, $kIP0K$testinglibrarydom.within)(rowGroup).queryAllByRole('row'));
317
+ }
318
+ /**
319
+ * Returns the currently selected rows within the table if any.
320
+ */ getSelectedRows() {
321
+ return this.getRows().filter((row)=>row.getAttribute('aria-selected') === 'true');
322
+ }
323
+ /**
324
+ * Returns the footer rows within the table if any.
325
+ */ getFooterRows() {
326
+ let rowGroups = this.getRowGroups();
327
+ if (rowGroups.length < 3) return [];
328
+ let footerRowGroup = rowGroups.at(-1);
329
+ return footerRowGroup ? (0, $kIP0K$testinglibrarydom.within)(footerRowGroup).queryAllByRole('row') : [];
330
+ }
331
+ /**
332
+ * Returns the row headers within the table if any.
333
+ */ getRowHeaders() {
334
+ return (0, $kIP0K$testinglibrarydom.within)(this.getTable()).queryAllByRole('rowheader');
335
+ }
336
+ /**
337
+ * Returns the cells within the table if any. Can be filtered against a specific row if provided
338
+ * via `element`.
339
+ */ getCells(opts = {}) {
340
+ let { element: element = this.getTable() } = opts;
341
+ return (0, $kIP0K$testinglibrarydom.within)(element).queryAllByRole('gridcell');
342
+ }
343
+ }
344
+
345
+
346
+ //# sourceMappingURL=table.cjs.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;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;IAChD;IAEA;;;GAGC,GACD,SAAS,OAAgC,CAAC,CAAC,EAAiB;QAC1D,IAAI,WAAC,UAAU,IAAI,CAAC,QAAQ,IAAG,GAAG;QAClC,OAAO,CAAA,GAAA,+BAAK,EAAE,SAAS,cAAc,CAAC;IACxC;AACF","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} from './act';\nimport {\n BaseGridRowInteractionOpts,\n Direction,\n GridRowActionOpts,\n TableTesterOpts,\n ToggleGridRowOpts,\n UserOpts\n} from './types';\nimport {formatTargetNode, getAltKey, getMetaKey, pressElement, triggerLongPress} from './utils';\nimport {waitFor, within} from '@testing-library/dom';\n\ninterface TableToggleRowOpts extends ToggleGridRowOpts {}\ninterface TableToggleExpansionOpts extends BaseGridRowInteractionOpts {}\ninterface TableToggleSortOpts {\n /**\n * The index, text, or node of the column to toggle selection for.\n */\n column: number | string | HTMLElement;\n /**\n * What interaction type to use when sorting the column. Defaults to the interaction type set on\n * the tester.\n */\n interactionType?: UserOpts['interactionType'];\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number;\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _direction: Direction;\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._direction = direction || 'ltr';\n this._table = root;\n let role = root.getAttribute('role');\n if (role !== 'grid' && role !== 'treegrid') {\n let table = within(root).queryByRole('grid') || within(root).queryByRole('treegrid');\n if (table) {\n this._table = table;\n }\n }\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n private async keyboardNavigateToRow(opts: {\n row: HTMLElement;\n selectionOnNav?: 'default' | 'none';\n }) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.getRows();\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Row provided is not in the table');\n }\n\n // Move focus into the table\n if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) {\n act(() => this._table.focus());\n }\n\n if (document.activeElement === this._table) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n let rowGroups = this.getRowGroups();\n // If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows\n if (rowGroups[0].contains(document.activeElement)) {\n do {\n await this.user.keyboard('[ArrowDown]');\n } while (!rowGroups[1].contains(document.activeElement));\n }\n\n // Move focus onto the row itself\n let focusPrevKey = this._direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft';\n if (\n rowGroups[1].contains(document.activeElement) &&\n document.activeElement!.getAttribute('role') !== 'row'\n ) {\n do {\n await this.user.keyboard(`[${focusPrevKey}]`);\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Current active element is not on any of the table rows');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n }\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set\n * on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getAltKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({indexOrText: row});\n }\n\n if (!row) {\n throw new Error(`Target row \"${formatTargetNode(opts.row)}\" not found in the table.`);\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (\n rowCheckbox?.getAttribute('disabled') === '' ||\n row.getAttribute('aria-disabled') === 'true'\n ) {\n throw new Error(`Cannot toggle selection on disabled row \"${formatTargetNode(opts.row)}\".`);\n }\n\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({\n row,\n selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'\n });\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({\n element: cell,\n advanceTimer: this._advanceTimer!,\n pointerOpts: {pointerType: 'touch'}\n });\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, cell, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n }\n\n /**\n * Toggles the expansion for the specified tree row. Defaults to using the interaction type set on\n * the tree tester.\n */\n async toggleRowExpansion(opts: TableToggleExpansionOpts): Promise<void> {\n let {row, interactionType = this._interactionType} = opts;\n if (!this.getTable().contains(document.activeElement)) {\n await act(async () => {\n this.getTable().focus();\n });\n }\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({indexOrText: row});\n }\n\n if (!row) {\n throw new Error(`Target row \"${formatTargetNode(opts.row)}\" not found in the table.`);\n } else if (row.getAttribute('aria-expanded') == null) {\n throw new Error(`Target row \"${formatTargetNode(opts.row)}\" is not expandable.`);\n }\n\n if (row.getAttribute('aria-disabled') === 'true') {\n throw new Error(`Cannot toggle expansion on disabled row \"${formatTargetNode(opts.row)}\".`);\n }\n\n if (interactionType === 'mouse' || interactionType === 'touch') {\n let rowExpander = within(row).getAllByRole('button')[0]; // what happens if the button is not first? how can we differentiate?\n await pressElement(this.user, rowExpander, interactionType);\n } else if (interactionType === 'keyboard') {\n // note that our keyboard navigation makes sure selection isn't changes\n await this.keyboardNavigateToRow({row});\n let collapseKey = this._direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft';\n let expandKey = this._direction === 'rtl' ? 'ArrowLeft' : 'ArrowRight';\n if (row.getAttribute('aria-expanded') === 'true') {\n await this.user.keyboard(`[${collapseKey}]`);\n } else {\n await this.user.keyboard(`[${expandKey}]`);\n }\n }\n }\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type\n * set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {column, interactionType = this._interactionType} = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.getColumns()[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.getRowGroups()[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(\n this.user,\n within(menu).getAllByRole('menuitem')[1],\n interactionType\n );\n } else {\n await pressElement(\n this.user,\n within(menu).getAllByRole('menuitem')[0],\n interactionType\n );\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error(\n 'Expected table column menu listbox to not be in the document after selecting an option'\n );\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 await act(async () => {\n await this._advanceTimer!(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(\n `Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`\n );\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type\n * set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {column, interactionType = this._interactionType, action} = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.getColumns()[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.getRowGroups()[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(\n this.user,\n within(menu).getAllByRole('menuitem')[action],\n interactionType\n );\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error(\n 'Expected table column menu listbox to not be in the document after selecting an option'\n );\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 await act(async () => {\n await this._advanceTimer!(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(\n `Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`\n );\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on\n * the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\n let {row, needsDoubleClick, interactionType = this._interactionType} = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({indexOrText: row});\n }\n\n if (!row) {\n throw new Error(`Target row \"${formatTargetNode(opts.row)}\" not found in the table.`);\n }\n\n if (row.getAttribute('aria-disabled') === 'true') {\n throw new Error(`Cannot trigger row action on disabled row \"${formatTargetNode(opts.row)}\".`);\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the\n * table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {interactionType = this._interactionType} = opts;\n if (interactionType === 'keyboard') {\n let metaKey = getMetaKey();\n let table = this.getTable();\n if (document.activeElement !== table && !table.contains(document.activeElement)) {\n act(() => table.focus());\n }\n await this.user.keyboard(`[${metaKey}>]a[/${metaKey}]`);\n } else {\n let checkbox = within(this.getTable()).getByLabelText('Select All');\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {indexOrText: number | string}): HTMLElement {\n let {indexOrText} = opts;\n\n let row;\n let rows = this.getRows();\n let bodyRowGroup = this.getRowGroups()[1];\n if (typeof indexOrText === 'number') {\n row = rows[indexOrText];\n } else if (typeof indexOrText === 'string') {\n row = within(bodyRowGroup).getByText(indexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {text} = opts;\n\n let cell = within(this.getTable()).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n getTable(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n getRowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n getColumns(): HTMLElement[] {\n let headerRowGroup = this.getRowGroups()[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any. Can be filtered to a specific row group if provided\n * via `element`.\n */\n getRows(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element} = opts;\n if (element != null) {\n return within(element).queryAllByRole('row');\n }\n return this.getRowGroups()\n .slice(1)\n .flatMap(rowGroup => within(rowGroup).queryAllByRole('row'));\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n getSelectedRows(): HTMLElement[] {\n return this.getRows().filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the footer rows within the table if any.\n */\n getFooterRows(): HTMLElement[] {\n let rowGroups = this.getRowGroups();\n if (rowGroups.length < 3) {\n return [];\n }\n let footerRowGroup = rowGroups.at(-1);\n return footerRowGroup ? within(footerRowGroup).queryAllByRole('row') : [];\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n getRowHeaders(): HTMLElement[] {\n return within(this.getTable()).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided\n * via `element`.\n */\n getCells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.getTable()} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.cjs.map"}