@react-aria/test-utils 3.0.0-nightly-e3913baaa-260422 → 3.0.0-nightly-ec7bc94b3-260424

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.
@@ -295,8 +295,7 @@ class $b9d4e4f005cd9015$export$4c6a9d6ae3b0086 {
295
295
  /**
296
296
  * Returns the rows within the table if any.
297
297
  */ get rows() {
298
- let bodyRowGroup = this.rowGroups[1];
299
- return bodyRowGroup ? (0, $kIP0K$testinglibraryreact.within)(bodyRowGroup).queryAllByRole('row') : [];
298
+ return this.rowGroups.slice(1).flatMap((rowGroup)=>(0, $kIP0K$testinglibraryreact.within)(rowGroup).queryAllByRole('row'));
300
299
  }
301
300
  /**
302
301
  * Returns the currently selected rows within the table if any.
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA0BM,MAAM;IAMX,YAAY,IAAqB,CAAE;QACjC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,MAAM,GAAG;IAChB;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAA6D,EAAE;QACjG,IAAI,OAAC,GAAG,kBAAE,iBAAiB,WAAU,GAAG;QACxC,IAAI,SAAS,CAAA,GAAA,mCAAQ;QACrB,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,4BAA4B;QAC5B,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CA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A,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA;;GAEC,GACD,IAAI,aAA4B;QAC9B,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,KAAK,EAAE,cAAc,CAAC;IAC3C;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,KAAK,EAAC,GAAG;QAC7B,OAAO,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;IACxC;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, waitFor, within} from '@testing-library/react';\nimport {BaseGridRowInteractionOpts, GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\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 the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Row provided is not in the table');\n }\n\n // Move focus into the table\n if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) {\n act(() => this._table.focus());\n }\n\n if (document.activeElement === this._table) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n // If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows\n if (this.rowGroups[0].contains(document.activeElement)) {\n do {\n await this.user.keyboard('[ArrowDown]');\n } while (!this.rowGroups[1].contains(document.activeElement));\n }\n\n // Move focus onto the row itself\n if (this.rowGroups[1].contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Current active element is not on any of the table rows');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getMetaKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, cell, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n };\n\n /**\n * Toggles the expansion for the specified tree row. Defaults to using the interaction type set on the tree tester.\n */\n async toggleRowExpansion(opts: TableToggleExpansionOpts): Promise<void> {\n let {\n row,\n interactionType = this._interactionType\n } = opts;\n if (!this.table.contains(document.activeElement)) {\n await act(async () => {\n this.table.focus();\n });\n }\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n } else if (row.getAttribute('aria-expanded') == null) {\n throw new Error('Target row is not expandable.');\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 if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n // TODO: We always Use Option/Ctrl when keyboard navigating so selection isn't changed\n // in selectionmode=\"replace\"/highlight selection when navigating to the row that the user wants\n // to expand. Discuss if this is useful or not\n await this.keyboardNavigateToRow({row});\n if (row.getAttribute('aria-expanded') === 'true') {\n await this.user.keyboard('[ArrowLeft]');\n } else {\n await this.user.keyboard('[ArrowRight]');\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.cjs.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA0BM,MAAM;IAMX,YAAY,IAAqB,CAAE;QACjC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,MAAM,GAAG;IAChB;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAA6D,EAAE;QACjG,IAAI,OAAC,GAAG,kBAAE,iBAAiB,WAAU,GAAG;QACxC,IAAI,SAAS,CAAA,GAAA,mCAAQ;QACrB,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,4BAA4B;QAC5B,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,aAAa,GACxF,CAAA,GAAA,8BAAE,EAAE,IAAM,IAAI,CAAC,MAAM,CAAC,KAAK;QAG7B,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,MAAM,EACxC,MAAM,IAAI,CAA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GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,KAAK,EAAC,GAAG;QAC7B,OAAO,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;IACxC;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, waitFor, within} from '@testing-library/react';\nimport {BaseGridRowInteractionOpts, GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\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 the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Row provided is not in the table');\n }\n\n // Move focus into the table\n if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) {\n act(() => this._table.focus());\n }\n\n if (document.activeElement === this._table) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n // If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows\n if (this.rowGroups[0].contains(document.activeElement)) {\n do {\n await this.user.keyboard('[ArrowDown]');\n } while (!this.rowGroups[1].contains(document.activeElement));\n }\n\n // Move focus onto the row itself\n if (this.rowGroups[1].contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Current active element is not on any of the table rows');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getMetaKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, cell, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n };\n\n /**\n * Toggles the expansion for the specified tree row. Defaults to using the interaction type set on the tree tester.\n */\n async toggleRowExpansion(opts: TableToggleExpansionOpts): Promise<void> {\n let {\n row,\n interactionType = this._interactionType\n } = opts;\n if (!this.table.contains(document.activeElement)) {\n await act(async () => {\n this.table.focus();\n });\n }\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n } else if (row.getAttribute('aria-expanded') == null) {\n throw new Error('Target row is not expandable.');\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 if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n // TODO: We always Use Option/Ctrl when keyboard navigating so selection isn't changed\n // in selectionmode=\"replace\"/highlight selection when navigating to the row that the user wants\n // to expand. Discuss if this is useful or not\n await this.keyboardNavigateToRow({row});\n if (row.getAttribute('aria-expanded') === 'true') {\n await this.user.keyboard('[ArrowLeft]');\n } else {\n await this.user.keyboard('[ArrowRight]');\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n return this.rowGroups.slice(1).flatMap(rowGroup => within(rowGroup).queryAllByRole('row'));\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.cjs.map"}
@@ -289,8 +289,7 @@ class $196900c7f8f394b6$export$4c6a9d6ae3b0086 {
289
289
  /**
290
290
  * Returns the rows within the table if any.
291
291
  */ get rows() {
292
- let bodyRowGroup = this.rowGroups[1];
293
- return bodyRowGroup ? (0, $5mys8$within)(bodyRowGroup).queryAllByRole('row') : [];
292
+ return this.rowGroups.slice(1).flatMap((rowGroup)=>(0, $5mys8$within)(rowGroup).queryAllByRole('row'));
294
293
  }
295
294
  /**
296
295
  * Returns the currently selected rows within the table if any.
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA0BM,MAAM;IAMX,YAAY,IAAqB,CAAE;QACjC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,MAAM,GAAG;IAChB;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAA6D,EAAE;QACjG,IAAI,OAAC,GAAG,kBAAE,iBAAiB,WAAU,GAAG;QACxC,IAAI,SAAS,CAAA,GAAA,yCAAQ;QACrB,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,4BAA4B;QAC5B,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,aAAa,GACx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AA4B;QAC9B,OAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,KAAK,EAAE,cAAc,CAAC;IAC3C;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,KAAK,EAAC,GAAG;QAC7B,OAAO,CAAA,GAAA,aAAK,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, waitFor, within} from '@testing-library/react';\nimport {BaseGridRowInteractionOpts, GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\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 the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Row provided is not in the table');\n }\n\n // Move focus into the table\n if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) {\n act(() => this._table.focus());\n }\n\n if (document.activeElement === this._table) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n // If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows\n if (this.rowGroups[0].contains(document.activeElement)) {\n do {\n await this.user.keyboard('[ArrowDown]');\n } while (!this.rowGroups[1].contains(document.activeElement));\n }\n\n // Move focus onto the row itself\n if (this.rowGroups[1].contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Current active element is not on any of the table rows');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getMetaKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, cell, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n };\n\n /**\n * Toggles the expansion for the specified tree row. Defaults to using the interaction type set on the tree tester.\n */\n async toggleRowExpansion(opts: TableToggleExpansionOpts): Promise<void> {\n let {\n row,\n interactionType = this._interactionType\n } = opts;\n if (!this.table.contains(document.activeElement)) {\n await act(async () => {\n this.table.focus();\n });\n }\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n } else if (row.getAttribute('aria-expanded') == null) {\n throw new Error('Target row is not expandable.');\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 if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n // TODO: We always Use Option/Ctrl when keyboard navigating so selection isn't changed\n // in selectionmode=\"replace\"/highlight selection when navigating to the row that the user wants\n // to expand. Discuss if this is useful or not\n await this.keyboardNavigateToRow({row});\n if (row.getAttribute('aria-expanded') === 'true') {\n await this.user.keyboard('[ArrowLeft]');\n } else {\n await this.user.keyboard('[ArrowRight]');\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA0BM,MAAM;IAMX,YAAY,IAAqB,CAAE;QACjC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,MAAM,GAAG;IAChB;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAA6D,EAAE;QACjG,IAAI,OAAC,GAAG,kBAAE,iBAAiB,WAAU,GAAG;QACxC,IAAI,SAAS,CAAA,GAAA,yCAAQ;QACrB,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,4BAA4B;QAC5B,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,aAAa,GACxF,CAAA,GAAA,UAAE,EAAE,IAAM,IAAI,CAAC,MAAM,CAAC,KAAK;QAG7B,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,MAAM,EACxC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAG3B,0IAA0I;QAC1I,IAAI,IAAI,CAAC,SAAS,CAAC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AA,aAAK,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, waitFor, within} from '@testing-library/react';\nimport {BaseGridRowInteractionOpts, GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\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 the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Row provided is not in the table');\n }\n\n // Move focus into the table\n if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) {\n act(() => this._table.focus());\n }\n\n if (document.activeElement === this._table) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n // If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows\n if (this.rowGroups[0].contains(document.activeElement)) {\n do {\n await this.user.keyboard('[ArrowDown]');\n } while (!this.rowGroups[1].contains(document.activeElement));\n }\n\n // Move focus onto the row itself\n if (this.rowGroups[1].contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Current active element is not on any of the table rows');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getMetaKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, cell, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n };\n\n /**\n * Toggles the expansion for the specified tree row. Defaults to using the interaction type set on the tree tester.\n */\n async toggleRowExpansion(opts: TableToggleExpansionOpts): Promise<void> {\n let {\n row,\n interactionType = this._interactionType\n } = opts;\n if (!this.table.contains(document.activeElement)) {\n await act(async () => {\n this.table.focus();\n });\n }\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n } else if (row.getAttribute('aria-expanded') == null) {\n throw new Error('Target row is not expandable.');\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 if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n // TODO: We always Use Option/Ctrl when keyboard navigating so selection isn't changed\n // in selectionmode=\"replace\"/highlight selection when navigating to the row that the user wants\n // to expand. Discuss if this is useful or not\n await this.keyboardNavigateToRow({row});\n if (row.getAttribute('aria-expanded') === 'true') {\n await this.user.keyboard('[ArrowLeft]');\n } else {\n await this.user.keyboard('[ArrowRight]');\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n return this.rowGroups.slice(1).flatMap(rowGroup => within(rowGroup).queryAllByRole('row'));\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/test-utils",
3
- "version": "3.0.0-nightly-e3913baaa-260422",
3
+ "version": "3.0.0-nightly-ec7bc94b3-260424",
4
4
  "description": "Testing utils for react-aria patterns",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
package/src/table.ts CHANGED
@@ -504,8 +504,7 @@ export class TableTester {
504
504
  * Returns the rows within the table if any.
505
505
  */
506
506
  get rows(): HTMLElement[] {
507
- let bodyRowGroup = this.rowGroups[1];
508
- return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];
507
+ return this.rowGroups.slice(1).flatMap(rowGroup => within(rowGroup).queryAllByRole('row'));
509
508
  }
510
509
 
511
510
  /**