@react-aria/test-utils 1.0.0-alpha.1 → 1.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/combobox.main.js +137 -0
  2. package/dist/combobox.main.js.map +1 -0
  3. package/dist/combobox.mjs +132 -0
  4. package/dist/combobox.module.js +132 -0
  5. package/dist/combobox.module.js.map +1 -0
  6. package/dist/events.main.js +25 -10
  7. package/dist/events.main.js.map +1 -1
  8. package/dist/events.mjs +25 -10
  9. package/dist/events.module.js +25 -10
  10. package/dist/events.module.js.map +1 -1
  11. package/dist/gridlist.main.js +97 -0
  12. package/dist/gridlist.main.js.map +1 -0
  13. package/dist/gridlist.mjs +92 -0
  14. package/dist/gridlist.module.js +92 -0
  15. package/dist/gridlist.module.js.map +1 -0
  16. package/dist/import.mjs +4 -2
  17. package/dist/main.js +10 -18
  18. package/dist/main.js.map +1 -1
  19. package/dist/menu.main.js +220 -0
  20. package/dist/menu.main.js.map +1 -0
  21. package/dist/menu.mjs +215 -0
  22. package/dist/menu.module.js +215 -0
  23. package/dist/menu.module.js.map +1 -0
  24. package/dist/module.js +4 -2
  25. package/dist/module.js.map +1 -1
  26. package/dist/select.main.js +113 -0
  27. package/dist/select.main.js.map +1 -0
  28. package/dist/select.mjs +108 -0
  29. package/dist/select.module.js +108 -0
  30. package/dist/select.module.js.map +1 -0
  31. package/dist/table.main.js +187 -0
  32. package/dist/table.main.js.map +1 -0
  33. package/dist/table.mjs +182 -0
  34. package/dist/table.module.js +182 -0
  35. package/dist/table.module.js.map +1 -0
  36. package/dist/testSetup.main.js +2 -6
  37. package/dist/testSetup.main.js.map +1 -1
  38. package/dist/testSetup.mjs +2 -6
  39. package/dist/testSetup.module.js +2 -6
  40. package/dist/testSetup.module.js.map +1 -1
  41. package/dist/types.d.ts +186 -4
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/user.main.js +65 -0
  44. package/dist/user.main.js.map +1 -0
  45. package/dist/user.mjs +56 -0
  46. package/dist/user.module.js +56 -0
  47. package/dist/user.module.js.map +1 -0
  48. package/package.json +5 -5
  49. package/src/combobox.ts +188 -0
  50. package/src/events.ts +28 -8
  51. package/src/gridlist.ts +116 -0
  52. package/src/index.ts +6 -3
  53. package/src/menu.ts +308 -0
  54. package/src/select.ts +158 -0
  55. package/src/table.ts +273 -0
  56. package/src/testSetup.ts +2 -6
  57. package/src/user.ts +73 -0
package/dist/types.d.ts CHANGED
@@ -1,11 +1,193 @@
1
1
  import { pointerKey } from "@testing-library/user-event/system/pointer/shared";
