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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +70 -0
  2. package/dist/import.mjs +6 -4
  3. package/dist/main.js +15 -23
  4. package/dist/main.js.map +1 -1
  5. package/dist/module.js +6 -4
  6. package/dist/module.js.map +1 -1
  7. package/dist/private/act.cjs +33 -0
  8. package/dist/private/act.cjs.map +1 -0
  9. package/dist/private/act.js +28 -0
  10. package/dist/private/act.js.map +1 -0
  11. package/dist/private/checkboxgroup.cjs +107 -0
  12. package/dist/private/checkboxgroup.cjs.map +1 -0
  13. package/dist/private/checkboxgroup.js +102 -0
  14. package/dist/private/checkboxgroup.js.map +1 -0
  15. package/dist/private/combobox.cjs +199 -0
  16. package/dist/private/combobox.cjs.map +1 -0
  17. package/dist/private/combobox.js +194 -0
  18. package/dist/private/combobox.js.map +1 -0
  19. package/dist/private/dialog.cjs +110 -0
  20. package/dist/private/dialog.cjs.map +1 -0
  21. package/dist/private/dialog.js +105 -0
  22. package/dist/private/dialog.js.map +1 -0
  23. package/dist/private/gridlist.cjs +173 -0
  24. package/dist/private/gridlist.cjs.map +1 -0
  25. package/dist/private/gridlist.js +168 -0
  26. package/dist/private/gridlist.js.map +1 -0
  27. package/dist/private/listbox.cjs +163 -0
  28. package/dist/private/listbox.cjs.map +1 -0
  29. package/dist/private/listbox.js +158 -0
  30. package/dist/private/listbox.js.map +1 -0
  31. package/dist/private/menu.cjs +265 -0
  32. package/dist/private/menu.cjs.map +1 -0
  33. package/dist/private/menu.js +260 -0
  34. package/dist/private/menu.js.map +1 -0
  35. package/dist/private/radiogroup.cjs +122 -0
  36. package/dist/private/radiogroup.cjs.map +1 -0
  37. package/dist/private/radiogroup.js +117 -0
  38. package/dist/private/radiogroup.js.map +1 -0
  39. package/dist/private/select.cjs +169 -0
  40. package/dist/private/select.cjs.map +1 -0
  41. package/dist/private/select.js +164 -0
  42. package/dist/private/select.js.map +1 -0
  43. package/dist/private/table.cjs +346 -0
  44. package/dist/private/table.cjs.map +1 -0
  45. package/dist/private/table.js +341 -0
  46. package/dist/private/table.js.map +1 -0
  47. package/dist/private/tabs.cjs +131 -0
  48. package/dist/private/tabs.cjs.map +1 -0
  49. package/dist/private/tabs.js +126 -0
  50. package/dist/private/tabs.js.map +1 -0
  51. package/dist/private/testSetup.cjs +87 -0
  52. package/dist/private/testSetup.cjs.map +1 -0
  53. package/dist/private/testSetup.js +81 -0
  54. package/dist/private/testSetup.js.map +1 -0
  55. package/dist/private/tree.cjs +181 -0
  56. package/dist/private/tree.cjs.map +1 -0
  57. package/dist/private/tree.js +176 -0
  58. package/dist/private/tree.js.map +1 -0
  59. package/dist/private/user.cjs +85 -0
  60. package/dist/private/user.cjs.map +1 -0
  61. package/dist/private/user.js +76 -0
  62. package/dist/private/user.js.map +1 -0
  63. package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
  64. package/dist/private/userEventMaps.cjs.map +1 -0
  65. package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
  66. package/dist/private/userEventMaps.js.map +1 -0
  67. package/dist/private/utils.cjs +136 -0
  68. package/dist/private/utils.cjs.map +1 -0
  69. package/dist/private/utils.js +127 -0
  70. package/dist/private/utils.js.map +1 -0
  71. package/dist/types/src/act.d.ts +4 -0
  72. package/dist/types/src/checkboxgroup.d.ts +47 -0
  73. package/dist/types/src/combobox.d.ts +87 -0
  74. package/dist/types/src/dialog.d.ts +37 -0
  75. package/dist/types/src/events.d.ts +25 -0
  76. package/dist/types/src/gridlist.d.ts +56 -0
  77. package/dist/types/src/index.d.ts +16 -0
  78. package/dist/types/src/listbox.d.ts +91 -0
  79. package/dist/types/src/menu.d.ts +112 -0
  80. package/dist/types/src/radiogroup.d.ts +47 -0
  81. package/dist/types/src/select.d.ts +74 -0
  82. package/dist/types/src/table.d.ts +120 -0
  83. package/dist/types/src/tabs.d.ts +59 -0
  84. package/dist/types/src/testSetup.d.ts +6 -0
  85. package/dist/types/src/tree.d.ts +62 -0
  86. package/dist/types/src/types.d.ts +143 -0
  87. package/dist/types/src/user.d.ts +49 -0
  88. package/dist/types/src/userEventMaps.d.ts +2 -0
  89. package/dist/types/src/utils.d.ts +29 -0
  90. package/package.json +26 -18
  91. package/src/act.ts +35 -0
  92. package/src/checkboxgroup.ts +165 -0
  93. package/src/combobox.ts +307 -0
  94. package/src/dialog.ts +155 -0
  95. package/src/gridlist.ts +278 -0
  96. package/src/index.ts +17 -3
  97. package/src/listbox.ts +300 -0
  98. package/src/menu.ts +479 -0
  99. package/src/radiogroup.ts +179 -0
  100. package/src/select.ts +273 -0
  101. package/src/table.ts +589 -0
  102. package/src/tabs.ts +204 -0
  103. package/src/testSetup.ts +41 -36
  104. package/src/tree.ts +290 -0
  105. package/src/types.ts +171 -0
  106. package/src/user.ts +153 -0
  107. package/src/userEventMaps.ts +1 -1
  108. package/src/utils.ts +155 -0
  109. package/dist/events.main.js +0 -37
  110. package/dist/events.main.js.map +0 -1
  111. package/dist/events.mjs +0 -31
  112. package/dist/events.module.js +0 -31
  113. package/dist/events.module.js.map +0 -1
  114. package/dist/testSetup.main.js +0 -82
  115. package/dist/testSetup.main.js.map +0 -1
  116. package/dist/testSetup.mjs +0 -76
  117. package/dist/testSetup.module.js +0 -76
  118. package/dist/testSetup.module.js.map +0 -1
  119. package/dist/types.d.ts +0 -16
  120. package/dist/types.d.ts.map +0 -1
  121. package/dist/userEventMaps.main.js.map +0 -1
  122. package/dist/userEventMaps.module.js +0 -38
  123. package/dist/userEventMaps.module.js.map +0 -1
  124. package/src/events.ts +0 -28
