@react-aria/test-utils 1.0.0-alpha.0 → 1.0.0-alpha.2

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 (58) 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 +26 -11
  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 +176 -0
  20. package/dist/menu.main.js.map +1 -0
  21. package/dist/menu.mjs +171 -0
  22. package/dist/menu.module.js +171 -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 +191 -0
  32. package/dist/table.main.js.map +1 -0
  33. package/dist/table.mjs +186 -0
  34. package/dist/table.module.js +186 -0
  35. package/dist/table.module.js.map +1 -0
  36. package/dist/testSetup.main.js +1 -1
  37. package/dist/testSetup.mjs +2 -2
  38. package/dist/testSetup.module.js +1 -1
  39. package/dist/types.d.ts +180 -4
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/user.main.js +65 -0
  42. package/dist/user.main.js.map +1 -0
  43. package/dist/user.mjs +56 -0
  44. package/dist/user.module.js +56 -0
  45. package/dist/user.module.js.map +1 -0
  46. package/dist/userEventMaps.main.js +15 -15
  47. package/dist/userEventMaps.mjs +16 -16
  48. package/dist/userEventMaps.module.js +15 -15
  49. package/package.json +6 -7
  50. package/src/combobox.ts +188 -0
  51. package/src/events.ts +28 -8
  52. package/src/gridlist.ts +116 -0
  53. package/src/index.ts +6 -3
  54. package/src/menu.ts +246 -0
  55. package/src/select.ts +158 -0
  56. package/src/table.ts +282 -0
  57. package/src/user.ts +73 -0
  58. package/LICENSE +0 -201
