@react-aria/test-utils 1.0.0-nightly.5042 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/dist/import.mjs +6 -4
- package/dist/main.js +15 -23
- package/dist/main.js.map +1 -1
- package/dist/module.js +6 -4
- package/dist/module.js.map +1 -1
- package/dist/private/act.cjs +33 -0
- package/dist/private/act.cjs.map +1 -0
- package/dist/private/act.js +28 -0
- package/dist/private/act.js.map +1 -0
- package/dist/private/checkboxgroup.cjs +107 -0
- package/dist/private/checkboxgroup.cjs.map +1 -0
- package/dist/private/checkboxgroup.js +102 -0
- package/dist/private/checkboxgroup.js.map +1 -0
- package/dist/private/combobox.cjs +199 -0
- package/dist/private/combobox.cjs.map +1 -0
- package/dist/private/combobox.js +194 -0
- package/dist/private/combobox.js.map +1 -0
- package/dist/private/dialog.cjs +110 -0
- package/dist/private/dialog.cjs.map +1 -0
- package/dist/private/dialog.js +105 -0
- package/dist/private/dialog.js.map +1 -0
- package/dist/private/gridlist.cjs +173 -0
- package/dist/private/gridlist.cjs.map +1 -0
- package/dist/private/gridlist.js +168 -0
- package/dist/private/gridlist.js.map +1 -0
- package/dist/private/listbox.cjs +163 -0
- package/dist/private/listbox.cjs.map +1 -0
- package/dist/private/listbox.js +158 -0
- package/dist/private/listbox.js.map +1 -0
- package/dist/private/menu.cjs +265 -0
- package/dist/private/menu.cjs.map +1 -0
- package/dist/private/menu.js +260 -0
- package/dist/private/menu.js.map +1 -0
- package/dist/private/radiogroup.cjs +122 -0
- package/dist/private/radiogroup.cjs.map +1 -0
- package/dist/private/radiogroup.js +117 -0
- package/dist/private/radiogroup.js.map +1 -0
- package/dist/private/select.cjs +169 -0
- package/dist/private/select.cjs.map +1 -0
- package/dist/private/select.js +164 -0
- package/dist/private/select.js.map +1 -0
- package/dist/private/table.cjs +346 -0
- package/dist/private/table.cjs.map +1 -0
- package/dist/private/table.js +341 -0
- package/dist/private/table.js.map +1 -0
- package/dist/private/tabs.cjs +131 -0
- package/dist/private/tabs.cjs.map +1 -0
- package/dist/private/tabs.js +126 -0
- package/dist/private/tabs.js.map +1 -0
- package/dist/private/testSetup.cjs +87 -0
- package/dist/private/testSetup.cjs.map +1 -0
- package/dist/private/testSetup.js +81 -0
- package/dist/private/testSetup.js.map +1 -0
- package/dist/private/tree.cjs +181 -0
- package/dist/private/tree.cjs.map +1 -0
- package/dist/private/tree.js +176 -0
- package/dist/private/tree.js.map +1 -0
- package/dist/private/user.cjs +85 -0
- package/dist/private/user.cjs.map +1 -0
- package/dist/private/user.js +76 -0
- package/dist/private/user.js.map +1 -0
- package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
- package/dist/private/userEventMaps.cjs.map +1 -0
- package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
- package/dist/private/userEventMaps.js.map +1 -0
- package/dist/private/utils.cjs +136 -0
- package/dist/private/utils.cjs.map +1 -0
- package/dist/private/utils.js +127 -0
- package/dist/private/utils.js.map +1 -0
- package/dist/types/src/act.d.ts +4 -0
- package/dist/types/src/checkboxgroup.d.ts +47 -0
- package/dist/types/src/combobox.d.ts +87 -0
- package/dist/types/src/dialog.d.ts +37 -0
- package/dist/types/src/events.d.ts +25 -0
- package/dist/types/src/gridlist.d.ts +56 -0
- package/dist/types/src/index.d.ts +16 -0
- package/dist/types/src/listbox.d.ts +91 -0
- package/dist/types/src/menu.d.ts +112 -0
- package/dist/types/src/radiogroup.d.ts +47 -0
- package/dist/types/src/select.d.ts +74 -0
- package/dist/types/src/table.d.ts +120 -0
- package/dist/types/src/tabs.d.ts +59 -0
- package/dist/types/src/testSetup.d.ts +6 -0
- package/dist/types/src/tree.d.ts +62 -0
- package/dist/types/src/types.d.ts +143 -0
- package/dist/types/src/user.d.ts +49 -0
- package/dist/types/src/userEventMaps.d.ts +2 -0
- package/dist/types/src/utils.d.ts +29 -0
- package/package.json +26 -18
- package/src/act.ts +35 -0
- package/src/checkboxgroup.ts +165 -0
- package/src/combobox.ts +307 -0
- package/src/dialog.ts +155 -0
- package/src/gridlist.ts +278 -0
- package/src/index.ts +17 -3
- package/src/listbox.ts +300 -0
- package/src/menu.ts +479 -0
- package/src/radiogroup.ts +179 -0
- package/src/select.ts +273 -0
- package/src/table.ts +589 -0
- package/src/tabs.ts +204 -0
- package/src/testSetup.ts +41 -36
- package/src/tree.ts +290 -0
- package/src/types.ts +171 -0
- package/src/user.ts +153 -0
- package/src/userEventMaps.ts +1 -1
- package/src/utils.ts +155 -0
- package/dist/events.main.js +0 -37
- package/dist/events.main.js.map +0 -1
- package/dist/events.mjs +0 -31
- package/dist/events.module.js +0 -31
- package/dist/events.module.js.map +0 -1
- package/dist/testSetup.main.js +0 -82
- package/dist/testSetup.main.js.map +0 -1
- package/dist/testSetup.mjs +0 -76
- package/dist/testSetup.module.js +0 -76
- package/dist/testSetup.module.js.map +0 -1
- package/dist/types.d.ts +0 -16
- package/dist/types.d.ts.map +0 -1
- package/dist/userEventMaps.main.js.map +0 -1
- package/dist/userEventMaps.module.js +0 -38
- package/dist/userEventMaps.module.js.map +0 -1
- package/src/events.ts +0 -28
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SelectTesterOpts, UserOpts } from './types';
|
|
2
|
+
interface SelectOpenOpts {
|
|
3
|
+
/**
|
|
4
|
+
* What interaction type to use when opening the select. Defaults to the interaction type set on
|
|
5
|
+
* the tester.
|
|
6
|
+
*/
|
|
7
|
+
interactionType?: UserOpts['interactionType'];
|
|
8
|
+
}
|
|
9
|
+
interface SelectTriggerOptionOpts extends SelectOpenOpts {
|
|
10
|
+
/**
|
|
11
|
+
* The index, text, or node of the option to select. Option nodes can be sourced via
|
|
12
|
+
* `getOptions()`.
|
|
13
|
+
*/
|
|
14
|
+
option: number | string | HTMLElement;
|
|
15
|
+
/**
|
|
16
|
+
* Whether or not the select closes on selection. Depends on select implementation and
|
|
17
|
+
* configuration.
|
|
18
|
+
*
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
closesOnSelect?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class SelectTester {
|
|
24
|
+
private user;
|
|
25
|
+
private _interactionType;
|
|
26
|
+
private _trigger;
|
|
27
|
+
constructor(opts: SelectTesterOpts);
|
|
28
|
+
/**
|
|
29
|
+
* Set the interaction type used by the select tester.
|
|
30
|
+
*/
|
|
31
|
+
setInteractionType(type: UserOpts['interactionType']): void;
|
|
32
|
+
/**
|
|
33
|
+
* Opens the select. Defaults to using the interaction type set on the select tester.
|
|
34
|
+
*/
|
|
35
|
+
open(opts?: SelectOpenOpts): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Closes the select.
|
|
38
|
+
*/
|
|
39
|
+
close(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Returns a option matching the specified index or text content.
|
|
42
|
+
*/
|
|
43
|
+
findOption(opts: {
|
|
44
|
+
indexOrText: number | string;
|
|
45
|
+
}): HTMLElement;
|
|
46
|
+
private keyboardNavigateToOption;
|
|
47
|
+
/**
|
|
48
|
+
* Toggles the selection of the desired select option if possible. Defaults to using the
|
|
49
|
+
* interaction type set on the select tester. If necessary, will open the select dropdown
|
|
50
|
+
* beforehand. The desired option can be targeted via the option's node, the option's text, or the
|
|
51
|
+
* option's index.
|
|
52
|
+
*/
|
|
53
|
+
toggleOptionSelection(opts: SelectTriggerOptionOpts): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the select's options if present. Can be filtered to a subsection of the listbox if
|
|
56
|
+
* provided via `element`.
|
|
57
|
+
*/
|
|
58
|
+
getOptions(opts?: {
|
|
59
|
+
element?: HTMLElement;
|
|
60
|
+
}): HTMLElement[];
|
|
61
|
+
/**
|
|
62
|
+
* Returns the select's trigger.
|
|
63
|
+
*/
|
|
64
|
+
getTrigger(): HTMLElement;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the select's listbox if present.
|
|
67
|
+
*/
|
|
68
|
+
getListbox(): HTMLElement | null;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the select's sections if present.
|
|
71
|
+
*/
|
|
72
|
+
getSections(): HTMLElement[];
|
|
73
|
+
}
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { BaseGridRowInteractionOpts, GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts } from './types';
|
|
2
|
+
interface TableToggleRowOpts extends ToggleGridRowOpts {
|
|
3
|
+
}
|
|
4
|
+
interface TableToggleExpansionOpts extends BaseGridRowInteractionOpts {
|
|
5
|
+
}
|
|
6
|
+
interface TableToggleSortOpts {
|
|
7
|
+
/**
|
|
8
|
+
* The index, text, or node of the column to toggle selection for.
|
|
9
|
+
*/
|
|
10
|
+
column: number | string | HTMLElement;
|
|
11
|
+
/**
|
|
12
|
+
* What interaction type to use when sorting the column. Defaults to the interaction type set on
|
|
13
|
+
* the tester.
|
|
14
|
+
*/
|
|
15
|
+
interactionType?: UserOpts['interactionType'];
|
|
16
|
+
}
|
|
17
|
+
interface TableColumnHeaderActionOpts extends TableToggleSortOpts {
|
|
18
|
+
/**
|
|
19
|
+
* The index of the column header action to trigger.
|
|
20
|
+
*/
|
|
21
|
+
action: number;
|
|
22
|
+
}
|
|
23
|
+
interface TableRowActionOpts extends GridRowActionOpts {
|
|
24
|
+
}
|
|
25
|
+
export declare class TableTester {
|
|
26
|
+
private user;
|
|
27
|
+
private _interactionType;
|
|
28
|
+
private _advanceTimer;
|
|
29
|
+
private _direction;
|
|
30
|
+
private _table;
|
|
31
|
+
constructor(opts: TableTesterOpts);
|
|
32
|
+
/**
|
|
33
|
+
* Set the interaction type used by the table tester.
|
|
34
|
+
*/
|
|
35
|
+
setInteractionType(type: UserOpts['interactionType']): void;
|
|
36
|
+
private keyboardNavigateToRow;
|
|
37
|
+
/**
|
|
38
|
+
* Toggles the selection for the specified table row. Defaults to using the interaction type set
|
|
39
|
+
* on the table tester.
|
|
40
|
+
*/
|
|
41
|
+
toggleRowSelection(opts: TableToggleRowOpts): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Toggles the expansion for the specified tree row. Defaults to using the interaction type set on
|
|
44
|
+
* the tree tester.
|
|
45
|
+
*/
|
|
46
|
+
toggleRowExpansion(opts: TableToggleExpansionOpts): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Toggles the sort order for the specified table column. Defaults to using the interaction type
|
|
49
|
+
* set on the table tester.
|
|
50
|
+
*/
|
|
51
|
+
toggleSort(opts: TableToggleSortOpts): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Triggers an action for the specified table column menu. Defaults to using the interaction type
|
|
54
|
+
* set on the table tester.
|
|
55
|
+
*/
|
|
56
|
+
triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Triggers the action for the specified table row. Defaults to using the interaction type set on
|
|
59
|
+
* the table tester.
|
|
60
|
+
*/
|
|
61
|
+
triggerRowAction(opts: TableRowActionOpts): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Toggle selection for all rows in the table. Defaults to using the interaction type set on the
|
|
64
|
+
* table tester.
|
|
65
|
+
*/
|
|
66
|
+
toggleSelectAll(opts?: {
|
|
67
|
+
interactionType?: UserOpts['interactionType'];
|
|
68
|
+
}): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Returns a row matching the specified index or text content.
|
|
71
|
+
*/
|
|
72
|
+
findRow(opts: {
|
|
73
|
+
indexOrText: number | string;
|
|
74
|
+
}): HTMLElement;
|
|
75
|
+
/**
|
|
76
|
+
* Returns a cell matching the specified text content.
|
|
77
|
+
*/
|
|
78
|
+
findCell(opts: {
|
|
79
|
+
text: string;
|
|
80
|
+
}): HTMLElement;
|
|
81
|
+
/**
|
|
82
|
+
* Returns the table.
|
|
83
|
+
*/
|
|
84
|
+
getTable(): HTMLElement;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the row groups within the table.
|
|
87
|
+
*/
|
|
88
|
+
getRowGroups(): HTMLElement[];
|
|
89
|
+
/**
|
|
90
|
+
* Returns the columns within the table.
|
|
91
|
+
*/
|
|
92
|
+
getColumns(): HTMLElement[];
|
|
93
|
+
/**
|
|
94
|
+
* Returns the rows within the table if any. Can be filtered to a specific row group if provided
|
|
95
|
+
* via `element`.
|
|
96
|
+
*/
|
|
97
|
+
getRows(opts?: {
|
|
98
|
+
element?: HTMLElement;
|
|
99
|
+
}): HTMLElement[];
|
|
100
|
+
/**
|
|
101
|
+
* Returns the currently selected rows within the table if any.
|
|
102
|
+
*/
|
|
103
|
+
getSelectedRows(): HTMLElement[];
|
|
104
|
+
/**
|
|
105
|
+
* Returns the footer rows within the table if any.
|
|
106
|
+
*/
|
|
107
|
+
getFooterRows(): HTMLElement[];
|
|
108
|
+
/**
|
|
109
|
+
* Returns the row headers within the table if any.
|
|
110
|
+
*/
|
|
111
|
+
getRowHeaders(): HTMLElement[];
|
|
112
|
+
/**
|
|
113
|
+
* Returns the cells within the table if any. Can be filtered against a specific row if provided
|
|
114
|
+
* via `element`.
|
|
115
|
+
*/
|
|
116
|
+
getCells(opts?: {
|
|
117
|
+
element?: HTMLElement;
|
|
118
|
+
}): HTMLElement[];
|
|
119
|
+
}
|
|
120
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TabsTesterOpts, UserOpts } from './types';
|
|
2
|
+
interface TriggerTabOptions {
|
|
3
|
+
/**
|
|
4
|
+
* What interaction type to use when triggering a tab. Defaults to the interaction type set on the
|
|
5
|
+
* tester.
|
|
6
|
+
*/
|
|
7
|
+
interactionType?: UserOpts['interactionType'];
|
|
8
|
+
/**
|
|
9
|
+
* The index, text, or node of the tab to toggle selection for.
|
|
10
|
+
*/
|
|
11
|
+
tab: number | string | HTMLElement;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the tab needs to be activated manually rather than on focus.
|
|
14
|
+
*/
|
|
15
|
+
manualActivation?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class TabsTester {
|
|
18
|
+
private user;
|
|
19
|
+
private _interactionType;
|
|
20
|
+
private _tablist;
|
|
21
|
+
private _direction;
|
|
22
|
+
constructor(opts: TabsTesterOpts);
|
|
23
|
+
/**
|
|
24
|
+
* Set the interaction type used by the tabs tester.
|
|
25
|
+
*/
|
|
26
|
+
setInteractionType(type: UserOpts['interactionType']): void;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a tab matching the specified index or text content.
|
|
29
|
+
*/
|
|
30
|
+
findTab(opts: {
|
|
31
|
+
indexOrText: number | string;
|
|
32
|
+
}): HTMLElement;
|
|
33
|
+
private keyboardNavigateToTab;
|
|
34
|
+
/**
|
|
35
|
+
* Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.
|
|
36
|
+
*/
|
|
37
|
+
triggerTab(opts: TriggerTabOptions): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the tablist.
|
|
40
|
+
*/
|
|
41
|
+
getTablist(): HTMLElement;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the tabpanels.
|
|
44
|
+
*/
|
|
45
|
+
getTabpanels(): HTMLElement[];
|
|
46
|
+
/**
|
|
47
|
+
* Returns the tabs in the tablist.
|
|
48
|
+
*/
|
|
49
|
+
getTabs(): HTMLElement[];
|
|
50
|
+
/**
|
|
51
|
+
* Returns the currently selected tab in the tablist if any.
|
|
52
|
+
*/
|
|
53
|
+
getSelectedTab(): HTMLElement | null;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the currently active tabpanel if any.
|
|
56
|
+
*/
|
|
57
|
+
getActiveTabpanel(): HTMLElement | null;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { BaseGridRowInteractionOpts, GridRowActionOpts, ToggleGridRowOpts, TreeTesterOpts, UserOpts } from './types';
|
|
2
|
+
interface TreeToggleExpansionOpts extends BaseGridRowInteractionOpts {
|
|
3
|
+
}
|
|
4
|
+
interface TreeToggleRowOpts extends ToggleGridRowOpts {
|
|
5
|
+
}
|
|
6
|
+
interface TreeRowActionOpts extends GridRowActionOpts {
|
|
7
|
+
}
|
|
8
|
+
export declare class TreeTester {
|
|
9
|
+
private user;
|
|
10
|
+
private _interactionType;
|
|
11
|
+
private _advanceTimer;
|
|
12
|
+
private _direction;
|
|
13
|
+
private _tree;
|
|
14
|
+
constructor(opts: TreeTesterOpts);
|
|
15
|
+
/**
|
|
16
|
+
* Set the interaction type used by the tree tester.
|
|
17
|
+
*/
|
|
18
|
+
setInteractionType(type: UserOpts['interactionType']): void;
|
|
19
|
+
/**
|
|
20
|
+
* Returns a row matching the specified index or text content.
|
|
21
|
+
*/
|
|
22
|
+
findRow(opts: {
|
|
23
|
+
indexOrText: number | string;
|
|
24
|
+
}): HTMLElement;
|
|
25
|
+
private keyboardNavigateToRow;
|
|
26
|
+
/**
|
|
27
|
+
* Toggles the selection for the specified tree row. Defaults to using the interaction type set on
|
|
28
|
+
* the tree tester. Note that this will endevor to always add/remove JUST the provided row to the
|
|
29
|
+
* set of selected rows.
|
|
30
|
+
*/
|
|
31
|
+
toggleRowSelection(opts: TreeToggleRowOpts): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Toggles the expansion for the specified tree row. Defaults to using the interaction type set on
|
|
34
|
+
* the tree tester.
|
|
35
|
+
*/
|
|
36
|
+
toggleRowExpansion(opts: TreeToggleExpansionOpts): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Triggers the action for the specified tree row. Defaults to using the interaction type set on
|
|
39
|
+
* the tree tester.
|
|
40
|
+
*/
|
|
41
|
+
triggerRowAction(opts: TreeRowActionOpts): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the tree.
|
|
44
|
+
*/
|
|
45
|
+
getTree(): HTMLElement;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the tree's rows if any.
|
|
48
|
+
*/
|
|
49
|
+
getRows(): HTMLElement[];
|
|
50
|
+
/**
|
|
51
|
+
* Returns the tree's selected rows if any.
|
|
52
|
+
*/
|
|
53
|
+
getSelectedRows(): HTMLElement[];
|
|
54
|
+
/**
|
|
55
|
+
* Returns the tree's cells if any. Can be filtered against a specific row if provided via
|
|
56
|
+
* `element`.
|
|
57
|
+
*/
|
|
58
|
+
getCells(opts?: {
|
|
59
|
+
element?: HTMLElement;
|
|
60
|
+
}): HTMLElement[];
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export type Orientation = 'horizontal' | 'vertical';
|
|
2
|
+
export type Direction = 'ltr' | 'rtl';
|
|
3
|
+
export interface UserOpts {
|
|
4
|
+
/**
|
|
5
|
+
* The interaction type (mouse, touch, keyboard) that the test util user will use when interacting
|
|
6
|
+
* with a component. This can be overridden at the aria pattern tester level if needed.
|
|
7
|
+
*
|
|
8
|
+
* @default mouse
|
|
9
|
+
*/
|
|
10
|
+
interactionType?: 'mouse' | 'touch' | 'keyboard';
|
|
11
|
+
/**
|
|
12
|
+
* A function used by the test utils to advance timers during interactions. Required for certain
|
|
13
|
+
* aria patterns (e.g. table). This can be overridden at the aria pattern tester level if needed.
|
|
14
|
+
*/
|
|
15
|
+
advanceTimer?: (time: number) => unknown | Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface BaseTesterOpts extends UserOpts {
|
|
18
|
+
/** @private */
|
|
19
|
+
user?: any;
|
|
20
|
+
/** The base element for the given tester (e.g. the table, menu trigger button, etc). */
|
|
21
|
+
root: HTMLElement;
|
|
22
|
+
/**
|
|
23
|
+
* The horizontal layout direction, typically affected by locale.
|
|
24
|
+
*
|
|
25
|
+
* @default 'ltr'
|
|
26
|
+
*/
|
|
27
|
+
direction?: Direction;
|
|
28
|
+
}
|
|
29
|
+
export interface CheckboxGroupTesterOpts extends BaseTesterOpts {
|
|
30
|
+
}
|
|
31
|
+
export interface ComboBoxTesterOpts extends BaseTesterOpts {
|
|
32
|
+
/**
|
|
33
|
+
* The base element for the combobox. If provided the wrapping element around the target combobox
|
|
34
|
+
* (as is the the case with a ref provided to RSP ComboBox), will automatically search for the
|
|
35
|
+
* combobox element within.
|
|
36
|
+
*/
|
|
37
|
+
root: HTMLElement;
|
|
38
|
+
/**
|
|
39
|
+
* The node of the combobox trigger button if any. If not provided, we will try to automatically
|
|
40
|
+
* use any button within the `root` provided or that the `root` serves as the trigger.
|
|
41
|
+
*/
|
|
42
|
+
trigger?: HTMLElement;
|
|
43
|
+
}
|
|
44
|
+
export interface DialogTesterOpts extends BaseTesterOpts {
|
|
45
|
+
/**
|
|
46
|
+
* The trigger element for the dialog.
|
|
47
|
+
*/
|
|
48
|
+
root: HTMLElement;
|
|
49
|
+
/**
|
|
50
|
+
* The overlay type of the dialog. Used to inform the tester how to find the dialog.
|
|
51
|
+
*/
|
|
52
|
+
overlayType?: 'modal' | 'popover';
|
|
53
|
+
}
|
|
54
|
+
export interface GridListTesterOpts extends BaseTesterOpts {
|
|
55
|
+
/**
|
|
56
|
+
* The layout of the gridlist.
|
|
57
|
+
*
|
|
58
|
+
* @default 'stack'
|
|
59
|
+
*/
|
|
60
|
+
layout?: 'stack' | 'grid';
|
|
61
|
+
}
|
|
62
|
+
export interface ListBoxTesterOpts extends BaseTesterOpts {
|
|
63
|
+
/**
|
|
64
|
+
* The layout of the listbox.
|
|
65
|
+
*
|
|
66
|
+
* @default 'stack'
|
|
67
|
+
*/
|
|
68
|
+
layout?: 'stack' | 'grid';
|
|
69
|
+
}
|
|
70
|
+
export interface MenuTesterOpts extends BaseTesterOpts {
|
|
71
|
+
/**
|
|
72
|
+
* The trigger element for the menu.
|
|
73
|
+
*/
|
|
74
|
+
root: HTMLElement;
|
|
75
|
+
/**
|
|
76
|
+
* Whether the current menu is a submenu.
|
|
77
|
+
*/
|
|
78
|
+
isSubmenu?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* The root menu of the menu tree. Only available if the menu is a submenu.
|
|
81
|
+
*/
|
|
82
|
+
rootMenu?: HTMLElement;
|
|
83
|
+
}
|
|
84
|
+
export interface RadioGroupTesterOpts extends BaseTesterOpts {
|
|
85
|
+
}
|
|
86
|
+
export interface SelectTesterOpts extends BaseTesterOpts {
|
|
87
|
+
/**
|
|
88
|
+
* The trigger element for the select. If provided the wrapping element around the target select
|
|
89
|
+
* (as is the case with a ref provided to RSP Select), will automatically search for the select's
|
|
90
|
+
* trigger element within.
|
|
91
|
+
*/
|
|
92
|
+
root: HTMLElement;
|
|
93
|
+
}
|
|
94
|
+
export interface TableTesterOpts extends BaseTesterOpts {
|
|
95
|
+
}
|
|
96
|
+
export interface TabsTesterOpts extends BaseTesterOpts {
|
|
97
|
+
}
|
|
98
|
+
export interface TreeTesterOpts extends BaseTesterOpts {
|
|
99
|
+
}
|
|
100
|
+
export interface BaseGridRowInteractionOpts {
|
|
101
|
+
/**
|
|
102
|
+
* The index, text, or node of the row to target.
|
|
103
|
+
*/
|
|
104
|
+
row: number | string | HTMLElement;
|
|
105
|
+
/**
|
|
106
|
+
* What interaction type to use when interacting with the row. Defaults to the interaction type
|
|
107
|
+
* set on the tester.
|
|
108
|
+
*/
|
|
109
|
+
interactionType?: UserOpts['interactionType'];
|
|
110
|
+
}
|
|
111
|
+
export interface ToggleGridRowOpts extends BaseGridRowInteractionOpts {
|
|
112
|
+
/**
|
|
113
|
+
* Whether the row needs to be long pressed to be selected. Depends on the components
|
|
114
|
+
* implementation.
|
|
115
|
+
*/
|
|
116
|
+
needsLongPress?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Whether the checkbox should be used to select the row. If false, will attempt to select the row
|
|
119
|
+
* via press.
|
|
120
|
+
*
|
|
121
|
+
* @default 'true'
|
|
122
|
+
*/
|
|
123
|
+
checkboxSelection?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Whether the grid has a selectionBehavior of "toggle" or "replace" (aka highlight selection).
|
|
126
|
+
* This affects the user operations required to toggle row selection by adding modifier keys
|
|
127
|
+
* during user actions, useful when performing multi-row selection in a "selectionBehavior:
|
|
128
|
+
* 'replace'" grid. If you would like to still simulate user actions (aka press) without these
|
|
129
|
+
* modifiers keys for a "selectionBehavior: replace" grid, simply omit this option. See the
|
|
130
|
+
* "Selection Behavior" section of the appropriate React Aria Component docs for more information
|
|
131
|
+
* (e.g. https://react-aria.adobe.com/Tree#selection-and-actions).
|
|
132
|
+
*
|
|
133
|
+
* @default 'toggle'
|
|
134
|
+
*/
|
|
135
|
+
selectionBehavior?: 'toggle' | 'replace';
|
|
136
|
+
}
|
|
137
|
+
export interface GridRowActionOpts extends BaseGridRowInteractionOpts {
|
|
138
|
+
/**
|
|
139
|
+
* Whether or not the row needs a double click to trigger the row action. Depends on the
|
|
140
|
+
* components implementation.
|
|
141
|
+
*/
|
|
142
|
+
needsDoubleClick?: boolean;
|
|
143
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CheckboxGroupTester } from './checkboxgroup';
|
|
2
|
+
import { CheckboxGroupTesterOpts, ComboBoxTesterOpts, DialogTesterOpts, GridListTesterOpts, ListBoxTesterOpts, MenuTesterOpts, RadioGroupTesterOpts, SelectTesterOpts, TableTesterOpts, TabsTesterOpts, TreeTesterOpts, UserOpts } from './types';
|
|
3
|
+
import { ComboBoxTester } from './combobox';
|
|
4
|
+
import { DialogTester } from './dialog';
|
|
5
|
+
import { GridListTester } from './gridlist';
|
|
6
|
+
import { ListBoxTester } from './listbox';
|
|
7
|
+
import { MenuTester } from './menu';
|
|
8
|
+
import { RadioGroupTester } from './radiogroup';
|
|
9
|
+
import { SelectTester } from './select';
|
|
10
|
+
import { TableTester } from './table';
|
|
11
|
+
import { TabsTester } from './tabs';
|
|
12
|
+
import { TreeTester } from './tree';
|
|
13
|
+
declare let keyToUtil: {
|
|
14
|
+
CheckboxGroup: typeof CheckboxGroupTester;
|
|
15
|
+
ComboBox: typeof ComboBoxTester;
|
|
16
|
+
Dialog: typeof DialogTester;
|
|
17
|
+
GridList: typeof GridListTester;
|
|
18
|
+
ListBox: typeof ListBoxTester;
|
|
19
|
+
Menu: typeof MenuTester;
|
|
20
|
+
RadioGroup: typeof RadioGroupTester;
|
|
21
|
+
Select: typeof SelectTester;
|
|
22
|
+
Table: typeof TableTester;
|
|
23
|
+
Tabs: typeof TabsTester;
|
|
24
|
+
Tree: typeof TreeTester;
|
|
25
|
+
};
|
|
26
|
+
export type PatternNames = keyof typeof keyToUtil;
|
|
27
|
+
type Tester<T> = T extends 'CheckboxGroup' ? CheckboxGroupTester : T extends 'ComboBox' ? ComboBoxTester : T extends 'Dialog' ? DialogTester : T extends 'GridList' ? GridListTester : T extends 'ListBox' ? ListBoxTester : T extends 'Menu' ? MenuTester : T extends 'RadioGroup' ? RadioGroupTester : T extends 'Select' ? SelectTester : T extends 'Table' ? TableTester : T extends 'Tabs' ? TabsTester : T extends 'Tree' ? TreeTester : never;
|
|
28
|
+
type TesterOpts<T> = T extends 'CheckboxGroup' ? CheckboxGroupTesterOpts : T extends 'ComboBox' ? ComboBoxTesterOpts : T extends 'Dialog' ? DialogTesterOpts : T extends 'GridList' ? GridListTesterOpts : T extends 'ListBox' ? ListBoxTesterOpts : T extends 'Menu' ? MenuTesterOpts : T extends 'RadioGroup' ? RadioGroupTesterOpts : T extends 'Select' ? SelectTesterOpts : T extends 'Table' ? TableTesterOpts : T extends 'Tabs' ? TabsTesterOpts : T extends 'Tree' ? TreeTesterOpts : never;
|
|
29
|
+
export declare class User {
|
|
30
|
+
private user;
|
|
31
|
+
/**
|
|
32
|
+
* The interaction type (mouse, touch, keyboard) that the test util user will use when interacting
|
|
33
|
+
* with a component. This can be overridden at the aria pattern util level if needed.
|
|
34
|
+
*
|
|
35
|
+
* @default mouse
|
|
36
|
+
*/
|
|
37
|
+
interactionType: UserOpts['interactionType'];
|
|
38
|
+
/**
|
|
39
|
+
* A function used by the test utils to advance timers during interactions. Required for certain
|
|
40
|
+
* aria patterns (e.g. table).
|
|
41
|
+
*/
|
|
42
|
+
advanceTimer: UserOpts['advanceTimer'];
|
|
43
|
+
constructor(opts?: UserOpts);
|
|
44
|
+
/**
|
|
45
|
+
* Creates an aria pattern tester, inheriting the options provided to the original user.
|
|
46
|
+
*/
|
|
47
|
+
createTester<T extends PatternNames>(patternName: T, opts: TesterOpts<T>): Tester<T>;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { UserOpts } from './types';
|
|
2
|
+
export declare const DEFAULT_LONG_PRESS_TIME = 500;
|
|
3
|
+
export declare function getAltKey(): 'Alt' | 'ControlLeft';
|
|
4
|
+
export declare function getMetaKey(): 'MetaLeft' | 'ControlLeft';
|
|
5
|
+
export declare function formatTargetNode(value: number | string | HTMLElement): string;
|
|
6
|
+
/**
|
|
7
|
+
* Simulates a "long press" event on a element.
|
|
8
|
+
*
|
|
9
|
+
* @param opts - Options for the long press.
|
|
10
|
+
* @param opts.element - Element to long press.
|
|
11
|
+
* @param opts.advanceTimer - Function that when called advances the timers in your test suite by a
|
|
12
|
+
* specific amount of time(ms).
|
|
13
|
+
* @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See
|
|
14
|
+
* https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.
|
|
15
|
+
*/
|
|
16
|
+
export declare function triggerLongPress(opts: {
|
|
17
|
+
element: HTMLElement;
|
|
18
|
+
advanceTimer: (time: number) => unknown | Promise<unknown>;
|
|
19
|
+
pointerOpts?: Record<string, any>;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
export declare function pressElement(user: {
|
|
22
|
+
click: (element: Element) => Promise<void>;
|
|
23
|
+
keyboard: (keys: string) => Promise<void>;
|
|
24
|
+
pointer: (opts: {
|
|
25
|
+
target: Element;
|
|
26
|
+
keys: string;
|
|
27
|
+
coords?: any;
|
|
28
|
+
}) => Promise<void>;
|
|
29
|
+
}, element: HTMLElement, interactionType: UserOpts['interactionType']): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,37 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/test-utils",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.0",
|
|
4
4
|
"description": "Testing utils for react-aria patterns",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"types": "./dist/types.d.ts",
|
|
10
|
-
"import": "./dist/import.mjs",
|
|
11
|
-
"require": "./dist/main.js"
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/adobe/react-spectrum"
|
|
12
9
|
},
|
|
13
|
-
"types": "dist/types.d.ts",
|
|
14
10
|
"source": "src/index.ts",
|
|
15
11
|
"files": [
|
|
16
12
|
"dist",
|
|
17
13
|
"src"
|
|
18
14
|
],
|
|
19
15
|
"sideEffects": false,
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
"main": "dist/main.js",
|
|
17
|
+
"module": "dist/module.js",
|
|
18
|
+
"types": "./dist/types/src/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
"source": "./src/index.ts",
|
|
21
|
+
"types": "./dist/types/src/index.d.ts",
|
|
22
|
+
"import": "./dist/import.mjs",
|
|
23
|
+
"require": "./dist/main.js"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
23
27
|
},
|
|
24
28
|
"dependencies": {
|
|
25
29
|
"@swc/helpers": "^0.5.0"
|
|
26
30
|
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
33
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
34
|
+
},
|
|
27
35
|
"peerDependencies": {
|
|
28
|
-
"@testing-library/
|
|
29
|
-
"@testing-library/user-event": "^
|
|
30
|
-
"
|
|
31
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
36
|
+
"@testing-library/dom": "^10.0.0",
|
|
37
|
+
"@testing-library/user-event": "^14.0.0",
|
|
38
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
39
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
32
40
|
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
41
|
+
"targets": {
|
|
42
|
+
"types": false
|
|
35
43
|
},
|
|
36
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "3577a20859b9585a000010c720f6ee39c1c588cc"
|
|
37
45
|
}
|
package/src/act.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import * as ReactDOMTestUtils from 'react-dom/test-utils';
|
|
15
|
+
|
|
16
|
+
let actImpl: typeof ReactDOMTestUtils.act;
|
|
17
|
+
if (typeof React.act === 'function') {
|
|
18
|
+
actImpl = React.act;
|
|
19
|
+
} else {
|
|
20
|
+
actImpl = ReactDOMTestUtils.act;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const act: typeof actImpl = fn => {
|
|
24
|
+
// only wrap in act if in test environment, breaks vite browser test if test utils are used otherwise
|
|
25
|
+
if (
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
typeof IS_REACT_ACT_ENVIRONMENT === 'boolean'
|
|
28
|
+
? // @ts-ignore
|
|
29
|
+
IS_REACT_ACT_ENVIRONMENT
|
|
30
|
+
: typeof jest !== 'undefined'
|
|
31
|
+
) {
|
|
32
|
+
return actImpl(fn);
|
|
33
|
+
}
|
|
34
|
+
return fn();
|
|
35
|
+
};
|