2
- export const DEFAULT_LONG_PRESS_TIME = 500;
2
+ interface ComboBoxOptions extends UserOpts, BaseTesterOpts {
3
+ user?: any;
4
+ trigger?: HTMLElement;
5
+ }
6
+ declare class ComboBoxTester {
7
+ constructor(opts: ComboBoxOptions);
8
+ setInteractionType: (type: UserOpts["interactionType"]) => void;
9
+ open: (opts?: {
10
+ triggerBehavior?: "focus" | "manual";
11
+ interactionType?: UserOpts["interactionType"];
12
+ }) => Promise<void>;
13
+ selectOption: (opts?: {
14
+ option?: HTMLElement;
15
+ optionText?: string;
16
+ triggerBehavior?: "focus" | "manual";
17
+ interactionType?: UserOpts["interactionType"];
18
+ }) => Promise<void>;
19
+ close: () => Promise<void>;
20
+ get combobox(): HTMLElement;
21
+ get trigger(): HTMLElement | undefined;
22
+ get listbox(): HTMLElement | undefined;
23
+ options: (opts?: {
24
+ element?: HTMLElement;
25
+ }) => HTMLElement[] | never[];
26
+ get sections(): HTMLElement[];
27
+ get focusedOption(): HTMLElement | null | undefined;
28
+ }
29
+ interface GridListOptions extends UserOpts, BaseTesterOpts {
30
+ user?: any;
31
+ }
32
+ declare class GridListTester {
33
+ constructor(opts: GridListOptions);
34
+ setInteractionType: (type: UserOpts["interactionType"]) => void;
35
+ toggleRowSelection: (opts?: {
36
+ index?: number;
37
+ text?: string;
38
+ interactionType?: UserOpts["interactionType"];
39
+ }) => Promise<void>;
40
+ findRow: (opts: {
41
+ index?: number;
42
+ text?: string;
43
+ }) => any;
44
+ triggerRowAction: (opts: {
45
+ index?: number;
46
+ text?: string;
47
+ needsDoubleClick?: boolean;
48
+ interactionType?: UserOpts["interactionType"];
49
+ }) => Promise<void>;
50
+ get gridlist(): HTMLElement;
51
+ get rows(): HTMLElement[];
52
+ get selectedRows(): HTMLElement[];
53
+ cells: (opts?: {
54
+ element?: HTMLElement;
55
+ }) => HTMLElement[];
56
+ }
57
+ interface MenuOptions extends UserOpts, BaseTesterOpts {
58
+ user?: any;
59
+ isSubmenu?: boolean;
60
+ }
61
+ declare class MenuTester {
62
+ constructor(opts: MenuOptions);
63
+ setInteractionType: (type: UserOpts["interactionType"]) => void;
64
+ open: (opts?: {
65
+ needsLongPress?: boolean;
66
+ interactionType?: UserOpts["interactionType"];
67
+ direction?: "up" | "down";
68
+ }) => Promise<void>;
69
+ selectOption: (opts: {
70
+ option?: HTMLElement;
71
+ optionText?: string;
72
+ menuSelectionMode?: "single" | "multiple";
73
+ needsLongPress?: boolean;
74
+ closesOnSelect?: boolean;
75
+ interactionType?: UserOpts["interactionType"];
76
+ keyboardActivation?: "Space" | "Enter";
77
+ }) => Promise<void>;
78
+ openSubmenu: (opts: {
79
+ submenuTrigger?: HTMLElement;
80
+ submenuTriggerText?: string;
81
+ needsLongPress?: boolean;
82
+ interactionType?: UserOpts["interactionType"];
83
+ }) => Promise<MenuTester | null>;
84
+ keyboardNavigateToOption: (opts: {
85
+ option: HTMLElement;
86
+ }) => Promise<void>;
87
+ close: () => Promise<void>;
88
+ get trigger(): HTMLElement;
89
+ get menu(): HTMLElement | null | undefined;
90
+ get options(): HTMLElement[];
91
+ get sections(): HTMLElement[];
92
+ get submenuTriggers(): HTMLElement[];
93
+ }
94
+ interface SelectOptions extends UserOpts, BaseTesterOpts {
95
+ user?: any;
96
+ }
97
+ declare class SelectTester {
98
+ constructor(opts: SelectOptions);
99
+ setInteractionType: (type: UserOpts["interactionType"]) => void;
100
+ open: (opts?: {
101
+ interactionType?: UserOpts["interactionType"];
102
+ }) => Promise<void>;
103
+ selectOption: (opts: {
104
+ optionText: string;
105
+ interactionType?: UserOpts["interactionType"];
106
+ }) => Promise<void>;
107
+ close: () => Promise<void>;
108
+ get trigger(): HTMLElement;
109
+ get listbox(): HTMLElement | null | undefined;
110
+ get options(): HTMLElement[];
111
+ get sections(): HTMLElement[];
112
+ }
113
+ interface TableOptions extends UserOpts, BaseTesterOpts {
114
+ user?: any;
115
+ advanceTimer: UserOpts['advanceTimer'];
116
+ }
117
+ declare class TableTester {
118
+ constructor(opts: TableOptions);
119
+ setInteractionType: (type: UserOpts["interactionType"]) => void;
120
+ toggleRowSelection: (opts?: {
121
+ index?: number;
122
+ text?: string;
123
+ needsLongPress?: boolean;
124
+ interactionType?: UserOpts["interactionType"];
125
+ }) => Promise<void>;
126
+ toggleSort: (opts?: {
127
+ index?: number;
128
+ text?: string;
129
+ interactionType?: UserOpts["interactionType"];
130
+ }) => Promise<void>;
131
+ triggerRowAction: (opts?: {
132
+ index?: number;
133
+ text?: string;
134
+ needsDoubleClick?: boolean;
135
+ interactionType?: UserOpts["interactionType"];
136
+ }) => Promise<void>;
137
+ toggleSelectAll: (opts?: {
138
+ interactionType?: UserOpts["interactionType"];
139
+ }) => Promise<void>;
140
+ findRow: (opts?: {
141
+ index?: number;
142
+ text?: string;
143
+ }) => any;
144
+ findCell: (opts: {
145
+ text: string;
146
+ }) => HTMLElement;
147
+ get table(): HTMLElement;
148
+ get rowGroups(): HTMLElement[];
149
+ get columns(): HTMLElement[];
150
+ get rows(): HTMLElement[];
151
+ get selectedRows(): HTMLElement[];
152
+ get rowHeaders(): HTMLElement[];
153
+ get cells(): HTMLElement[];
154
+ }
155
+ export interface UserOpts {
156
+ interactionType?: 'mouse' | 'touch' | 'keyboard';
157
+ advanceTimer?: (time?: number) => void | Promise<unknown>;
158
+ }
159
+ interface BaseTesterOpts {
160
+ root: HTMLElement;
161
+ }
162
+ declare let keyToUtil: {
163
+ readonly Select: typeof SelectTester;
164
+ readonly Table: typeof TableTester;
165
+ readonly Menu: typeof MenuTester;
166
+ readonly ComboBox: typeof ComboBoxTester;
167
+ readonly GridList: typeof GridListTester;
168
+ };
169
+ type PatternNames = keyof typeof keyToUtil;
170
+ type ObjectType<T> = T extends 'Select' ? SelectTester : T extends 'Table' ? TableTester : T extends 'Menu' ? MenuTester : T extends 'ComboBox' ? ComboBoxTester : T extends 'GridList' ? GridListTester : never;
171
+ type ObjectOptionsTypes<T> = T extends 'Select' ? SelectOptions : T extends 'Table' ? TableOptions : T extends 'Menu' ? MenuOptions : T extends 'ComboBox' ? ComboBoxOptions : T extends 'GridList' ? GridListOptions : never;
172
+ export class User {
173
+ user: any;
174
+ interactionType: UserOpts['interactionType'];
175
+ advanceTimer: UserOpts['advanceTimer'];
176
+ constructor(opts?: UserOpts);
177
+ createTester<T extends PatternNames>(patternName: T, opts: ObjectOptionsTypes<T>): ObjectType<T>;
178
+ }
3
179
  /**
4
180
  * Simulates a "long press" event on a element.
5
- * @param element - Element to long press.
6
- * @param opts - Options to pass to the simulated event. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.
181
+ * @param opts - Options for the long press.
182
+ * @param opts.element - Element to long press.
183
+ * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).
184
+ * @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.
7
185
  */
