@react-aria/test-utils 1.0.0-alpha.3 → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/combobox.main.js +116 -82
- package/dist/combobox.main.js.map +1 -1
- package/dist/combobox.mjs +117 -83
- package/dist/combobox.module.js +117 -83
- package/dist/combobox.module.js.map +1 -1
- package/dist/events.main.js.map +1 -1
- package/dist/events.module.js.map +1 -1
- package/dist/gridlist.main.js +102 -59
- package/dist/gridlist.main.js.map +1 -1
- package/dist/gridlist.mjs +103 -60
- package/dist/gridlist.module.js +103 -60
- package/dist/gridlist.module.js.map +1 -1
- package/dist/listbox.main.js +135 -0
- package/dist/listbox.main.js.map +1 -0
- package/dist/listbox.mjs +130 -0
- package/dist/listbox.module.js +130 -0
- package/dist/listbox.module.js.map +1 -0
- package/dist/main.js.map +1 -1
- package/dist/menu.main.js +195 -161
- package/dist/menu.main.js.map +1 -1
- package/dist/menu.mjs +196 -162
- package/dist/menu.module.js +196 -162
- package/dist/menu.module.js.map +1 -1
- package/dist/module.js.map +1 -1
- package/dist/select.main.js +116 -70
- package/dist/select.main.js.map +1 -1
- package/dist/select.mjs +117 -71
- package/dist/select.module.js +117 -71
- package/dist/select.module.js.map +1 -1
- package/dist/table.main.js +170 -139
- package/dist/table.main.js.map +1 -1
- package/dist/table.mjs +171 -140
- package/dist/table.module.js +171 -140
- package/dist/table.module.js.map +1 -1
- package/dist/tabs.main.js +133 -0
- package/dist/tabs.main.js.map +1 -0
- package/dist/tabs.mjs +128 -0
- package/dist/tabs.module.js +128 -0
- package/dist/tabs.module.js.map +1 -0
- package/dist/tree.main.js +165 -0
- package/dist/tree.main.js.map +1 -0
- package/dist/tree.mjs +160 -0
- package/dist/tree.module.js +160 -0
- package/dist/tree.module.js.map +1 -0
- package/dist/types.d.ts +607 -145
- package/dist/types.d.ts.map +1 -1
- package/dist/user.main.js +15 -4
- package/dist/user.main.js.map +1 -1
- package/dist/user.mjs +15 -4
- package/dist/user.module.js +15 -4
- package/dist/user.module.js.map +1 -1
- package/package.json +2 -3
- package/src/combobox.ts +105 -36
- package/src/events.ts +1 -1
- package/src/gridlist.ts +146 -59
- package/src/index.ts +1 -1
- package/src/listbox.ts +226 -0
- package/src/menu.ts +152 -62
- package/src/select.ts +137 -44
- package/src/table.ts +129 -64
- package/src/tabs.ts +198 -0
- package/src/tree.ts +248 -0
- package/src/types.ts +133 -0
- package/src/user.ts +62 -37
package/dist/table.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
|
|
2
|
-
import {within as $2KUjE$within,
|
|
2
|
+
import {within as $2KUjE$within, act as $2KUjE$act, fireEvent as $2KUjE$fireEvent, waitFor as $2KUjE$waitFor} from "@testing-library/react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* Copyright 2024 Adobe. All rights reserved.
|
|
@@ -14,161 +14,192 @@ import {within as $2KUjE$within, fireEvent as $2KUjE$fireEvent, waitFor as $2KUj
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
class $6d1e4cf220920c37$export$4c6a9d6ae3b0086 {
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Set the interaction type used by the table tester.
|
|
19
|
+
*/ setInteractionType(type) {
|
|
20
|
+
this._interactionType = type;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.
|
|
24
|
+
*/ async toggleRowSelection(opts) {
|
|
25
|
+
let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
|
|
26
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
27
|
+
rowIndexOrText: row
|
|
28
|
+
});
|
|
29
|
+
if (!row) throw new Error('Target row not found in the table.');
|
|
30
|
+
let rowCheckbox = (0, $2KUjE$within)(row).queryByRole('checkbox');
|
|
31
|
+
if (interactionType === 'keyboard' && !checkboxSelection) {
|
|
32
|
+
// TODO: for now focus the row directly until I add keyboard navigation
|
|
33
|
+
await (0, $2KUjE$act)(async ()=>{
|
|
34
|
+
row.focus();
|
|
35
|
+
});
|
|
36
|
+
await this.user.keyboard('{Space}');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
|
|
40
|
+
else {
|
|
41
|
+
let cell = (0, $2KUjE$within)(row).getAllByRole('gridcell')[0];
|
|
42
|
+
if (needsLongPress && interactionType === 'touch') {
|
|
43
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
44
|
+
// Note that long press interactions with rows is strictly touch only for grid rows
|
|
45
|
+
await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
|
|
46
|
+
element: cell,
|
|
47
|
+
advanceTimer: this._advanceTimer,
|
|
48
|
+
pointerOpts: {
|
|
49
|
+
pointerType: 'touch'
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
// TODO: interestingly enough, we need to do a followup click otherwise future row selections may not fire properly?
|
|
53
|
+
// To reproduce, try removing this, forcing toggleRowSelection to hit "needsLongPress ? await triggerLongPress(cell) : await action(cell);" and
|
|
54
|
+
// run Table.test's "should support long press to enter selection mode on touch" test to see what happens
|
|
55
|
+
await (0, $2KUjE$fireEvent).click(cell);
|
|
56
|
+
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.
|
|
61
|
+
*/ async toggleSort(opts) {
|
|
62
|
+
let { column: column, interactionType: interactionType = this._interactionType } = opts;
|
|
63
|
+
let columnheader;
|
|
64
|
+
if (typeof column === 'number') columnheader = this.columns[column];
|
|
65
|
+
else if (typeof column === 'string') {
|
|
66
|
+
columnheader = (0, $2KUjE$within)(this.rowGroups[0]).getByText(column);
|
|
67
|
+
while(columnheader && !/columnheader/.test(columnheader.getAttribute('role')))columnheader = columnheader.parentElement;
|
|
68
|
+
} else columnheader = column;
|
|
69
|
+
let menuButton = (0, $2KUjE$within)(columnheader).queryByRole('button');
|
|
70
|
+
if (menuButton) {
|
|
71
|
+
let currentSort = columnheader.getAttribute('aria-sort');
|
|
72
|
+
// TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like
|
|
73
|
+
// the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the
|
|
74
|
+
// column header except if the active element is already the menu button within the column header
|
|
75
|
+
if (interactionType === 'keyboard' && document.activeElement !== menuButton) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, columnheader, interactionType);
|
|
76
|
+
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, menuButton, interactionType);
|
|
77
|
+
await (0, $2KUjE$waitFor)(()=>{
|
|
78
|
+
if (menuButton.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on table column dropdown menu trigger element.');
|
|
79
|
+
else return true;
|
|
80
|
+
});
|
|
81
|
+
let menuId = menuButton.getAttribute('aria-controls');
|
|
82
|
+
await (0, $2KUjE$waitFor)(()=>{
|
|
83
|
+
if (!menuId || document.getElementById(menuId) == null) throw new Error(`Table column header menu with id of ${menuId} not found in document.`);
|
|
84
|
+
else return true;
|
|
85
|
+
});
|
|
86
|
+
if (menuId) {
|
|
87
|
+
let menu = document.getElementById(menuId);
|
|
88
|
+
if (menu) {
|
|
89
|
+
if (currentSort === 'ascending') await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, (0, $2KUjE$within)(menu).getAllByRole('menuitem')[1], interactionType);
|
|
90
|
+
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, (0, $2KUjE$within)(menu).getAllByRole('menuitem')[0], interactionType);
|
|
91
|
+
await (0, $2KUjE$waitFor)(()=>{
|
|
92
|
+
if (document.contains(menu)) throw new Error('Expected table column menu listbox to not be in the document after selecting an option');
|
|
93
|
+
else return true;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Handle cases where the table may transition in response to the row selection/deselection
|
|
98
|
+
if (!this._advanceTimer) throw new Error('No advanceTimers provided for table transition.');
|
|
99
|
+
await (0, $2KUjE$act)(async ()=>{
|
|
100
|
+
var _this__advanceTimer, _this;
|
|
101
|
+
await ((_this__advanceTimer = (_this = this)._advanceTimer) === null || _this__advanceTimer === void 0 ? void 0 : _this__advanceTimer.call(_this, 200));
|
|
102
|
+
});
|
|
103
|
+
await (0, $2KUjE$waitFor)(()=>{
|
|
104
|
+
if (document.activeElement !== menuButton) throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);
|
|
105
|
+
else return true;
|
|
106
|
+
});
|
|
107
|
+
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, columnheader, interactionType);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.
|
|
111
|
+
*/ async triggerRowAction(opts) {
|
|
112
|
+
let { row: row, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
113
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
114
|
+
rowIndexOrText: row
|
|
115
|
+
});
|
|
116
|
+
if (!row) throw new Error('Target row not found in the table.');
|
|
117
|
+
if (needsDoubleClick) await this.user.dblClick(row);
|
|
118
|
+
else if (interactionType === 'keyboard') {
|
|
119
|
+
// TODO: add keyboard navigation instead of focusing the row directly. Will need to consider if the focus in in the columns
|
|
120
|
+
(0, $2KUjE$act)(()=>row.focus());
|
|
121
|
+
await this.user.keyboard('[Enter]');
|
|
122
|
+
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
|
|
123
|
+
}
|
|
124
|
+
// 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.
|
|
125
|
+
// 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
|
|
126
|
+
// on the mocks the user sets up for their row height/etc.
|
|
127
|
+
// 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
|
|
128
|
+
// add much value if we provide that to them
|
|
129
|
+
/**
|
|
130
|
+
* Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.
|
|
131
|
+
*/ async toggleSelectAll(opts = {}) {
|
|
132
|
+
let { interactionType: interactionType = this._interactionType } = opts;
|
|
133
|
+
let checkbox = (0, $2KUjE$within)(this.table).getByLabelText('Select All');
|
|
134
|
+
if (interactionType === 'keyboard') // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.
|
|
135
|
+
await this.user.click(checkbox);
|
|
136
|
+
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, checkbox, interactionType);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns a row matching the specified index or text content.
|
|
140
|
+
*/ findRow(opts) {
|
|
141
|
+
let { rowIndexOrText: rowIndexOrText } = opts;
|
|
142
|
+
let row;
|
|
143
|
+
let rows = this.rows;
|
|
144
|
+
let bodyRowGroup = this.rowGroups[1];
|
|
145
|
+
if (typeof rowIndexOrText === 'number') row = rows[rowIndexOrText];
|
|
146
|
+
else if (typeof rowIndexOrText === 'string') {
|
|
147
|
+
row = (0, $2KUjE$within)(bodyRowGroup).getByText(rowIndexOrText);
|
|
148
|
+
while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
|
|
149
|
+
}
|
|
150
|
+
return row;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Returns a cell matching the specified text content.
|
|
154
|
+
*/ findCell(opts) {
|
|
155
|
+
let { text: text } = opts;
|
|
156
|
+
let cell = (0, $2KUjE$within)(this.table).getByText(text);
|
|
157
|
+
if (cell) while(cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')){
|
|
158
|
+
if (cell.parentElement) cell = cell.parentElement;
|
|
159
|
+
else break;
|
|
160
|
+
}
|
|
161
|
+
return cell;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Returns the table.
|
|
165
|
+
*/ get table() {
|
|
18
166
|
return this._table;
|
|
19
167
|
}
|
|
20
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Returns the row groups within the table.
|
|
170
|
+
*/ get rowGroups() {
|
|
21
171
|
let table = this._table;
|
|
22
172
|
return table ? (0, $2KUjE$within)(table).queryAllByRole('rowgroup') : [];
|
|
23
173
|
}
|
|
24
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Returns the columns within the table.
|
|
176
|
+
*/ get columns() {
|
|
25
177
|
let headerRowGroup = this.rowGroups[0];
|
|
26
178
|
return headerRowGroup ? (0, $2KUjE$within)(headerRowGroup).queryAllByRole('columnheader') : [];
|
|
27
179
|
}
|
|
28
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Returns the rows within the table if any.
|
|
182
|
+
*/ get rows() {
|
|
29
183
|
let bodyRowGroup = this.rowGroups[1];
|
|
30
184
|
return bodyRowGroup ? (0, $2KUjE$within)(bodyRowGroup).queryAllByRole('row') : [];
|
|
31
185
|
}
|
|
32
|
-
|
|
186
|
+
/**
|
|
187
|
+
* Returns the currently selected rows within the table if any.
|
|
188
|
+
*/ get selectedRows() {
|
|
33
189
|
return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
|
|
34
190
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Returns the row headers within the table if any.
|
|
193
|
+
*/ get rowHeaders() {
|
|
194
|
+
return (0, $2KUjE$within)(this.table).queryAllByRole('rowheader');
|
|
38
195
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.
|
|
198
|
+
*/ cells(opts = {}) {
|
|
199
|
+
let { element: element = this.table } = opts;
|
|
200
|
+
return (0, $2KUjE$within)(element).queryAllByRole('gridcell');
|
|
42
201
|
}
|
|
43
202
|
constructor(opts){
|
|
44
|
-
this.setInteractionType = (type)=>{
|
|
45
|
-
this._interactionType = type;
|
|
46
|
-
};
|
|
47
|
-
this.toggleRowSelection = async (opts = {})=>{
|
|
48
|
-
let { index: index, text: text, needsLongPress: needsLongPress, interactionType: interactionType = this._interactionType } = opts;
|
|
49
|
-
let row = this.findRow({
|
|
50
|
-
index: index,
|
|
51
|
-
text: text
|
|
52
|
-
});
|
|
53
|
-
let rowCheckbox = (0, $2KUjE$within)(row).queryByRole('checkbox');
|
|
54
|
-
if (rowCheckbox) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
|
|
55
|
-
else {
|
|
56
|
-
let cell = (0, $2KUjE$within)(row).getAllByRole('gridcell')[0];
|
|
57
|
-
if (needsLongPress && interactionType === 'touch') {
|
|
58
|
-
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
59
|
-
// Note that long press interactions with rows is strictly touch only for grid rows
|
|
60
|
-
await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
|
|
61
|
-
element: cell,
|
|
62
|
-
advanceTimer: this._advanceTimer,
|
|
63
|
-
pointerOpts: {
|
|
64
|
-
pointerType: 'touch'
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
// TODO: interestingly enough, we need to do a followup click otherwise future row selections may not fire properly?
|
|
68
|
-
// To reproduce, try removing this, forcing toggleRowSelection to hit "needsLongPress ? await triggerLongPress(cell) : await action(cell);" and
|
|
69
|
-
// run Table.test's "should support long press to enter selection mode on touch" test to see what happens
|
|
70
|
-
await (0, $2KUjE$fireEvent).click(cell);
|
|
71
|
-
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
this.toggleSort = async (opts = {})=>{
|
|
75
|
-
let { index: index, text: text, interactionType: interactionType = this._interactionType } = opts;
|
|
76
|
-
let columnheader;
|
|
77
|
-
if (index != null) columnheader = this.columns[index];
|
|
78
|
-
else if (text != null) {
|
|
79
|
-
columnheader = (0, $2KUjE$within)(this.rowGroups[0]).getByText(text);
|
|
80
|
-
while(columnheader && !/columnheader/.test(columnheader.getAttribute('role')))columnheader = columnheader.parentElement;
|
|
81
|
-
}
|
|
82
|
-
let menuButton = (0, $2KUjE$within)(columnheader).queryByRole('button');
|
|
83
|
-
if (menuButton) {
|
|
84
|
-
let currentSort = columnheader.getAttribute('aria-sort');
|
|
85
|
-
// TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like
|
|
86
|
-
// the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the
|
|
87
|
-
// column header except if the active element is already the menu button within the column header
|
|
88
|
-
if (interactionType === 'keyboard' && document.activeElement !== menuButton) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, columnheader, interactionType);
|
|
89
|
-
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, menuButton, interactionType);
|
|
90
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
91
|
-
if (menuButton.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on table column dropdown menu trigger element.');
|
|
92
|
-
else return true;
|
|
93
|
-
});
|
|
94
|
-
let menuId = menuButton.getAttribute('aria-controls');
|
|
95
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
96
|
-
if (!menuId || document.getElementById(menuId) == null) throw new Error(`Table column header menu with id of ${menuId} not found in document.`);
|
|
97
|
-
else return true;
|
|
98
|
-
});
|
|
99
|
-
if (menuId) {
|
|
100
|
-
let menu = document.getElementById(menuId);
|
|
101
|
-
if (menu) {
|
|
102
|
-
if (currentSort === 'ascending') await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, (0, $2KUjE$within)(menu).getAllByRole('menuitem')[1], interactionType);
|
|
103
|
-
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, (0, $2KUjE$within)(menu).getAllByRole('menuitem')[0], interactionType);
|
|
104
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
105
|
-
if (document.contains(menu)) throw new Error('Expected table column menu listbox to not be in the document after selecting an option');
|
|
106
|
-
else return true;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Handle cases where the table may transition in response to the row selection/deselection
|
|
111
|
-
if (!this._advanceTimer) throw new Error('No advanceTimers provided for table transition.');
|
|
112
|
-
await (0, $2KUjE$act)(async ()=>{
|
|
113
|
-
var _this__advanceTimer, _this;
|
|
114
|
-
await ((_this__advanceTimer = (_this = this)._advanceTimer) === null || _this__advanceTimer === void 0 ? void 0 : _this__advanceTimer.call(_this, 200));
|
|
115
|
-
});
|
|
116
|
-
await (0, $2KUjE$waitFor)(()=>{
|
|
117
|
-
if (document.activeElement !== menuButton) throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);
|
|
118
|
-
else return true;
|
|
119
|
-
});
|
|
120
|
-
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, columnheader, interactionType);
|
|
121
|
-
};
|
|
122
|
-
// TODO: should there be a util for triggering a row action? Perhaps there should be but it would rely on the user teling us the config of the
|
|
123
|
-
// table. Maybe we could rely on the user knowing to trigger a press/double click? We could have the user pass in "needsDoubleClick"
|
|
124
|
-
// It is also iffy if there is any row selected because then the table is in selectionMode and the below actions will simply toggle row selection
|
|
125
|
-
this.triggerRowAction = async (opts = {})=>{
|
|
126
|
-
let { index: index, text: text, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
127
|
-
let row = this.findRow({
|
|
128
|
-
index: index,
|
|
129
|
-
text: text
|
|
130
|
-
});
|
|
131
|
-
if (row) {
|
|
132
|
-
if (needsDoubleClick) await this.user.dblClick(row);
|
|
133
|
-
else if (interactionType === 'keyboard') {
|
|
134
|
-
(0, $2KUjE$act)(()=>row.focus());
|
|
135
|
-
await this.user.keyboard('[Enter]');
|
|
136
|
-
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
// 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.
|
|
140
|
-
// 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
|
|
141
|
-
// on the mocks the user sets up for their row height/etc.
|
|
142
|
-
// 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
|
|
143
|
-
// add much value if we provide that to them
|
|
144
|
-
this.toggleSelectAll = async (opts = {})=>{
|
|
145
|
-
let { interactionType: interactionType = this._interactionType } = opts;
|
|
146
|
-
let checkbox = (0, $2KUjE$within)(this.table).getByLabelText('Select All');
|
|
147
|
-
if (interactionType === 'keyboard') // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.
|
|
148
|
-
await this.user.click(checkbox);
|
|
149
|
-
else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, checkbox, interactionType);
|
|
150
|
-
};
|
|
151
|
-
this.findRow = (opts = {})=>{
|
|
152
|
-
let { index: index, text: text } = opts;
|
|
153
|
-
let row;
|
|
154
|
-
let rows = this.rows;
|
|
155
|
-
let bodyRowGroup = this.rowGroups[1];
|
|
156
|
-
if (index != null) row = rows[index];
|
|
157
|
-
else if (text != null) {
|
|
158
|
-
row = (0, $2KUjE$within)(bodyRowGroup).getByText(text);
|
|
159
|
-
while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
|
|
160
|
-
}
|
|
161
|
-
return row;
|
|
162
|
-
};
|
|
163
|
-
this.findCell = (opts)=>{
|
|
164
|
-
let { text: text } = opts;
|
|
165
|
-
let cell = (0, $2KUjE$within)(this.table).getByText(text);
|
|
166
|
-
if (cell) while(cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')){
|
|
167
|
-
if (cell.parentElement) cell = cell.parentElement;
|
|
168
|
-
else break;
|
|
169
|
-
}
|
|
170
|
-
return cell;
|
|
171
|
-
};
|
|
172
203
|
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
173
204
|
this.user = user;
|
|
174
205
|
this._interactionType = interactionType || 'mouse';
|
package/dist/table.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAaM,MAAM;IAyNX,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM;IACpB;IAEA,IAAI,YAAY;QACd,IAAI,QAAQ,IAAI,CAAC,MAAM;QACvB,OAAO,QAAQ,CAAA,GAAA,aAAK,EAAE,OAAO,cAAc,CAAC,cAAc,EAAE;IAC9D;IAEA,IAAI,UAAU;QACZ,IAAI,iBAAiB,IAAI,CAAC,SAAS,CAAC,EAAE;QACtC,OAAO,iBAAiB,CAAA,GAAA,aAAK,EAAE,gBAAgB,cAAc,CAAC,kBAAkB,EAAE;IACpF;IAEA,IAAI,OAAO;QACT,IAAI,eAAe,IAAI,CAAC,SAAS,CAAC,EAAE;QACpC,OAAO,eAAe,CAAA,GAAA,aAAK,EAAE,cAAc,cAAc,CAAC,SAAS,EAAE;IACvE;IAEA,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;I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AAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,MAAM,GAAG;IAChB;AA6OF","sources":["packages/@react-aria/test-utils/src/table.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, fireEvent, waitFor, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\nimport {pressElement, triggerLongPress} from './events';\nexport interface TableOptions extends UserOpts, BaseTesterOpts {\n user?: any,\n advanceTimer: UserOpts['advanceTimer']\n}\n\n// TODO: Previously used logic like https://github.com/testing-library/react-testing-library/blame/c63b873072d62c858959c2a19e68f8e2cc0b11be/src/pure.js#L16\n// but https://github.com/testing-library/dom-testing-library/issues/987#issuecomment-891901804 indicates that it may falsely indicate that fake timers are enabled\n// when they aren't\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableOptions) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n toggleRowSelection = async (opts: {index?: number, text?: string, needsLongPress?: boolean, interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n index,\n text,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\n let row = this.findRow({index, text});\n let rowCheckbox = within(row).queryByRole('checkbox');\n if (rowCheckbox) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n // TODO: interestingly enough, we need to do a followup click otherwise future row selections may not fire properly?\n // To reproduce, try removing this, forcing toggleRowSelection to hit \"needsLongPress ? await triggerLongPress(cell) : await action(cell);\" and\n // run Table.test's \"should support long press to enter selection mode on touch\" test to see what happens\n await fireEvent.click(cell);\n } else {\n await pressElement(this.user, cell, interactionType);\n }\n }\n };\n\n toggleSort = async (opts: {index?: number, text?: string, interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n index,\n text,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (index != null) {\n columnheader = this.columns[index];\n } else if (text != null) {\n columnheader = within(this.rowGroups[0]).getByText(text);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n };\n // TODO: should there be a util for triggering a row action? Perhaps there should be but it would rely on the user teling us the config of the\n // table. Maybe we could rely on the user knowing to trigger a press/double click? We could have the user pass in \"needsDoubleClick\"\n // It is also iffy if there is any row selected because then the table is in selectionMode and the below actions will simply toggle row selection\n triggerRowAction = async (opts: {index?: number, text?: string, needsDoubleClick?: boolean, interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n index,\n text,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n let row = this.findRow({index, text});\n if (row) {\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n act(() => row.focus());\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n };\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n\n toggleSelectAll = async (opts: {interactionType?: UserOpts['interactionType']} = {}) => {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n };\n\n findRow = (opts: {index?: number, text?: string} = {}) => {\n let {\n index,\n text\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (index != null) {\n row = rows[index];\n } else if (text != null) {\n row = within(bodyRowGroup).getByText(text);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n };\n\n findCell = (opts: {text: string}) => {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n };\n\n get table() {\n return this._table;\n }\n\n get rowGroups() {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n get columns() {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n get rows() {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n get selectedRows() {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n get rowHeaders() {\n let table = this.table;\n return table ? within(table).queryAllByRole('rowheader') : [];\n }\n\n get cells() {\n let table = this.table;\n return table ? within(table).queryAllByRole('gridcell') : [];\n }\n}\n"],"names":[],"version":3,"file":"table.module.js.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAmBM,MAAM;IAcX;;GAEC,GACD,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ved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, fireEvent, waitFor, within} from '@testing-library/react';\nimport {GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\n\ninterface TableToggleRowOpts extends ToggleGridRowOpts {}\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 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']) {\n this._interactionType = type;\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) {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\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 let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && !checkboxSelection) {\n // TODO: for now focus the row directly until I add keyboard navigation\n await act(async () => {\n row.focus();\n });\n await this.user.keyboard('{Space}');\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 // TODO: interestingly enough, we need to do a followup click otherwise future row selections may not fire properly?\n // To reproduce, try removing this, forcing toggleRowSelection to hit \"needsLongPress ? await triggerLongPress(cell) : await action(cell);\" and\n // run Table.test's \"should support long press to enter selection mode on touch\" test to see what happens\n await fireEvent.click(cell);\n } else {\n await pressElement(this.user, cell, interactionType);\n }\n }\n };\n\n /**\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) {\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 the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts) {\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 // TODO: add keyboard navigation instead of focusing the row directly. Will need to consider if the focus in in the columns\n act(() => row.focus());\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']} = {}) {\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}) {\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.module.js.map"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
var $5a8bfe1663b8366d$exports = require("./events.main.js");
|
|
2
|
+
var $1inx6$testinglibraryreact = require("@testing-library/react");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "TabsTester", () => $19633c03aff25ae5$export$f1539bff3fc7d485);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
class $19633c03aff25ae5$export$f1539bff3fc7d485 {
|
|
23
|
+
/**
|
|
24
|
+
* Set the interaction type used by the tabs tester.
|
|
25
|
+
*/ setInteractionType(type) {
|
|
26
|
+
this._interactionType = type;
|
|
27
|
+
}
|
|
28
|
+
// TODO: This is pretty similar across most the utils, refactor to make it generic?
|
|
29
|
+
/**
|
|
30
|
+
* Returns a tab matching the specified index or text content.
|
|
31
|
+
*/ findTab(opts) {
|
|
32
|
+
let { tabIndexOrText: tabIndexOrText } = opts;
|
|
33
|
+
let tab;
|
|
34
|
+
let tabs = this.tabs;
|
|
35
|
+
if (typeof tabIndexOrText === 'number') tab = tabs[tabIndexOrText];
|
|
36
|
+
else if (typeof tabIndexOrText === 'string') tab = (0, $1inx6$testinglibraryreact.within)(this._tablist).getByText(tabIndexOrText).closest('[role=tab]');
|
|
37
|
+
return tab;
|
|
38
|
+
}
|
|
39
|
+
// TODO: also quite similar across more utils albeit with orientation, refactor to make generic
|
|
40
|
+
async keyboardNavigateToTab(opts) {
|
|
41
|
+
let { tab: tab, orientation: orientation = 'vertical' } = opts;
|
|
42
|
+
let tabs = this.tabs;
|
|
43
|
+
let targetIndex = tabs.indexOf(tab);
|
|
44
|
+
if (targetIndex === -1) throw new Error('Tab provided is not in the tablist');
|
|
45
|
+
if (!this._tablist.contains(document.activeElement)) {
|
|
46
|
+
let selectedTab = this.selectedTab;
|
|
47
|
+
if (selectedTab != null) (0, $1inx6$testinglibraryreact.act)(()=>selectedTab.focus());
|
|
48
|
+
else (0, $1inx6$testinglibraryreact.act)(()=>{
|
|
49
|
+
var _tabs_find;
|
|
50
|
+
return (_tabs_find = tabs.find((tab)=>!(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'))) === null || _tabs_find === void 0 ? void 0 : _tabs_find.focus();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
let currIndex = this.tabs.indexOf(document.activeElement);
|
|
54
|
+
if (currIndex === -1) throw new Error('ActiveElement is not in the tablist');
|
|
55
|
+
let arrowUp = 'ArrowUp';
|
|
56
|
+
let arrowDown = 'ArrowDown';
|
|
57
|
+
if (orientation === 'horizontal') {
|
|
58
|
+
if (this._direction === 'ltr') {
|
|
59
|
+
arrowUp = 'ArrowLeft';
|
|
60
|
+
arrowDown = 'ArrowRight';
|
|
61
|
+
} else {
|
|
62
|
+
arrowUp = 'ArrowRight';
|
|
63
|
+
arrowDown = 'ArrowLeft';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let movementDirection = targetIndex > currIndex ? 'down' : 'up';
|
|
67
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.
|
|
71
|
+
*/ async triggerTab(opts) {
|
|
72
|
+
let { tab: tab, interactionType: interactionType = this._interactionType, manualActivation: manualActivation } = opts;
|
|
73
|
+
if (typeof tab === 'string' || typeof tab === 'number') tab = this.findTab({
|
|
74
|
+
tabIndexOrText: tab
|
|
75
|
+
});
|
|
76
|
+
if (!tab) throw new Error('Target tab not found in the tablist.');
|
|
77
|
+
else if (tab.hasAttribute('disabled')) throw new Error('Target tab is disabled.');
|
|
78
|
+
if (interactionType === 'keyboard') {
|
|
79
|
+
if (document.activeElement !== this._tablist || !this._tablist.contains(document.activeElement)) (0, $1inx6$testinglibraryreact.act)(()=>this._tablist.focus());
|
|
80
|
+
let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';
|
|
81
|
+
await this.keyboardNavigateToTab({
|
|
82
|
+
tab: tab,
|
|
83
|
+
orientation: tabsOrientation
|
|
84
|
+
});
|
|
85
|
+
if (manualActivation) await this.user.keyboard('[Enter]');
|
|
86
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, tab, interactionType);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the tablist.
|
|
90
|
+
*/ get tablist() {
|
|
91
|
+
return this._tablist;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns the tabpanels.
|
|
95
|
+
*/ get tabpanels() {
|
|
96
|
+
let tabpanels = [];
|
|
97
|
+
for (let tab of this.tabs){
|
|
98
|
+
let controlId = tab.getAttribute('aria-controls');
|
|
99
|
+
let panel = controlId != null ? document.getElementById(controlId) : null;
|
|
100
|
+
if (panel != null) tabpanels.push(panel);
|
|
101
|
+
}
|
|
102
|
+
return tabpanels;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns the tabs in the tablist.
|
|
106
|
+
*/ get tabs() {
|
|
107
|
+
return (0, $1inx6$testinglibraryreact.within)(this.tablist).queryAllByRole('tab');
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns the currently selected tab in the tablist if any.
|
|
111
|
+
*/ get selectedTab() {
|
|
112
|
+
return this.tabs.find((tab)=>tab.getAttribute('aria-selected') === 'true') || null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns the currently active tabpanel if any.
|
|
116
|
+
*/ get activeTabpanel() {
|
|
117
|
+
var _this_selectedTab;
|
|
118
|
+
let activeTabpanelId = (_this_selectedTab = this.selectedTab) === null || _this_selectedTab === void 0 ? void 0 : _this_selectedTab.getAttribute('aria-controls');
|
|
119
|
+
return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;
|
|
120
|
+
}
|
|
121
|
+
constructor(opts){
|
|
122
|
+
let { root: root, user: user, interactionType: interactionType, direction: direction } = opts;
|
|
123
|
+
this.user = user;
|
|
124
|
+
this._interactionType = interactionType || 'mouse';
|
|
125
|
+
this._direction = direction || 'ltr';
|
|
126
|
+
this._tablist = root;
|
|
127
|
+
let tablist = (0, $1inx6$testinglibraryreact.within)(root).queryAllByRole('tablist');
|
|
128
|
+
if (tablist.length > 0) this._tablist = tablist[0];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=tabs.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";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AAI,YAAY,EAAE;QAClB,KAAK,IAAI,OAAO,IAAI,CAAC,IAAI,CAAE;YACzB,IAAI,YAAY,IAAI,YAAY,CAAC;YACjC,IAAI,QAAQ,aAAa,OAAO,SAAS,cAAc,CAAC,aAAa;YACrE,IAAI,SAAS,MACX,UAAU,IAAI,CAAC;QAEnB;QAEA,OAAO;IACT;IAEA;;GAEC,GACD,IAAI,OAAsB;QACxB,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC;IAC7C;IAEA;;GAEC,GACD,IAAI,cAAkC;QACpC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB,WAAW;IAChF;IAEA;;GAEC,GACD,IAAI,iBAAqC;YAChB;QAAvB,IAAI,oBAAmB,oBAAA,IAAI,CAAC,WAAW,cAAhB,wCAAA,kBAAkB,YAAY,CAAC;QACtD,OAAO,mBAAmB,SAAS,cAAc,CAAC,oBAAoB;IACxE;IA/JA,YAAY,IAAoB,CAAE;QAChC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,aAAE,SAAS,EAAC,GAAG;QAC/C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,aAAa;QAE/B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI,QAAQ,MAAM,GAAG,GACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAAE;IAE9B;AAqJF","sources":["packages/@react-aria/test-utils/src/tabs.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerTabOptions {\n /**\n * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the tab to toggle selection for.\n */\n tab: number | string | HTMLElement,\n /**\n * Whether the tab needs to be activated manually rather than on focus.\n */\n manualActivation?: boolean\n}\n\nexport class TabsTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _tablist: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: TabsTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._tablist = root;\n let tablist = within(root).queryAllByRole('tablist');\n if (tablist.length > 0) {\n this._tablist = tablist[0];\n }\n }\n\n /**\n * Set the interaction type used by the tabs tester.\n */\n setInteractionType(type: UserOpts['interactionType']) {\n this._interactionType = type;\n }\n\n // TODO: This is pretty similar across most the utils, refactor to make it generic?\n /**\n * Returns a tab matching the specified index or text content.\n */\n findTab(opts: {tabIndexOrText: number | string}): HTMLElement {\n let {\n tabIndexOrText\n } = opts;\n\n let tab;\n let tabs = this.tabs;\n if (typeof tabIndexOrText === 'number') {\n tab = tabs[tabIndexOrText];\n } else if (typeof tabIndexOrText === 'string') {\n tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;\n }\n\n return tab;\n }\n\n // TODO: also quite similar across more utils albeit with orientation, refactor to make generic\n private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {\n let {tab, orientation = 'vertical'} = opts;\n let tabs = this.tabs;\n let targetIndex = tabs.indexOf(tab);\n if (targetIndex === -1) {\n throw new Error('Tab provided is not in the tablist');\n }\n\n if (!this._tablist.contains(document.activeElement)) {\n let selectedTab = this.selectedTab;\n if (selectedTab != null) {\n act(() => selectedTab.focus());\n } else {\n act(() => tabs.find(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'))?.focus());\n }\n }\n\n let currIndex = this.tabs.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the tablist');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.\n */\n async triggerTab(opts: TriggerTabOptions) {\n let {\n tab,\n interactionType = this._interactionType,\n manualActivation\n } = opts;\n\n if (typeof tab === 'string' || typeof tab === 'number') {\n tab = this.findTab({tabIndexOrText: tab});\n }\n\n if (!tab) {\n throw new Error('Target tab not found in the tablist.');\n } else if (tab.hasAttribute('disabled')) {\n throw new Error('Target tab is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== this._tablist || !this._tablist.contains(document.activeElement)) {\n act(() => this._tablist.focus());\n }\n\n let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});\n if (manualActivation) {\n await this.user.keyboard('[Enter]');\n }\n } else {\n await pressElement(this.user, tab, interactionType);\n }\n }\n\n /**\n * Returns the tablist.\n */\n get tablist(): HTMLElement {\n return this._tablist;\n }\n\n /**\n * Returns the tabpanels.\n */\n get tabpanels(): HTMLElement[] {\n let tabpanels = [] as HTMLElement[];\n for (let tab of this.tabs) {\n let controlId = tab.getAttribute('aria-controls');\n let panel = controlId != null ? document.getElementById(controlId) : null;\n if (panel != null) {\n tabpanels.push(panel);\n }\n }\n\n return tabpanels;\n }\n\n /**\n * Returns the tabs in the tablist.\n */\n get tabs(): HTMLElement[] {\n return within(this.tablist).queryAllByRole('tab');\n }\n\n /**\n * Returns the currently selected tab in the tablist if any.\n */\n get selectedTab(): HTMLElement | null {\n return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;\n }\n\n /**\n * Returns the currently active tabpanel if any.\n */\n get activeTabpanel(): HTMLElement | null {\n let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');\n return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;\n }\n}\n"],"names":[],"version":3,"file":"tabs.main.js.map"}
|