@@ -0,0 +1,137 @@
1
+ var $f8PS3$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, "ComboBoxTester", () => $15e4b71f2b6c4964$export$f97e14e96d71ab3b);
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
+ class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
21
+ get combobox() {
22
+ return this._combobox;
23
+ }
24
+ get trigger() {
25
+ return this._trigger;
26
+ }
27
+ get listbox() {
28
+ let listBoxId = this.combobox.getAttribute('aria-controls');
29
+ return listBoxId ? document.getElementById(listBoxId) || undefined : undefined;
30
+ }
31
+ get sections() {
32
+ let listbox = this.listbox;
33
+ if (listbox) return (0, $f8PS3$testinglibraryreact.within)(listbox).queryAllByRole('group');
34
+ else return [];
35
+ }
36
+ get focusedOption() {
37
+ let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');
38
+ return focusedOptionId ? document.getElementById(focusedOptionId) : undefined;
39
+ }
40
+ constructor(opts){
41
+ this.setInteractionType = (type)=>{
42
+ this._interactionType = type;
43
+ };
44
+ this.open = async (opts = {})=>{
45
+ let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
46
+ let trigger = this.trigger;
47
+ let combobox = this.combobox;
48
+ let isDisabled = trigger.hasAttribute('disabled');
49
+ if (interactionType === 'mouse') {
50
+ if (triggerBehavior === 'focus') await this.user.click(combobox);
51
+ else await this.user.click(trigger);
52
+ } else if (interactionType === 'keyboard' && this._trigger != null) {
53
+ (0, $f8PS3$testinglibraryreact.act)(()=>this._trigger.focus());
54
+ if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
55
+ } else if (interactionType === 'touch') {
56
+ if (triggerBehavior === 'focus') await this.user.pointer({
57
+ target: combobox,
58
+ keys: '[TouchA]'
59
+ });
60
+ else await this.user.pointer({
61
+ target: trigger,
62
+ keys: '[TouchA]'
63
+ });
64
+ }
65
+ await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
66
+ if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
67
+ else return true;
68
+ });
69
+ let listBoxId = combobox.getAttribute('aria-controls');
70
+ await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
71
+ if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
72
+ else return true;
73
+ });
74
+ };
75
+ this.selectOption = async (opts = {})=>{
76
+ let { optionText: optionText, option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType } = opts;
77
+ if (!this.combobox.getAttribute('aria-controls')) await this.open({
78
+ triggerBehavior: triggerBehavior
79
+ });
80
+ let listbox = this.listbox;
81
+ if (listbox) {
82
+ if (!option && optionText) option = (0, $f8PS3$testinglibraryreact.within)(listbox).getByText(optionText);
83
+ // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow
84
+ // the required amount of times to reach the option. For now just click the option even in keyboard mode
85
+ if (interactionType === 'mouse' || interactionType === 'keyboard') await this.user.click(option);
86
+ else await this.user.pointer({
87
+ target: option,
88
+ keys: '[TouchA]'
89
+ });
90
+ if (option && option.getAttribute('href') == null) await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
91
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
92
+ else return true;
93
+ });
94
+ } else throw new Error("Attempted to select a option in the combobox, but the listbox wasn't found.");
95
+ };
96
+ this.close = async ()=>{
97
+ let listbox = this.listbox;
98
+ if (listbox) {
99
+ (0, $f8PS3$testinglibraryreact.act)(()=>this.combobox.focus());
100
+ await this.user.keyboard('[Escape]');
101
+ await (0, $f8PS3$testinglibraryreact.waitFor)(()=>{
102
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
103
+ else return true;
104
+ });
105
+ }
106
+ };
107
+ this.options = (opts = {})=>{
108
+ let { element: element } = opts;
109
+ element = element || this.listbox;
110
+ let options = [];
111
+ if (element) options = (0, $f8PS3$testinglibraryreact.within)(element).queryAllByRole('option');
112
+ return options;
113
+ };
114
+ let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
115
+ this.user = user;
116
+ this._interactionType = interactionType || 'mouse';
117
+ // 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
118
+ // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
119
+ this._combobox = root;
120
+ let combobox = (0, $f8PS3$testinglibraryreact.within)(root).queryByRole('combobox');
121
+ if (combobox) this._combobox = combobox;
122
+ // 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)
123
+ if (trigger) this._trigger = trigger;
124
+ else {
125
+ let trigger = (0, $f8PS3$testinglibraryreact.within)(root).queryByRole('button', {
126
+ hidden: true
127
+ });
128
+ if (trigger) this._trigger = trigger;
129
+ else // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
130
+ // is also the trigger button
131
+ this._trigger = this._combobox;
132
+ }
133
+ }
134
+ }
135
+
136
+
137
+ //# sourceMappingURL=combobox.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAUM,MAAM;IAkIX,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,SAAS;IACvB;IAEA,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QAC3C,OAAO,YAAY,SAAS,cAAc,CAAC,cAAc,YAAY;IACvE;IAaA,IAAI,WAAW;QACb,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,SACF,OAAO,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;aAEtC,OAAO,EAAE;IAEb;IAEA,IAAI,gBAAgB;QAClB,IAAI,kBAAkB,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QACjD,OAAO,kBAAkB,SAAS,cAAc,CAAC,mBAAmB;IACtE;IAhKA,YAAY,IAAqB,CAAE;aA4BnC,qBAAqB,CAAC;YACpB,IAAI,CAAC,gBAAgB,GAAG;QAC1B;aAEA,OAAO,OAAO,OAA8F,CAAC,CAAC;YAC5G,IAAI,mBAAC,kBAAkB,2BAAU,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;YAC5E,IAAI,UAAU,IAAI,CAAC,OAAO;YAC1B,IAAI,WAAW,IAAI,CAAC,QAAQ;YAC5B,IAAI,aAAa,QAAS,YAAY,CAAC;YAEvC,IAAI,oBAAoB;gBACtB,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;qBAEtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;mBAEnB,IAAI,oBAAoB,c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IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,WAAW,CAAC,UAAU;gBAAC,QAAQ;YAAI;YAC9D,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;iBAEhB,qHAAqH;YACrH,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;QAElC;IACF;AAuIF","sources":["packages/@react-aria/test-utils/src/combobox.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\n\nexport interface ComboBoxOptions extends UserOpts, BaseTesterOpts {\n user: any,\n trigger?: HTMLElement\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement | undefined;\n\n constructor(opts: ComboBoxOptions) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // 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\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // 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)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let trigger = within(root).queryByRole('button', {hidden: true});\n if (trigger) {\n this._trigger = trigger;\n } else {\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = this._combobox;\n }\n }\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n open = async (opts: {triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard' && this._trigger != null) {\n act(() => this._trigger!.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`Listbox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n };\n\n selectOption = async (opts: {option?: HTMLElement, optionText?: string, triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {\n let {optionText, option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (listbox) {\n if (!option && optionText) {\n option = within(listbox).getByText(optionText);\n }\n\n // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option && option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n };\n\n close = async () => {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n };\n\n get combobox() {\n return this._combobox;\n }\n\n get trigger() {\n return this._trigger;\n }\n\n get listbox() {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || undefined : undefined;\n }\n\n options = (opts: {element?: HTMLElement} = {}): HTMLElement[] | never[] => {\n let {element} = opts;\n element = element || this.listbox;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n };\n\n get sections() {\n let listbox = this.listbox;\n if (listbox) {\n return within(listbox).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n get focusedOption() {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : undefined;\n }\n}\n"],"names":[],"version":3,"file":"combobox.main.js.map"}
@@ -0,0 +1,132 @@
1
+ import {within as $1n52X$within, act as $1n52X$act, waitFor as $1n52X$waitFor} from "@testing-library/react";
2
+
3
+ /*
4
+ * Copyright 2024 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
+ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
15
+ get combobox() {
16
+ return this._combobox;
17
+ }
18
+ get trigger() {
19
+ return this._trigger;
20
+ }
21
+ get listbox() {
22
+ let listBoxId = this.combobox.getAttribute('aria-controls');
23
+ return listBoxId ? document.getElementById(listBoxId) || undefined : undefined;
24
+ }
25
+ get sections() {
26
+ let listbox = this.listbox;
27
+ if (listbox) return (0, $1n52X$within)(listbox).queryAllByRole('group');
28
+ else return [];
29
+ }
30
+ get focusedOption() {
31
+ let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');
32
+ return focusedOptionId ? document.getElementById(focusedOptionId) : undefined;
33
+ }
34
+ constructor(opts){
35
+ this.setInteractionType = (type)=>{
36
+ this._interactionType = type;
37
+ };
38
+ this.open = async (opts = {})=>{
39
+ let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
40
+ let trigger = this.trigger;
41
+ let combobox = this.combobox;
42
+ let isDisabled = trigger.hasAttribute('disabled');
43
+ if (interactionType === 'mouse') {
44
+ if (triggerBehavior === 'focus') await this.user.click(combobox);
45
+ else await this.user.click(trigger);
46
+ } else if (interactionType === 'keyboard' && this._trigger != null) {
47
+ (0, $1n52X$act)(()=>this._trigger.focus());
48
+ if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
49
+ } else if (interactionType === 'touch') {
50
+ if (triggerBehavior === 'focus') await this.user.pointer({
51
+ target: combobox,
52
+ keys: '[TouchA]'
53
+ });
54
+ else await this.user.pointer({
55
+ target: trigger,
56
+ keys: '[TouchA]'
57
+ });
58
+ }
59
+ await (0, $1n52X$waitFor)(()=>{
60
+ if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
61
+ else return true;
62
+ });
63
+ let listBoxId = combobox.getAttribute('aria-controls');
64
+ await (0, $1n52X$waitFor)(()=>{
65
+ if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
66
+ else return true;
67
+ });
68
+ };
69
+ this.selectOption = async (opts = {})=>{
70
+ let { optionText: optionText, option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType } = opts;
71
+ if (!this.combobox.getAttribute('aria-controls')) await this.open({
72
+ triggerBehavior: triggerBehavior
73
+ });
74
+ let listbox = this.listbox;
75
+ if (listbox) {
76
+ if (!option && optionText) option = (0, $1n52X$within)(listbox).getByText(optionText);
77
+ // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow
78
+ // the required amount of times to reach the option. For now just click the option even in keyboard mode
79
+ if (interactionType === 'mouse' || interactionType === 'keyboard') await this.user.click(option);
80
+ else await this.user.pointer({
81
+ target: option,
82
+ keys: '[TouchA]'
83
+ });
84
+ if (option && option.getAttribute('href') == null) await (0, $1n52X$waitFor)(()=>{
85
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
86
+ else return true;
87
+ });
88
+ } else throw new Error("Attempted to select a option in the combobox, but the listbox wasn't found.");
89
+ };
90
+ this.close = async ()=>{
91
+ let listbox = this.listbox;
92
+ if (listbox) {
93
+ (0, $1n52X$act)(()=>this.combobox.focus());
94
+ await this.user.keyboard('[Escape]');
95
+ await (0, $1n52X$waitFor)(()=>{
96
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
97
+ else return true;
98
+ });
99
+ }
100
+ };
101
+ this.options = (opts = {})=>{
102
+ let { element: element } = opts;
103
+ element = element || this.listbox;
104
+ let options = [];
105
+ if (element) options = (0, $1n52X$within)(element).queryAllByRole('option');
106
+ return options;
107
+ };
108
+ let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
109
+ this.user = user;
110
+ this._interactionType = interactionType || 'mouse';
111
+ // 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
112
+ // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
113
+ this._combobox = root;
114
+ let combobox = (0, $1n52X$within)(root).queryByRole('combobox');
115
+ if (combobox) this._combobox = combobox;
116
+ // 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)
117
+ if (trigger) this._trigger = trigger;
118
+ else {
119
+ let trigger = (0, $1n52X$within)(root).queryByRole('button', {
120
+ hidden: true
121
+ });
122
+ if (trigger) this._trigger = trigger;
123
+ else // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
124
+ // is also the trigger button
125
+ this._trigger = this._combobox;
126
+ }
127
+ }
128
+ }
129
+
130
+
131
+ export {$dab75f394483aa9c$export$f97e14e96d71ab3b as ComboBoxTester};
132
+ //# sourceMappingURL=combobox.module.js.map
@@ -0,0 +1,132 @@
1
+ import {within as $1n52X$within, act as $1n52X$act, waitFor as $1n52X$waitFor} from "@testing-library/react";
2
+
3
+ /*
4
+ * Copyright 2024 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
+ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
15
+ get combobox() {
16
+ return this._combobox;
17
+ }
18
+ get trigger() {
19
+ return this._trigger;
20
+ }
21
+ get listbox() {
22
+ let listBoxId = this.combobox.getAttribute('aria-controls');
23
+ return listBoxId ? document.getElementById(listBoxId) || undefined : undefined;
24
+ }
25
+ get sections() {
26
+ let listbox = this.listbox;
27
+ if (listbox) return (0, $1n52X$within)(listbox).queryAllByRole('group');
28
+ else return [];
29
+ }
30
+ get focusedOption() {
31
+ let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');
32
+ return focusedOptionId ? document.getElementById(focusedOptionId) : undefined;
33
+ }
34
+ constructor(opts){
35
+ this.setInteractionType = (type)=>{
36
+ this._interactionType = type;
37
+ };
38
+ this.open = async (opts = {})=>{
39
+ let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
40
+ let trigger = this.trigger;
41
+ let combobox = this.combobox;
42
+ let isDisabled = trigger.hasAttribute('disabled');
43
+ if (interactionType === 'mouse') {
44
+ if (triggerBehavior === 'focus') await this.user.click(combobox);
45
+ else await this.user.click(trigger);
46
+ } else if (interactionType === 'keyboard' && this._trigger != null) {
47
+ (0, $1n52X$act)(()=>this._trigger.focus());
48
+ if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
49
+ } else if (interactionType === 'touch') {
50
+ if (triggerBehavior === 'focus') await this.user.pointer({
51
+ target: combobox,
52
+ keys: '[TouchA]'
53
+ });
54
+ else await this.user.pointer({
55
+ target: trigger,
56
+ keys: '[TouchA]'
57
+ });
58
+ }
59
+ await (0, $1n52X$waitFor)(()=>{
60
+ if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
61
+ else return true;
62
+ });
63
+ let listBoxId = combobox.getAttribute('aria-controls');
64
+ await (0, $1n52X$waitFor)(()=>{
65
+ if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
66
+ else return true;
67
+ });
68
+ };
69
+ this.selectOption = async (opts = {})=>{
70
+ let { optionText: optionText, option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType } = opts;
71
+ if (!this.combobox.getAttribute('aria-controls')) await this.open({
72
+ triggerBehavior: triggerBehavior
73
+ });
74
+ let listbox = this.listbox;
75
+ if (listbox) {
76
+ if (!option && optionText) option = (0, $1n52X$within)(listbox).getByText(optionText);
77
+ // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow
78
+ // the required amount of times to reach the option. For now just click the option even in keyboard mode
79
+ if (interactionType === 'mouse' || interactionType === 'keyboard') await this.user.click(option);
80
+ else await this.user.pointer({
81
+ target: option,
82
+ keys: '[TouchA]'
83
+ });
84
+ if (option && option.getAttribute('href') == null) await (0, $1n52X$waitFor)(()=>{
85
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
86
+ else return true;
87
+ });
88
+ } else throw new Error("Attempted to select a option in the combobox, but the listbox wasn't found.");
89
+ };
90
+ this.close = async ()=>{
91
+ let listbox = this.listbox;
92
+ if (listbox) {
93
+ (0, $1n52X$act)(()=>this.combobox.focus());
94
+ await this.user.keyboard('[Escape]');
95
+ await (0, $1n52X$waitFor)(()=>{
96
+ if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
97
+ else return true;
98
+ });
99
+ }
100
+ };
101
+ this.options = (opts = {})=>{
102
+ let { element: element } = opts;
103
+ element = element || this.listbox;
104
+ let options = [];
105
+ if (element) options = (0, $1n52X$within)(element).queryAllByRole('option');
106
+ return options;
107
+ };
108
+ let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
109
+ this.user = user;
110
+ this._interactionType = interactionType || 'mouse';
111
+ // 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
112
+ // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
113
+ this._combobox = root;
114
+ let combobox = (0, $1n52X$within)(root).queryByRole('combobox');
115
+ if (combobox) this._combobox = combobox;
116
+ // 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)
117
+ if (trigger) this._trigger = trigger;
118
+ else {
119
+ let trigger = (0, $1n52X$within)(root).queryByRole('button', {
120
+ hidden: true
121
+ });
122
+ if (trigger) this._trigger = trigger;
123
+ else // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
124
+ // is also the trigger button
125
+ this._trigger =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;gBAAC,QAAQ;YAAI;YAC9D,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;iBAEhB,qHAAqH;YACrH,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;QAElC;IACF;AAuIF","sources":["packages/@react-aria/test-utils/src/combobox.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\n\nexport interface ComboBoxOptions extends UserOpts, BaseTesterOpts {\n user: any,\n trigger?: HTMLElement\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement | undefined;\n\n constructor(opts: ComboBoxOptions) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // 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\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // 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)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let trigger = within(root).queryByRole('button', {hidden: true});\n if (trigger) {\n this._trigger = trigger;\n } else {\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = this._combobox;\n }\n }\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n open = async (opts: {triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard' && this._trigger != null) {\n act(() => this._trigger!.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`Listbox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n };\n\n selectOption = async (opts: {option?: HTMLElement, optionText?: string, triggerBehavior?: 'focus' | 'manual', interactionType?: UserOpts['interactionType']} = {}) => {\n let {optionText, option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (listbox) {\n if (!option && optionText) {\n option = within(listbox).getByText(optionText);\n }\n\n // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option && option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n };\n\n close = async () => {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n };\n\n get combobox() {\n return this._combobox;\n }\n\n get trigger() {\n return this._trigger;\n }\n\n get listbox() {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || undefined : undefined;\n }\n\n options = (opts: {element?: HTMLElement} = {}): HTMLElement[] | never[] => {\n let {element} = opts;\n element = element || this.listbox;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n };\n\n get sections() {\n let listbox = this.listbox;\n if (listbox) {\n return within(listbox).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n get focusedOption() {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : undefined;\n }\n}\n"],"names":[],"version":3,"file":"combobox.module.js.map"}
@@ -5,8 +5,8 @@ function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
- $parcel$export(module.exports, "DEFAULT_LONG_PRESS_TIME", () => $5a8bfe1663b8366d$export$4bd1d2d5ba6f5eaf);
9
8
  $parcel$export(module.exports, "triggerLongPress", () => $5a8bfe1663b8366d$export$3a22a5a9bc0fd3b);
9
+ $parcel$export(module.exports, "pressElement", () => $5a8bfe1663b8366d$export$6ffa3eb717517feb);
10
10
  /*
11
11
  * Copyright 2023 Adobe. All rights reserved.
12
12
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -19,17 +19,32 @@ $parcel$export(module.exports, "triggerLongPress", () => $5a8bfe1663b8366d$expor
19
19
  * governing permissions and limitations under the License.
20
20
  */
