@frontile/forms 0.18.0-alpha.1 → 0.18.0-alpha.11
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/components/select.d.ts +2 -2
- package/declarations/index.d.ts +1 -17
- package/declarations/template-registry.d.ts +1 -15
- package/declarations/test-support.d.ts +1 -2
- package/dist/index.js +13 -15
- package/dist/index.js.map +1 -1
- package/dist/test-support.js +1 -1336
- package/dist/test-support.js.map +1 -1
- package/package.json +4 -30
- package/dist/_app_/components/checkbox-group.js +0 -1
- package/dist/_app_/components/checkbox.js +0 -1
- package/dist/_app_/components/field-types.js +0 -1
- package/dist/_app_/components/field.js +0 -1
- package/dist/_app_/components/form-control.js +0 -1
- package/dist/_app_/components/form-description.js +0 -1
- package/dist/_app_/components/form-feedback.js +0 -1
- package/dist/_app_/components/form.js +0 -1
- package/dist/_app_/components/icons.js +0 -1
- package/dist/_app_/components/input.js +0 -1
- package/dist/_app_/components/label.js +0 -1
- package/dist/_app_/components/native-select.js +0 -1
- package/dist/_app_/components/radio-group.js +0 -1
- package/dist/_app_/components/radio.js +0 -1
- package/dist/_app_/components/select.js +0 -1
- package/dist/_app_/components/switch.js +0 -1
- package/dist/_app_/components/textarea.js +0 -1
- package/dist/components/checkbox-group.js +0 -29
- package/dist/components/checkbox-group.js.map +0 -1
- package/dist/components/checkbox.js +0 -50
- package/dist/components/checkbox.js.map +0 -1
- package/dist/components/field-types.js +0 -2
- package/dist/components/field-types.js.map +0 -1
- package/dist/components/field.js +0 -103
- package/dist/components/field.js.map +0 -1
- package/dist/components/form-control.js +0 -61
- package/dist/components/form-control.js.map +0 -1
- package/dist/components/form-description.js +0 -24
- package/dist/components/form-description.js.map +0 -1
- package/dist/components/form-feedback.js +0 -36
- package/dist/components/form-feedback.js.map +0 -1
- package/dist/components/form.js +0 -13
- package/dist/components/form.js.map +0 -1
- package/dist/components/icons.js +0 -13
- package/dist/components/icons.js.map +0 -1
- package/dist/components/input.js +0 -106
- package/dist/components/input.js.map +0 -1
- package/dist/components/label.js +0 -23
- package/dist/components/label.js.map +0 -1
- package/dist/components/native-select.js +0 -134
- package/dist/components/native-select.js.map +0 -1
- package/dist/components/radio-group.js +0 -29
- package/dist/components/radio-group.js.map +0 -1
- package/dist/components/radio.js +0 -49
- package/dist/components/radio.js.map +0 -1
- package/dist/components/select.js +0 -386
- package/dist/components/select.js.map +0 -1
- package/dist/components/switch.js +0 -63
- package/dist/components/switch.js.map +0 -1
- package/dist/components/textarea.js +0 -53
- package/dist/components/textarea.js.map +0 -1
package/dist/test-support.js
CHANGED
|
@@ -1,1337 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { VERSION } from '@ember/version';
|
|
3
|
-
import { _backburner } from '@ember/runloop';
|
|
4
|
-
import EmberObject from '@ember/object';
|
|
5
|
-
import '@ember/application/instance';
|
|
6
|
-
import Ember from 'ember';
|
|
7
|
-
import { Test } from 'ember-testing';
|
|
8
|
-
import { pendingRequests as pendingRequests$1 } from 'ember-testing/lib/test/pending_requests';
|
|
9
|
-
import { registerDeprecationHandler, registerWarnHandler } from '@ember/debug';
|
|
10
|
-
import '@ember/destroyable';
|
|
11
|
-
import { getPendingWaiterState, hasPendingWaiters } from '@ember/test-waiters';
|
|
12
|
-
import '@glimmer/manager';
|
|
13
|
-
import { precompileTemplate } from '@ember/template-compilation';
|
|
14
|
-
import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';
|
|
15
|
-
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
Checks if the currently running Ember version is greater than or equal to the
|
|
20
|
-
specified major and minor version numbers.
|
|
21
|
-
|
|
22
|
-
@private
|
|
23
|
-
@param {number} major the major version number to compare
|
|
24
|
-
@param {number} minor the minor version number to compare
|
|
25
|
-
@returns {boolean} true if the Ember version is >= MAJOR.MINOR specified, false otherwise
|
|
26
|
-
*/
|
|
27
|
-
function hasEmberVersion(major, minor) {
|
|
28
|
-
const numbers = VERSION.split('-')[0]?.split('.');
|
|
29
|
-
if (!numbers || !numbers[0] || !numbers[1]) {
|
|
30
|
-
throw new Error('`Ember.VERSION` is not set.');
|
|
31
|
-
}
|
|
32
|
-
const actualMajor = parseInt(numbers[0], 10);
|
|
33
|
-
const actualMinor = parseInt(numbers[1], 10);
|
|
34
|
-
return actualMajor > major || actualMajor === major && actualMinor >= minor;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// These utter shenanigans allow this to work regardless of what types you are
|
|
38
|
-
// importing from. The idea is: you supply multiple imports, each of which is
|
|
39
|
-
// mutually exclusive with the others in terms of valid imports, then ignore the
|
|
40
|
-
// imports so they type check, then "resolve" between them based on which one is
|
|
41
|
-
// actually defined. 😭
|
|
42
|
-
//
|
|
43
|
-
// TODO: at the next major version (4.0), when we drop support for Ember < 5.1
|
|
44
|
-
// or some later version and can therefore either depend *somewhat* more on
|
|
45
|
-
// these import locations *or* can drop them entirely (depending on the path
|
|
46
|
-
// taken in terms of the `Owner` stack), switch to the normal imports:
|
|
47
|
-
// ```
|
|
48
|
-
// import {
|
|
49
|
-
// ContainerProxyMixin,
|
|
50
|
-
// RegistryProxyMixin,
|
|
51
|
-
// } from '@ember/-internals/runtime';
|
|
52
|
-
// ```
|
|
53
|
-
//
|
|
54
|
-
// For now, we are stuck with this utterly horrifying hack to get the types for
|
|
55
|
-
// these reliably.
|
|
56
|
-
|
|
57
|
-
const ContainerProxyMixin = Ember._ContainerProxyMixin;
|
|
58
|
-
const RegistryProxyMixin = Ember._RegistryProxyMixin;
|
|
59
|
-
|
|
60
|
-
// NOTE: this is the same as what `EngineInstance`/`ApplicationInstance`
|
|
61
|
-
// implement, and is thus a superset of the `InternalOwner` contract from Ember
|
|
62
|
-
// itself.
|
|
63
|
-
|
|
64
|
-
EmberObject.extend(RegistryProxyMixin, ContainerProxyMixin, {
|
|
65
|
-
_emberTestHelpersMockOwner: true,
|
|
66
|
-
/* eslint-disable valid-jsdoc */
|
|
67
|
-
/**
|
|
68
|
-
* Unregister a factory and its instance.
|
|
69
|
-
*
|
|
70
|
-
* Overrides `RegistryProxy#unregister` in order to clear any cached instances
|
|
71
|
-
* of the unregistered factory.
|
|
72
|
-
*
|
|
73
|
-
* @param {string} fullName Name of the factory to unregister.
|
|
74
|
-
*
|
|
75
|
-
* @see {@link https://github.com/emberjs/ember.js/pull/12680}
|
|
76
|
-
* @see {@link https://github.com/emberjs/ember.js/blob/v4.5.0-alpha.5/packages/%40ember/engine/instance.ts#L152-L167}
|
|
77
|
-
*/
|
|
78
|
-
/* eslint-enable valid-jsdoc */
|
|
79
|
-
unregister(fullName) {
|
|
80
|
-
// SAFETY: this is always present, but only the stable type definitions from
|
|
81
|
-
// Ember actually preserve it, since it is private API.
|
|
82
|
-
this['__container__'].reset(fullName);
|
|
83
|
-
|
|
84
|
-
// We overwrote this method from RegistryProxyMixin.
|
|
85
|
-
// SAFETY: this is always present, but only the stable type definitions from
|
|
86
|
-
// Ember actually preserve it, since it is private API.
|
|
87
|
-
this['__registry__'].unregister(fullName);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// eslint-disable-next-line require-jsdoc
|
|
92
|
-
function isElement(target) {
|
|
93
|
-
return target !== null && typeof target === 'object' && Reflect.get(target, 'nodeType') === Node.ELEMENT_NODE;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// eslint-disable-next-line require-jsdoc
|
|
97
|
-
function isWindow(target) {
|
|
98
|
-
return target instanceof Window;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// eslint-disable-next-line require-jsdoc
|
|
102
|
-
function isDocument(target) {
|
|
103
|
-
return target !== null && typeof target === 'object' && Reflect.get(target, 'nodeType') === Node.DOCUMENT_NODE;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const FORM_CONTROL_TAGS = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'];
|
|
107
|
-
/**
|
|
108
|
-
@private
|
|
109
|
-
@param {Element} element the element to check
|
|
110
|
-
@returns {boolean} `true` when the element is a form control, `false` otherwise
|
|
111
|
-
*/
|
|
112
|
-
function isFormControl(element) {
|
|
113
|
-
return !isWindow(element) && !isDocument(element) && FORM_CONTROL_TAGS.indexOf(element.tagName) > -1 && element.type !== 'hidden';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const futureTick = setTimeout;
|
|
117
|
-
|
|
118
|
-
const TIMEOUTS = [0, 1, 2, 5, 7];
|
|
119
|
-
const MAX_TIMEOUT = 10;
|
|
120
|
-
/**
|
|
121
|
-
Wait for the provided callback to return a truthy value.
|
|
122
|
-
|
|
123
|
-
This does not leverage `settled()`, and as such can be used to manage async
|
|
124
|
-
while _not_ settled (e.g. "loading" or "pending" states).
|
|
125
|
-
|
|
126
|
-
@public
|
|
127
|
-
@param {Function} callback the callback to use for testing when waiting should stop
|
|
128
|
-
@param {Object} [options] options used to override defaults
|
|
129
|
-
@param {number} [options.timeout=1000] the maximum amount of time to wait
|
|
130
|
-
@param {string} [options.timeoutMessage='waitUntil timed out'] the message to use in the reject on timeout
|
|
131
|
-
@returns {Promise} resolves with the callback value when it returns a truthy value
|
|
132
|
-
|
|
133
|
-
@example
|
|
134
|
-
<caption>
|
|
135
|
-
Waiting until a selected element displays text:
|
|
136
|
-
</caption>
|
|
137
|
-
await waitUntil(function() {
|
|
138
|
-
return find('.my-selector').textContent.includes('something')
|
|
139
|
-
}, { timeout: 2000 })
|
|
140
|
-
*/
|
|
141
|
-
function waitUntil(callback, options = {}) {
|
|
142
|
-
const timeout = 'timeout' in options ? options.timeout : 1000;
|
|
143
|
-
const timeoutMessage = 'timeoutMessage' in options ? options.timeoutMessage : 'waitUntil timed out';
|
|
144
|
-
|
|
145
|
-
// creating this error eagerly so it has the proper invocation stack
|
|
146
|
-
const waitUntilTimedOut = new Error(timeoutMessage);
|
|
147
|
-
return new Promise(function (resolve, reject) {
|
|
148
|
-
let time = 0;
|
|
149
|
-
|
|
150
|
-
// eslint-disable-next-line require-jsdoc
|
|
151
|
-
function scheduleCheck(timeoutsIndex) {
|
|
152
|
-
const knownTimeout = TIMEOUTS[timeoutsIndex];
|
|
153
|
-
const interval = knownTimeout === undefined ? MAX_TIMEOUT : knownTimeout;
|
|
154
|
-
futureTick(function () {
|
|
155
|
-
time += interval;
|
|
156
|
-
let value;
|
|
157
|
-
try {
|
|
158
|
-
value = callback();
|
|
159
|
-
} catch (error) {
|
|
160
|
-
reject(error);
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
if (value) {
|
|
164
|
-
resolve(value);
|
|
165
|
-
} else if (time < timeout) {
|
|
166
|
-
scheduleCheck(timeoutsIndex + 1);
|
|
167
|
-
} else {
|
|
168
|
-
reject(waitUntilTimedOut);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
}, interval);
|
|
172
|
-
}
|
|
173
|
-
scheduleCheck(0);
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/* globals global */
|
|
178
|
-
|
|
179
|
-
var global$1 = (() => {
|
|
180
|
-
if (typeof self !== 'undefined') {
|
|
181
|
-
return self;
|
|
182
|
-
} else if (typeof window !== 'undefined') {
|
|
183
|
-
return window;
|
|
184
|
-
// @ts-ignore -- global does not exist
|
|
185
|
-
} else if (typeof global !== 'undefined') {
|
|
186
|
-
// @ts-ignore -- global does not exist
|
|
187
|
-
return global;
|
|
188
|
-
} else {
|
|
189
|
-
return Function('return this')();
|
|
190
|
-
}
|
|
191
|
-
})();
|
|
192
|
-
|
|
193
|
-
const DEPRECATIONS = new WeakMap();
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
*
|
|
197
|
-
* Provides the list of deprecation failures associated with a given base context;
|
|
198
|
-
*
|
|
199
|
-
* @private
|
|
200
|
-
* @param {BaseContext} [context] the test context
|
|
201
|
-
* @return {Array<DeprecationFailure>} the Deprecation Failures associated with the corresponding BaseContext;
|
|
202
|
-
*/
|
|
203
|
-
function getDeprecationsForContext(context) {
|
|
204
|
-
if (!context) {
|
|
205
|
-
throw new TypeError(`[@ember/test-helpers] could not get deprecations for an invalid test context: '${context}'`);
|
|
206
|
-
}
|
|
207
|
-
let deprecations = DEPRECATIONS.get(context);
|
|
208
|
-
if (!Array.isArray(deprecations)) {
|
|
209
|
-
deprecations = [];
|
|
210
|
-
DEPRECATIONS.set(context, deprecations);
|
|
211
|
-
}
|
|
212
|
-
return deprecations;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// This provides (when the environment supports) queryParam support for deprecations:
|
|
216
|
-
// * squelch deprecations by name via: `/tests/index.html?disabledDeprecations=this-property-fallback,some-other-thing`
|
|
217
|
-
// * enable a debuggger when a deprecation by a specific name is encountered via: `/tests/index.html?debugDeprecations=some-other-thing` when the
|
|
218
|
-
if (typeof URLSearchParams !== 'undefined') {
|
|
219
|
-
const queryParams = new URLSearchParams(document.location.search.substring(1));
|
|
220
|
-
const disabledDeprecations = queryParams.get('disabledDeprecations');
|
|
221
|
-
const debugDeprecations = queryParams.get('debugDeprecations');
|
|
222
|
-
|
|
223
|
-
// When using `/tests/index.html?disabledDeprecations=this-property-fallback,some-other-thing`
|
|
224
|
-
// those deprecations will be squelched
|
|
225
|
-
if (disabledDeprecations) {
|
|
226
|
-
registerDeprecationHandler((message, options, next) => {
|
|
227
|
-
if (!options || !disabledDeprecations.includes(options.id)) {
|
|
228
|
-
next.apply(null, [message, options]);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// When using `/tests/index.html?debugDeprecations=some-other-thing` when the
|
|
234
|
-
// `some-other-thing` deprecation is triggered, this `debugger` will be hit`
|
|
235
|
-
if (debugDeprecations) {
|
|
236
|
-
registerDeprecationHandler((message, options, next) => {
|
|
237
|
-
if (options && debugDeprecations.includes(options.id)) {
|
|
238
|
-
debugger; // eslint-disable-line no-debugger
|
|
239
|
-
}
|
|
240
|
-
next.apply(null, [message, options]);
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// the WARNINGS data structure which is used to weakly associated warnings with
|
|
246
|
-
// the test context their occurred within
|
|
247
|
-
const WARNINGS = new WeakMap();
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
*
|
|
251
|
-
* Provides the list of warnings associated with a given base context;
|
|
252
|
-
*
|
|
253
|
-
* @private
|
|
254
|
-
* @param {BaseContext} [context] the test context
|
|
255
|
-
* @return {Array<Warning>} the warnings associated with the corresponding BaseContext;
|
|
256
|
-
*/
|
|
257
|
-
function getWarningsForContext(context) {
|
|
258
|
-
if (!context) {
|
|
259
|
-
throw new TypeError(`[@ember/test-helpers] could not get warnings for an invalid test context: '${context}'`);
|
|
260
|
-
}
|
|
261
|
-
let warnings = WARNINGS.get(context);
|
|
262
|
-
if (!Array.isArray(warnings)) {
|
|
263
|
-
warnings = [];
|
|
264
|
-
WARNINGS.set(context, warnings);
|
|
265
|
-
}
|
|
266
|
-
return warnings;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// This provides (when the environment supports) queryParam support for warnings:
|
|
270
|
-
// * squelch warnings by name via: `/tests/index.html?disabledWarnings=this-property-fallback,some-other-thing`
|
|
271
|
-
// * enable a debuggger when a warning by a specific name is encountered via: `/tests/index.html?debugWarnings=some-other-thing` when the
|
|
272
|
-
if (typeof URLSearchParams !== 'undefined') {
|
|
273
|
-
const queryParams = new URLSearchParams(document.location.search.substring(1));
|
|
274
|
-
const disabledWarnings = queryParams.get('disabledWarnings');
|
|
275
|
-
const debugWarnings = queryParams.get('debugWarnings');
|
|
276
|
-
|
|
277
|
-
// When using `/tests/index.html?disabledWarnings=this-property-fallback,some-other-thing`
|
|
278
|
-
// those warnings will be squelched
|
|
279
|
-
if (disabledWarnings) {
|
|
280
|
-
registerWarnHandler((message, options, next) => {
|
|
281
|
-
if (!options || !disabledWarnings.includes(options.id)) {
|
|
282
|
-
next.apply(null, [message, options]);
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// When using `/tests/index.html?debugWarnings=some-other-thing` when the
|
|
288
|
-
// `some-other-thing` warning is triggered, this `debugger` will be hit`
|
|
289
|
-
if (debugWarnings) {
|
|
290
|
-
registerWarnHandler((message, options, next) => {
|
|
291
|
-
if (options && debugWarnings.includes(options.id)) {
|
|
292
|
-
debugger; // eslint-disable-line no-debugger
|
|
293
|
-
}
|
|
294
|
-
next.apply(null, [message, options]);
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const registeredHooks = new Map();
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* @private
|
|
303
|
-
* @param {string} helperName The name of the test helper in which to run the hook.
|
|
304
|
-
* @param {string} label A label to help identify the hook.
|
|
305
|
-
* @returns {string} The compound key for the helper.
|
|
306
|
-
*/
|
|
307
|
-
function getHelperKey(helperName, label) {
|
|
308
|
-
return `${helperName}:${label}`;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Registers a function to be run during the invocation of a test helper.
|
|
313
|
-
*
|
|
314
|
-
* @param {string} helperName The name of the test helper in which to run the hook.
|
|
315
|
-
* Test helper names include `blur`, `click`, `doubleClick`, `fillIn`,
|
|
316
|
-
* `fireEvent`, `focus`, `render`, `scrollTo`, `select`, `tab`, `tap`, `triggerEvent`,
|
|
317
|
-
* `triggerKeyEvent`, `typeIn`, and `visit`.
|
|
318
|
-
* @param {string} label A label to help identify the hook. Built-in labels include `start`, `end`,
|
|
319
|
-
* and `targetFound`, the former designating either the start or end of
|
|
320
|
-
* the helper invocation.
|
|
321
|
-
* @param {Function} hook The hook function to run when the test helper is invoked.
|
|
322
|
-
* @returns {HookUnregister} An object containing an `unregister` function that unregisters
|
|
323
|
-
* the specific hook initially registered to the helper.
|
|
324
|
-
* @example
|
|
325
|
-
* <caption>
|
|
326
|
-
* Registering a hook for the `end` point of the `click` test helper invocation
|
|
327
|
-
* </caption>
|
|
328
|
-
*
|
|
329
|
-
* const hook = registerHook('click', 'end', () => {
|
|
330
|
-
* console.log('Running `click:end` test helper hook');
|
|
331
|
-
* });
|
|
332
|
-
*
|
|
333
|
-
* // Unregister the hook at some later point in time
|
|
334
|
-
* hook.unregister();
|
|
335
|
-
*/
|
|
336
|
-
function registerHook(helperName, label, hook) {
|
|
337
|
-
const helperKey = getHelperKey(helperName, label);
|
|
338
|
-
let hooksForHelper = registeredHooks.get(helperKey);
|
|
339
|
-
if (hooksForHelper === undefined) {
|
|
340
|
-
hooksForHelper = new Set();
|
|
341
|
-
registeredHooks.set(helperKey, hooksForHelper);
|
|
342
|
-
}
|
|
343
|
-
hooksForHelper.add(hook);
|
|
344
|
-
return {
|
|
345
|
-
unregister() {
|
|
346
|
-
hooksForHelper.delete(hook);
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Runs all hooks registered for a specific test helper.
|
|
353
|
-
*
|
|
354
|
-
* @param {string} helperName The name of the test helper in which to run the hook.
|
|
355
|
-
* Test helper names include `blur`, `click`, `doubleClick`, `fillIn`,
|
|
356
|
-
* `fireEvent`, `focus`, `render`, `scrollTo`, `select`, `tab`, `tap`, `triggerEvent`,
|
|
357
|
-
* `triggerKeyEvent`, `typeIn`, and `visit`.
|
|
358
|
-
* @param {string} label A label to help identify the hook. Built-in labels include `start`, `end`,
|
|
359
|
-
* and `targetFound`, the former designating either the start or end of
|
|
360
|
-
* the helper invocation.
|
|
361
|
-
* @param {unknown[]} args Any arguments originally passed to the test helper.
|
|
362
|
-
* @returns {Promise<void>} A promise representing the serial invocation of the hooks.
|
|
363
|
-
*/
|
|
364
|
-
function runHooks(helperName, label, ...args) {
|
|
365
|
-
const hooks = registeredHooks.get(getHelperKey(helperName, label)) || new Set();
|
|
366
|
-
const promises = [];
|
|
367
|
-
hooks.forEach(hook => {
|
|
368
|
-
const hookResult = hook(...args);
|
|
369
|
-
promises.push(hookResult);
|
|
370
|
-
});
|
|
371
|
-
return Promise.all(promises).then(() => {});
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const debugInfoHelpers = new Set();
|
|
375
|
-
|
|
376
|
-
// @ts-ignore: this is private API. This import will work Ember 5.1+ since it
|
|
377
|
-
// "provides" this public API, but does not for earlier versions. As a result,
|
|
378
|
-
// this type will be `any`.
|
|
379
|
-
const PENDING_AJAX_REQUESTS = 'Pending AJAX requests';
|
|
380
|
-
const PENDING_TEST_WAITERS = 'Pending test waiters';
|
|
381
|
-
const SCHEDULED_ASYNC = 'Scheduled async';
|
|
382
|
-
const SCHEDULED_AUTORUN = 'Scheduled autorun';
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* The base functionality which may be present on the `SettledState` interface
|
|
386
|
-
* in the `settled` module (**not** the one in this module).
|
|
387
|
-
*/
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Determines if the `getDebugInfo` method is available in the
|
|
391
|
-
* running verison of backburner.
|
|
392
|
-
*
|
|
393
|
-
* @returns {boolean} True if `getDebugInfo` is present in backburner, otherwise false.
|
|
394
|
-
*/
|
|
395
|
-
function backburnerDebugInfoAvailable() {
|
|
396
|
-
return typeof _backburner.getDebugInfo === 'function';
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Retrieves debug information from backburner's current deferred actions queue (runloop instance).
|
|
401
|
-
* If the `getDebugInfo` method isn't available, it returns `null`.
|
|
402
|
-
*
|
|
403
|
-
* @public
|
|
404
|
-
* @returns {MaybeDebugInfo | null} Backburner debugInfo or, if the getDebugInfo method is not present, null
|
|
405
|
-
*/
|
|
406
|
-
function getDebugInfo() {
|
|
407
|
-
return _backburner.DEBUG === true && backburnerDebugInfoAvailable() ? _backburner.getDebugInfo() : null;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Encapsulates debug information for an individual test. Aggregates information
|
|
412
|
-
* from:
|
|
413
|
-
* - info provided by getSettledState
|
|
414
|
-
* - hasPendingTimers
|
|
415
|
-
* - hasRunLoop
|
|
416
|
-
* - hasPendingWaiters
|
|
417
|
-
* - hasPendingRequests
|
|
418
|
-
* - info provided by backburner's getDebugInfo method (timers, schedules, and stack trace info)
|
|
419
|
-
*
|
|
420
|
-
*/
|
|
421
|
-
class TestDebugInfo {
|
|
422
|
-
_settledState;
|
|
423
|
-
_debugInfo;
|
|
424
|
-
_summaryInfo = undefined;
|
|
425
|
-
constructor(settledState, debugInfo = getDebugInfo()) {
|
|
426
|
-
this._settledState = settledState;
|
|
427
|
-
this._debugInfo = debugInfo;
|
|
428
|
-
}
|
|
429
|
-
get summary() {
|
|
430
|
-
if (!this._summaryInfo) {
|
|
431
|
-
this._summaryInfo = {
|
|
432
|
-
...this._settledState
|
|
433
|
-
};
|
|
434
|
-
if (this._debugInfo) {
|
|
435
|
-
this._summaryInfo.autorunStackTrace = this._debugInfo.autorun && this._debugInfo.autorun.stack;
|
|
436
|
-
this._summaryInfo.pendingTimersCount = this._debugInfo.timers.length;
|
|
437
|
-
this._summaryInfo.hasPendingTimers = this._settledState.hasPendingTimers && this._summaryInfo.pendingTimersCount > 0;
|
|
438
|
-
this._summaryInfo.pendingTimersStackTraces = this._debugInfo.timers.map(timer => timer.stack);
|
|
439
|
-
this._summaryInfo.pendingScheduledQueueItemCount = this._debugInfo.instanceStack.filter(isNotNullable).reduce((total, item) => {
|
|
440
|
-
Object.values(item).forEach(queueItems => {
|
|
441
|
-
// SAFETY: this cast is required for versions of Ember which do
|
|
442
|
-
// not supply a correct definition of these types. It should
|
|
443
|
-
// also be compatible with the version where Ember *does* supply
|
|
444
|
-
// the types correctly.
|
|
445
|
-
total += queueItems?.length ?? 0;
|
|
446
|
-
});
|
|
447
|
-
return total;
|
|
448
|
-
}, 0);
|
|
449
|
-
this._summaryInfo.pendingScheduledQueueItemStackTraces = this._debugInfo.instanceStack.filter(isNotNullable).reduce((stacks, deferredActionQueues) => {
|
|
450
|
-
Object.values(deferredActionQueues).forEach(queueItems => {
|
|
451
|
-
// SAFETY: this cast is required for versions of Ember which do
|
|
452
|
-
// not supply a correct definition of these types. It should
|
|
453
|
-
// also be compatible with the version where Ember *does* supply
|
|
454
|
-
// the types correctly.
|
|
455
|
-
queueItems?.forEach(queueItem => queueItem.stack && stacks.push(queueItem.stack));
|
|
456
|
-
});
|
|
457
|
-
return stacks;
|
|
458
|
-
}, []);
|
|
459
|
-
}
|
|
460
|
-
if (this._summaryInfo.hasPendingTestWaiters) {
|
|
461
|
-
this._summaryInfo.pendingTestWaiterInfo = getPendingWaiterState();
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return this._summaryInfo;
|
|
465
|
-
}
|
|
466
|
-
toConsole(_console = console) {
|
|
467
|
-
const summary = this.summary;
|
|
468
|
-
if (summary.hasPendingRequests) {
|
|
469
|
-
_console.log(PENDING_AJAX_REQUESTS);
|
|
470
|
-
}
|
|
471
|
-
if (summary.hasPendingLegacyWaiters) {
|
|
472
|
-
_console.log(PENDING_TEST_WAITERS);
|
|
473
|
-
}
|
|
474
|
-
if (summary.hasPendingTestWaiters) {
|
|
475
|
-
if (!summary.hasPendingLegacyWaiters) {
|
|
476
|
-
_console.log(PENDING_TEST_WAITERS);
|
|
477
|
-
}
|
|
478
|
-
Object.keys(summary.pendingTestWaiterInfo.waiters).forEach(waiterName => {
|
|
479
|
-
const waiterDebugInfo = summary.pendingTestWaiterInfo.waiters[waiterName];
|
|
480
|
-
if (Array.isArray(waiterDebugInfo)) {
|
|
481
|
-
_console.group(waiterName);
|
|
482
|
-
waiterDebugInfo.forEach(debugInfo => {
|
|
483
|
-
_console.log(`${debugInfo.label ? debugInfo.label : 'stack'}: ${debugInfo.stack}`);
|
|
484
|
-
});
|
|
485
|
-
_console.groupEnd();
|
|
486
|
-
} else {
|
|
487
|
-
_console.log(waiterName);
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
if (summary.hasPendingTimers || summary.pendingScheduledQueueItemCount > 0) {
|
|
492
|
-
_console.group(SCHEDULED_ASYNC);
|
|
493
|
-
summary.pendingTimersStackTraces.forEach(timerStack => {
|
|
494
|
-
_console.log(timerStack);
|
|
495
|
-
});
|
|
496
|
-
summary.pendingScheduledQueueItemStackTraces.forEach(scheduleQueueItemStack => {
|
|
497
|
-
_console.log(scheduleQueueItemStack);
|
|
498
|
-
});
|
|
499
|
-
_console.groupEnd();
|
|
500
|
-
}
|
|
501
|
-
if (summary.hasRunLoop && summary.pendingTimersCount === 0 && summary.pendingScheduledQueueItemCount === 0) {
|
|
502
|
-
_console.log(SCHEDULED_AUTORUN);
|
|
503
|
-
if (summary.autorunStackTrace) {
|
|
504
|
-
_console.log(summary.autorunStackTrace);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
debugInfoHelpers.forEach(helper => {
|
|
508
|
-
helper.log();
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
_formatCount(title, count) {
|
|
512
|
-
return `${title}: ${count}`;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// eslint-disable-next-line require-jsdoc, @typescript-eslint/no-empty-object-type
|
|
517
|
-
function isNotNullable(value) {
|
|
518
|
-
return value != null;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const CAN_USE_ROUTER_EVENTS = hasEmberVersion(3, 6);
|
|
522
|
-
let routerTransitionsPending = null;
|
|
523
|
-
const ROUTER = new WeakMap();
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
Determines if we have any pending router transitions (used to determine `settled` state)
|
|
527
|
-
|
|
528
|
-
@public
|
|
529
|
-
@returns {(boolean|null)} if there are pending transitions
|
|
530
|
-
*/
|
|
531
|
-
function hasPendingTransitions() {
|
|
532
|
-
if (CAN_USE_ROUTER_EVENTS) {
|
|
533
|
-
return routerTransitionsPending;
|
|
534
|
-
}
|
|
535
|
-
const context = getContext();
|
|
536
|
-
|
|
537
|
-
// there is no current context, we cannot check
|
|
538
|
-
if (context === undefined) {
|
|
539
|
-
return null;
|
|
540
|
-
}
|
|
541
|
-
const router = ROUTER.get(context);
|
|
542
|
-
if (router === undefined) {
|
|
543
|
-
// if there is no router (e.g. no `visit` calls made yet), we cannot
|
|
544
|
-
// check for pending transitions but this is explicitly not an error
|
|
545
|
-
// condition
|
|
546
|
-
return null;
|
|
547
|
-
}
|
|
548
|
-
const routerMicrolib = router._routerMicrolib || router.router;
|
|
549
|
-
if (routerMicrolib === undefined) {
|
|
550
|
-
return null;
|
|
551
|
-
}
|
|
552
|
-
return !!routerMicrolib.activeTransition;
|
|
553
|
-
}
|
|
554
|
-
hasEmberVersion(2, 13);
|
|
555
|
-
const checkWaiters = Test.checkWaiters;
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
@private
|
|
559
|
-
@returns {number} the count of pending requests
|
|
560
|
-
*/
|
|
561
|
-
function pendingRequests() {
|
|
562
|
-
const localRequestsPending = 0;
|
|
563
|
-
const internalRequestsPending = pendingRequests$1();
|
|
564
|
-
return localRequestsPending + internalRequestsPending;
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
Check various settledness metrics, and return an object with the following properties:
|
|
568
|
-
|
|
569
|
-
- `hasRunLoop` - Checks if a run-loop has been started. If it has, this will
|
|
570
|
-
be `true` otherwise it will be `false`.
|
|
571
|
-
- `hasPendingTimers` - Checks if there are scheduled timers in the run-loop.
|
|
572
|
-
These pending timers are primarily registered by `Ember.run.schedule`. If
|
|
573
|
-
there are pending timers, this will be `true`, otherwise `false`.
|
|
574
|
-
- `hasPendingWaiters` - Checks if any registered test waiters are still
|
|
575
|
-
pending (e.g. the waiter returns `true`). If there are pending waiters,
|
|
576
|
-
this will be `true`, otherwise `false`.
|
|
577
|
-
- `hasPendingRequests` - Checks if there are pending AJAX requests (based on
|
|
578
|
-
`ajaxSend` / `ajaxComplete` events triggered by `jQuery.ajax`). If there
|
|
579
|
-
are pending requests, this will be `true`, otherwise `false`.
|
|
580
|
-
- `hasPendingTransitions` - Checks if there are pending route transitions. If the
|
|
581
|
-
router has not been instantiated / setup for the test yet this will return `null`,
|
|
582
|
-
if there are pending transitions, this will be `true`, otherwise `false`.
|
|
583
|
-
- `pendingRequestCount` - The count of pending AJAX requests.
|
|
584
|
-
- `debugInfo` - Debug information that's combined with info return from backburner's
|
|
585
|
-
getDebugInfo method.
|
|
586
|
-
- `isRenderPending` - Checks if there are any pending render operations. This will be true as long
|
|
587
|
-
as there are tracked values in the template that have not been rerendered yet.
|
|
588
|
-
|
|
589
|
-
@public
|
|
590
|
-
@returns {Object} object with properties for each of the metrics used to determine settledness
|
|
591
|
-
*/
|
|
592
|
-
function getSettledState() {
|
|
593
|
-
const hasPendingTimers = _backburner.hasTimers();
|
|
594
|
-
const hasRunLoop = Boolean(_backburner.currentInstance);
|
|
595
|
-
const hasPendingLegacyWaiters = checkWaiters();
|
|
596
|
-
const hasPendingTestWaiters = hasPendingWaiters();
|
|
597
|
-
const pendingRequestCount = pendingRequests();
|
|
598
|
-
const hasPendingRequests = pendingRequestCount > 0;
|
|
599
|
-
// TODO: Ideally we'd have a function in Ember itself that can synchronously identify whether
|
|
600
|
-
// or not there are any pending render operations, but this will have to suffice for now
|
|
601
|
-
const isRenderPending = !!hasRunLoop;
|
|
602
|
-
return {
|
|
603
|
-
hasPendingTimers,
|
|
604
|
-
hasRunLoop,
|
|
605
|
-
hasPendingWaiters: hasPendingLegacyWaiters || hasPendingTestWaiters,
|
|
606
|
-
hasPendingRequests,
|
|
607
|
-
hasPendingTransitions: hasPendingTransitions(),
|
|
608
|
-
isRenderPending,
|
|
609
|
-
pendingRequestCount,
|
|
610
|
-
debugInfo: new TestDebugInfo({
|
|
611
|
-
hasPendingTimers,
|
|
612
|
-
hasRunLoop,
|
|
613
|
-
hasPendingLegacyWaiters,
|
|
614
|
-
hasPendingTestWaiters,
|
|
615
|
-
hasPendingRequests,
|
|
616
|
-
isRenderPending
|
|
617
|
-
})
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
Checks various settledness metrics (via `getSettledState()`) to determine if things are settled or not.
|
|
623
|
-
|
|
624
|
-
Settled generally means that there are no pending timers, no pending waiters,
|
|
625
|
-
no pending AJAX requests, and no current run loop. However, new settledness
|
|
626
|
-
metrics may be added and used as they become available.
|
|
627
|
-
|
|
628
|
-
@public
|
|
629
|
-
@returns {boolean} `true` if settled, `false` otherwise
|
|
630
|
-
*/
|
|
631
|
-
function isSettled() {
|
|
632
|
-
const {
|
|
633
|
-
hasPendingTimers,
|
|
634
|
-
hasRunLoop,
|
|
635
|
-
hasPendingRequests,
|
|
636
|
-
hasPendingWaiters,
|
|
637
|
-
hasPendingTransitions,
|
|
638
|
-
isRenderPending
|
|
639
|
-
} = getSettledState();
|
|
640
|
-
if (hasPendingTimers || hasRunLoop || hasPendingRequests || hasPendingWaiters || hasPendingTransitions || isRenderPending) {
|
|
641
|
-
return false;
|
|
642
|
-
}
|
|
643
|
-
return true;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
/**
|
|
647
|
-
Returns a promise that resolves when in a settled state (see `isSettled` for
|
|
648
|
-
a definition of "settled state").
|
|
649
|
-
|
|
650
|
-
@public
|
|
651
|
-
@returns {Promise<void>} resolves when settled
|
|
652
|
-
*/
|
|
653
|
-
function settled() {
|
|
654
|
-
return waitUntil(isSettled, {
|
|
655
|
-
timeout: Infinity
|
|
656
|
-
}).then(() => {});
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
// @ts-ignore: this is private API. This import will work Ember 5.1+ since it
|
|
660
|
-
// "provides" this public API, but does not for earlier versions. As a result,
|
|
661
|
-
// this type will be `any`.
|
|
662
|
-
// This handler exists to provide the underlying data to enable the following methods:
|
|
663
|
-
// * getDeprecations()
|
|
664
|
-
// * getDeprecationsDuringCallback()
|
|
665
|
-
// * getDeprecationsDuringCallbackForContext()
|
|
666
|
-
registerDeprecationHandler((message, options, next) => {
|
|
667
|
-
const context = getContext();
|
|
668
|
-
if (context === undefined) {
|
|
669
|
-
next.apply(null, [message, options]);
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
getDeprecationsForContext(context).push({
|
|
673
|
-
message,
|
|
674
|
-
options
|
|
675
|
-
});
|
|
676
|
-
next.apply(null, [message, options]);
|
|
677
|
-
});
|
|
678
|
-
|
|
679
|
-
// This handler exists to provide the underlying data to enable the following methods:
|
|
680
|
-
// * getWarnings()
|
|
681
|
-
// * getWarningsDuringCallback()
|
|
682
|
-
// * getWarningsDuringCallbackForContext()
|
|
683
|
-
registerWarnHandler((message, options, next) => {
|
|
684
|
-
const context = getContext();
|
|
685
|
-
if (context === undefined) {
|
|
686
|
-
next.apply(null, [message, options]);
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
getWarningsForContext(context).push({
|
|
690
|
-
message,
|
|
691
|
-
options
|
|
692
|
-
});
|
|
693
|
-
next.apply(null, [message, options]);
|
|
694
|
-
});
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* The public API for the test context, which test authors can depend on being
|
|
698
|
-
* available.
|
|
699
|
-
*
|
|
700
|
-
* Note: this is *not* user-constructible; it becomes available by calling
|
|
701
|
-
* `setupContext()` with a base context object.
|
|
702
|
-
*/
|
|
703
|
-
|
|
704
|
-
// eslint-disable-next-line require-jsdoc
|
|
705
|
-
function isTestContext(context) {
|
|
706
|
-
const maybeContext = context;
|
|
707
|
-
return typeof maybeContext['pauseTest'] === 'function' && typeof maybeContext['resumeTest'] === 'function';
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
/**
|
|
711
|
-
@private
|
|
712
|
-
@param {Object} it the global object to test
|
|
713
|
-
@returns {Boolean} it exists
|
|
714
|
-
*/
|
|
715
|
-
function check(it) {
|
|
716
|
-
// Math is known to exist as a global in every environment.
|
|
717
|
-
return it && it.Math === Math && it;
|
|
718
|
-
}
|
|
719
|
-
const globalObject = check(typeof globalThis == 'object' && globalThis) || check(typeof window === 'object' && window) || check(typeof self === 'object' && self) ||
|
|
720
|
-
// @ts-ignore -- global does not exist
|
|
721
|
-
check(typeof global$1 === 'object' && global$1);
|
|
722
|
-
|
|
723
|
-
/**
|
|
724
|
-
Retrieve the "global testing context" as stored by `setContext`.
|
|
725
|
-
|
|
726
|
-
@public
|
|
727
|
-
@returns {Object} the previously stored testing context
|
|
728
|
-
*/
|
|
729
|
-
function getContext() {
|
|
730
|
-
return globalObject.__test_context__;
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
/**
|
|
734
|
-
Get the root element of the application under test (usually `#ember-testing`)
|
|
735
|
-
|
|
736
|
-
@public
|
|
737
|
-
@returns {Element} the root element
|
|
738
|
-
|
|
739
|
-
@example
|
|
740
|
-
<caption>
|
|
741
|
-
Getting the root element of the application and checking that it is equal
|
|
742
|
-
to the element with id 'ember-testing'.
|
|
743
|
-
</caption>
|
|
744
|
-
assert.equal(getRootElement(), document.querySelector('#ember-testing'));
|
|
745
|
-
*/
|
|
746
|
-
function getRootElement() {
|
|
747
|
-
const context = getContext();
|
|
748
|
-
if (!context || !isTestContext(context) || !context.owner) {
|
|
749
|
-
throw new Error('Must setup rendering context before attempting to interact with elements.');
|
|
750
|
-
}
|
|
751
|
-
const owner = context.owner;
|
|
752
|
-
let rootElement;
|
|
753
|
-
// When the host app uses `setApplication` (instead of `setResolver`) the owner has
|
|
754
|
-
// a `rootElement` set on it with the element or id to be used
|
|
755
|
-
if (owner && owner._emberTestHelpersMockOwner === undefined) {
|
|
756
|
-
rootElement = owner.rootElement;
|
|
757
|
-
} else {
|
|
758
|
-
rootElement = '#ember-testing';
|
|
759
|
-
}
|
|
760
|
-
if (rootElement instanceof Window) {
|
|
761
|
-
rootElement = rootElement.document;
|
|
762
|
-
}
|
|
763
|
-
if (isElement(rootElement) || isDocument(rootElement)) {
|
|
764
|
-
return rootElement;
|
|
765
|
-
} else if (typeof rootElement === 'string') {
|
|
766
|
-
const _rootElement = document.querySelector(rootElement);
|
|
767
|
-
if (_rootElement) {
|
|
768
|
-
return _rootElement;
|
|
769
|
-
}
|
|
770
|
-
throw new Error(`Application.rootElement (${rootElement}) not found`);
|
|
771
|
-
} else {
|
|
772
|
-
throw new Error('Application.rootElement must be an element or a selector string');
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
precompileTemplate("{{outlet}}", {
|
|
777
|
-
strictMode: false
|
|
778
|
-
});
|
|
779
|
-
precompileTemplate("", {
|
|
780
|
-
strictMode: false
|
|
781
|
-
});
|
|
782
|
-
precompileTemplate("<this.ProvidedComponent />", {
|
|
783
|
-
strictMode: false
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
if (macroCondition(dependencySatisfies('ember-source', '>=4.5.0-beta.1'))) {
|
|
787
|
-
//@ts-ignore
|
|
788
|
-
importSync('@ember/renderer').renderSettled;
|
|
789
|
-
} else {
|
|
790
|
-
//@ts-ignore
|
|
791
|
-
importSync('@ember/-internals/glimmer').renderSettled;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
const IS_DESCRIPTOR = '__dom_element_descriptor_is_descriptor__';
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Determine if the argument is an {@link IDOMElementDescriptor}.
|
|
798
|
-
*
|
|
799
|
-
* This does not check if the argument is registered, just that it's type is
|
|
800
|
-
* {@link IDOMElementDescriptor}.
|
|
801
|
-
*/
|
|
802
|
-
function isDescriptor(target) {
|
|
803
|
-
return Boolean(typeof target === 'object' && target && IS_DESCRIPTOR in target);
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Get the registry instance.
|
|
808
|
-
*
|
|
809
|
-
* We store it on the window to ensure that if some dependency/hoisting horkage
|
|
810
|
-
* results in the presence of multiple copies of this library, they are all
|
|
811
|
-
* using the same registry.
|
|
812
|
-
*
|
|
813
|
-
* @returns the registry
|
|
814
|
-
*/
|
|
815
|
-
function getRegistry() {
|
|
816
|
-
const win = window;
|
|
817
|
-
win.domElementDescriptorsRegistry = win.domElementDescriptorsRegistry || new WeakMap();
|
|
818
|
-
return win.domElementDescriptorsRegistry;
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Look up registered descriptor data
|
|
822
|
-
*
|
|
823
|
-
* @param descriptor the descriptor
|
|
824
|
-
* @returns the descriptor's data, or null if none is set
|
|
825
|
-
*/
|
|
826
|
-
function lookupDescriptorData(descriptor) {
|
|
827
|
-
return getRegistry().get(descriptor) || null;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
/**
|
|
831
|
-
* Given a descriptor or descriptor data, get the single/first element it would
|
|
832
|
-
* match.
|
|
833
|
-
*
|
|
834
|
-
* This is analogous to `querySelector()`, and is meant to be used by DOM helper
|
|
835
|
-
* libraries to resolve the targets of single-element operations.
|
|
836
|
-
*
|
|
837
|
-
* @param target the descriptor or descriptor data
|
|
838
|
-
* @returns the resolved DOM element, or null if no element matched
|
|
839
|
-
*/
|
|
840
|
-
function resolveDOMElement(target) {
|
|
841
|
-
let data = isDescriptor(target) ? lookupDescriptorData(target) : target;
|
|
842
|
-
if (!data) {
|
|
843
|
-
return null;
|
|
844
|
-
}
|
|
845
|
-
if (data.element !== undefined) {
|
|
846
|
-
return data.element;
|
|
847
|
-
} else {
|
|
848
|
-
for (let element of data.elements || []) {
|
|
849
|
-
return element;
|
|
850
|
-
}
|
|
851
|
-
return null;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
/**
|
|
856
|
-
Used internally by the DOM interaction helpers to find one element.
|
|
857
|
-
|
|
858
|
-
@private
|
|
859
|
-
@param {string|Element} target the element or selector to retrieve
|
|
860
|
-
@returns {Element} the target or selector
|
|
861
|
-
*/
|
|
862
|
-
function getElement(target) {
|
|
863
|
-
if (typeof target === 'string') {
|
|
864
|
-
const rootElement = getRootElement();
|
|
865
|
-
return rootElement.querySelector(target);
|
|
866
|
-
} else if (isElement(target) || isDocument(target)) {
|
|
867
|
-
return target;
|
|
868
|
-
} else if (target instanceof Window) {
|
|
869
|
-
return target.document;
|
|
870
|
-
} else {
|
|
871
|
-
const descriptorData = lookupDescriptorData(target);
|
|
872
|
-
if (descriptorData) {
|
|
873
|
-
return resolveDOMElement(descriptorData);
|
|
874
|
-
} else {
|
|
875
|
-
throw new Error('Must use an element, selector string, or DOM element descriptor');
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
/**
|
|
881
|
-
Used internally by the DOM interaction helpers to find either window or an element.
|
|
882
|
-
|
|
883
|
-
@private
|
|
884
|
-
@param {string|Element} target the window, an element or selector to retrieve
|
|
885
|
-
@returns {Element|Window} the target or selector
|
|
886
|
-
*/
|
|
887
|
-
function getWindowOrElement(target) {
|
|
888
|
-
if (isWindow(target)) {
|
|
889
|
-
return target;
|
|
890
|
-
}
|
|
891
|
-
return getElement(target);
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
895
|
-
|
|
896
|
-
// eslint-disable-next-line require-jsdoc
|
|
897
|
-
function tuple(...args) {
|
|
898
|
-
return args;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
/**
|
|
902
|
-
* Logs a debug message to the console if the `testHelperLogging` query
|
|
903
|
-
* parameter is set.
|
|
904
|
-
*
|
|
905
|
-
* @private
|
|
906
|
-
* @param {string} helperName Name of the helper
|
|
907
|
-
* @param {string|Element} target The target element or selector
|
|
908
|
-
*/
|
|
909
|
-
function log(helperName, target, ...args) {
|
|
910
|
-
if (loggingEnabled()) {
|
|
911
|
-
// eslint-disable-next-line no-console
|
|
912
|
-
console.log(`${helperName}(${[elementToString(target), ...args.filter(Boolean)].join(', ')})`);
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
/**
|
|
917
|
-
* Returns whether the test helper logging is enabled or not via the
|
|
918
|
-
* `testHelperLogging` query parameter.
|
|
919
|
-
*
|
|
920
|
-
* @private
|
|
921
|
-
* @returns {boolean} true if enabled
|
|
922
|
-
*/
|
|
923
|
-
function loggingEnabled() {
|
|
924
|
-
return typeof location !== 'undefined' && location.search.indexOf('testHelperLogging') !== -1;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
/**
|
|
928
|
-
* This generates a human-readable description to a DOM element.
|
|
929
|
-
*
|
|
930
|
-
* @private
|
|
931
|
-
* @param {*} el The element that should be described
|
|
932
|
-
* @returns {string} A human-readable description
|
|
933
|
-
*/
|
|
934
|
-
function elementToString(el) {
|
|
935
|
-
let desc;
|
|
936
|
-
if (el instanceof NodeList) {
|
|
937
|
-
if (el.length === 0) {
|
|
938
|
-
return 'empty NodeList';
|
|
939
|
-
}
|
|
940
|
-
desc = Array.prototype.slice.call(el, 0, 5).map(elementToString).join(', ');
|
|
941
|
-
return el.length > 5 ? `${desc}... (+${el.length - 5} more)` : desc;
|
|
942
|
-
}
|
|
943
|
-
if (!(el instanceof HTMLElement || el instanceof SVGElement)) {
|
|
944
|
-
return String(el);
|
|
945
|
-
}
|
|
946
|
-
desc = el.tagName.toLowerCase();
|
|
947
|
-
if (el.id) {
|
|
948
|
-
desc += `#${el.id}`;
|
|
949
|
-
}
|
|
950
|
-
if (el.className && !(el.className instanceof SVGAnimatedString)) {
|
|
951
|
-
desc += `.${String(el.className).replace(/\s+/g, '.')}`;
|
|
952
|
-
}
|
|
953
|
-
Array.prototype.forEach.call(el.attributes, function (attr) {
|
|
954
|
-
if (attr.name !== 'class' && attr.name !== 'id') {
|
|
955
|
-
desc += `[${attr.name}${attr.value ? `="${attr.value}"]` : ']'}`;
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
return desc;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
registerHook('fireEvent', 'start', target => {
|
|
962
|
-
log('fireEvent', target);
|
|
963
|
-
});
|
|
964
|
-
|
|
965
|
-
// eslint-disable-next-line require-jsdoc
|
|
966
|
-
const MOUSE_EVENT_CONSTRUCTOR = (() => {
|
|
967
|
-
try {
|
|
968
|
-
new MouseEvent('test');
|
|
969
|
-
return true;
|
|
970
|
-
} catch {
|
|
971
|
-
return false;
|
|
972
|
-
}
|
|
973
|
-
})();
|
|
974
|
-
const DEFAULT_EVENT_OPTIONS = {
|
|
975
|
-
bubbles: true,
|
|
976
|
-
cancelable: true
|
|
977
|
-
};
|
|
978
|
-
const KEYBOARD_EVENT_TYPES = tuple('keydown', 'keypress', 'keyup');
|
|
979
|
-
// eslint-disable-next-line require-jsdoc
|
|
980
|
-
function isKeyboardEventType(eventType) {
|
|
981
|
-
return KEYBOARD_EVENT_TYPES.indexOf(eventType) > -1;
|
|
982
|
-
}
|
|
983
|
-
const MOUSE_EVENT_TYPES = tuple('click', 'mousedown', 'mouseup', 'dblclick', 'mouseenter', 'mouseleave', 'mousemove', 'mouseout', 'mouseover');
|
|
984
|
-
// eslint-disable-next-line require-jsdoc
|
|
985
|
-
function isMouseEventType(eventType) {
|
|
986
|
-
return MOUSE_EVENT_TYPES.indexOf(eventType) > -1;
|
|
987
|
-
}
|
|
988
|
-
const FILE_SELECTION_EVENT_TYPES = tuple('change');
|
|
989
|
-
// eslint-disable-next-line require-jsdoc
|
|
990
|
-
function isFileSelectionEventType(eventType) {
|
|
991
|
-
return FILE_SELECTION_EVENT_TYPES.indexOf(eventType) > -1;
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
// eslint-disable-next-line require-jsdoc
|
|
995
|
-
function isFileSelectionInput(element) {
|
|
996
|
-
return element.files;
|
|
997
|
-
}
|
|
998
|
-
/**
|
|
999
|
-
Internal helper used to build and dispatch events throughout the other DOM helpers.
|
|
1000
|
-
|
|
1001
|
-
@private
|
|
1002
|
-
@param {Element} element the element to dispatch the event to
|
|
1003
|
-
@param {string} eventType the type of event
|
|
1004
|
-
@param {Object} [options] additional properties to be set on the event
|
|
1005
|
-
@returns {Event} the event that was dispatched
|
|
1006
|
-
*/
|
|
1007
|
-
function fireEvent(element, eventType, options = {}) {
|
|
1008
|
-
return Promise.resolve().then(() => runHooks('fireEvent', 'start', element)).then(() => runHooks(`fireEvent:${eventType}`, 'start', element)).then(() => {
|
|
1009
|
-
if (!element) {
|
|
1010
|
-
throw new Error('Must pass an element to `fireEvent`');
|
|
1011
|
-
}
|
|
1012
|
-
let event;
|
|
1013
|
-
if (isKeyboardEventType(eventType)) {
|
|
1014
|
-
event = _buildKeyboardEvent(eventType, options);
|
|
1015
|
-
} else if (isMouseEventType(eventType)) {
|
|
1016
|
-
let rect;
|
|
1017
|
-
if (element instanceof Window && element.document.documentElement) {
|
|
1018
|
-
rect = element.document.documentElement.getBoundingClientRect();
|
|
1019
|
-
} else if (isDocument(element)) {
|
|
1020
|
-
rect = element.documentElement.getBoundingClientRect();
|
|
1021
|
-
} else if (isElement(element)) {
|
|
1022
|
-
rect = element.getBoundingClientRect();
|
|
1023
|
-
} else {
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
const x = rect.left + 1;
|
|
1027
|
-
const y = rect.top + 1;
|
|
1028
|
-
const simulatedCoordinates = {
|
|
1029
|
-
screenX: x + 5,
|
|
1030
|
-
// Those numbers don't really mean anything.
|
|
1031
|
-
screenY: y + 95,
|
|
1032
|
-
// They're just to make the screenX/Y be different of clientX/Y..
|
|
1033
|
-
clientX: x,
|
|
1034
|
-
clientY: y,
|
|
1035
|
-
...options
|
|
1036
|
-
};
|
|
1037
|
-
event = buildMouseEvent(eventType, simulatedCoordinates);
|
|
1038
|
-
} else if (isFileSelectionEventType(eventType) && isFileSelectionInput(element)) {
|
|
1039
|
-
event = buildFileEvent(eventType, element, options);
|
|
1040
|
-
} else {
|
|
1041
|
-
event = buildBasicEvent(eventType, options);
|
|
1042
|
-
}
|
|
1043
|
-
element.dispatchEvent(event);
|
|
1044
|
-
return event;
|
|
1045
|
-
}).then(event => runHooks(`fireEvent:${eventType}`, 'end', element).then(() => event)).then(event => runHooks('fireEvent', 'end', element).then(() => event));
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
// eslint-disable-next-line require-jsdoc
|
|
1049
|
-
function buildBasicEvent(type, options = {}) {
|
|
1050
|
-
const event = document.createEvent('Events');
|
|
1051
|
-
const bubbles = options.bubbles !== undefined ? options.bubbles : true;
|
|
1052
|
-
const cancelable = options.cancelable !== undefined ? options.cancelable : true;
|
|
1053
|
-
delete options.bubbles;
|
|
1054
|
-
delete options.cancelable;
|
|
1055
|
-
|
|
1056
|
-
// bubbles and cancelable are readonly, so they can be
|
|
1057
|
-
// set when initializing event
|
|
1058
|
-
event.initEvent(type, bubbles, cancelable);
|
|
1059
|
-
for (const prop in options) {
|
|
1060
|
-
event[prop] = options[prop];
|
|
1061
|
-
}
|
|
1062
|
-
return event;
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
// eslint-disable-next-line require-jsdoc
|
|
1066
|
-
function buildMouseEvent(type, options = {}) {
|
|
1067
|
-
let event;
|
|
1068
|
-
const eventOpts = {
|
|
1069
|
-
view: window,
|
|
1070
|
-
...DEFAULT_EVENT_OPTIONS,
|
|
1071
|
-
...options
|
|
1072
|
-
};
|
|
1073
|
-
if (MOUSE_EVENT_CONSTRUCTOR) {
|
|
1074
|
-
event = new MouseEvent(type, eventOpts);
|
|
1075
|
-
} else {
|
|
1076
|
-
try {
|
|
1077
|
-
event = document.createEvent('MouseEvents');
|
|
1078
|
-
event.initMouseEvent(type, eventOpts.bubbles, eventOpts.cancelable, window, eventOpts.detail, eventOpts.screenX, eventOpts.screenY, eventOpts.clientX, eventOpts.clientY, eventOpts.ctrlKey, eventOpts.altKey, eventOpts.shiftKey, eventOpts.metaKey, eventOpts.button, eventOpts.relatedTarget);
|
|
1079
|
-
} catch {
|
|
1080
|
-
event = buildBasicEvent(type, options);
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
return event;
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
// @private
|
|
1087
|
-
// eslint-disable-next-line require-jsdoc
|
|
1088
|
-
function _buildKeyboardEvent(type, options = {}) {
|
|
1089
|
-
const eventOpts = {
|
|
1090
|
-
...DEFAULT_EVENT_OPTIONS,
|
|
1091
|
-
...options
|
|
1092
|
-
};
|
|
1093
|
-
let event;
|
|
1094
|
-
let eventMethodName;
|
|
1095
|
-
try {
|
|
1096
|
-
event = new KeyboardEvent(type, eventOpts);
|
|
1097
|
-
|
|
1098
|
-
// Property definitions are required for B/C for keyboard event usage
|
|
1099
|
-
// If this properties are not defined, when listening for key events
|
|
1100
|
-
// keyCode/which will be 0. Also, keyCode and which now are string
|
|
1101
|
-
// and if app compare it with === with integer key definitions,
|
|
1102
|
-
// there will be a fail.
|
|
1103
|
-
//
|
|
1104
|
-
// https://w3c.github.io/uievents/#interface-keyboardevent
|
|
1105
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
|
|
1106
|
-
Object.defineProperty(event, 'keyCode', {
|
|
1107
|
-
get() {
|
|
1108
|
-
return parseInt(eventOpts.keyCode);
|
|
1109
|
-
}
|
|
1110
|
-
});
|
|
1111
|
-
Object.defineProperty(event, 'which', {
|
|
1112
|
-
get() {
|
|
1113
|
-
return parseInt(eventOpts.which);
|
|
1114
|
-
}
|
|
1115
|
-
});
|
|
1116
|
-
return event;
|
|
1117
|
-
} catch {
|
|
1118
|
-
// left intentionally blank
|
|
1119
|
-
}
|
|
1120
|
-
try {
|
|
1121
|
-
event = document.createEvent('KeyboardEvents');
|
|
1122
|
-
eventMethodName = 'initKeyboardEvent';
|
|
1123
|
-
} catch {
|
|
1124
|
-
// left intentionally blank
|
|
1125
|
-
}
|
|
1126
|
-
if (!event) {
|
|
1127
|
-
try {
|
|
1128
|
-
event = document.createEvent('KeyEvents');
|
|
1129
|
-
eventMethodName = 'initKeyEvent';
|
|
1130
|
-
} catch {
|
|
1131
|
-
// left intentionally blank
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
if (event && eventMethodName) {
|
|
1135
|
-
event[eventMethodName](type, eventOpts.bubbles, eventOpts.cancelable, window, eventOpts.ctrlKey, eventOpts.altKey, eventOpts.shiftKey, eventOpts.metaKey, eventOpts.keyCode, eventOpts.charCode);
|
|
1136
|
-
} else {
|
|
1137
|
-
event = buildBasicEvent(type, options);
|
|
1138
|
-
}
|
|
1139
|
-
return event;
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
// eslint-disable-next-line require-jsdoc
|
|
1143
|
-
function buildFileEvent(type, element, options = {}) {
|
|
1144
|
-
const event = buildBasicEvent(type);
|
|
1145
|
-
const files = options.files;
|
|
1146
|
-
if (Array.isArray(options)) {
|
|
1147
|
-
throw new Error('Please pass an object with a files array to `triggerEvent` instead of passing the `options` param as an array to.');
|
|
1148
|
-
}
|
|
1149
|
-
if (Array.isArray(files)) {
|
|
1150
|
-
Object.defineProperty(files, 'item', {
|
|
1151
|
-
value(index) {
|
|
1152
|
-
return typeof index === 'number' ? this[index] : null;
|
|
1153
|
-
},
|
|
1154
|
-
configurable: true
|
|
1155
|
-
});
|
|
1156
|
-
Object.defineProperty(element, 'files', {
|
|
1157
|
-
value: files,
|
|
1158
|
-
configurable: true
|
|
1159
|
-
});
|
|
1160
|
-
const elementProto = Object.getPrototypeOf(element);
|
|
1161
|
-
const valueProp = Object.getOwnPropertyDescriptor(elementProto, 'value');
|
|
1162
|
-
Object.defineProperty(element, 'value', {
|
|
1163
|
-
configurable: true,
|
|
1164
|
-
get() {
|
|
1165
|
-
return valueProp.get.call(element);
|
|
1166
|
-
},
|
|
1167
|
-
set(value) {
|
|
1168
|
-
valueProp.set.call(element, value);
|
|
1169
|
-
|
|
1170
|
-
// We are sure that the value is empty here.
|
|
1171
|
-
// For a non-empty value the original setter must raise an exception.
|
|
1172
|
-
Object.defineProperty(element, 'files', {
|
|
1173
|
-
configurable: true,
|
|
1174
|
-
value: []
|
|
1175
|
-
});
|
|
1176
|
-
}
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
Object.defineProperty(event, 'target', {
|
|
1180
|
-
value: element
|
|
1181
|
-
});
|
|
1182
|
-
return event;
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
/**
|
|
1186
|
-
Used internally by the DOM interaction helpers to get a description of a
|
|
1187
|
-
target for debug/error messaging.
|
|
1188
|
-
|
|
1189
|
-
@private
|
|
1190
|
-
@param {Target} target the target
|
|
1191
|
-
@returns {string} a description of the target
|
|
1192
|
-
*/
|
|
1193
|
-
function getDescription(target) {
|
|
1194
|
-
const data = isDescriptor(target) ? lookupDescriptorData(target) : null;
|
|
1195
|
-
if (data) {
|
|
1196
|
-
return data.description || '<unknown descriptor>';
|
|
1197
|
-
} else {
|
|
1198
|
-
return `${target}`;
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
registerHook('blur', 'start', target => {
|
|
1203
|
-
log('blur', target);
|
|
1204
|
-
});
|
|
1205
|
-
|
|
1206
|
-
registerHook('focus', 'start', target => {
|
|
1207
|
-
log('focus', target);
|
|
1208
|
-
});
|
|
1209
|
-
|
|
1210
|
-
registerHook('click', 'start', target => {
|
|
1211
|
-
log('click', target);
|
|
1212
|
-
});
|
|
1213
|
-
|
|
1214
|
-
registerHook('doubleClick', 'start', target => {
|
|
1215
|
-
log('doubleClick', target);
|
|
1216
|
-
});
|
|
1217
|
-
|
|
1218
|
-
registerHook('tab', 'start', target => {
|
|
1219
|
-
log('tab', target);
|
|
1220
|
-
});
|
|
1221
|
-
|
|
1222
|
-
registerHook('tap', 'start', target => {
|
|
1223
|
-
log('tap', target);
|
|
1224
|
-
});
|
|
1225
|
-
|
|
1226
|
-
registerHook('triggerEvent', 'start', (target, eventType) => {
|
|
1227
|
-
log('triggerEvent', target, eventType);
|
|
1228
|
-
});
|
|
1229
|
-
|
|
1230
|
-
/**
|
|
1231
|
-
* Triggers an event on the specified target.
|
|
1232
|
-
*
|
|
1233
|
-
* @public
|
|
1234
|
-
* @param {string|Element|IDOMElementDescriptor} target the element, selector, or descriptor to trigger the event on
|
|
1235
|
-
* @param {string} eventType the type of event to trigger
|
|
1236
|
-
* @param {Object} options additional properties to be set on the event
|
|
1237
|
-
* @return {Promise<void>} resolves when the application is settled
|
|
1238
|
-
*
|
|
1239
|
-
* @example
|
|
1240
|
-
* <caption>
|
|
1241
|
-
* Using `triggerEvent` to upload a file
|
|
1242
|
-
*
|
|
1243
|
-
* When using `triggerEvent` to upload a file the `eventType` must be `change` and you must pass the
|
|
1244
|
-
* `options` param as an object with a key `files` containing an array of
|
|
1245
|
-
* [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
|
|
1246
|
-
* </caption>
|
|
1247
|
-
*
|
|
1248
|
-
* triggerEvent(
|
|
1249
|
-
* 'input.fileUpload',
|
|
1250
|
-
* 'change',
|
|
1251
|
-
* { files: [new Blob(['Ember Rules!'])] }
|
|
1252
|
-
* );
|
|
1253
|
-
*
|
|
1254
|
-
*
|
|
1255
|
-
* @example
|
|
1256
|
-
* <caption>
|
|
1257
|
-
* Using `triggerEvent` to upload a dropped file
|
|
1258
|
-
*
|
|
1259
|
-
* When using `triggerEvent` to handle a dropped (via drag-and-drop) file, the `eventType` must be `drop`. Assuming your `drop` event handler uses the [DataTransfer API](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer),
|
|
1260
|
-
* you must pass the `options` param as an object with a key of `dataTransfer`. The `options.dataTransfer` object should have a `files` key, containing an array of [File](https://developer.mozilla.org/en-US/docs/Web/API/File).
|
|
1261
|
-
* </caption>
|
|
1262
|
-
*
|
|
1263
|
-
* triggerEvent(
|
|
1264
|
-
* '[data-test-drop-zone]',
|
|
1265
|
-
* 'drop',
|
|
1266
|
-
* {
|
|
1267
|
-
* dataTransfer: {
|
|
1268
|
-
* files: [new File(['Ember Rules!'], 'ember-rules.txt')]
|
|
1269
|
-
* }
|
|
1270
|
-
* }
|
|
1271
|
-
* )
|
|
1272
|
-
*/
|
|
1273
|
-
function triggerEvent(target, eventType, options) {
|
|
1274
|
-
return Promise.resolve().then(() => {
|
|
1275
|
-
return runHooks('triggerEvent', 'start', target, eventType, options);
|
|
1276
|
-
}).then(() => {
|
|
1277
|
-
if (!target) {
|
|
1278
|
-
throw new Error('Must pass an element, selector, or descriptor to `triggerEvent`.');
|
|
1279
|
-
}
|
|
1280
|
-
const element = getWindowOrElement(target);
|
|
1281
|
-
if (!element) {
|
|
1282
|
-
const description = getDescription(target);
|
|
1283
|
-
throw new Error(`Element not found when calling \`triggerEvent('${description}', ...)\`.`);
|
|
1284
|
-
}
|
|
1285
|
-
if (isFormControl(element) && element.disabled) {
|
|
1286
|
-
throw new Error(`Can not \`triggerEvent\` on disabled ${element}`);
|
|
1287
|
-
}
|
|
1288
|
-
return fireEvent(element, eventType, options).then(settled);
|
|
1289
|
-
}).then(() => {
|
|
1290
|
-
return runHooks('triggerEvent', 'end', target, eventType, options);
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
registerHook('triggerKeyEvent', 'start', (target, eventType, key) => {
|
|
1295
|
-
log('triggerKeyEvent', target, eventType, key);
|
|
1296
|
-
});
|
|
1297
|
-
|
|
1298
|
-
registerHook('fillIn', 'start', (target, text) => {
|
|
1299
|
-
log('fillIn', target, text);
|
|
1300
|
-
});
|
|
1301
|
-
|
|
1302
|
-
registerHook('typeIn', 'start', (target, text) => {
|
|
1303
|
-
log('typeIn', target, text);
|
|
1304
|
-
});
|
|
1305
|
-
|
|
1306
|
-
function selectOptionByKey(selectSelector, key) {
|
|
1307
|
-
return changeOption('selectOptionByKey', selectSelector, key, false);
|
|
1308
|
-
}
|
|
1309
|
-
function toggleOptionByKey(selectSelector, key) {
|
|
1310
|
-
return changeOption('toggleOptionByKey', selectSelector, key, true);
|
|
1311
|
-
}
|
|
1312
|
-
function changeOption(functionName, selectSelector, key, toggle) {
|
|
1313
|
-
const container = document.querySelector(selectSelector);
|
|
1314
|
-
if (!container) {
|
|
1315
|
-
throw new Error(`You called "${functionName}('${selectSelector}', '${key}')" but no select was found using selector "${selectSelector}"`);
|
|
1316
|
-
}
|
|
1317
|
-
let select = container;
|
|
1318
|
-
if (container.tagName !== 'SELECT') {
|
|
1319
|
-
select = container.querySelector('[data-component="native-select"]');
|
|
1320
|
-
}
|
|
1321
|
-
if (!select) {
|
|
1322
|
-
throw new Error(`You called "${functionName}('${selectSelector}', '${key}')" but no select was found inside container using selector "${selectSelector}"`);
|
|
1323
|
-
}
|
|
1324
|
-
const option = select.querySelector(`[data-key="${key}"]`);
|
|
1325
|
-
if (!option) {
|
|
1326
|
-
throw new Error(`You called "${functionName}('${selectSelector}', '${key}')" but no option with key "${key}" was found`);
|
|
1327
|
-
}
|
|
1328
|
-
if (toggle && option.selected) {
|
|
1329
|
-
option.selected = false;
|
|
1330
|
-
} else {
|
|
1331
|
-
option.selected = true;
|
|
1332
|
-
}
|
|
1333
|
-
return triggerEvent(select, 'change');
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
export { selectOptionByKey, toggleOptionByKey };
|
|
1
|
+
export * from 'frontile/test-support';
|
|
1337
2
|
//# sourceMappingURL=test-support.js.map
|