frontile 0.18.0 → 0.18.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.
- package/declarations/-private/get-config.d.ts.map +1 -1
- package/declarations/-private/timer.d.ts +3 -3
- package/declarations/-private/timer.d.ts.map +1 -1
- package/declarations/components/buttons/chip.d.ts +1 -1
- package/declarations/components/buttons/chip.d.ts.map +1 -1
- package/declarations/components/buttons/close-button.d.ts +2 -2
- package/declarations/components/buttons/close-button.d.ts.map +1 -1
- package/declarations/components/collections/listbox/item.d.ts +2 -2
- package/declarations/components/collections/listbox/item.d.ts.map +1 -1
- package/declarations/components/collections/simple-table/column.d.ts +6 -0
- package/declarations/components/collections/simple-table/column.d.ts.map +1 -1
- package/declarations/components/collections/simple-table/footer.d.ts +2 -1
- package/declarations/components/collections/simple-table/footer.d.ts.map +1 -1
- package/declarations/components/collections/simple-table/header.d.ts +2 -1
- package/declarations/components/collections/simple-table/header.d.ts.map +1 -1
- package/declarations/components/collections/simple-table/index.d.ts +1 -1
- package/declarations/components/collections/simple-table/index.d.ts.map +1 -1
- package/declarations/components/collections/table/checkbox.d.ts +1 -1
- package/declarations/components/collections/table/checkbox.d.ts.map +1 -1
- package/declarations/components/collections/table/column-visibility.d.ts +2 -2
- package/declarations/components/collections/table/column-visibility.d.ts.map +1 -1
- package/declarations/components/collections/table/table.d.ts +9 -7
- package/declarations/components/collections/table/table.d.ts.map +1 -1
- package/declarations/components/forms/autocomplete.d.ts +12 -12
- package/declarations/components/forms/checkbox.d.ts +2 -2
- package/declarations/components/forms/checkbox.d.ts.map +1 -1
- package/declarations/components/forms/date-input/clipboard.d.ts +34 -0
- package/declarations/components/forms/date-input/clipboard.d.ts.map +1 -0
- package/declarations/components/forms/date-input/date-input.d.ts +93 -0
- package/declarations/components/forms/date-input/date-input.d.ts.map +1 -0
- package/declarations/components/forms/date-input/segment-group.d.ts +132 -0
- package/declarations/components/forms/date-input/segment-group.d.ts.map +1 -0
- package/declarations/components/forms/date-input/segments.d.ts +163 -0
- package/declarations/components/forms/date-input/segments.d.ts.map +1 -0
- package/declarations/components/forms/date-input/types.d.ts +175 -0
- package/declarations/components/forms/date-input/types.d.ts.map +1 -0
- package/declarations/components/forms/date-input.d.ts +6 -0
- package/declarations/components/forms/date-input.d.ts.map +1 -0
- package/declarations/components/forms/date-picker/date-picker.d.ts +263 -15
- package/declarations/components/forms/date-picker/date-picker.d.ts.map +1 -1
- package/declarations/components/forms/date-picker/end-content.d.ts +33 -3
- package/declarations/components/forms/date-picker/end-content.d.ts.map +1 -1
- package/declarations/components/forms/date-picker/types.d.ts +45 -2
- package/declarations/components/forms/date-picker/types.d.ts.map +1 -1
- package/declarations/components/forms/date-picker/value.d.ts +21 -5
- package/declarations/components/forms/date-picker/value.d.ts.map +1 -1
- package/declarations/components/forms/field.d.ts +7 -5
- package/declarations/components/forms/field.d.ts.map +1 -1
- package/declarations/components/forms/form.d.ts +5 -5
- package/declarations/components/forms/form.d.ts.map +1 -1
- package/declarations/components/forms/index.d.ts +1 -0
- package/declarations/components/forms/index.d.ts.map +1 -1
- package/declarations/components/forms/input-otp.d.ts +5 -5
- package/declarations/components/forms/input-otp.d.ts.map +1 -1
- package/declarations/components/forms/input.d.ts +15 -15
- package/declarations/components/forms/input.d.ts.map +1 -1
- package/declarations/components/forms/native-select.d.ts +10 -10
- package/declarations/components/forms/native-select.d.ts.map +1 -1
- package/declarations/components/forms/radio.d.ts +2 -2
- package/declarations/components/forms/radio.d.ts.map +1 -1
- package/declarations/components/forms/select/select.d.ts +16 -16
- package/declarations/components/forms/textarea.d.ts +10 -10
- package/declarations/components/forms/textarea.d.ts.map +1 -1
- package/declarations/components/navigation/pagination/pagination.d.ts +32 -1
- package/declarations/components/navigation/pagination/pagination.d.ts.map +1 -1
- package/declarations/components/overlays/overlay.d.ts +4 -4
- package/declarations/components/overlays/overlay.d.ts.map +1 -1
- package/declarations/components/utilities/avatar.d.ts +35 -2
- package/declarations/components/utilities/avatar.d.ts.map +1 -1
- package/declarations/components/utilities/collapsible.d.ts +16 -0
- package/declarations/components/utilities/collapsible.d.ts.map +1 -1
- package/declarations/test-support.d.ts +30 -0
- package/declarations/test-support.d.ts.map +1 -1
- package/declarations/utils/forms-utils-index.d.ts +1 -1
- package/declarations/utils/forms-utils-index.d.ts.map +1 -1
- package/declarations/utils/nested-data.d.ts +17 -0
- package/declarations/utils/nested-data.d.ts.map +1 -1
- package/dist/components/buttons/chip.js.map +1 -1
- package/dist/components/buttons/close-button.js +5 -12
- package/dist/components/buttons/close-button.js.map +1 -1
- package/dist/components/collections/listbox/item.js +4 -11
- package/dist/components/collections/listbox/item.js.map +1 -1
- package/dist/components/collections/simple-table/column.js +2 -2
- package/dist/components/collections/simple-table/column.js.map +1 -1
- package/dist/components/collections/simple-table/footer.js +1 -1
- package/dist/components/collections/simple-table/footer.js.map +1 -1
- package/dist/components/collections/simple-table/header.js +1 -1
- package/dist/components/collections/simple-table/header.js.map +1 -1
- package/dist/components/collections/simple-table/index.js +1 -1
- package/dist/components/collections/simple-table/index.js.map +1 -1
- package/dist/components/collections/table/checkbox.js +2 -7
- package/dist/components/collections/table/checkbox.js.map +1 -1
- package/dist/components/collections/table/column-visibility.js +2 -7
- package/dist/components/collections/table/column-visibility.js.map +1 -1
- package/dist/components/forms/checkbox.js +4 -12
- package/dist/components/forms/checkbox.js.map +1 -1
- package/dist/components/forms/date-input/clipboard.js +231 -0
- package/dist/components/forms/date-input/clipboard.js.map +1 -0
- package/dist/components/forms/date-input/date-input.js +204 -0
- package/dist/components/forms/date-input/date-input.js.map +1 -0
- package/dist/components/forms/date-input/segment-group.js +292 -0
- package/dist/components/forms/date-input/segment-group.js.map +1 -0
- package/dist/components/forms/date-input/segments.js +562 -0
- package/dist/components/forms/date-input/segments.js.map +1 -0
- package/dist/components/forms/date-input/types.js +2 -0
- package/dist/components/forms/date-input/types.js.map +1 -0
- package/dist/components/forms/date-input.js +4 -0
- package/dist/components/forms/date-input.js.map +1 -0
- package/dist/components/forms/date-picker/date-picker.js +361 -20
- package/dist/components/forms/date-picker/date-picker.js.map +1 -1
- package/dist/components/forms/date-picker/end-content.js +17 -4
- package/dist/components/forms/date-picker/end-content.js.map +1 -1
- package/dist/components/forms/date-picker/value.js +44 -6
- package/dist/components/forms/date-picker/value.js.map +1 -1
- package/dist/components/forms/field.js +12 -20
- package/dist/components/forms/field.js.map +1 -1
- package/dist/components/forms/form.js +11 -27
- package/dist/components/forms/form.js.map +1 -1
- package/dist/components/forms/index.js +5 -2
- package/dist/components/forms/index.js.map +1 -1
- package/dist/components/forms/input-otp.js +10 -26
- package/dist/components/forms/input-otp.js.map +1 -1
- package/dist/components/forms/input.js +9 -22
- package/dist/components/forms/input.js.map +1 -1
- package/dist/components/forms/native-select.js +5 -12
- package/dist/components/forms/native-select.js.map +1 -1
- package/dist/components/forms/radio.js +4 -12
- package/dist/components/forms/radio.js.map +1 -1
- package/dist/components/forms/textarea.js +6 -17
- package/dist/components/forms/textarea.js.map +1 -1
- package/dist/components/navigation/pagination/pagination.js +18 -2
- package/dist/components/navigation/pagination/pagination.js.map +1 -1
- package/dist/components/notifications/index.js +1 -1
- package/dist/components/overlays/overlay.js +8 -21
- package/dist/components/overlays/overlay.js.map +1 -1
- package/dist/components/utilities/avatar.js +26 -5
- package/dist/components/utilities/avatar.js.map +1 -1
- package/dist/components/utilities/collapsible.js +47 -3
- package/dist/components/utilities/collapsible.js.map +1 -1
- package/dist/forms.js +5 -2
- package/dist/forms.js.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/{manager-jDaRVZ5o.js → manager-Dge4r8Vn.js} +9 -19
- package/dist/manager-Dge4r8Vn.js.map +1 -0
- package/dist/notifications.js +1 -1
- package/dist/services/notifications.js +1 -1
- package/dist/test-support.js +903 -389
- package/dist/test-support.js.map +1 -1
- package/dist/utils/forms-utils-index.js +1 -1
- package/dist/utils/forms-utils-index.js.map +1 -1
- package/dist/utils/nested-data.js +28 -1
- package/dist/utils/nested-data.js.map +1 -1
- package/package.json +10 -10
- package/dist/manager-jDaRVZ5o.js.map +0 -1
package/dist/test-support.js
CHANGED
|
@@ -1,175 +1,23 @@
|
|
|
1
|
-
import '@ember/application';
|
|
2
|
-
import { VERSION } from '@ember/version';
|
|
3
1
|
import { _backburner } from '@ember/runloop';
|
|
4
2
|
import EmberObject from '@ember/object';
|
|
3
|
+
import '@ember/application';
|
|
5
4
|
import '@ember/application/instance';
|
|
6
5
|
import '@ember/-internals/container';
|
|
7
6
|
import { RegistryProxyMixin, ContainerProxyMixin } from '@ember/-internals/runtime';
|
|
8
7
|
import { Test } from 'ember-testing';
|
|
9
8
|
import '@ember/-internals/error-handling';
|
|
10
9
|
import { registerDeprecationHandler, registerWarnHandler } from '@ember/debug';
|
|
10
|
+
import { VERSION } from '@ember/version';
|
|
11
11
|
import { getPendingWaiterState, hasPendingWaiters } from '@ember/test-waiters';
|
|
12
12
|
import '@ember/destroyable';
|
|
13
13
|
import '@ember/-internals/views';
|
|
14
14
|
import '@glimmer/manager';
|
|
15
|
+
import { macroCondition, appEmberSatisfies, importSync, dependencySatisfies } from '@embroider/macros';
|
|
15
16
|
import { precompileTemplate } from '@ember/template-compilation';
|
|
16
|
-
import {
|
|
17
|
+
import { capabilities } from '@ember/component';
|
|
18
|
+
import { parseDate } from './components/forms/date-picker/value.js';
|
|
17
19
|
export { setPrefersReducedMotion } from './utils/prefers-reduced-motion.js';
|
|
18
20
|
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
Checks if the currently running Ember version is greater than or equal to the
|
|
23
|
-
specified major and minor version numbers.
|
|
24
|
-
|
|
25
|
-
@private
|
|
26
|
-
@param {number} major the major version number to compare
|
|
27
|
-
@param {number} minor the minor version number to compare
|
|
28
|
-
@returns {boolean} true if the Ember version is >= MAJOR.MINOR specified, false otherwise
|
|
29
|
-
*/
|
|
30
|
-
function hasEmberVersion(major, minor) {
|
|
31
|
-
const numbers = VERSION.split('-')[0]?.split('.');
|
|
32
|
-
if (!numbers || !numbers[0] || !numbers[1]) {
|
|
33
|
-
throw new Error('`Ember.VERSION` is not set.');
|
|
34
|
-
}
|
|
35
|
-
const actualMajor = parseInt(numbers[0], 10);
|
|
36
|
-
const actualMinor = parseInt(numbers[1], 10);
|
|
37
|
-
return actualMajor > major || actualMajor === major && actualMinor >= minor;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// NOTE: this is the same as what `EngineInstance`/`ApplicationInstance`
|
|
41
|
-
// implement, and is thus a superset of the `InternalOwner` contract from Ember
|
|
42
|
-
// itself.
|
|
43
|
-
|
|
44
|
-
EmberObject.extend(RegistryProxyMixin, ContainerProxyMixin, {
|
|
45
|
-
_emberTestHelpersMockOwner: true,
|
|
46
|
-
/* eslint-disable valid-jsdoc */
|
|
47
|
-
/**
|
|
48
|
-
* Unregister a factory and its instance.
|
|
49
|
-
*
|
|
50
|
-
* Overrides `RegistryProxy#unregister` in order to clear any cached instances
|
|
51
|
-
* of the unregistered factory.
|
|
52
|
-
*
|
|
53
|
-
* @param {string} fullName Name of the factory to unregister.
|
|
54
|
-
*
|
|
55
|
-
* @see {@link https://github.com/emberjs/ember.js/pull/12680}
|
|
56
|
-
* @see {@link https://github.com/emberjs/ember.js/blob/v4.5.0-alpha.5/packages/%40ember/engine/instance.ts#L152-L167}
|
|
57
|
-
*/
|
|
58
|
-
/* eslint-enable valid-jsdoc */
|
|
59
|
-
unregister(fullName) {
|
|
60
|
-
// SAFETY: this is always present, but only the stable type definitions from
|
|
61
|
-
// Ember actually preserve it, since it is private API.
|
|
62
|
-
this['__container__'].reset(fullName);
|
|
63
|
-
|
|
64
|
-
// We overwrote this method from RegistryProxyMixin.
|
|
65
|
-
// SAFETY: this is always present, but only the stable type definitions from
|
|
66
|
-
// Ember actually preserve it, since it is private API.
|
|
67
|
-
this['__registry__'].unregister(fullName);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// eslint-disable-next-line require-jsdoc
|
|
72
|
-
function isElement(target) {
|
|
73
|
-
return target !== null && typeof target === 'object' && Reflect.get(target, 'nodeType') === Node.ELEMENT_NODE;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// eslint-disable-next-line require-jsdoc
|
|
77
|
-
function isWindow(target) {
|
|
78
|
-
return target instanceof Window;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// eslint-disable-next-line require-jsdoc
|
|
82
|
-
function isDocument(target) {
|
|
83
|
-
return target !== null && typeof target === 'object' && Reflect.get(target, 'nodeType') === Node.DOCUMENT_NODE;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const FORM_CONTROL_TAGS = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'];
|
|
87
|
-
/**
|
|
88
|
-
@private
|
|
89
|
-
@param {Element} element the element to check
|
|
90
|
-
@returns {boolean} `true` when the element is a form control, `false` otherwise
|
|
91
|
-
*/
|
|
92
|
-
function isFormControl(element) {
|
|
93
|
-
return !isWindow(element) && !isDocument(element) && FORM_CONTROL_TAGS.indexOf(element.tagName) > -1 && element.type !== 'hidden';
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const futureTick = setTimeout;
|
|
97
|
-
|
|
98
|
-
const TIMEOUTS = [0, 1, 2, 5, 7];
|
|
99
|
-
const MAX_TIMEOUT = 10;
|
|
100
|
-
/**
|
|
101
|
-
Wait for the provided callback to return a truthy value.
|
|
102
|
-
|
|
103
|
-
This does not leverage `settled()`, and as such can be used to manage async
|
|
104
|
-
while _not_ settled (e.g. "loading" or "pending" states).
|
|
105
|
-
|
|
106
|
-
@public
|
|
107
|
-
@param {Function} callback the callback to use for testing when waiting should stop
|
|
108
|
-
@param {Object} [options] options used to override defaults
|
|
109
|
-
@param {number} [options.timeout=1000] the maximum amount of time to wait
|
|
110
|
-
@param {string} [options.timeoutMessage='waitUntil timed out'] the message to use in the reject on timeout
|
|
111
|
-
@returns {Promise} resolves with the callback value when it returns a truthy value
|
|
112
|
-
|
|
113
|
-
@example
|
|
114
|
-
<caption>
|
|
115
|
-
Waiting until a selected element displays text:
|
|
116
|
-
</caption>
|
|
117
|
-
await waitUntil(function() {
|
|
118
|
-
return find('.my-selector').textContent.includes('something')
|
|
119
|
-
}, { timeout: 2000 })
|
|
120
|
-
*/
|
|
121
|
-
function waitUntil(callback, options = {}) {
|
|
122
|
-
const timeout = 'timeout' in options ? options.timeout : 1000;
|
|
123
|
-
const timeoutMessage = 'timeoutMessage' in options ? options.timeoutMessage : 'waitUntil timed out';
|
|
124
|
-
|
|
125
|
-
// creating this error eagerly so it has the proper invocation stack
|
|
126
|
-
const waitUntilTimedOut = new Error(timeoutMessage);
|
|
127
|
-
return new Promise(function (resolve, reject) {
|
|
128
|
-
let time = 0;
|
|
129
|
-
|
|
130
|
-
// eslint-disable-next-line require-jsdoc
|
|
131
|
-
function scheduleCheck(timeoutsIndex) {
|
|
132
|
-
const knownTimeout = TIMEOUTS[timeoutsIndex];
|
|
133
|
-
const interval = knownTimeout === undefined ? MAX_TIMEOUT : knownTimeout;
|
|
134
|
-
futureTick(function () {
|
|
135
|
-
time += interval;
|
|
136
|
-
let value;
|
|
137
|
-
try {
|
|
138
|
-
value = callback();
|
|
139
|
-
} catch (error) {
|
|
140
|
-
reject(error);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (value) {
|
|
144
|
-
resolve(value);
|
|
145
|
-
} else if (time < timeout) {
|
|
146
|
-
scheduleCheck(timeoutsIndex + 1);
|
|
147
|
-
} else {
|
|
148
|
-
reject(waitUntilTimedOut);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}, interval);
|
|
152
|
-
}
|
|
153
|
-
scheduleCheck(0);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/* globals global */
|
|
158
|
-
|
|
159
|
-
var global$1 = (() => {
|
|
160
|
-
if (typeof self !== 'undefined') {
|
|
161
|
-
return self;
|
|
162
|
-
} else if (typeof window !== 'undefined') {
|
|
163
|
-
return window;
|
|
164
|
-
// @ts-ignore -- global does not exist
|
|
165
|
-
} else if (typeof global !== 'undefined') {
|
|
166
|
-
// @ts-ignore -- global does not exist
|
|
167
|
-
return global;
|
|
168
|
-
} else {
|
|
169
|
-
return Function('return this')();
|
|
170
|
-
}
|
|
171
|
-
})();
|
|
172
|
-
|
|
173
21
|
const DEPRECATIONS = new WeakMap();
|
|
174
22
|
|
|
175
23
|
/**
|
|
@@ -276,79 +124,25 @@ if (typeof URLSearchParams !== 'undefined') {
|
|
|
276
124
|
}
|
|
277
125
|
}
|
|
278
126
|
|
|
279
|
-
|
|
127
|
+
// @ts-ignore
|
|
280
128
|
|
|
281
129
|
/**
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
* @param {string} label A label to help identify the hook.
|
|
285
|
-
* @returns {string} The compound key for the helper.
|
|
286
|
-
*/
|
|
287
|
-
function getHelperKey(helperName, label) {
|
|
288
|
-
return `${helperName}:${label}`;
|
|
289
|
-
}
|
|
130
|
+
Checks if the currently running Ember version is greater than or equal to the
|
|
131
|
+
specified major and minor version numbers.
|
|
290
132
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
* the helper invocation.
|
|
301
|
-
* @param {Function} hook The hook function to run when the test helper is invoked.
|
|
302
|
-
* @returns {HookUnregister} An object containing an `unregister` function that unregisters
|
|
303
|
-
* the specific hook initially registered to the helper.
|
|
304
|
-
* @example
|
|
305
|
-
* <caption>
|
|
306
|
-
* Registering a hook for the `end` point of the `click` test helper invocation
|
|
307
|
-
* </caption>
|
|
308
|
-
*
|
|
309
|
-
* const hook = registerHook('click', 'end', () => {
|
|
310
|
-
* console.log('Running `click:end` test helper hook');
|
|
311
|
-
* });
|
|
312
|
-
*
|
|
313
|
-
* // Unregister the hook at some later point in time
|
|
314
|
-
* hook.unregister();
|
|
315
|
-
*/
|
|
316
|
-
function registerHook(helperName, label, hook) {
|
|
317
|
-
const helperKey = getHelperKey(helperName, label);
|
|
318
|
-
let hooksForHelper = registeredHooks.get(helperKey);
|
|
319
|
-
if (hooksForHelper === undefined) {
|
|
320
|
-
hooksForHelper = new Set();
|
|
321
|
-
registeredHooks.set(helperKey, hooksForHelper);
|
|
133
|
+
@private
|
|
134
|
+
@param {number} major the major version number to compare
|
|
135
|
+
@param {number} minor the minor version number to compare
|
|
136
|
+
@returns {boolean} true if the Ember version is >= MAJOR.MINOR specified, false otherwise
|
|
137
|
+
*/
|
|
138
|
+
function hasEmberVersion(major, minor) {
|
|
139
|
+
const numbers = VERSION.split('-')[0]?.split('.');
|
|
140
|
+
if (!numbers || !numbers[0] || !numbers[1]) {
|
|
141
|
+
throw new Error('`Ember.VERSION` is not set.');
|
|
322
142
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
hooksForHelper.delete(hook);
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Runs all hooks registered for a specific test helper.
|
|
333
|
-
*
|
|
334
|
-
* @param {string} helperName The name of the test helper in which to run the hook.
|
|
335
|
-
* Test helper names include `blur`, `click`, `doubleClick`, `fillIn`,
|
|
336
|
-
* `fireEvent`, `focus`, `render`, `scrollTo`, `select`, `tab`, `tap`, `triggerEvent`,
|
|
337
|
-
* `triggerKeyEvent`, `typeIn`, and `visit`.
|
|
338
|
-
* @param {string} label A label to help identify the hook. Built-in labels include `start`, `end`,
|
|
339
|
-
* and `targetFound`, the former designating either the start or end of
|
|
340
|
-
* the helper invocation.
|
|
341
|
-
* @param {unknown[]} args Any arguments originally passed to the test helper.
|
|
342
|
-
* @returns {Promise<void>} A promise representing the serial invocation of the hooks.
|
|
343
|
-
*/
|
|
344
|
-
function runHooks(helperName, label, ...args) {
|
|
345
|
-
const hooks = registeredHooks.get(getHelperKey(helperName, label)) || new Set();
|
|
346
|
-
const promises = [];
|
|
347
|
-
hooks.forEach(hook => {
|
|
348
|
-
const hookResult = hook(...args);
|
|
349
|
-
promises.push(hookResult);
|
|
350
|
-
});
|
|
351
|
-
return Promise.all(promises).then(() => {});
|
|
143
|
+
const actualMajor = parseInt(numbers[0], 10);
|
|
144
|
+
const actualMinor = parseInt(numbers[1], 10);
|
|
145
|
+
return actualMajor > major || actualMajor === major && actualMinor >= minor;
|
|
352
146
|
}
|
|
353
147
|
|
|
354
148
|
const debugInfoHelpers = new Set();
|
|
@@ -498,21 +292,229 @@ function isNotNullable(value) {
|
|
|
498
292
|
return value != null;
|
|
499
293
|
}
|
|
500
294
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
295
|
+
// NOTE: this is the same as what `EngineInstance`/`ApplicationInstance`
|
|
296
|
+
// implement, and is thus a superset of the `InternalOwner` contract from Ember
|
|
297
|
+
// itself.
|
|
298
|
+
// This is the same merging pattern Ember itself uses for `Engine` etc.: the
|
|
299
|
+
// interface reflects the mixins actually applied in the `extends` clause.
|
|
300
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
504
301
|
|
|
505
|
-
|
|
506
|
-
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
303
|
+
class Owner extends EmberObject.extend(RegistryProxyMixin, ContainerProxyMixin) {
|
|
304
|
+
_emberTestHelpersMockOwner = true;
|
|
507
305
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
306
|
+
/* eslint-disable valid-jsdoc */
|
|
307
|
+
/**
|
|
308
|
+
* Unregister a factory and its instance.
|
|
309
|
+
*
|
|
310
|
+
* Overrides `RegistryProxy#unregister` in order to clear any cached instances
|
|
311
|
+
* of the unregistered factory.
|
|
312
|
+
*
|
|
313
|
+
* @param {string} fullName Name of the factory to unregister.
|
|
314
|
+
*
|
|
315
|
+
* @see {@link https://github.com/emberjs/ember.js/pull/12680}
|
|
316
|
+
* @see {@link https://github.com/emberjs/ember.js/blob/v4.5.0-alpha.5/packages/%40ember/engine/instance.ts#L152-L167}
|
|
317
|
+
*/
|
|
318
|
+
/* eslint-enable valid-jsdoc */
|
|
319
|
+
unregister(fullName) {
|
|
320
|
+
// SAFETY: this is always present, but only the stable type definitions from
|
|
321
|
+
// Ember actually preserve it, since it is private API.
|
|
322
|
+
this['__container__'].reset(fullName);
|
|
323
|
+
|
|
324
|
+
// We overwrote this method from RegistryProxyMixin.
|
|
325
|
+
// SAFETY: this is always present, but only the stable type definitions from
|
|
326
|
+
// Ember actually preserve it, since it is private API.
|
|
327
|
+
this['__registry__'].unregister(fullName);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// eslint-disable-next-line require-jsdoc
|
|
332
|
+
function isElement(target) {
|
|
333
|
+
return target !== null && typeof target === 'object' && Reflect.get(target, 'nodeType') === Node.ELEMENT_NODE;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// eslint-disable-next-line require-jsdoc
|
|
337
|
+
function isWindow(target) {
|
|
338
|
+
return target instanceof Window;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// eslint-disable-next-line require-jsdoc
|
|
342
|
+
function isDocument(target) {
|
|
343
|
+
return target !== null && typeof target === 'object' && Reflect.get(target, 'nodeType') === Node.DOCUMENT_NODE;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// eslint-disable-next-line require-jsdoc
|
|
347
|
+
function isContentEditable(element) {
|
|
348
|
+
return 'isContentEditable' in element && element.isContentEditable;
|
|
349
|
+
}
|
|
350
|
+
const FORM_CONTROL_TAGS = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'];
|
|
351
|
+
/**
|
|
352
|
+
@private
|
|
353
|
+
@param {Element} element the element to check
|
|
354
|
+
@returns {boolean} `true` when the element is a form control, `false` otherwise
|
|
355
|
+
*/
|
|
356
|
+
function isFormControl(element) {
|
|
357
|
+
return !isWindow(element) && !isDocument(element) && FORM_CONTROL_TAGS.indexOf(element.tagName) > -1 && element.type !== 'hidden';
|
|
358
|
+
}
|
|
359
|
+
const futureTick = setTimeout;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
Returns whether the passed in string consists only of numeric characters.
|
|
363
|
+
|
|
364
|
+
@private
|
|
365
|
+
@param {string} n input string
|
|
366
|
+
@returns {boolean} whether the input string consists only of numeric characters
|
|
367
|
+
*/
|
|
368
|
+
function isNumeric(n) {
|
|
369
|
+
return !isNaN(parseFloat(n)) && isFinite(Number(n));
|
|
370
|
+
}
|
|
371
|
+
const TIMEOUTS = [0, 1, 2, 5, 7];
|
|
372
|
+
const MAX_TIMEOUT = 10;
|
|
373
|
+
/**
|
|
374
|
+
Wait for the provided callback to return a truthy value.
|
|
375
|
+
|
|
376
|
+
This does not leverage `settled()`, and as such can be used to manage async
|
|
377
|
+
while _not_ settled (e.g. "loading" or "pending" states).
|
|
378
|
+
|
|
379
|
+
@public
|
|
380
|
+
@param {Function} callback the callback to use for testing when waiting should stop
|
|
381
|
+
@param {Object} [options] options used to override defaults
|
|
382
|
+
@param {number} [options.timeout=1000] the maximum amount of time to wait
|
|
383
|
+
@param {string} [options.timeoutMessage='waitUntil timed out'] the message to use in the reject on timeout
|
|
384
|
+
@returns {Promise} resolves with the callback value when it returns a truthy value
|
|
385
|
+
|
|
386
|
+
@example
|
|
387
|
+
<caption>
|
|
388
|
+
Waiting until a selected element displays text:
|
|
389
|
+
</caption>
|
|
390
|
+
await waitUntil(function() {
|
|
391
|
+
return find('.my-selector').textContent.includes('something')
|
|
392
|
+
}, { timeout: 2000 })
|
|
393
|
+
*/
|
|
394
|
+
function waitUntil(callback, options = {}) {
|
|
395
|
+
const timeout = 'timeout' in options ? options.timeout : 1000;
|
|
396
|
+
const timeoutMessage = 'timeoutMessage' in options ? options.timeoutMessage : 'waitUntil timed out';
|
|
397
|
+
|
|
398
|
+
// creating this error eagerly so it has the proper invocation stack
|
|
399
|
+
const waitUntilTimedOut = new Error(timeoutMessage);
|
|
400
|
+
return new Promise(function (resolve, reject) {
|
|
401
|
+
let time = 0;
|
|
402
|
+
|
|
403
|
+
// eslint-disable-next-line require-jsdoc
|
|
404
|
+
function scheduleCheck(timeoutsIndex) {
|
|
405
|
+
const knownTimeout = TIMEOUTS[timeoutsIndex];
|
|
406
|
+
const interval = knownTimeout === undefined ? MAX_TIMEOUT : knownTimeout;
|
|
407
|
+
futureTick(function () {
|
|
408
|
+
time += interval;
|
|
409
|
+
let value;
|
|
410
|
+
try {
|
|
411
|
+
value = callback();
|
|
412
|
+
} catch (error) {
|
|
413
|
+
reject(error);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (value) {
|
|
417
|
+
resolve(value);
|
|
418
|
+
} else if (time < timeout) {
|
|
419
|
+
scheduleCheck(timeoutsIndex + 1);
|
|
420
|
+
} else {
|
|
421
|
+
reject(waitUntilTimedOut);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
}, interval);
|
|
425
|
+
}
|
|
426
|
+
scheduleCheck(0);
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
const registeredHooks = new Map();
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* @private
|
|
433
|
+
* @param {string} helperName The name of the test helper in which to run the hook.
|
|
434
|
+
* @param {string} label A label to help identify the hook.
|
|
435
|
+
* @returns {string} The compound key for the helper.
|
|
436
|
+
*/
|
|
437
|
+
function getHelperKey(helperName, label) {
|
|
438
|
+
return `${helperName}:${label}`;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Registers a function to be run during the invocation of a test helper.
|
|
443
|
+
*
|
|
444
|
+
* @param {string} helperName The name of the test helper in which to run the hook.
|
|
445
|
+
* Test helper names include `blur`, `click`, `doubleClick`, `fillIn`,
|
|
446
|
+
* `fireEvent`, `focus`, `render`, `scrollTo`, `select`, `tab`, `tap`, `triggerEvent`,
|
|
447
|
+
* `triggerKeyEvent`, `typeIn`, and `visit`.
|
|
448
|
+
* @param {string} label A label to help identify the hook. Built-in labels include `start`, `end`,
|
|
449
|
+
* and `targetFound`, the former designating either the start or end of
|
|
450
|
+
* the helper invocation.
|
|
451
|
+
* @param {Function} hook The hook function to run when the test helper is invoked.
|
|
452
|
+
* @returns {HookUnregister} An object containing an `unregister` function that unregisters
|
|
453
|
+
* the specific hook initially registered to the helper.
|
|
454
|
+
* @example
|
|
455
|
+
* <caption>
|
|
456
|
+
* Registering a hook for the `end` point of the `click` test helper invocation
|
|
457
|
+
* </caption>
|
|
458
|
+
*
|
|
459
|
+
* const hook = registerHook('click', 'end', () => {
|
|
460
|
+
* console.log('Running `click:end` test helper hook');
|
|
461
|
+
* });
|
|
462
|
+
*
|
|
463
|
+
* // Unregister the hook at some later point in time
|
|
464
|
+
* hook.unregister();
|
|
465
|
+
*/
|
|
466
|
+
function registerHook(helperName, label, hook) {
|
|
467
|
+
const helperKey = getHelperKey(helperName, label);
|
|
468
|
+
let hooksForHelper = registeredHooks.get(helperKey);
|
|
469
|
+
if (hooksForHelper === undefined) {
|
|
470
|
+
hooksForHelper = new Set();
|
|
471
|
+
registeredHooks.set(helperKey, hooksForHelper);
|
|
472
|
+
}
|
|
473
|
+
hooksForHelper.add(hook);
|
|
474
|
+
return {
|
|
475
|
+
unregister() {
|
|
476
|
+
hooksForHelper.delete(hook);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Runs all hooks registered for a specific test helper.
|
|
483
|
+
*
|
|
484
|
+
* @param {string} helperName The name of the test helper in which to run the hook.
|
|
485
|
+
* Test helper names include `blur`, `click`, `doubleClick`, `fillIn`,
|
|
486
|
+
* `fireEvent`, `focus`, `render`, `scrollTo`, `select`, `tab`, `tap`, `triggerEvent`,
|
|
487
|
+
* `triggerKeyEvent`, `typeIn`, and `visit`.
|
|
488
|
+
* @param {string} label A label to help identify the hook. Built-in labels include `start`, `end`,
|
|
489
|
+
* and `targetFound`, the former designating either the start or end of
|
|
490
|
+
* the helper invocation.
|
|
491
|
+
* @param {unknown[]} args Any arguments originally passed to the test helper.
|
|
492
|
+
* @returns {Promise<void>} A promise representing the serial invocation of the hooks.
|
|
493
|
+
*/
|
|
494
|
+
function runHooks(helperName, label, ...args) {
|
|
495
|
+
const hooks = registeredHooks.get(getHelperKey(helperName, label)) || new Set();
|
|
496
|
+
const promises = [];
|
|
497
|
+
hooks.forEach(hook => {
|
|
498
|
+
const hookResult = hook(...args);
|
|
499
|
+
promises.push(hookResult);
|
|
500
|
+
});
|
|
501
|
+
return Promise.all(promises).then(() => {});
|
|
502
|
+
}
|
|
503
|
+
const CAN_USE_ROUTER_EVENTS = hasEmberVersion(3, 6);
|
|
504
|
+
let routerTransitionsPending = null;
|
|
505
|
+
const ROUTER = new WeakMap();
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
Determines if we have any pending router transitions (used to determine `settled` state)
|
|
509
|
+
|
|
510
|
+
@public
|
|
511
|
+
@returns {(boolean|null)} if there are pending transitions
|
|
512
|
+
*/
|
|
513
|
+
function hasPendingTransitions() {
|
|
514
|
+
if (CAN_USE_ROUTER_EVENTS) {
|
|
515
|
+
return routerTransitionsPending;
|
|
516
|
+
}
|
|
517
|
+
const context = getContext();
|
|
516
518
|
|
|
517
519
|
// there is no current context, we cannot check
|
|
518
520
|
if (context === undefined) {
|
|
@@ -634,6 +636,22 @@ function settled() {
|
|
|
634
636
|
}).then(() => {});
|
|
635
637
|
}
|
|
636
638
|
|
|
639
|
+
/* globals global */
|
|
640
|
+
|
|
641
|
+
var global$1 = (() => {
|
|
642
|
+
if (typeof self !== 'undefined') {
|
|
643
|
+
return self;
|
|
644
|
+
} else if (typeof window !== 'undefined') {
|
|
645
|
+
return window;
|
|
646
|
+
// @ts-ignore -- global does not exist
|
|
647
|
+
} else if (typeof global !== 'undefined') {
|
|
648
|
+
// @ts-ignore -- global does not exist
|
|
649
|
+
return global;
|
|
650
|
+
} else {
|
|
651
|
+
return Function('return this')();
|
|
652
|
+
}
|
|
653
|
+
})();
|
|
654
|
+
|
|
637
655
|
// @ts-ignore: this is private API. This import will work Ember 5.1+ since it
|
|
638
656
|
// "provides" this public API, but does not for earlier versions. As a result,
|
|
639
657
|
// this type will be `any`.
|
|
@@ -708,67 +726,6 @@ function getContext() {
|
|
|
708
726
|
return globalObject.__test_context__;
|
|
709
727
|
}
|
|
710
728
|
|
|
711
|
-
/**
|
|
712
|
-
Get the root element of the application under test (usually `#ember-testing`)
|
|
713
|
-
|
|
714
|
-
@public
|
|
715
|
-
@returns {Element} the root element
|
|
716
|
-
|
|
717
|
-
@example
|
|
718
|
-
<caption>
|
|
719
|
-
Getting the root element of the application and checking that it is equal
|
|
720
|
-
to the element with id 'ember-testing'.
|
|
721
|
-
</caption>
|
|
722
|
-
assert.equal(getRootElement(), document.querySelector('#ember-testing'));
|
|
723
|
-
*/
|
|
724
|
-
function getRootElement() {
|
|
725
|
-
const context = getContext();
|
|
726
|
-
if (!context || !isTestContext(context) || !context.owner) {
|
|
727
|
-
throw new Error('Must setup rendering context before attempting to interact with elements.');
|
|
728
|
-
}
|
|
729
|
-
const owner = context.owner;
|
|
730
|
-
let rootElement;
|
|
731
|
-
// When the host app uses `setApplication` (instead of `setResolver`) the owner has
|
|
732
|
-
// a `rootElement` set on it with the element or id to be used
|
|
733
|
-
if (owner && owner._emberTestHelpersMockOwner === undefined) {
|
|
734
|
-
rootElement = owner.rootElement;
|
|
735
|
-
} else {
|
|
736
|
-
rootElement = '#ember-testing';
|
|
737
|
-
}
|
|
738
|
-
if (rootElement instanceof Window) {
|
|
739
|
-
rootElement = rootElement.document;
|
|
740
|
-
}
|
|
741
|
-
if (isElement(rootElement) || isDocument(rootElement)) {
|
|
742
|
-
return rootElement;
|
|
743
|
-
} else if (typeof rootElement === 'string') {
|
|
744
|
-
const _rootElement = document.querySelector(rootElement);
|
|
745
|
-
if (_rootElement) {
|
|
746
|
-
return _rootElement;
|
|
747
|
-
}
|
|
748
|
-
throw new Error(`Application.rootElement (${rootElement}) not found`);
|
|
749
|
-
} else {
|
|
750
|
-
throw new Error('Application.rootElement must be an element or a selector string');
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
precompileTemplate("{{outlet}}", {
|
|
755
|
-
strictMode: false
|
|
756
|
-
});
|
|
757
|
-
precompileTemplate("", {
|
|
758
|
-
strictMode: false
|
|
759
|
-
});
|
|
760
|
-
precompileTemplate("<this.ProvidedComponent />", {
|
|
761
|
-
strictMode: false
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
if (macroCondition(dependencySatisfies('ember-source', '>=4.5.0-beta.1'))) {
|
|
765
|
-
//@ts-ignore
|
|
766
|
-
importSync('@ember/renderer').renderSettled;
|
|
767
|
-
} else {
|
|
768
|
-
//@ts-ignore
|
|
769
|
-
importSync('@ember/-internals/glimmer').renderSettled;
|
|
770
|
-
}
|
|
771
|
-
|
|
772
729
|
const IS_DESCRIPTOR = '__dom_element_descriptor_is_descriptor__';
|
|
773
730
|
|
|
774
731
|
/**
|
|
@@ -806,28 +763,164 @@ function lookupDescriptorData(descriptor) {
|
|
|
806
763
|
}
|
|
807
764
|
|
|
808
765
|
/**
|
|
809
|
-
* Given a descriptor or descriptor data, get the single/first element it would
|
|
810
|
-
* match.
|
|
811
|
-
*
|
|
812
|
-
* This is analogous to `querySelector()`, and is meant to be used by DOM helper
|
|
813
|
-
* libraries to resolve the targets of single-element operations.
|
|
766
|
+
* Given a descriptor or descriptor data, get the single/first element it would
|
|
767
|
+
* match.
|
|
768
|
+
*
|
|
769
|
+
* This is analogous to `querySelector()`, and is meant to be used by DOM helper
|
|
770
|
+
* libraries to resolve the targets of single-element operations.
|
|
771
|
+
*
|
|
772
|
+
* @param target the descriptor or descriptor data
|
|
773
|
+
* @returns the resolved DOM element, or null if no element matched
|
|
774
|
+
*/
|
|
775
|
+
function resolveDOMElement(target) {
|
|
776
|
+
let data = isDescriptor(target) ? lookupDescriptorData(target) : target;
|
|
777
|
+
if (!data) {
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
if (data.element !== undefined) {
|
|
781
|
+
return data.element;
|
|
782
|
+
} else {
|
|
783
|
+
for (let element of data.elements || []) {
|
|
784
|
+
return element;
|
|
785
|
+
}
|
|
786
|
+
return null;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Logs a debug message to the console if the `testHelperLogging` query
|
|
792
|
+
* parameter is set.
|
|
793
|
+
*
|
|
794
|
+
* @private
|
|
795
|
+
* @param {string} helperName Name of the helper
|
|
796
|
+
* @param {string|Element} target The target element or selector
|
|
797
|
+
*/
|
|
798
|
+
function log(helperName, target, ...args) {
|
|
799
|
+
if (loggingEnabled()) {
|
|
800
|
+
// eslint-disable-next-line no-console
|
|
801
|
+
console.log(`${helperName}(${[elementToString(target), ...args.filter(Boolean)].join(', ')})`);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Returns whether the test helper logging is enabled or not via the
|
|
807
|
+
* `testHelperLogging` query parameter.
|
|
808
|
+
*
|
|
809
|
+
* @private
|
|
810
|
+
* @returns {boolean} true if enabled
|
|
811
|
+
*/
|
|
812
|
+
function loggingEnabled() {
|
|
813
|
+
return typeof location !== 'undefined' && location.search.indexOf('testHelperLogging') !== -1;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* This generates a human-readable description to a DOM element.
|
|
818
|
+
*
|
|
819
|
+
* @private
|
|
820
|
+
* @param {*} el The element that should be described
|
|
821
|
+
* @returns {string} A human-readable description
|
|
822
|
+
*/
|
|
823
|
+
function elementToString(el) {
|
|
824
|
+
let desc;
|
|
825
|
+
if (el instanceof NodeList) {
|
|
826
|
+
if (el.length === 0) {
|
|
827
|
+
return 'empty NodeList';
|
|
828
|
+
}
|
|
829
|
+
desc = Array.prototype.slice.call(el, 0, 5).map(elementToString).join(', ');
|
|
830
|
+
return el.length > 5 ? `${desc}... (+${el.length - 5} more)` : desc;
|
|
831
|
+
}
|
|
832
|
+
if (!(el instanceof HTMLElement || el instanceof SVGElement)) {
|
|
833
|
+
return String(el);
|
|
834
|
+
}
|
|
835
|
+
desc = el.tagName.toLowerCase();
|
|
836
|
+
if (el.id) {
|
|
837
|
+
desc += `#${el.id}`;
|
|
838
|
+
}
|
|
839
|
+
if (el.className && !(el.className instanceof SVGAnimatedString)) {
|
|
840
|
+
desc += `.${String(el.className).replace(/\s+/g, '.')}`;
|
|
841
|
+
}
|
|
842
|
+
Array.prototype.forEach.call(el.attributes, function (attr) {
|
|
843
|
+
if (attr.name !== 'class' && attr.name !== 'id') {
|
|
844
|
+
desc += `[${attr.name}${attr.value ? `="${attr.value}"]` : ']'}`;
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
return desc;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
Get the root element of the application under test (usually `#ember-testing`)
|
|
852
|
+
|
|
853
|
+
@public
|
|
854
|
+
@returns {Element} the root element
|
|
855
|
+
|
|
856
|
+
@example
|
|
857
|
+
<caption>
|
|
858
|
+
Getting the root element of the application and checking that it is equal
|
|
859
|
+
to the element with id 'ember-testing'.
|
|
860
|
+
</caption>
|
|
861
|
+
assert.equal(getRootElement(), document.querySelector('#ember-testing'));
|
|
862
|
+
*/
|
|
863
|
+
function getRootElement() {
|
|
864
|
+
const context = getContext();
|
|
865
|
+
if (!context || !isTestContext(context) || !context.owner) {
|
|
866
|
+
throw new Error('Must setup rendering context before attempting to interact with elements.');
|
|
867
|
+
}
|
|
868
|
+
const owner = context.owner;
|
|
869
|
+
let rootElement;
|
|
870
|
+
// When the host app uses `setApplication` (instead of `setResolver`) the owner has
|
|
871
|
+
// a `rootElement` set on it with the element or id to be used
|
|
872
|
+
if (owner && owner._emberTestHelpersMockOwner === undefined) {
|
|
873
|
+
rootElement = owner.rootElement;
|
|
874
|
+
} else {
|
|
875
|
+
rootElement = '#ember-testing';
|
|
876
|
+
}
|
|
877
|
+
if (rootElement instanceof Window) {
|
|
878
|
+
rootElement = rootElement.document;
|
|
879
|
+
}
|
|
880
|
+
if (isElement(rootElement) || isDocument(rootElement)) {
|
|
881
|
+
return rootElement;
|
|
882
|
+
} else if (typeof rootElement === 'string') {
|
|
883
|
+
const _rootElement = document.querySelector(rootElement);
|
|
884
|
+
if (_rootElement) {
|
|
885
|
+
return _rootElement;
|
|
886
|
+
}
|
|
887
|
+
throw new Error(`Application.rootElement (${rootElement}) not found`);
|
|
888
|
+
} else {
|
|
889
|
+
throw new Error('Application.rootElement must be an element or a selector string');
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* while renderComponent landed in ember-source @ 6.8.0-alpha.1,
|
|
895
|
+
* it was not fully usable (in serious) until 6.12.0-alpha.4
|
|
896
|
+
* when https://github.com/emberjs/ember.js/pull/20996 was merged.
|
|
814
897
|
*
|
|
815
|
-
*
|
|
816
|
-
*
|
|
898
|
+
* ... but even then, we still needed a debugRenderTree fix,
|
|
899
|
+
* which didn't land until 6.12.1.
|
|
900
|
+
* https://github.com/emberjs/ember.js/pull/21623
|
|
817
901
|
*/
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
902
|
+
if (macroCondition(appEmberSatisfies('>=6.12.1'))) {
|
|
903
|
+
importSync('@ember/renderer').renderComponent;
|
|
904
|
+
}
|
|
905
|
+
precompileTemplate("{{outlet}}", {
|
|
906
|
+
strictMode: false
|
|
907
|
+
});
|
|
908
|
+
precompileTemplate("", {
|
|
909
|
+
strictMode: false
|
|
910
|
+
});
|
|
911
|
+
precompileTemplate("<this.ProvidedComponent />", {
|
|
912
|
+
strictMode: false
|
|
913
|
+
});
|
|
914
|
+
capabilities('3.13', {
|
|
915
|
+
destructor: false,
|
|
916
|
+
asyncLifecycleCallbacks: false
|
|
917
|
+
});
|
|
918
|
+
if (macroCondition(dependencySatisfies('ember-source', '>=4.5.0-beta.1'))) {
|
|
919
|
+
//@ts-ignore
|
|
920
|
+
importSync('@ember/renderer').renderSettled;
|
|
921
|
+
} else {
|
|
922
|
+
//@ts-ignore
|
|
923
|
+
importSync('@ember/-internals/glimmer').renderSettled;
|
|
831
924
|
}
|
|
832
925
|
|
|
833
926
|
/**
|
|
@@ -875,67 +968,6 @@ function getWindowOrElement(target) {
|
|
|
875
968
|
function tuple(...args) {
|
|
876
969
|
return args;
|
|
877
970
|
}
|
|
878
|
-
|
|
879
|
-
/**
|
|
880
|
-
* Logs a debug message to the console if the `testHelperLogging` query
|
|
881
|
-
* parameter is set.
|
|
882
|
-
*
|
|
883
|
-
* @private
|
|
884
|
-
* @param {string} helperName Name of the helper
|
|
885
|
-
* @param {string|Element} target The target element or selector
|
|
886
|
-
*/
|
|
887
|
-
function log(helperName, target, ...args) {
|
|
888
|
-
if (loggingEnabled()) {
|
|
889
|
-
// eslint-disable-next-line no-console
|
|
890
|
-
console.log(`${helperName}(${[elementToString(target), ...args.filter(Boolean)].join(', ')})`);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
/**
|
|
895
|
-
* Returns whether the test helper logging is enabled or not via the
|
|
896
|
-
* `testHelperLogging` query parameter.
|
|
897
|
-
*
|
|
898
|
-
* @private
|
|
899
|
-
* @returns {boolean} true if enabled
|
|
900
|
-
*/
|
|
901
|
-
function loggingEnabled() {
|
|
902
|
-
return typeof location !== 'undefined' && location.search.indexOf('testHelperLogging') !== -1;
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* This generates a human-readable description to a DOM element.
|
|
907
|
-
*
|
|
908
|
-
* @private
|
|
909
|
-
* @param {*} el The element that should be described
|
|
910
|
-
* @returns {string} A human-readable description
|
|
911
|
-
*/
|
|
912
|
-
function elementToString(el) {
|
|
913
|
-
let desc;
|
|
914
|
-
if (el instanceof NodeList) {
|
|
915
|
-
if (el.length === 0) {
|
|
916
|
-
return 'empty NodeList';
|
|
917
|
-
}
|
|
918
|
-
desc = Array.prototype.slice.call(el, 0, 5).map(elementToString).join(', ');
|
|
919
|
-
return el.length > 5 ? `${desc}... (+${el.length - 5} more)` : desc;
|
|
920
|
-
}
|
|
921
|
-
if (!(el instanceof HTMLElement || el instanceof SVGElement)) {
|
|
922
|
-
return String(el);
|
|
923
|
-
}
|
|
924
|
-
desc = el.tagName.toLowerCase();
|
|
925
|
-
if (el.id) {
|
|
926
|
-
desc += `#${el.id}`;
|
|
927
|
-
}
|
|
928
|
-
if (el.className && !(el.className instanceof SVGAnimatedString)) {
|
|
929
|
-
desc += `.${String(el.className).replace(/\s+/g, '.')}`;
|
|
930
|
-
}
|
|
931
|
-
Array.prototype.forEach.call(el.attributes, function (attr) {
|
|
932
|
-
if (attr.name !== 'class' && attr.name !== 'id') {
|
|
933
|
-
desc += `[${attr.name}${attr.value ? `="${attr.value}"]` : ']'}`;
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
return desc;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
971
|
registerHook('fireEvent', 'start', target => {
|
|
940
972
|
log('fireEvent', target);
|
|
941
973
|
});
|
|
@@ -1160,6 +1192,35 @@ function buildFileEvent(type, element, options = {}) {
|
|
|
1160
1192
|
return event;
|
|
1161
1193
|
}
|
|
1162
1194
|
|
|
1195
|
+
// For reference:
|
|
1196
|
+
// https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
|
1197
|
+
const FOCUSABLE_TAGS = ['A', 'SUMMARY'];
|
|
1198
|
+
// eslint-disable-next-line require-jsdoc
|
|
1199
|
+
function isFocusableElement(element) {
|
|
1200
|
+
return FOCUSABLE_TAGS.indexOf(element.tagName) > -1;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
@private
|
|
1205
|
+
@param {Element} element the element to check
|
|
1206
|
+
@returns {boolean} `true` when the element is focusable, `false` otherwise
|
|
1207
|
+
*/
|
|
1208
|
+
function isFocusable(element) {
|
|
1209
|
+
if (isWindow(element)) {
|
|
1210
|
+
return false;
|
|
1211
|
+
}
|
|
1212
|
+
if (isDocument(element)) {
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
if (isFormControl(element)) {
|
|
1216
|
+
return !element.disabled;
|
|
1217
|
+
}
|
|
1218
|
+
if (isContentEditable(element) || isFocusableElement(element)) {
|
|
1219
|
+
return true;
|
|
1220
|
+
}
|
|
1221
|
+
return element.hasAttribute('tabindex');
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1163
1224
|
/**
|
|
1164
1225
|
Used internally by the DOM interaction helpers to get a description of a
|
|
1165
1226
|
target for debug/error messaging.
|
|
@@ -1176,31 +1237,168 @@ function getDescription(target) {
|
|
|
1176
1237
|
return `${target}`;
|
|
1177
1238
|
}
|
|
1178
1239
|
}
|
|
1179
|
-
|
|
1180
1240
|
registerHook('blur', 'start', target => {
|
|
1181
1241
|
log('blur', target);
|
|
1182
1242
|
});
|
|
1183
1243
|
|
|
1244
|
+
/**
|
|
1245
|
+
@private
|
|
1246
|
+
@param {Element} element the element to trigger events on
|
|
1247
|
+
@param {Element} relatedTarget the element that is focused after blur
|
|
1248
|
+
@return {Promise<Event | void>} resolves when settled
|
|
1249
|
+
*/
|
|
1250
|
+
function __blur__(element, relatedTarget = null) {
|
|
1251
|
+
if (!isFocusable(element)) {
|
|
1252
|
+
throw new Error(`${element} is not focusable`);
|
|
1253
|
+
}
|
|
1254
|
+
const browserIsNotFocused = document.hasFocus && !document.hasFocus();
|
|
1255
|
+
const needsCustomEventOptions = relatedTarget !== null;
|
|
1256
|
+
if (!needsCustomEventOptions) {
|
|
1257
|
+
// makes `document.activeElement` be `body`.
|
|
1258
|
+
// If the browser is focused, it also fires a blur event
|
|
1259
|
+
element.blur();
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// Chrome/Firefox does not trigger the `blur` event if the window
|
|
1263
|
+
// does not have focus. If the document does not have focus then
|
|
1264
|
+
// fire `blur` event via native event.
|
|
1265
|
+
const options = {
|
|
1266
|
+
relatedTarget
|
|
1267
|
+
};
|
|
1268
|
+
return browserIsNotFocused || needsCustomEventOptions ? Promise.resolve().then(() => fireEvent(element, 'blur', {
|
|
1269
|
+
bubbles: false,
|
|
1270
|
+
...options
|
|
1271
|
+
})).then(() => fireEvent(element, 'focusout', options)) : Promise.resolve();
|
|
1272
|
+
}
|
|
1184
1273
|
registerHook('focus', 'start', target => {
|
|
1185
1274
|
log('focus', target);
|
|
1186
1275
|
});
|
|
1276
|
+
/**
|
|
1277
|
+
Get the closest focusable ancestor of a given element (or the element itself
|
|
1278
|
+
if it's focusable)
|
|
1279
|
+
|
|
1280
|
+
@private
|
|
1281
|
+
@param {Element} element the element to trigger events on
|
|
1282
|
+
@returns {HTMLElement|SVGElement|null} the focusable element/ancestor or null
|
|
1283
|
+
if there is none
|
|
1284
|
+
*/
|
|
1285
|
+
function getClosestFocusable(element) {
|
|
1286
|
+
if (isDocument(element)) {
|
|
1287
|
+
return null;
|
|
1288
|
+
}
|
|
1289
|
+
let maybeFocusable = element;
|
|
1290
|
+
while (maybeFocusable && !isFocusable(maybeFocusable)) {
|
|
1291
|
+
maybeFocusable = maybeFocusable.parentElement;
|
|
1292
|
+
}
|
|
1293
|
+
return maybeFocusable;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
@private
|
|
1298
|
+
@param {Element} element the element to trigger events on
|
|
1299
|
+
@return {Promise<FocusRecord | Event | void>} resolves when settled
|
|
1300
|
+
*/
|
|
1301
|
+
function __focus__(element) {
|
|
1302
|
+
return Promise.resolve().then(() => {
|
|
1303
|
+
const focusTarget = getClosestFocusable(element);
|
|
1304
|
+
const previousFocusedElement = document.activeElement && document.activeElement !== focusTarget && isFocusable(document.activeElement) ? document.activeElement : null;
|
|
1305
|
+
|
|
1306
|
+
// fire __blur__ manually with the null relatedTarget when the target is not focusable
|
|
1307
|
+
// and there was a previously focused element
|
|
1308
|
+
return !focusTarget && previousFocusedElement ? __blur__(previousFocusedElement, null).then(() => Promise.resolve({
|
|
1309
|
+
focusTarget,
|
|
1310
|
+
previousFocusedElement
|
|
1311
|
+
})) : Promise.resolve({
|
|
1312
|
+
focusTarget,
|
|
1313
|
+
previousFocusedElement
|
|
1314
|
+
});
|
|
1315
|
+
}).then(({
|
|
1316
|
+
focusTarget,
|
|
1317
|
+
previousFocusedElement
|
|
1318
|
+
}) => {
|
|
1319
|
+
if (!focusTarget) {
|
|
1320
|
+
throw new Error('There was a previously focused element');
|
|
1321
|
+
}
|
|
1322
|
+
const browserIsNotFocused = !document?.hasFocus();
|
|
1323
|
+
|
|
1324
|
+
// fire __blur__ manually with the correct relatedTarget when the browser is not
|
|
1325
|
+
// already in focus and there was a previously focused element
|
|
1326
|
+
return previousFocusedElement && browserIsNotFocused ? __blur__(previousFocusedElement, focusTarget).then(() => Promise.resolve({
|
|
1327
|
+
focusTarget
|
|
1328
|
+
})) : Promise.resolve({
|
|
1329
|
+
focusTarget
|
|
1330
|
+
});
|
|
1331
|
+
}).then(({
|
|
1332
|
+
focusTarget
|
|
1333
|
+
}) => {
|
|
1334
|
+
// makes `document.activeElement` be `element`. If the browser is focused, it also fires a focus event
|
|
1335
|
+
focusTarget.focus();
|
|
1336
|
+
|
|
1337
|
+
// Firefox does not trigger the `focusin` event if the window
|
|
1338
|
+
// does not have focus. If the document does not have focus then
|
|
1339
|
+
// fire `focusin` event as well.
|
|
1340
|
+
const browserIsFocused = document?.hasFocus();
|
|
1341
|
+
return browserIsFocused ? Promise.resolve() :
|
|
1342
|
+
// if the browser is not focused the previous `el.focus()` didn't fire an event, so we simulate it
|
|
1343
|
+
Promise.resolve().then(() => fireEvent(focusTarget, 'focus', {
|
|
1344
|
+
bubbles: false
|
|
1345
|
+
})).then(() => fireEvent(focusTarget, 'focusin')).then(() => settled());
|
|
1346
|
+
}).catch(() => {});
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
Focus the specified target.
|
|
1351
|
+
|
|
1352
|
+
Sends a number of events intending to simulate a "real" user focusing an
|
|
1353
|
+
element.
|
|
1354
|
+
|
|
1355
|
+
The following events are triggered (in order):
|
|
1356
|
+
|
|
1357
|
+
- `focus`
|
|
1358
|
+
- `focusin`
|
|
1359
|
+
|
|
1360
|
+
The exact listing of events that are triggered may change over time as needed
|
|
1361
|
+
to continue to emulate how actual browsers handle focusing a given element.
|
|
1362
|
+
|
|
1363
|
+
@public
|
|
1364
|
+
@param {string|Element|IDOMElementDescriptor} target the element, selector, or descriptor to focus
|
|
1365
|
+
@return {Promise<void>} resolves when the application is settled
|
|
1366
|
+
|
|
1367
|
+
@example
|
|
1368
|
+
<caption>
|
|
1369
|
+
Emulating focusing an input using `focus`
|
|
1370
|
+
</caption>
|
|
1187
1371
|
|
|
1372
|
+
focus('input');
|
|
1373
|
+
*/
|
|
1374
|
+
function focus(target) {
|
|
1375
|
+
return Promise.resolve().then(() => runHooks('focus', 'start', target)).then(() => {
|
|
1376
|
+
if (!target) {
|
|
1377
|
+
throw new Error('Must pass an element, selector, or descriptor to `focus`.');
|
|
1378
|
+
}
|
|
1379
|
+
const element = getElement(target);
|
|
1380
|
+
if (!element) {
|
|
1381
|
+
const description = getDescription(target);
|
|
1382
|
+
throw new Error(`Element not found when calling \`focus('${description}')\`.`);
|
|
1383
|
+
}
|
|
1384
|
+
if (!isFocusable(element)) {
|
|
1385
|
+
throw new Error(`${element} is not focusable`);
|
|
1386
|
+
}
|
|
1387
|
+
return __focus__(element).then(settled);
|
|
1388
|
+
}).then(() => runHooks('focus', 'end', target));
|
|
1389
|
+
}
|
|
1188
1390
|
registerHook('click', 'start', target => {
|
|
1189
1391
|
log('click', target);
|
|
1190
1392
|
});
|
|
1191
|
-
|
|
1192
1393
|
registerHook('doubleClick', 'start', target => {
|
|
1193
1394
|
log('doubleClick', target);
|
|
1194
1395
|
});
|
|
1195
|
-
|
|
1196
1396
|
registerHook('tab', 'start', target => {
|
|
1197
1397
|
log('tab', target);
|
|
1198
1398
|
});
|
|
1199
|
-
|
|
1200
1399
|
registerHook('tap', 'start', target => {
|
|
1201
1400
|
log('tap', target);
|
|
1202
1401
|
});
|
|
1203
|
-
|
|
1204
1402
|
registerHook('triggerEvent', 'start', (target, eventType) => {
|
|
1205
1403
|
log('triggerEvent', target, eventType);
|
|
1206
1404
|
});
|
|
@@ -1269,15 +1467,222 @@ function triggerEvent(target, eventType, options, force = false) {
|
|
|
1269
1467
|
return runHooks('triggerEvent', 'end', target, eventType, options);
|
|
1270
1468
|
});
|
|
1271
1469
|
}
|
|
1272
|
-
|
|
1273
1470
|
registerHook('triggerKeyEvent', 'start', (target, eventType, key) => {
|
|
1274
1471
|
log('triggerKeyEvent', target, eventType, key);
|
|
1275
1472
|
});
|
|
1473
|
+
const DEFAULT_MODIFIERS = Object.freeze({
|
|
1474
|
+
ctrlKey: false,
|
|
1475
|
+
altKey: false,
|
|
1476
|
+
shiftKey: false,
|
|
1477
|
+
metaKey: false
|
|
1478
|
+
});
|
|
1479
|
+
|
|
1480
|
+
// This is not a comprehensive list, but it is better than nothing.
|
|
1481
|
+
const keyFromKeyCode = {
|
|
1482
|
+
8: 'Backspace',
|
|
1483
|
+
9: 'Tab',
|
|
1484
|
+
13: 'Enter',
|
|
1485
|
+
16: 'Shift',
|
|
1486
|
+
17: 'Control',
|
|
1487
|
+
18: 'Alt',
|
|
1488
|
+
20: 'CapsLock',
|
|
1489
|
+
27: 'Escape',
|
|
1490
|
+
32: ' ',
|
|
1491
|
+
37: 'ArrowLeft',
|
|
1492
|
+
38: 'ArrowUp',
|
|
1493
|
+
39: 'ArrowRight',
|
|
1494
|
+
40: 'ArrowDown',
|
|
1495
|
+
48: '0',
|
|
1496
|
+
49: '1',
|
|
1497
|
+
50: '2',
|
|
1498
|
+
51: '3',
|
|
1499
|
+
52: '4',
|
|
1500
|
+
53: '5',
|
|
1501
|
+
54: '6',
|
|
1502
|
+
55: '7',
|
|
1503
|
+
56: '8',
|
|
1504
|
+
57: '9',
|
|
1505
|
+
65: 'a',
|
|
1506
|
+
66: 'b',
|
|
1507
|
+
67: 'c',
|
|
1508
|
+
68: 'd',
|
|
1509
|
+
69: 'e',
|
|
1510
|
+
70: 'f',
|
|
1511
|
+
71: 'g',
|
|
1512
|
+
72: 'h',
|
|
1513
|
+
73: 'i',
|
|
1514
|
+
74: 'j',
|
|
1515
|
+
75: 'k',
|
|
1516
|
+
76: 'l',
|
|
1517
|
+
77: 'm',
|
|
1518
|
+
78: 'n',
|
|
1519
|
+
79: 'o',
|
|
1520
|
+
80: 'p',
|
|
1521
|
+
81: 'q',
|
|
1522
|
+
82: 'r',
|
|
1523
|
+
83: 's',
|
|
1524
|
+
84: 't',
|
|
1525
|
+
85: 'u',
|
|
1526
|
+
86: 'v',
|
|
1527
|
+
87: 'w',
|
|
1528
|
+
88: 'x',
|
|
1529
|
+
89: 'y',
|
|
1530
|
+
90: 'z',
|
|
1531
|
+
91: 'Meta',
|
|
1532
|
+
93: 'Meta',
|
|
1533
|
+
// There is two keys that map to meta,
|
|
1534
|
+
186: ';',
|
|
1535
|
+
187: '=',
|
|
1536
|
+
188: ',',
|
|
1537
|
+
189: '-',
|
|
1538
|
+
190: '.',
|
|
1539
|
+
191: '/',
|
|
1540
|
+
219: '[',
|
|
1541
|
+
220: '\\',
|
|
1542
|
+
221: ']',
|
|
1543
|
+
222: "'"
|
|
1544
|
+
};
|
|
1545
|
+
const keyFromKeyCodeWithShift = {
|
|
1546
|
+
48: ')',
|
|
1547
|
+
49: '!',
|
|
1548
|
+
50: '@',
|
|
1549
|
+
51: '#',
|
|
1550
|
+
52: '$',
|
|
1551
|
+
53: '%',
|
|
1552
|
+
54: '^',
|
|
1553
|
+
55: '&',
|
|
1554
|
+
56: '*',
|
|
1555
|
+
57: '(',
|
|
1556
|
+
186: ':',
|
|
1557
|
+
187: '+',
|
|
1558
|
+
188: '<',
|
|
1559
|
+
189: '_',
|
|
1560
|
+
190: '>',
|
|
1561
|
+
191: '?',
|
|
1562
|
+
219: '{',
|
|
1563
|
+
220: '|',
|
|
1564
|
+
221: '}',
|
|
1565
|
+
222: '"'
|
|
1566
|
+
};
|
|
1567
|
+
|
|
1568
|
+
/**
|
|
1569
|
+
Calculates the value of KeyboardEvent#key given a keycode and the modifiers.
|
|
1570
|
+
Note that this works if the key is pressed in combination with the shift key, but it cannot
|
|
1571
|
+
detect if caps lock is enabled.
|
|
1572
|
+
@param {number} keycode The keycode of the event.
|
|
1573
|
+
@param {object} modifiers The modifiers of the event.
|
|
1574
|
+
@returns {string} The key string for the event.
|
|
1575
|
+
*/
|
|
1576
|
+
function keyFromKeyCodeAndModifiers(keycode, modifiers) {
|
|
1577
|
+
if (keycode > 64 && keycode < 91) {
|
|
1578
|
+
if (modifiers.shiftKey) {
|
|
1579
|
+
return String.fromCharCode(keycode);
|
|
1580
|
+
} else {
|
|
1581
|
+
return String.fromCharCode(keycode).toLocaleLowerCase();
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
return modifiers.shiftKey && keyFromKeyCodeWithShift[keycode] || keyFromKeyCode[keycode];
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
/**
|
|
1588
|
+
* Infers the keycode from the given key
|
|
1589
|
+
* @param {string} key The KeyboardEvent#key string
|
|
1590
|
+
* @returns {number} The keycode for the given key
|
|
1591
|
+
*/
|
|
1592
|
+
function keyCodeFromKey(key) {
|
|
1593
|
+
const keys = Object.keys(keyFromKeyCode);
|
|
1594
|
+
const keyCode = keys.find(keyCode => keyFromKeyCode[Number(keyCode)] === key) || keys.find(keyCode => keyFromKeyCode[Number(keyCode)] === key.toLowerCase());
|
|
1595
|
+
return keyCode !== undefined ? parseInt(keyCode) : undefined;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
/**
|
|
1599
|
+
@private
|
|
1600
|
+
@param {Element | Document} element the element to trigger the key event on
|
|
1601
|
+
@param {'keydown' | 'keyup' | 'keypress'} eventType the type of event to trigger
|
|
1602
|
+
@param {number|string} key the `keyCode`(number) or `key`(string) of the event being triggered
|
|
1603
|
+
@param {Object} [modifiers] the state of various modifier keys
|
|
1604
|
+
@return {Promise<Event>} resolves when settled
|
|
1605
|
+
*/
|
|
1606
|
+
function __triggerKeyEvent__(element, eventType, key, modifiers = DEFAULT_MODIFIERS) {
|
|
1607
|
+
return Promise.resolve().then(() => {
|
|
1608
|
+
let props;
|
|
1609
|
+
if (typeof key === 'number') {
|
|
1610
|
+
props = {
|
|
1611
|
+
keyCode: key,
|
|
1612
|
+
which: key,
|
|
1613
|
+
key: keyFromKeyCodeAndModifiers(key, modifiers),
|
|
1614
|
+
...modifiers
|
|
1615
|
+
};
|
|
1616
|
+
} else if (typeof key === 'string' && key.length !== 0) {
|
|
1617
|
+
const firstCharacter = key[0];
|
|
1618
|
+
if (!firstCharacter || firstCharacter !== firstCharacter.toUpperCase()) {
|
|
1619
|
+
throw new Error(`Must provide a \`key\` to \`triggerKeyEvent\` that starts with an uppercase character but you passed \`${key}\`.`);
|
|
1620
|
+
}
|
|
1621
|
+
if (isNumeric(key) && key.length > 1) {
|
|
1622
|
+
throw new Error(`Must provide a numeric \`keyCode\` to \`triggerKeyEvent\` but you passed \`${key}\` as a string.`);
|
|
1623
|
+
}
|
|
1624
|
+
const keyCode = keyCodeFromKey(key);
|
|
1625
|
+
props = {
|
|
1626
|
+
keyCode,
|
|
1627
|
+
which: keyCode,
|
|
1628
|
+
key,
|
|
1629
|
+
...modifiers
|
|
1630
|
+
};
|
|
1631
|
+
} else {
|
|
1632
|
+
throw new Error(`Must provide a \`key\` or \`keyCode\` to \`triggerKeyEvent\``);
|
|
1633
|
+
}
|
|
1634
|
+
return fireEvent(element, eventType, props);
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
/**
|
|
1639
|
+
Triggers a keyboard event of given type in the target element.
|
|
1640
|
+
It also requires the developer to provide either a string with the [`key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
|
|
1641
|
+
or the numeric [`keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) of the pressed key.
|
|
1642
|
+
Optionally the user can also provide a POJO with extra modifiers for the event.
|
|
1643
|
+
|
|
1644
|
+
@public
|
|
1645
|
+
@param {string|Element|IDOMElementDescriptor} target the element, selector, or descriptor to trigger the event on
|
|
1646
|
+
@param {'keydown' | 'keyup' | 'keypress'} eventType the type of event to trigger
|
|
1647
|
+
@param {number|string} key the `keyCode`(number) or `key`(string) of the event being triggered
|
|
1648
|
+
@param {Object} [modifiers] the state of various modifier keys
|
|
1649
|
+
@param {boolean} [modifiers.ctrlKey=false] if true the generated event will indicate the control key was pressed during the key event
|
|
1650
|
+
@param {boolean} [modifiers.altKey=false] if true the generated event will indicate the alt key was pressed during the key event
|
|
1651
|
+
@param {boolean} [modifiers.shiftKey=false] if true the generated event will indicate the shift key was pressed during the key event
|
|
1652
|
+
@param {boolean} [modifiers.metaKey=false] if true the generated event will indicate the meta key was pressed during the key event
|
|
1653
|
+
@return {Promise<void>} resolves when the application is settled unless awaitSettled is false
|
|
1276
1654
|
|
|
1655
|
+
@example
|
|
1656
|
+
<caption>
|
|
1657
|
+
Emulating pressing the `ENTER` key on a button using `triggerKeyEvent`
|
|
1658
|
+
</caption>
|
|
1659
|
+
triggerKeyEvent('button', 'keydown', 'Enter');
|
|
1660
|
+
*/
|
|
1661
|
+
function triggerKeyEvent(target, eventType, key, modifiers = DEFAULT_MODIFIERS) {
|
|
1662
|
+
return Promise.resolve().then(() => {
|
|
1663
|
+
return runHooks('triggerKeyEvent', 'start', target, eventType, key);
|
|
1664
|
+
}).then(() => {
|
|
1665
|
+
if (!target) {
|
|
1666
|
+
throw new Error('Must pass an element, selector, or descriptor to `triggerKeyEvent`.');
|
|
1667
|
+
}
|
|
1668
|
+
const element = getElement(target);
|
|
1669
|
+
if (!element) {
|
|
1670
|
+
const description = getDescription(target);
|
|
1671
|
+
throw new Error(`Element not found when calling \`triggerKeyEvent('${description}')\`.`);
|
|
1672
|
+
}
|
|
1673
|
+
if (!isKeyboardEventType(eventType)) {
|
|
1674
|
+
const validEventTypes = KEYBOARD_EVENT_TYPES.join(', ');
|
|
1675
|
+
throw new Error(`Must provide an \`eventType\` of ${validEventTypes} to \`triggerKeyEvent\` but you passed \`${eventType}\`.`);
|
|
1676
|
+
}
|
|
1677
|
+
if (isFormControl(element) && element.disabled) {
|
|
1678
|
+
throw new Error(`Can not \`triggerKeyEvent\` on disabled ${element}`);
|
|
1679
|
+
}
|
|
1680
|
+
return __triggerKeyEvent__(element, eventType, key, modifiers).then(settled);
|
|
1681
|
+
}).then(() => runHooks('triggerKeyEvent', 'end', target, eventType, key));
|
|
1682
|
+
}
|
|
1277
1683
|
registerHook('fillIn', 'start', (target, text) => {
|
|
1278
1684
|
log('fillIn', target, text);
|
|
1279
1685
|
});
|
|
1280
|
-
|
|
1281
1686
|
registerHook('typeIn', 'start', (target, text) => {
|
|
1282
1687
|
log('typeIn', target, text);
|
|
1283
1688
|
});
|
|
@@ -1350,5 +1755,114 @@ function ownParts(root, part) {
|
|
|
1350
1755
|
});
|
|
1351
1756
|
}
|
|
1352
1757
|
|
|
1353
|
-
|
|
1758
|
+
/**
|
|
1759
|
+
* Types a date into a segmented `DateInput` or `DatePicker`.
|
|
1760
|
+
*
|
|
1761
|
+
* `fillIn` cannot do this and, worse, does not fail when you try. The segments
|
|
1762
|
+
* are `contenteditable`, so `fillIn` writes their text and fires `input`
|
|
1763
|
+
* without complaint -- but the component renders from its own segments and
|
|
1764
|
+
* listens only to `beforeinput`/`keydown`, so nothing reaches the value. The
|
|
1765
|
+
* result is a test that reads green, whose `assert.dom(...).hasText('01')`
|
|
1766
|
+
* even passes, while the component's value stayed `null` and the form would
|
|
1767
|
+
* submit empty.
|
|
1768
|
+
*
|
|
1769
|
+
* This types the digits segment by segment the way a person does, so the value
|
|
1770
|
+
* composes through the same commit path as real input.
|
|
1771
|
+
*
|
|
1772
|
+
* ```js
|
|
1773
|
+
* await fillDate('[data-test-due]', '2026-01-20');
|
|
1774
|
+
* await fillDate('[data-test-due]', new Date(2026, 0, 20));
|
|
1775
|
+
* ```
|
|
1776
|
+
*
|
|
1777
|
+
* For `@mode="range"` use {@link fillDateRange}.
|
|
1778
|
+
*/
|
|
1779
|
+
function fillDate(selector, value) {
|
|
1780
|
+
return fillGroup('fillDate', selector, value, 0);
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
/**
|
|
1784
|
+
* Types both ends of a range into a segmented `DatePicker @mode="range"`.
|
|
1785
|
+
*
|
|
1786
|
+
* ```js
|
|
1787
|
+
* await fillDateRange('[data-test-trip]', '2026-01-20', '2026-01-25');
|
|
1788
|
+
* ```
|
|
1789
|
+
*/
|
|
1790
|
+
async function fillDateRange(selector, start, end) {
|
|
1791
|
+
await fillGroup('fillDateRange', selector, start, 0);
|
|
1792
|
+
await fillGroup('fillDateRange', selector, end, 1);
|
|
1793
|
+
}
|
|
1794
|
+
function clockHour(hours, segment) {
|
|
1795
|
+
const min = Number(segment.getAttribute('aria-valuemin'));
|
|
1796
|
+
const max = Number(segment.getAttribute('aria-valuemax'));
|
|
1797
|
+
if (max === 12) return hours % 12 || 12;
|
|
1798
|
+
if (max === 11) return hours % 12;
|
|
1799
|
+
if (min === 1) return hours || 24;
|
|
1800
|
+
return hours;
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
/**
|
|
1804
|
+
* AM/PM is typed by a letter that depends on the locale, so it is stepped
|
|
1805
|
+
* instead: ArrowUp fills an empty segment and toggles a filled one.
|
|
1806
|
+
*/
|
|
1807
|
+
async function setDayPeriod(segment, value) {
|
|
1808
|
+
await focus(segment);
|
|
1809
|
+
for (let i = 0; i < 2; i++) {
|
|
1810
|
+
if (segment.getAttribute('aria-valuenow') === String(value)) return;
|
|
1811
|
+
await triggerKeyEvent(segment, 'keydown', 'ArrowUp');
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
/**
|
|
1816
|
+
* Reuses the component's own parser rather than restating the wire format, so
|
|
1817
|
+
* the helper cannot drift from what `@value` actually accepts -- but turns a
|
|
1818
|
+
* refusal into a thrown error, since a test helper handed a bad date should
|
|
1819
|
+
* say so rather than quietly fill nothing.
|
|
1820
|
+
*/
|
|
1821
|
+
function asDate(functionName, value) {
|
|
1822
|
+
const parsed = parseDate(value);
|
|
1823
|
+
if (!parsed) {
|
|
1824
|
+
throw new Error(`You called "${functionName}" with "${String(value)}", which is neither a Date nor a yyyy-MM-dd or yyyy-MM-ddTHH:mm string.`);
|
|
1825
|
+
}
|
|
1826
|
+
return parsed;
|
|
1827
|
+
}
|
|
1828
|
+
async function fillGroup(functionName, selector, value, which) {
|
|
1829
|
+
const container = document.querySelector(selector);
|
|
1830
|
+
if (!container) {
|
|
1831
|
+
throw new Error(`You called "${functionName}('${selector}', ...)" but no element was found using selector "${selector}".`);
|
|
1832
|
+
}
|
|
1833
|
+
const group = container.querySelectorAll('[data-part="group"]')[which];
|
|
1834
|
+
if (!group) {
|
|
1835
|
+
// Far and away the likeliest cause: the field is on the button-trigger
|
|
1836
|
+
// path, where there is nothing to type into at all.
|
|
1837
|
+
const hasButtonTrigger = container.querySelector('[data-part="input"]');
|
|
1838
|
+
throw new Error(hasButtonTrigger ? `You called "${functionName}('${selector}', ...)" on a date field rendering its button trigger, which cannot be typed into. Drop @isEditable={{false}}, or click the trigger and pick from the calendar.` : `You called "${functionName}('${selector}', ...)" but found no date segments inside "${selector}".`);
|
|
1839
|
+
}
|
|
1840
|
+
const date = asDate(functionName, value);
|
|
1841
|
+
const pad = (n, width = 2) => String(n).padStart(width, '0');
|
|
1842
|
+
const digits = {
|
|
1843
|
+
year: pad(date.getFullYear(), 4),
|
|
1844
|
+
month: pad(date.getMonth() + 1),
|
|
1845
|
+
day: pad(date.getDate()),
|
|
1846
|
+
minute: pad(date.getMinutes())
|
|
1847
|
+
};
|
|
1848
|
+
for (const segment of group.querySelectorAll('[data-part="segment"]')) {
|
|
1849
|
+
const element = segment;
|
|
1850
|
+
const type = element.dataset['type'];
|
|
1851
|
+
if (type === 'dayPeriod') {
|
|
1852
|
+
await setDayPeriod(element, date.getHours() < 12 ? 0 : 1);
|
|
1853
|
+
continue;
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
// The hour goes in as the field's own clock counts it, which its
|
|
1857
|
+
// spinbutton bounds give away: 1-12 or 0-11 for AM/PM, 0-23 or 1-24 not.
|
|
1858
|
+
const run = type === 'hour' ? pad(clockHour(date.getHours(), element)) : type ? digits[type] : undefined;
|
|
1859
|
+
if (!run) continue;
|
|
1860
|
+
await focus(element);
|
|
1861
|
+
for (const digit of run) {
|
|
1862
|
+
await triggerKeyEvent(element, 'keydown', digit);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
export { fillDate, fillDateRange, ownParts, selectOptionByKey, toggleOptionByKey };
|
|
1354
1868
|
//# sourceMappingURL=test-support.js.map
|