package/src/types.ts ADDED
@@ -0,0 +1,171 @@
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
+ export type Orientation = 'horizontal' | 'vertical';
14
+ export type Direction = 'ltr' | 'rtl';
15
+
16
+ // https://github.com/testing-library/dom-testing-library/issues/939#issuecomment-830771708 is an interesting way of allowing users to configure the timers
17
+ // curent way is like https://testing-library.com/docs/user-event/options/#advancetimers,
18
+ export interface UserOpts {
19
+ /**
20
+ * The interaction type (mouse, touch, keyboard) that the test util user will use when interacting
21
+ * with a component. This can be overridden at the aria pattern tester level if needed.
22
+ *
23
+ * @default mouse
24
+ */
25
+ interactionType?: 'mouse' | 'touch' | 'keyboard';
26
+ // If using fake timers user should provide something like (time) => jest.advanceTimersByTime(time))}.
27
+ // A real timer user would pass (waitTime) => new Promise((resolve) => setTimeout(resolve, waitTime))
28
+ // Time is in ms.
29
+ /**
30
+ * A function used by the test utils to advance timers during interactions. Required for certain
31
+ * aria patterns (e.g. table). This can be overridden at the aria pattern tester level if needed.
32
+ */
33
+ advanceTimer?: (time: number) => unknown | Promise<unknown>;
34
+ }
35
+
36
+ export interface BaseTesterOpts extends UserOpts {
37
+ /** @private */
38
+ user?: any;
39
+ /** The base element for the given tester (e.g. the table, menu trigger button, etc). */
40
+ root: HTMLElement;
41
+ /**
42
+ * The horizontal layout direction, typically affected by locale.
43
+ *
44
+ * @default 'ltr'
45
+ */
46
+ direction?: Direction;
47
+ }
48
+
49
+ export interface CheckboxGroupTesterOpts extends BaseTesterOpts {}
50
+
51
+ export interface ComboBoxTesterOpts extends BaseTesterOpts {
52
+ /**
53
+ * The base element for the combobox. If provided the wrapping element around the target combobox
54
+ * (as is the the case with a ref provided to RSP ComboBox), will automatically search for the
55
+ * combobox element within.
56
+ */
57
+ root: HTMLElement;
58
+ /**
59
+ * The node of the combobox trigger button if any. If not provided, we will try to automatically
60
+ * use any button within the `root` provided or that the `root` serves as the trigger.
61
+ */
62
+ trigger?: HTMLElement;
63
+ }
64
+
65
+ export interface DialogTesterOpts extends BaseTesterOpts {
66
+ /**
67
+ * The trigger element for the dialog.
68
+ */
69
+ root: HTMLElement;
70
+ /**
71
+ * The overlay type of the dialog. Used to inform the tester how to find the dialog.
72
+ */
73
+ overlayType?: 'modal' | 'popover';
74
+ }
75
+
76
+ export interface GridListTesterOpts extends BaseTesterOpts {
77
+ /**
78
+ * The layout of the gridlist.
79
+ *
80
+ * @default 'stack'
81
+ */
82
+ layout?: 'stack' | 'grid';
83
+ }
84
+
85
+ export interface ListBoxTesterOpts extends BaseTesterOpts {
86
+ /**
87
+ * The layout of the listbox.
88
+ *
89
+ * @default 'stack'
90
+ */
91
+ layout?: 'stack' | 'grid';
92
+ }
93
+
94
+ export interface MenuTesterOpts extends BaseTesterOpts {
95
+ /**
96
+ * The trigger element for the menu.
97
+ */
98
+ root: HTMLElement;
99
+ /**
100
+ * Whether the current menu is a submenu.
101
+ */
102
+ isSubmenu?: boolean;
103
+ /**
104
+ * The root menu of the menu tree. Only available if the menu is a submenu.
105
+ */
106
+ rootMenu?: HTMLElement;
107
+ }
108
+
109
+ export interface RadioGroupTesterOpts extends BaseTesterOpts {}
110
+
111
+ export interface SelectTesterOpts extends BaseTesterOpts {
112
+ /**
113
+ * The trigger element for the select. If provided the wrapping element around the target select
114
+ * (as is the case with a ref provided to RSP Select), will automatically search for the select's
115
+ * trigger element within.
116
+ */
117
+ root: HTMLElement;
118
+ }
119
+
120
+ export interface TableTesterOpts extends BaseTesterOpts {}
121
+
122
+ export interface TabsTesterOpts extends BaseTesterOpts {}
123
+
124
+ export interface TreeTesterOpts extends BaseTesterOpts {}
125
+
126
+ export interface BaseGridRowInteractionOpts {
127
+ /**
128
+ * The index, text, or node of the row to target.
129
+ */
130
+ row: number | string | HTMLElement;
131
+ /**
132
+ * What interaction type to use when interacting with the row. Defaults to the interaction type
133
+ * set on the tester.
134
+ */
135
+ interactionType?: UserOpts['interactionType'];
136
+ }
137
+
138
+ export interface ToggleGridRowOpts extends BaseGridRowInteractionOpts {
139
+ /**
140
+ * Whether the row needs to be long pressed to be selected. Depends on the components
141
+ * implementation.
142
+ */
143
+ needsLongPress?: boolean;
144
+ /**
145
+ * Whether the checkbox should be used to select the row. If false, will attempt to select the row
146
+ * via press.
147
+ *
148
+ * @default 'true'
149
+ */
150
+ checkboxSelection?: boolean;
151
+ /**
152
+ * Whether the grid has a selectionBehavior of "toggle" or "replace" (aka highlight selection).
153
+ * This affects the user operations required to toggle row selection by adding modifier keys
154
+ * during user actions, useful when performing multi-row selection in a "selectionBehavior:
155
+ * 'replace'" grid. If you would like to still simulate user actions (aka press) without these
156
+ * modifiers keys for a "selectionBehavior: replace" grid, simply omit this option. See the
157
+ * "Selection Behavior" section of the appropriate React Aria Component docs for more information
158
+ * (e.g. https://react-aria.adobe.com/Tree#selection-and-actions).
159
+ *
160
+ * @default 'toggle'
161
+ */
162
+ selectionBehavior?: 'toggle' | 'replace';
163
+ }
164
+
165
+ export interface GridRowActionOpts extends BaseGridRowInteractionOpts {
166
+ /**
167
+ * Whether or not the row needs a double click to trigger the row action. Depends on the
168
+ * components implementation.
169
+ */
170
+ needsDoubleClick?: boolean;
171
+ }
package/src/user.ts ADDED
@@ -0,0 +1,153 @@
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 {CheckboxGroupTester} from './checkboxgroup';
14
+ import {
15
+ CheckboxGroupTesterOpts,
16
+ ComboBoxTesterOpts,
17
+ DialogTesterOpts,
18
+ GridListTesterOpts,
19
+ ListBoxTesterOpts,
20
+ MenuTesterOpts,
21
+ RadioGroupTesterOpts,
22
+ SelectTesterOpts,
23
+ TableTesterOpts,
24
+ TabsTesterOpts,
25
+ TreeTesterOpts,
26
+ UserOpts
27
+ } from './types';
28
+ import {ComboBoxTester} from './combobox';
29
+ import {DialogTester} from './dialog';
30
+ import {GridListTester} from './gridlist';
31
+ import {ListBoxTester} from './listbox';
32
+ import {MenuTester} from './menu';
33
+ import {pointerMap} from './';
34
+ import {RadioGroupTester} from './radiogroup';
35
+ import {SelectTester} from './select';
36
+ import {TableTester} from './table';
37
+ import {TabsTester} from './tabs';
38
+ import {TreeTester} from './tree';
39
+ import userEvent from '@testing-library/user-event';
40
+
41
+ let keyToUtil: {
42
+ CheckboxGroup: typeof CheckboxGroupTester;
43
+ ComboBox: typeof ComboBoxTester;
44
+ Dialog: typeof DialogTester;
45
+ GridList: typeof GridListTester;
46
+ ListBox: typeof ListBoxTester;
47
+ Menu: typeof MenuTester;
48
+ RadioGroup: typeof RadioGroupTester;
49
+ Select: typeof SelectTester;
50
+ Table: typeof TableTester;
51
+ Tabs: typeof TabsTester;
52
+ Tree: typeof TreeTester;
53
+ } = {
54
+ CheckboxGroup: CheckboxGroupTester,
55
+ ComboBox: ComboBoxTester,
56
+ Dialog: DialogTester,
57
+ GridList: GridListTester,
58
+ ListBox: ListBoxTester,
59
+ Menu: MenuTester,
60
+ RadioGroup: RadioGroupTester,
61
+ Select: SelectTester,
62
+ Table: TableTester,
63
+ Tabs: TabsTester,
64
+ Tree: TreeTester
65
+ } as const;
66
+ export type PatternNames = keyof typeof keyToUtil;
67
+
68
+ // Conditional type: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
69
+ type Tester<T> = T extends 'CheckboxGroup'
70
+ ? CheckboxGroupTester
71
+ : T extends 'ComboBox'
72
+ ? ComboBoxTester
73
+ : T extends 'Dialog'
74
+ ? DialogTester
75
+ : T extends 'GridList'
76
+ ? GridListTester
77
+ : T extends 'ListBox'
78
+ ? ListBoxTester
79
+ : T extends 'Menu'
80
+ ? MenuTester
81
+ : T extends 'RadioGroup'
82
+ ? RadioGroupTester
83
+ : T extends 'Select'
84
+ ? SelectTester
85
+ : T extends 'Table'
86
+ ? TableTester
87
+ : T extends 'Tabs'
88
+ ? TabsTester
89
+ : T extends 'Tree'
90
+ ? TreeTester
91
+ : never;
92
+
93
+ type TesterOpts<T> = T extends 'CheckboxGroup'
94
+ ? CheckboxGroupTesterOpts
95
+ : T extends 'ComboBox'
96
+ ? ComboBoxTesterOpts
97
+ : T extends 'Dialog'
98
+ ? DialogTesterOpts
99
+ : T extends 'GridList'
100
+ ? GridListTesterOpts
101
+ : T extends 'ListBox'
102
+ ? ListBoxTesterOpts
103
+ : T extends 'Menu'
104
+ ? MenuTesterOpts
105
+ : T extends 'RadioGroup'
106
+ ? RadioGroupTesterOpts
107
+ : T extends 'Select'
108
+ ? SelectTesterOpts
109
+ : T extends 'Table'
110
+ ? TableTesterOpts
111
+ : T extends 'Tabs'
112
+ ? TabsTesterOpts
113
+ : T extends 'Tree'
114
+ ? TreeTesterOpts
115
+ : never;
116
+
117
+ let defaultAdvanceTimer = (waitTime: number | undefined) =>
118
+ new Promise(resolve => setTimeout(resolve, waitTime));
119
+
120
+ export class User {
121
+ private user;
122
+ /**
123
+ * The interaction type (mouse, touch, keyboard) that the test util user will use when interacting
124
+ * with a component. This can be overridden at the aria pattern util level if needed.
125
+ *
126
+ * @default mouse
127
+ */
128
+ interactionType: UserOpts['interactionType'];
129
+ /**
130
+ * A function used by the test utils to advance timers during interactions. Required for certain
131
+ * aria patterns (e.g. table).
132
+ */
133
+ advanceTimer: UserOpts['advanceTimer'];
134
+
135
+ constructor(opts: UserOpts = {}) {
136
+ let {interactionType, advanceTimer} = opts;
137
+ this.user = userEvent.setup({delay: null, pointerMap});
138
+ this.interactionType = interactionType;
139
+ this.advanceTimer = advanceTimer || defaultAdvanceTimer;
140
+ }
141
+
142
+ /**
143
+ * Creates an aria pattern tester, inheriting the options provided to the original user.
144
+ */
145
+ createTester<T extends PatternNames>(patternName: T, opts: TesterOpts<T>): Tester<T> {
146
+ return new keyToUtil[patternName]({
147
+ interactionType: this.interactionType,
148
+ advanceTimer: this.advanceTimer,
149
+ ...opts,
150
+ user: this.user
151
+ }) as Tester<T>;
152
+ }
153
+ }
@@ -1,4 +1,4 @@
1
- import {pointerKey} from '@testing-library/user-event/system/pointer/shared';
1
+ import {pointerKey} from '@testing-library/user-event';
2
2
 