21
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
22
+ async function $5a8bfe1663b8366d$export$3a22a5a9bc0fd3b(opts) {
23
+ // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the
24
+ // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the
25
+ // util before first render. Will need to document it well
26
+ let { element: element, advanceTimer: advanceTimer, pointerOpts: pointerOpts = {} } = opts;
27
+ await (0, $jxdbS$testinglibraryreact.fireEvent).pointerDown(element, {
28
+ pointerType: 'mouse',
29
+ ...pointerOpts
26
30
  });
27
- (0, $jxdbS$testinglibraryreact.act)(()=>{
28
- jest.advanceTimersByTime($5a8bfe1663b8366d$export$4bd1d2d5ba6f5eaf);
31
+ await (0, $jxdbS$testinglibraryreact.act)(async ()=>await advanceTimer($5a8bfe1663b8366d$export$4bd1d2d5ba6f5eaf));
32
+ await (0, $jxdbS$testinglibraryreact.fireEvent).pointerUp(element, {
33
+ pointerType: 'mouse',
34
+ ...pointerOpts
29
35
  });
30
- (0, $jxdbS$testinglibraryreact.fireEvent).pointerUp(element, {
31
- pointerType: "touch",
32
- ...opts
36
+ }
37
+ async function $5a8bfe1663b8366d$export$6ffa3eb717517feb(user, element, interactionType) {
38
+ if (interactionType === 'mouse') await user.click(element);
39
+ else if (interactionType === 'keyboard') {
40
+ // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should
41
+ // stick to simulting an actual user's keyboard operations as closely as possible
42
+ // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.
43
+ (0, $jxdbS$testinglibraryreact.act)(()=>element.focus());
44
+ await user.keyboard('[Space]');
45
+ } else if (interactionType === 'touch') await user.pointer({
46
+ target: element,
47
+ keys: '[TouchA]'
33
48
  });
34
49
  }
35
50
 
@@ -1 +1 @@
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"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AAShC,eAAe,yCAAiB,IAAwG;IAC7I,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;IAChD,MAAM,CAAA,GAAA,oCAAQ,EAAE,WAAW,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;IAC1E,MAAM,CAAA,GAAA,8BAAE,EAAE,UAAY,MAAM,aAAa;IACzC,MAAM,CAAA,GAAA,oCAAQ,EAAE,SAAS,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;AAC1E;AAGO,eAAe,0CAAa,IAAI,EAAE,OAAoB,EAAE,eAA4C;IACzG,IAAI,oBAAoB,SACtB,MAAM,KAAK,KAAK,CAAC;SACZ,IAAI,oBAAoB,YAAY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,KAAK;QACvB,MAAM,KAAK,QAAQ,CAAC;IACtB,OAAO,IAAI,oBAAoB,SAC7B,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;IAAU;AAEzD","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';\nimport {UserOpts} from './user';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param opts - Options for the long press.\n * @param opts.element - Element to long press.\n * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).\n * @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.\n */\nexport async function triggerLongPress(opts: {element: HTMLElement, advanceTimer: (time?: number) => void | Promise<unknown>, pointerOpts?: {}}) {\n // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the\n // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the\n // util before first render. Will need to document it well\n let {element, advanceTimer, pointerOpts = {}} = opts;\n await fireEvent.pointerDown(element, {pointerType: 'mouse', ...pointerOpts});\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n await fireEvent.pointerUp(element, {pointerType: 'mouse', ...pointerOpts});\n}\n\n\nexport async function pressElement(user, element: HTMLElement, interactionType: UserOpts['interactionType']) {\n if (interactionType === 'mouse') {\n await user.click(element);\n } else if (interactionType === 'keyboard') {\n // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should\n // stick to simulting an actual user's keyboard operations as closely as possible\n // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.\n act(() => element.focus());\n await user.keyboard('[Space]');\n } else if (interactionType === 'touch') {\n await user.pointer({target: element, keys: '[TouchA]'});\n }\n}\n"],"names":[],"version":3,"file":"events.main.js.map"}
package/dist/events.mjs CHANGED
@@ -12,20 +12,35 @@ import {fireEvent as $hhVmT$fireEvent, act as $hhVmT$act} from "@testing-library
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
  const $5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf = 500;
15
- function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(element, opts = {}) {
16
- (0, $hhVmT$fireEvent).pointerDown(element, {
17
- pointerType: "touch",
18
- ...opts
15
+ async function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(opts) {
16
+ // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the
17
+ // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the
18
+ // util before first render. Will need to document it well
19
+ let { element: element, advanceTimer: advanceTimer, pointerOpts: pointerOpts = {} } = opts;
20
+ await (0, $hhVmT$fireEvent).pointerDown(element, {
21
+ pointerType: 'mouse',
22
+ ...pointerOpts
19
23
  });
20
- (0, $hhVmT$act)(()=>{
21
- jest.advanceTimersByTime($5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf);
24
+ await (0, $hhVmT$act)(async ()=>await advanceTimer($5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf));
25
+ await (0, $hhVmT$fireEvent).pointerUp(element, {
26
+ pointerType: 'mouse',
27
+ ...pointerOpts
22
28
  });
23
- (0, $hhVmT$fireEvent).pointerUp(element, {
24
- pointerType: "touch",
25
- ...opts
29
+ }
30
+ async function $5d1eca18f92ad0e6$export$6ffa3eb717517feb(user, element, interactionType) {
31
+ if (interactionType === 'mouse') await user.click(element);
32
+ else if (interactionType === 'keyboard') {
33
+ // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should
34
+ // stick to simulting an actual user's keyboard operations as closely as possible
35
+ // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.
36
+ (0, $hhVmT$act)(()=>element.focus());
37
+ await user.keyboard('[Space]');
38
+ } else if (interactionType === 'touch') await user.pointer({
39
+ target: element,
40
+ keys: '[TouchA]'
26
41
  });
27
42
  }
28
43
 
29
44
 
30
- export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress};
31
- //# sourceMappingURL=events.mjs.map
45
+ export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $5d1eca18f92ad0e6$export$6ffa3eb717517feb as pressElement};
46
+ //# sourceMappingURL=events.module.js.map
@@ -12,20 +12,35 @@ import {fireEvent as $hhVmT$fireEvent, act as $hhVmT$act} from "@testing-library
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
  const $5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf = 500;
15
- function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(element, opts = {}) {
16
- (0, $hhVmT$fireEvent).pointerDown(element, {
17
- pointerType: "touch",
18
- ...opts
15
+ async function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(opts) {
16
+ // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the
17
+ // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the
18
+ // util before first render. Will need to document it well
19
+ let { element: element, advanceTimer: advanceTimer, pointerOpts: pointerOpts = {} } = opts;
20
+ await (0, $hhVmT$fireEvent).pointerDown(element, {
21
+ pointerType: 'mouse',
22
+ ...pointerOpts
19
23
  });
20
- (0, $hhVmT$act)(()=>{
21
- jest.advanceTimersByTime($5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf);
24
+ await (0, $hhVmT$act)(async ()=>await advanceTimer($5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf));
25
+ await (0, $hhVmT$fireEvent).pointerUp(element, {
26
+ pointerType: 'mouse',
27
+ ...pointerOpts
22
28
  });
23
- (0, $hhVmT$fireEvent).pointerUp(element, {
24
- pointerType: "touch",
25
- ...opts
29
+ }
30
+ async function $5d1eca18f92ad0e6$export$6ffa3eb717517feb(user, element, interactionType) {
31
+ if (interactionType === 'mouse') await user.click(element);
32
+ else if (interactionType === 'keyboard') {
33
+ // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should
34
+ // stick to simulting an actual user's keyboard operations as closely as possible
35
+ // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.
36
+ (0, $hhVmT$act)(()=>element.focus());
37
+ await user.keyboard('[Space]');
38
+ } else if (interactionType === 'touch') await user.pointer({
39
+ target: element,
40
+ keys: '[TouchA]'
26
41
  });
27
42
  }
28
43
 
29
44
 
30
- export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress};
45
+ export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $5d1eca18f92ad0e6$export$6ffa3eb717517feb as pressElement};
31
46
  //# sourceMappingURL=events.module.js.map
@@ -1 +1 @@
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
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AAShC,eAAe,yCAAiB,IAAwG;IAC7I,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;IAChD,MAAM,CAAA,GAAA,gBAAQ,EAAE,WAAW,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;IAC1E,MAAM,CAAA,GAAA,UAAE,EAAE,UAAY,MAAM,aAAa;IACzC,MAAM,CAAA,GAAA,gBAAQ,EAAE,SAAS,CAAC,SAAS;QAAC,aAAa;QAAS,GAAG,WAAW;IAAA;AAC1E;AAGO,eAAe,0CAAa,IAAI,EAAE,OAAoB,EAAE,eAA4C;IACzG,IAAI,oBAAoB,SACtB,MAAM,KAAK,KAAK,CAAC;SACZ,IAAI,oBAAoB,YAAY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,UAAE,EAAE,IAAM,QAAQ,KAAK;QACvB,MAAM,KAAK,QAAQ,CAAC;IACtB,OAAO,IAAI,oBAAoB,SAC7B,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;IAAU;AAEzD","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';\nimport {UserOpts} from './user';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param opts - Options for the long press.\n * @param opts.element - Element to long press.\n * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).\n * @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.\n */\nexport async function triggerLongPress(opts: {element: HTMLElement, advanceTimer: (time?: number) => void | Promise<unknown>, pointerOpts?: {}}) {\n // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the\n // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the\n // util before first render. Will need to document it well\n let {element, advanceTimer, pointerOpts = {}} = opts;\n await fireEvent.pointerDown(element, {pointerType: 'mouse', ...pointerOpts});\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n await fireEvent.pointerUp(element, {pointerType: 'mouse', ...pointerOpts});\n}\n\n\nexport async function pressElement(user, element: HTMLElement, interactionType: UserOpts['interactionType']) {\n if (interactionType === 'mouse') {\n await user.click(element);\n } else if (interactionType === 'keyboard') {\n // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should\n // stick to simulting an actual user's keyboard operations as closely as possible\n // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.\n act(() => element.focus());\n await user.keyboard('[Space]');\n } else if (interactionType === 'touch') {\n await user.pointer({target: element, keys: '[TouchA]'});\n }\n}\n"],"names":[],"version":3,"file":"events.module.js.map"}