8
- export function triggerLongPress(element: HTMLElement, opts?: {}): void;
186
+ export function triggerLongPress(opts: {
187
+ element: HTMLElement;
188
+ advanceTimer: (time?: number) => void | Promise<unknown>;
189
+ pointerOpts?: {};
190
+ }): Promise<void>;
9
191
  /**
10
192
  * Enables reading pageX/pageY from fireEvent.mouse*(..., {pageX: ..., pageY: ...}).
11
193
  */
@@ -1 +1 @@
1
- {"mappings":";AAcA,OAAO,MAAM,6BAA6B,CAAC;AAE3C;;;;GAIG;AACH,iCAAiC,OAAO,EAAE,WAAW,EAAE,IAAI,KAAK,GAAG,IAAI,CAMtE;ACfD;;GAEG;AACH,0CAwBC;AAED,4CAiCC;ACxED,OAAO,IAAI,YAAY,UAAU,EAOL,CAAC","sources":["packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/events.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/testSetup.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/userEventMaps.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/index.ts","packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './events';\nexport * from './testSetup';\nexport * from './userEventMaps';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";AAeA,yBAAiC,SAAQ,QAAQ,EAAE,cAAc;IAC/D,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,WAAW,CAAA;CACtB;AAED;gBAMc,IAAI,EAAE,eAAe;IA4BjC,kBAAkB,SAAU,QAAQ,CAAC,iBAAiB,CAAC,UAErD;IAEF,IAAI,UAAgB;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;QAAC,eAAe,CAAC,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAA;KAAC,mBAwCvG;IAEF,YAAY,UAAgB;QAAC,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,QAAQ,CA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E3B,IAAI,GAAE,QAAa;IAO/B,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,mBAAmB,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC;CAGjG;ACvDD;;;;;;GAMG;AACH,iCAAuC,IAAI,EAAE;IAAC,OAAO,EAAE,WAAW,CAAC;IAAC,YAAY,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAAC,WAAW,CAAC,EAAE,EAAE,CAAA;CAAC,iBAQ9I;ACpBD;;GAEG;AACH,0CAoBC;AAED,4CAiCC;ACpED,OAAO,IAAI,YAAY,UAAU,EAOL,CAAC","sources":["packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/combobox.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/gridlist.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/menu.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/select.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/table.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/user.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/events.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/testSetup.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/userEventMaps.ts","packages/@react-aria/test-utils/src/packages/@react-aria/test-utils/src/index.ts","packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\n\nexport type {UserOpts} from './user';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -0,0 +1,65 @@
1
+ var $15e4b71f2b6c4964$exports = require("./combobox.main.js");
2
+ var $30ee8e379774bea4$exports = require("./gridlist.main.js");
3
+ var $31965f39292c8e99$exports = require("./menu.main.js");
4
+ var $0e568517a25183a7$exports = require("./userEventMaps.main.js");
5
+ var $b97d5a42df7c75b2$exports = require("./select.main.js");
6
+ var $80a9def682ac1297$exports = require("./table.main.js");
7
+ var $iYqJR$testinglibraryuserevent = require("@testing-library/user-event");
8
+
9
+
10
+ function $parcel$interopDefault(a) {
11
+ return a && a.__esModule ? a.default : a;
12
+ }
13
+
14
+ function $parcel$export(e, n, v, s) {
15
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
16
+ }
17
+
18
+ $parcel$export(module.exports, "User", () => $4168d511756883ff$export$1f44aaf2ec115b54);
19
+ /*
20
+ * Copyright 2024 Adobe. All rights reserved.
21
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
22
+ * you may not use this file except in compliance with the License. You may obtain a copy
23
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software distributed under
26
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
27
+ * OF ANY KIND, either express or implied. See the License for the specific language
28
+ * governing permissions and limitations under the License.
29
+ */
30
+
31
+
32
+
33
+
34
+
35
+
36
+ let $4168d511756883ff$var$keyToUtil = {
37
+ 'Select': (0, $b97d5a42df7c75b2$exports.SelectTester),
38
+ 'Table': (0, $80a9def682ac1297$exports.TableTester),
39
+ 'Menu': (0, $31965f39292c8e99$exports.MenuTester),
40
+ 'ComboBox': (0, $15e4b71f2b6c4964$exports.ComboBoxTester),
41
+ 'GridList': (0, $30ee8e379774bea4$exports.GridListTester)
42
+ };
43
+ let $4168d511756883ff$var$defaultAdvanceTimer = async (waitTime)=>await new Promise((resolve)=>setTimeout(resolve, waitTime));
44
+ class $4168d511756883ff$export$1f44aaf2ec115b54 {
45
+ createTester(patternName, opts) {
46
+ return new $4168d511756883ff$var$keyToUtil[patternName]({
47
+ user: this.user,
48
+ interactionType: this.interactionType,
49
+ advanceTimer: this.advanceTimer,
50
+ ...opts
51
+ });
52
+ }
53
+ constructor(opts = {}){
54
+ let { interactionType: interactionType, advanceTimer: advanceTimer } = opts;
55
+ this.user = (0, ($parcel$interopDefault($iYqJR$testinglibraryuserevent))).setup({
56
+ delay: null,
57
+ pointerMap: $0e568517a25183a7$exports.pointerMap
58
+ });
59
+ this.interactionType = interactionType;
60
+ this.advanceTimer = advanceTimer || $4168d511756883ff$var$defaultAdvanceTimer;
61
+ }
62
+ }
63
+
64
+
65
+ //# sourceMappingURL=user.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAyBD,IAAI,kCAAY;IAAC,UAAU,CAAA,GAAA,sCAAW;IAAG,SAAS,CAAA,GAAA,qCAAU;IAAG,QAAQ,CAAA,GAAA,oCAAS;IAAG,YAAY,CAAA,GAAA,wCAAa;IAAG,YAAY,CAAA,GAAA,wCAAa;AAAC;AAoBzI,IAAI,4CAAsB,OAAO,WAAiC,MAAM,IAAI,QAAQ,CAAC,UAAY,WAAW,SAAS;AAE9G,MAAM;IAYX,aAAqC,WAAc,EAAE,IAA2B,EAAiB;QAC/F,OAAO,IAAI,AAAC,+BAAU,CAAC,YAAY,CAAC;YAAC,MAAM,IAAI,CAAC,IAAI;YAAE,iBAAiB,IAAI,CAAC,eAAe;YAAE,cAAc,IAAI,CAAC,YAAY;YAAE,GAAG,IAAI;QAAA;IACvI;IATA,YAAY,OAAiB,CAAC,CAAC,CAAE;QAC/B,IAAI,mBAAC,eAAe,gBAAE,YAAY,EAAC,GAAG;QACtC,IAAI,CAAC,IAAI,GAAG,CAAA,GAAA,wDAAQ,EAAE,KAAK,CAAC;YAAC,OAAO;wBAAM;QAAU;QACpD,IAAI,CAAC,eAAe,GAAG;QACvB,IAAI,CAAC,YAAY,GAAG,gBAAgB;IACtC;AAKF","sources":["packages/@react-aria/test-utils/src/user.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 {ComboBoxOptions, ComboBoxTester} from './combobox';\nimport {GridListOptions, GridListTester} from './gridlist';\nimport {MenuOptions, MenuTester} from './menu';\nimport {pointerMap} from './';\nimport {SelectOptions, SelectTester} from './select';\nimport {TableOptions, TableTester} from './table';\nimport userEvent from '@testing-library/user-event';\n\n// https://github.com/testing-library/dom-testing-library/issues/939#issuecomment-830771708 is an interesting way of allowing users to configure the timers\n// curent way is like https://testing-library.com/docs/user-event/options/#advancetimers,\nexport interface UserOpts {\n interactionType?: 'mouse' | 'touch' | 'keyboard',\n // If using fake timers user should provide something like (time) => jest.advanceTimersByTime(time))}\n // A real timer user would pass async () => await new Promise((resolve) => setTimeout(resolve, waitTime))\n // Time is in ms.\n advanceTimer?: (time?: number) => void | Promise<unknown>\n}\n\nexport interface BaseTesterOpts {\n // The base element for the given tester (e.g. the table, menu trigger, etc)\n root: HTMLElement\n}\n\nlet keyToUtil = {'Select': SelectTester, 'Table': TableTester, 'Menu': MenuTester, 'ComboBox': ComboBoxTester, 'GridList': GridListTester} as const;\nexport type PatternNames = keyof typeof keyToUtil;\n\n// Conditional type: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html\ntype ObjectType<T> =\n T extends 'Select' ? SelectTester :\n T extends 'Table' ? TableTester :\n T extends 'Menu' ? MenuTester :\n T extends 'ComboBox' ? ComboBoxTester :\n T extends 'GridList' ? GridListTester :\n never;\n\ntype ObjectOptionsTypes<T> =\n T extends 'Select' ? SelectOptions :\n T extends 'Table' ? TableOptions :\n T extends 'Menu' ? MenuOptions :\n T extends 'ComboBox' ? ComboBoxOptions :\n T extends 'GridList' ? GridListOptions :\n never;\n\nlet defaultAdvanceTimer = async (waitTime: number | undefined) => await new Promise((resolve) => setTimeout(resolve, waitTime));\n\nexport class User {\n user;\n interactionType: UserOpts['interactionType'];\n advanceTimer: UserOpts['advanceTimer'];\n\n constructor(opts: UserOpts = {}) {\n let {interactionType, advanceTimer} = opts;\n this.user = userEvent.setup({delay: null, pointerMap});\n this.interactionType = interactionType;\n this.advanceTimer = advanceTimer || defaultAdvanceTimer;\n }\n\n createTester<T extends PatternNames>(patternName: T, opts: ObjectOptionsTypes<T>): ObjectType<T> {\n return new (keyToUtil)[patternName]({user: this.user, interactionType: this.interactionType, advanceTimer: this.advanceTimer, ...opts}) as ObjectType<T>;\n }\n}\n"],"names":[],"version":3,"file":"user.main.js.map"}
package/dist/user.mjs ADDED
@@ -0,0 +1,56 @@
1
+ import {ComboBoxTester as $dab75f394483aa9c$export$f97e14e96d71ab3b} from "./combobox.mjs";
2
+ import {GridListTester as $5ca9e9228f508f75$export$93a85aaed9fabd83} from "./gridlist.mjs";
3
+ import {MenuTester as $74b93f0617179929$export$f73bbc9212ed861e} from "./menu.mjs";
4
+ import {pointerMap as $50ecfb18069ec897$export$7dbde2c4caaa8d35} from "./userEventMaps.mjs";
5
+ import {SelectTester as $4350df3e19e40e36$export$d1859707465446a9} from "./select.mjs";
6
+ import {TableTester as $6d1e4cf220920c37$export$4c6a9d6ae3b0086} from "./table.mjs";
7
+ import $gmkhN$testinglibraryuserevent from "@testing-library/user-event";
8
+
9
+ /*
10
+ * Copyright 2024 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+
21
+
22
+
23
+
24
+
25
+
26
+ let $0d71b4e9cc4df40a$var$keyToUtil = {
27
+ 'Select': (0, $4350df3e19e40e36$export$d1859707465446a9),
28
+ 'Table': (0, $6d1e4cf220920c37$export$4c6a9d6ae3b0086),
29
+ 'Menu': (0, $74b93f0617179929$export$f73bbc9212ed861e),
30
+ 'ComboBox': (0, $dab75f394483aa9c$export$f97e14e96d71ab3b),
31
+ 'GridList': (0, $5ca9e9228f508f75$export$93a85aaed9fabd83)
32
+ };
33
+ let $0d71b4e9cc4df40a$var$defaultAdvanceTimer = async (waitTime)=>await new Promise((resolve)=>setTimeout(resolve, waitTime));
34
+ class $0d71b4e9cc4df40a$export$1f44aaf2ec115b54 {
35
+ createTester(patternName, opts) {
36
+ return new $0d71b4e9cc4df40a$var$keyToUtil[patternName]({
37
+ user: this.user,
38
+ interactionType: this.interactionType,
39
+ advanceTimer: this.advanceTimer,
40
+ ...opts
41
+ });
42
+ }
43
+ constructor(opts = {}){
44
+ let { interactionType: interactionType, advanceTimer: advanceTimer } = opts;
45
+ this.user = (0, $gmkhN$testinglibraryuserevent).setup({
46
+ delay: null,
47
+ pointerMap: $50ecfb18069ec897$export$7dbde2c4caaa8d35
48
+ });
49
+ this.interactionType = interactionType;
50
+ this.advanceTimer = advanceTimer || $0d71b4e9cc4df40a$var$defaultAdvanceTimer;
51
+ }
52
+ }
53
+
54
+
55
+ export {$0d71b4e9cc4df40a$export$1f44aaf2ec115b54 as User};
56
+ //# sourceMappingURL=user.module.js.map
@@ -0,0 +1,56 @@
1
+ import {ComboBoxTester as $dab75f394483aa9c$export$f97e14e96d71ab3b} from "./combobox.module.js";
2
+ import {GridListTester as $5ca9e9228f508f75$export$93a85aaed9fabd83} from "./gridlist.module.js";
3
+ import {MenuTester as $74b93f0617179929$export$f73bbc9212ed861e} from "./menu.module.js";
4
+ import {pointerMap as $50ecfb18069ec897$export$7dbde2c4caaa8d35} from "./userEventMaps.module.js";
5
+ import {SelectTester as $4350df3e19e40e36$export$d1859707465446a9} from "./select.module.js";
6
+ import {TableTester as $6d1e4cf220920c37$export$4c6a9d6ae3b0086} from "./table.module.js";
7
+ import $gmkhN$testinglibraryuserevent from "@testing-library/user-event";
8
+
9
+ /*
10
+ * Copyright 2024 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+
21
+
22
+
23
+
24
+
25
+
26
+ let $0d71b4e9cc4df40a$var$keyToUtil = {
27
+ 'Select': (0, $4350df3e19e40e36$export$d1859707465446a9),
28
+ 'Table': (0, $6d1e4cf220920c37$export$4c6a9d6ae3b0086),
29
+ 'Menu': (0, $74b93f0617179929$export$f73bbc9212ed861e),
30
+ 'ComboBox': (0, $dab75f394483aa9c$export$f97e14e96d71ab3b),
31
+ 'GridList': (0, $5ca9e9228f508f75$export$93a85aaed9fabd83)
32
+ };
33
+ let $0d71b4e9cc4df40a$var$defaultAdvanceTimer = async (waitTime)=>await new Promise((resolve)=>setTimeout(resolve, waitTime));
34
+ class $0d71b4e9cc4df40a$export$1f44aaf2ec115b54 {
35
+ createTester(patternName, opts) {
36
+ return new $0d71b4e9cc4df40a$var$keyToUtil[patternName]({
37
+ user: this.user,
38
+ interactionType: this.interactionType,
39
+ advanceTimer: this.advanceTimer,
40
+ ...opts
41
+ });
42
+ }
43
+ constructor(opts = {}){
44
+ let { interactionType: interactionType, advanceTimer: advanceTimer } = opts;
45
+ this.user = (0, $gmkhN$testinglibraryuserevent).setup({
46
+ delay: null,
47
+ pointerMap: $50ecfb18069ec897$export$7dbde2c4caaa8d35
48
+ });
49
+ this.interactionType = interactionType;
50
+ this.advanceTimer = advanceTimer || $0d71b4e9cc4df40a$var$defaultAdvanceTimer;
51
+ }
52
+ }
53
+
54
+
55
+ export {$0d71b4e9cc4df40a$export$1f44aaf2ec115b54 as User};
56
+ //# sourceMappingURL=user.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAyBD,IAAI,kCAAY;IAAC,UAAU,CAAA,GAAA,yCAAW;IAAG,SAAS,CAAA,GAAA,wCAAU;IAAG,QAAQ,CAAA,GAAA,yCAAS;IAAG,YAAY,CAAA,GAAA,yCAAa;IAAG,YAAY,CAAA,GAAA,yCAAa;AAAC;AAoBzI,IAAI,4CAAsB,OAAO,WAAiC,MAAM,IAAI,QAAQ,CAAC,UAAY,WAAW,SAAS;AAE9G,MAAM;IAYX,aAAqC,WAAc,EAAE,IAA2B,EAAiB;QAC/F,OAAO,IAAI,AAAC,+BAAU,CAAC,YAAY,CAAC;YAAC,MAAM,IAAI,CAAC,IAAI;YAAE,iBAAiB,IAAI,CAAC,eAAe;YAAE,cAAc,IAAI,CAAC,YAAY;YAAE,GAAG,IAAI;QAAA;IACvI;IATA,YAAY,OAAiB,CAAC,CAAC,CAAE;QAC/B,IAAI,mBAAC,eAAe,gBAAE,YAAY,EAAC,GAAG;QACtC,IAAI,CAAC,IAAI,GAAG,CAAA,GAAA,8BAAQ,EAAE,KAAK,CAAC;YAAC,OAAO;wBAAM;QAAU;QACpD,IAAI,CAAC,eAAe,GAAG;QACvB,IAAI,CAAC,YAAY,GAAG,gBAAgB;IACtC;AAKF","sources":["packages/@react-aria/test-utils/src/user.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 {ComboBoxOptions, ComboBoxTester} from './combobox';\nimport {GridListOptions, GridListTester} from './gridlist';\nimport {MenuOptions, MenuTester} from './menu';\nimport {pointerMap} from './';\nimport {SelectOptions, SelectTester} from './select';\nimport {TableOptions, TableTester} from './table';\nimport userEvent from '@testing-library/user-event';\n\n// https://github.com/testing-library/dom-testing-library/issues/939#issuecomment-830771708 is an interesting way of allowing users to configure the timers\n// curent way is like https://testing-library.com/docs/user-event/options/#advancetimers,\nexport interface UserOpts {\n interactionType?: 'mouse' | 'touch' | 'keyboard',\n // If using fake timers user should provide something like (time) => jest.advanceTimersByTime(time))}\n // A real timer user would pass async () => await new Promise((resolve) => setTimeout(resolve, waitTime))\n // Time is in ms.\n advanceTimer?: (time?: number) => void | Promise<unknown>\n}\n\nexport interface BaseTesterOpts {\n // The base element for the given tester (e.g. the table, menu trigger, etc)\n root: HTMLElement\n}\n\nlet keyToUtil = {'Select': SelectTester, 'Table': TableTester, 'Menu': MenuTester, 'ComboBox': ComboBoxTester, 'GridList': GridListTester} as const;\nexport type PatternNames = keyof typeof keyToUtil;\n\n// Conditional type: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html\ntype ObjectType<T> =\n T extends 'Select' ? SelectTester :\n T extends 'Table' ? TableTester :\n T extends 'Menu' ? MenuTester :\n T extends 'ComboBox' ? ComboBoxTester :\n T extends 'GridList' ? GridListTester :\n never;\n\ntype ObjectOptionsTypes<T> =\n T extends 'Select' ? SelectOptions :\n T extends 'Table' ? TableOptions :\n T extends 'Menu' ? MenuOptions :\n T extends 'ComboBox' ? ComboBoxOptions :\n T extends 'GridList' ? GridListOptions :\n never;\n\nlet defaultAdvanceTimer = async (waitTime: number | undefined) => await new Promise((resolve) => setTimeout(resolve, waitTime));\n\nexport class User {\n user;\n interactionType: UserOpts['interactionType'];\n advanceTimer: UserOpts['advanceTimer'];\n\n constructor(opts: UserOpts = {}) {\n let {interactionType, advanceTimer} = opts;\n this.user = userEvent.setup({delay: null, pointerMap});\n this.interactionType = interactionType;\n this.advanceTimer = advanceTimer || defaultAdvanceTimer;\n }\n\n createTester<T extends PatternNames>(patternName: T, opts: ObjectOptionsTypes<T>): ObjectType<T> {\n return new (keyToUtil)[patternName]({user: this.user, interactionType: this.interactionType, advanceTimer: this.advanceTimer, ...opts}) as ObjectType<T>;\n }\n}\n"],"names":[],"version":3,"file":"user.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/test-utils",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.3",
4
4
  "description": "Testing utils for react-aria patterns",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -25,13 +25,13 @@
25
25
  "@swc/helpers": "^0.5.0"
26
26
  },
27
27
  "peerDependencies": {
28
- "@testing-library/react": "^13.0.0 || ^14.0.0",
28
+ "@testing-library/react": "^15.0.7",
29
29
  "@testing-library/user-event": "^13.0.0 || ^14.0.0",
30
- "jest": "^27.0.0",
31
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
30
+ "jest": "^29.5.0",
31
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
36
+ "gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
37
37
  }
@@ -0,0 +1,188 @@
1
+ /*
2
+ * Copyright 2024 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 {act, waitFor, within} from '@testing-library/react';
14
+ import {BaseTesterOpts, UserOpts} from './user';
15
+
16
+ export interface ComboBoxOptions extends UserOpts, BaseTesterOpts {
17
+ user?: any,
18
+ trigger?: HTMLElement
19
+ }
20
+
21
+ export class ComboBoxTester {
22
+ private user;
23
+ private _interactionType: UserOpts['interactionType'];
24
+ private _combobox: HTMLElement;
25
+ private _trigger: HTMLElement | undefined;
26
+
27
+ constructor(opts: ComboBoxOptions) {
28
+ let {root, trigger, user, interactionType} = opts;
29
+ this.user = user;
30
+ this._interactionType = interactionType || 'mouse';
31
+
32
+ // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to
33
+ // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
34
+ this._combobox = root;
35
+ let combobox = within(root).queryByRole('combobox');
36
+ if (combobox) {
37
+ this._combobox = combobox;
38
+ }
39
+
40
+ // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)
41
+ if (trigger) {
42
+ this._trigger = trigger;
43
+ } else {
44
+ let trigger = within(root).queryByRole('button', {hidden: true});
45
+ if (trigger) {
46
+ this._trigger = trigger;
47
+ } else {
48
+ // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
49
+ // is also the trigger button
50
+ this._trigger = this._combobox;
51
+ }
52
+ }
53
+ }
54
+
55
+ setInteractionType = (type: UserOpts['interactionType']) => {
56
+ this._interactionType = type;
57
+ };
58
+
59
+ open = async (opts: {triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {
60
+ let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;
61
+ let trigger = this.trigger;
62
+ let combobox = this.combobox;
63
+ let isDisabled = trigger!.hasAttribute('disabled');
64
+
65
+ if (interactionType === 'mouse') {
66
+ if (triggerBehavior === 'focus') {
67
+ await this.user.click(combobox);
68
+ } else {
69
+ await this.user.click(trigger);
70
+ }
71
+ } else if (interactionType === 'keyboard' && this._trigger != null) {
72
+ act(() => this._trigger!.focus());
73
+ if (triggerBehavior !== 'focus') {
74
+ await this.user.keyboard('{ArrowDown}');
75
+ }
76
+ } else if (interactionType === 'touch') {
77
+ if (triggerBehavior === 'focus') {
78
+ await this.user.pointer({target: combobox, keys: '[TouchA]'});
79
+ } else {
80
+ await this.user.pointer({target: trigger, keys: '[TouchA]'});
81
+ }
82
+ }
83
+
84
+ await waitFor(() => {
85
+ if (!isDisabled && combobox.getAttribute('aria-controls') == null) {
86
+ throw new Error('No aria-controls found on combobox trigger element.');
87
+ } else {
88
+ return true;
89
+ }
90
+ });
91
+ let listBoxId = combobox.getAttribute('aria-controls');
92
+ await waitFor(() => {
93
+ if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {
94
+ throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
95
+ } else {
96
+ return true;
97
+ }
98
+ });
99
+ };
100
+
101
+ selectOption = async (opts: {option?: HTMLElement, optionText?: string, triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {
102
+ let {optionText, option, triggerBehavior, interactionType = this._interactionType} = opts;
103
+ if (!this.combobox.getAttribute('aria-controls')) {
104
+ await this.open({triggerBehavior});
105
+ }
106
+
107
+ let listbox = this.listbox;
108
+ if (listbox) {
109
+ if (!option && optionText) {
110
+ option = within(listbox).getByText(optionText);
111
+ }
112
+
113
+ // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow
114
+ // the required amount of times to reach the option. For now just click the option even in keyboard mode
115
+ if (interactionType === 'mouse' || interactionType === 'keyboard') {
116
+ await this.user.click(option);
117
+ } else {
118
+ await this.user.pointer({target: option, keys: '[TouchA]'});
119
+ }
120
+
121
+ if (option && option.getAttribute('href') == null) {
122
+ await waitFor(() => {
123
+ if (document.contains(listbox)) {
124
+ throw new Error('Expected listbox element to not be in the document after selecting an option');
125
+ } else {
126
+ return true;
127
+ }
128
+ });
129
+ }
130
+ } else {
131
+ throw new Error("Attempted to select a option in the combobox, but the listbox wasn't found.");
132
+ }
133
+ };
134
+
135
+ close = async () => {
136
+ let listbox = this.listbox;
137
+ if (listbox) {
138
+ act(() => this.combobox.focus());
139
+ await this.user.keyboard('[Escape]');
140
+
141
+ await waitFor(() => {
142
+ if (document.contains(listbox)) {
143
+ throw new Error('Expected listbox element to not be in the document after selecting an option');
144
+ } else {
145
+ return true;
146
+ }
147
+ });
148
+ }
149
+ };
150
+
151
+ get combobox() {
152
+ return this._combobox;
153
+ }
154
+
155
+ get trigger() {
156
+ return this._trigger;
157
+ }
158
+
159
+ get listbox() {
160
+ let listBoxId = this.combobox.getAttribute('aria-controls');
161
+ return listBoxId ? document.getElementById(listBoxId) || undefined : undefined;
162
+ }
163
+
164
+ options = (opts: {element?: HTMLElement} = {}): HTMLElement[] | never[] => {
165
+ let {element} = opts;
166
+ element = element || this.listbox;
167
+ let options = [];
168
+ if (element) {
169
+ options = within(element).queryAllByRole('option');
170
+ }
171
+
172
+ return options;
173
+ };
174
+
175
+ get sections() {
176
+ let listbox = this.listbox;
177
+ if (listbox) {
178
+ return within(listbox).queryAllByRole('group');
179
+ } else {
180
+ return [];
181
+ }
182
+ }
183
+
184
+ get focusedOption() {
185
+ let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');
186
+ return focusedOptionId ? document.getElementById(focusedOptionId) : undefined;
187
+ }
188
+ }