3
3
  export let pointerMap: pointerKey[] = [
4
4
  {name: 'MouseLeft', pointerType: 'mouse', button: 'primary', height: 1, width: 1, pressure: 0.5},
package/src/utils.ts ADDED
@@ -0,0 +1,155 @@
1
+ /*
2
+ * Copyright 2023 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} from './act';
14
+ import {fireEvent} from '@testing-library/dom';
15
+ import {UserOpts} from './types';
16
+
17
+ export const DEFAULT_LONG_PRESS_TIME = 500;
18
+ function testPlatform(re: RegExp) {
19
+ return typeof window !== 'undefined' && window.navigator != null
20
+ ? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform)
21
+ : false;
22
+ }
23
+
24
+ function cached(fn: () => boolean) {
25
+ if (process.env.NODE_ENV === 'test') {
26
+ return fn;
27
+ }
28
+
29
+ let res: boolean | null = null;
30
+ return () => {
31
+ if (res == null) {
32
+ res = fn();
33
+ }
34
+ return res;
35
+ };
36
+ }
37
+
38
+ const isMac = cached(function () {
39
+ return testPlatform(/^Mac/i);
40
+ });
41
+
42
+ export function getAltKey(): 'Alt' | 'ControlLeft' {
43
+ return isMac() ? 'Alt' : 'ControlLeft';
44
+ }
45
+
46
+ export function getMetaKey(): 'MetaLeft' | 'ControlLeft' {
47
+ return isMac() ? 'MetaLeft' : 'ControlLeft';
48
+ }
49
+
50
+ export function formatTargetNode(value: number | string | HTMLElement): string {
51
+ if (typeof HTMLElement !== 'undefined' && value instanceof HTMLElement) {
52
+ return (value.cloneNode(false) as HTMLElement).outerHTML;
53
+ }
54
+ return String(value);
55
+ }
56
+
57
+ /**
58
+ * Simulates a "long press" event on a element.
59
+ *
60
+ * @param opts - Options for the long press.
61
+ * @param opts.element - Element to long press.
62
+ * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a
63
+ * specific amount of time(ms).
64
+ * @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See
65
+ * https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.
66
+ */
67
+ export async function triggerLongPress(opts: {
68
+ element: HTMLElement;
69
+ advanceTimer: (time: number) => unknown | Promise<unknown>;
70
+ pointerOpts?: Record<string, any>;
71
+ }): Promise<void> {
72
+ let {element, advanceTimer, pointerOpts = {}} = opts;
73
+ let pointerType = pointerOpts.pointerType ?? 'mouse';
74
+ let shouldFireCompatibilityEvents = false;
75
+ act(() => {
76
+ shouldFireCompatibilityEvents = fireEvent.pointerDown(element, {pointerType, ...pointerOpts});
77
+ });
78
+ let shouldFocus = true;
79
+ if (shouldFireCompatibilityEvents) {
80
+ if (pointerType === 'touch') {
81
+ act(() => {
82
+ shouldFocus = shouldFireCompatibilityEvents = fireEvent.touchStart(element, {
83
+ targetTouches: [
84
+ {
85
+ identifier: pointerOpts.pointerId,
86
+ clientX: pointerOpts.clientX,
87
+ clientY: pointerOpts.clientY
88
+ }
89
+ ]
90
+ });
91
+ });
92
+ } else if (pointerType === 'mouse') {
93
+ act(() => {
94
+ shouldFocus = fireEvent.mouseDown(element, pointerOpts);
95
+ });
96
+ if (shouldFocus) {
97
+ act(() => element.focus());
98
+ }
99
+ }
100
+ }
101
+ await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));
102
+ act(() => {
103
+ fireEvent.pointerUp(element, {pointerType, ...pointerOpts});
104
+ });
105
+ if (shouldFireCompatibilityEvents) {
106
+ if (pointerType === 'touch') {
107
+ act(() => {
108
+ shouldFocus = fireEvent.touchEnd(element, {
109
+ targetTouches: [
110
+ {
111
+ identifier: pointerOpts.pointerId,
112
+ clientX: pointerOpts.clientX,
113
+ clientY: pointerOpts.clientY
114
+ }
115
+ ]
116
+ });
117
+ shouldFocus = fireEvent.mouseDown(element, pointerOpts);
118
+ });
119
+ if (shouldFocus) {
120
+ act(() => element.focus());
121
+ }
122
+ act(() => {
123
+ fireEvent.mouseUp(element, pointerOpts);
124
+ });
125
+ } else if (pointerType === 'mouse') {
126
+ act(() => {
127
+ fireEvent.mouseUp(element, pointerOpts);
128
+ });
129
+ }
130
+ }
131
+ act(() => {
132
+ fireEvent.click(element, {detail: 1, ...pointerOpts});
133
+ });
134
+ }
135
+
136
+ // Docs cannot handle the types that userEvent actually declares, so hopefully this sub set is okay
137
+ export async function pressElement(
138
+ user: {
139
+ click: (element: Element) => Promise<void>;
140
+ keyboard: (keys: string) => Promise<void>;
141
+ pointer: (opts: {target: Element; keys: string; coords?: any}) => Promise<void>;
142
+ },
143
+ element: HTMLElement,
144
+ interactionType: UserOpts['interactionType']
145
+ ): Promise<void> {
146
+ if (interactionType === 'mouse') {
147
+ // Add coords with pressure so this isn't detected as a virtual click
148
+ await user.pointer({target: element, keys: '[MouseLeft]', coords: {pressure: 0.5}});
149
+ } else if (interactionType === 'keyboard') {
150
+ act(() => element.focus());
151
+ await user.keyboard('[Space]');
152
+ } else if (interactionType === 'touch') {
153
+ await user.pointer({target: element, keys: '[TouchA]'});
154
+ }
155
+ }
@@ -1,37 +0,0 @@
1
- var $jxdbS$testinglibraryreact = require("@testing-library/react");
2
-
3
-
4
- function $parcel$export(e, n, v, s) {
5
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
- }
7
-
8
- $parcel$export(module.exports, "DEFAULT_LONG_PRESS_TIME", () => $5a8bfe1663b8366d$export$4bd1d2d5ba6f5eaf);
9
- $parcel$export(module.exports, "triggerLongPress", () => $5a8bfe1663b8366d$export$3a22a5a9bc0fd3b);
10
- /*
11
- * Copyright 2023 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
- const $5a8bfe1663b8366d$export$4bd1d2d5ba6f5eaf = 500;
22
- function $5a8bfe1663b8366d$export$3a22a5a9bc0fd3b(element, opts = {}) {
23
- (0, $jxdbS$testinglibraryreact.fireEvent).pointerDown(element, {
24
- pointerType: 'touch',
25
- ...opts
26
- });
27
- (0, $jxdbS$testinglibraryreact.act)(()=>{
28
- jest.advanceTimersByTime($5a8bfe1663b8366d$export$4bd1d2d5ba6f5eaf);
29
- });
30
- (0, $jxdbS$testinglibraryreact.fireEvent).pointerUp(element, {
31
- pointerType: 'touch',
32
- ...opts
33
- });
34
- }
35
-
36
-
37
- //# sourceMappingURL=events.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;AAIM,MAAM,4CAA0B;AAOhC,SAAS,yCAAiB,OAAoB,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAA,GAAA,oCAAQ,EAAE,WAAW,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,IAAI;IAAA;IAC7D,CAAA,GAAA,8BAAE,EAAE;QACF,KAAK,mBAAmB,CAAC;IAC3B;IACA,CAAA,GAAA,oCAAQ,EAAE,SAAS,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,IAAI;IAAA;AAC7D","sources":["packages/@react-aria/test-utils/src/events.ts"],"sourcesContent":["/*\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\nimport {act, fireEvent} from '@testing-library/react';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param element - Element to long press.\n * @param opts - Options to pass to the simulated event. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.\n */\nexport function triggerLongPress(element: HTMLElement, opts = {}): void {\n fireEvent.pointerDown(element, {pointerType: 'touch', ...opts});\n act(() => {\n jest.advanceTimersByTime(DEFAULT_LONG_PRESS_TIME);\n });\n fireEvent.pointerUp(element, {pointerType: 'touch', ...opts});\n}\n"],"names":[],"version":3,"file":"events.main.js.map"}
package/dist/events.mjs DELETED
@@ -1,31 +0,0 @@
1
- import {fireEvent as $hhVmT$fireEvent, act as $hhVmT$act} from "@testing-library/react";
2
-
3
- /*
4
- * Copyright 2023 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- */
14
- const $5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf = 500;
15
- function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(element, opts = {}) {
16
- (0, $hhVmT$fireEvent).pointerDown(element, {
17
- pointerType: 'touch',
18
- ...opts
19
- });
20
- (0, $hhVmT$act)(()=>{
21
- jest.advanceTimersByTime($5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf);
22
- });
23
- (0, $hhVmT$fireEvent).pointerUp(element, {
24
- pointerType: 'touch',
25
- ...opts
26
- });
27
- }
28
-
29
-
30
- export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress};
31
- //# sourceMappingURL=events.module.js.map
@@ -1,31 +0,0 @@
1
- import {fireEvent as $hhVmT$fireEvent, act as $hhVmT$act} from "@testing-library/react";
2
-
3
- /*
4
- * Copyright 2023 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- */
14
- const $5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf = 500;
15
- function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(element, opts = {}) {
16
- (0, $hhVmT$fireEvent).pointerDown(element, {
17
- pointerType: 'touch',
18
- ...opts
19
- });
20
- (0, $hhVmT$act)(()=>{
21
- jest.advanceTimersByTime($5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf);
22
- });
23
- (0, $hhVmT$fireEvent).pointerUp(element, {
24
- pointerType: 'touch',
25
- ...opts
26
- });
27
- }
28
-
29
-
30
- export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress};
31
- //# sourceMappingURL=events.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAIM,MAAM,4CAA0B;AAOhC,SAAS,yCAAiB,OAAoB,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAA,GAAA,gBAAQ,EAAE,WAAW,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,IAAI;IAAA;IAC7D,CAAA,GAAA,UAAE,EAAE;QACF,KAAK,mBAAmB,CAAC;IAC3B;IACA,CAAA,GAAA,gBAAQ,EAAE,SAAS,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,IAAI;IAAA;AAC7D","sources":["packages/@react-aria/test-utils/src/events.ts"],"sourcesContent":["/*\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\nimport {act, fireEvent} from '@testing-library/react';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param element - Element to long press.\n * @param opts - Options to pass to the simulated event. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.\n */\nexport function triggerLongPress(element: HTMLElement, opts = {}): void {\n fireEvent.pointerDown(element, {pointerType: 'touch', ...opts});\n act(() => {\n jest.advanceTimersByTime(DEFAULT_LONG_PRESS_TIME);\n });\n fireEvent.pointerUp(element, {pointerType: 'touch', ...opts});\n}\n"],"names":[],"version":3,"file":"events.module.js.map"}
@@ -1,82 +0,0 @@
1
-
2
- var $parcel$global = globalThis;
3
-
4
- function $parcel$export(e, n, v, s) {
5
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
- }
7
-
8
- $parcel$export(module.exports, "installMouseEvent", () => $b53408e40e8d56d0$export$de31e3987c917741);
9
- $parcel$export(module.exports, "installPointerEvent", () => $b53408e40e8d56d0$export$82f0b04c1d69a901);
10
- /*
11
- * Copyright 2023 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
- * Enables reading pageX/pageY from fireEvent.mouse*(..., {pageX: ..., pageY: ...}).
22
- */ function $b53408e40e8d56d0$export$de31e3987c917741() {
23
- beforeAll(()=>{
24
- let oldMouseEvent = MouseEvent;
25
- // @ts-ignore
26
- $parcel$global.MouseEvent = class FakeMouseEvent extends MouseEvent {
27
- get pageX() {
28
- return this._init.pageX;
29
- }
30
- get pageY() {
31
- return this._init.pageY;
32
- }
33
- constructor(name, init){
34
- super(name, init);
35
- this._init = init;
36
- }
37
- };
38
- // @ts-ignore
39
- $parcel$global.MouseEvent.oldMouseEvent = oldMouseEvent;
40
- });
41
- afterAll(()=>{
42
- // @ts-ignore
43
- $parcel$global.MouseEvent = $parcel$global.MouseEvent.oldMouseEvent;
44
- });
45
- }
46
- function $b53408e40e8d56d0$export$82f0b04c1d69a901() {
47
- beforeAll(()=>{
48
- // @ts-ignore
49
- $parcel$global.PointerEvent = class FakePointerEvent extends MouseEvent {
50
- get pointerType() {
51
- var _this__init_pointerType;
52
- return (_this__init_pointerType = this._init.pointerType) !== null && _this__init_pointerType !== void 0 ? _this__init_pointerType : 'mouse';
53
- }
54
- get pointerId() {
55
- return this._init.pointerId;
56
- }
57
- get pageX() {
58
- return this._init.pageX;
59
- }
60
- get pageY() {
61
- return this._init.pageY;
62
- }
63
- get width() {
64
- return this._init.width;
65
- }
66
- get height() {
67
- return this._init.height;
68
- }
69
- constructor(name, init){
70
- super(name, init);
71
- this._init = init;
72
- }
73
- };
74
- });
75
- afterAll(()=>{
76
- // @ts-ignore
77
- delete $parcel$global.PointerEvent;
78
- });
79
- }
80
-
81
-
82
- //# sourceMappingURL=testSetup.main.js.map