@angular/cdk 20.0.0-next.9 → 20.0.0-rc.1
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/_adev_assets/cdk_drag_drop.json +7123 -0
- package/_adev_assets/cdk_testing.json +7032 -1
- package/_adev_assets/cdk_testing_protractor.json +1747 -1
- package/_adev_assets/cdk_testing_selenium_webdriver.json +1801 -1
- package/_adev_assets/cdk_testing_testbed.json +1903 -1
- package/dialog/index.d.ts +1 -1
- package/fesm2022/{a11y-module-DpEjWNCj.mjs → a11y-module-CbrGzbQN.mjs} +27 -27
- package/fesm2022/{a11y-module-DpEjWNCj.mjs.map → a11y-module-CbrGzbQN.mjs.map} +1 -1
- package/fesm2022/a11y.mjs +16 -16
- package/fesm2022/a11y.mjs.map +1 -1
- package/fesm2022/accordion.mjs +12 -12
- package/fesm2022/accordion.mjs.map +1 -1
- package/fesm2022/bidi.mjs +9 -9
- package/fesm2022/bidi.mjs.map +1 -1
- package/fesm2022/{breakpoints-observer-DpQzdtrE.mjs → breakpoints-observer-CNqHxU7z.mjs} +8 -8
- package/fesm2022/{breakpoints-observer-DpQzdtrE.mjs.map → breakpoints-observer-CNqHxU7z.mjs.map} +1 -1
- package/fesm2022/cdk.mjs +1 -1
- package/fesm2022/cdk.mjs.map +1 -1
- package/fesm2022/clipboard.mjs +10 -10
- package/fesm2022/clipboard.mjs.map +1 -1
- package/fesm2022/collections.mjs +1 -1
- package/fesm2022/dialog.mjs +19 -19
- package/fesm2022/dialog.mjs.map +1 -1
- package/fesm2022/{directionality-Ck5Uc9Se.mjs → directionality-E3zek-p1.mjs} +4 -4
- package/fesm2022/{directionality-Ck5Uc9Se.mjs.map → directionality-E3zek-p1.mjs.map} +1 -1
- package/fesm2022/drag-drop.mjs +35 -35
- package/fesm2022/drag-drop.mjs.map +1 -1
- package/fesm2022/{focus-monitor-DKFfep8Q.mjs → focus-monitor-T5ZlFpu4.mjs} +11 -11
- package/fesm2022/{focus-monitor-DKFfep8Q.mjs.map → focus-monitor-T5ZlFpu4.mjs.map} +1 -1
- package/fesm2022/{id-generator-BwB8lolC.mjs → id-generator-C27MsMu2.mjs} +4 -4
- package/fesm2022/{id-generator-BwB8lolC.mjs.map → id-generator-C27MsMu2.mjs.map} +1 -1
- package/fesm2022/layout.mjs +6 -6
- package/fesm2022/layout.mjs.map +1 -1
- package/fesm2022/listbox.mjs +13 -13
- package/fesm2022/listbox.mjs.map +1 -1
- package/fesm2022/menu.mjs +56 -56
- package/fesm2022/menu.mjs.map +1 -1
- package/fesm2022/observers/private.mjs +3 -3
- package/fesm2022/observers/private.mjs.map +1 -1
- package/fesm2022/observers.mjs +13 -13
- package/fesm2022/observers.mjs.map +1 -1
- package/fesm2022/{overlay-module-BaGhSGqO.mjs → overlay-module-CCzhcXfK.mjs} +39 -39
- package/fesm2022/{overlay-module-BaGhSGqO.mjs.map → overlay-module-CCzhcXfK.mjs.map} +1 -1
- package/fesm2022/overlay.mjs +9 -9
- package/fesm2022/overlay.mjs.map +1 -1
- package/fesm2022/{platform-CPg0IbDW.mjs → platform-gLq1JIgc.mjs} +4 -4
- package/fesm2022/{platform-CPg0IbDW.mjs.map → platform-gLq1JIgc.mjs.map} +1 -1
- package/fesm2022/platform.mjs +5 -5
- package/fesm2022/platform.mjs.map +1 -1
- package/fesm2022/portal.mjs +16 -16
- package/fesm2022/portal.mjs.map +1 -1
- package/fesm2022/private.mjs +4 -4
- package/fesm2022/private.mjs.map +1 -1
- package/fesm2022/scrolling.mjs +37 -37
- package/fesm2022/scrolling.mjs.map +1 -1
- package/fesm2022/stepper.mjs +24 -24
- package/fesm2022/stepper.mjs.map +1 -1
- package/fesm2022/{style-loader-BDEAZOey.mjs → style-loader-i2d7TEeo.mjs} +4 -4
- package/fesm2022/{style-loader-BDEAZOey.mjs.map → style-loader-i2d7TEeo.mjs.map} +1 -1
- package/fesm2022/table.mjs +75 -75
- package/fesm2022/table.mjs.map +1 -1
- package/fesm2022/testing.mjs +255 -52
- package/fesm2022/testing.mjs.map +1 -1
- package/fesm2022/text-field.mjs +18 -18
- package/fesm2022/text-field.mjs.map +1 -1
- package/fesm2022/tree.mjs +26 -26
- package/fesm2022/tree.mjs.map +1 -1
- package/fesm2022/{unique-selection-dispatcher-Cag6cZJ2.mjs → unique-selection-dispatcher-YfWmNNyz.mjs} +4 -4
- package/fesm2022/{unique-selection-dispatcher-Cag6cZJ2.mjs.map → unique-selection-dispatcher-YfWmNNyz.mjs.map} +1 -1
- package/{harness-environment.d-BatBdODN.d.ts → harness-environment.d-BbFzIFDE.d.ts} +362 -89
- package/package.json +1 -1
- package/schematics/ng-add/index.js +1 -1
- package/testing/index.d.ts +6 -2
- package/testing/selenium-webdriver/index.d.ts +1 -1
- package/testing/testbed/index.d.ts +1 -1
package/fesm2022/testing.mjs
CHANGED
|
@@ -95,9 +95,8 @@ async function parallel(values) {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* Base class for component harnesses that all component harness authors should extend. This
|
|
99
|
-
* component harness provides the basic ability to locate element and sub-component
|
|
100
|
-
* should be inherited when defining user's own harness.
|
|
98
|
+
* Base class for component test harnesses that all component harness authors should extend. This
|
|
99
|
+
* base component harness provides the basic ability to locate element and sub-component harnesses.
|
|
101
100
|
*/
|
|
102
101
|
class ComponentHarness {
|
|
103
102
|
locatorFactory;
|
|
@@ -119,6 +118,21 @@ class ComponentHarness {
|
|
|
119
118
|
/**
|
|
120
119
|
* Creates an asynchronous locator function that can be used to find a `ComponentHarness` instance
|
|
121
120
|
* or element under the host element of this `ComponentHarness`.
|
|
121
|
+
*
|
|
122
|
+
* For example, given the following DOM and assuming `DivHarness.hostSelector` is `'div'`
|
|
123
|
+
*
|
|
124
|
+
* ```html
|
|
125
|
+
* <div id="d1"></div><div id="d2"></div>
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* then we expect:
|
|
129
|
+
*
|
|
130
|
+
* ```ts
|
|
131
|
+
* await ch.locatorFor(DivHarness, 'div')() // Gets a `DivHarness` instance for #d1
|
|
132
|
+
* await ch.locatorFor('div', DivHarness)() // Gets a `TestElement` instance for #d1
|
|
133
|
+
* await ch.locatorFor('span')() // Throws because the `Promise` rejects
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
122
136
|
* @param queries A list of queries specifying which harnesses and elements to search for:
|
|
123
137
|
* - A `string` searches for elements matching the CSS selector specified by the string.
|
|
124
138
|
* - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
|
|
@@ -130,12 +144,6 @@ class ComponentHarness {
|
|
|
130
144
|
* order in the DOM, and second by order in the queries list. If no matches are found, the
|
|
131
145
|
* `Promise` rejects. The type that the `Promise` resolves to is a union of all result types for
|
|
132
146
|
* each query.
|
|
133
|
-
*
|
|
134
|
-
* e.g. Given the following DOM: `<div id="d1" /><div id="d2" />`, and assuming
|
|
135
|
-
* `DivHarness.hostSelector === 'div'`:
|
|
136
|
-
* - `await ch.locatorFor(DivHarness, 'div')()` gets a `DivHarness` instance for `#d1`
|
|
137
|
-
* - `await ch.locatorFor('div', DivHarness)()` gets a `TestElement` instance for `#d1`
|
|
138
|
-
* - `await ch.locatorFor('span')()` throws because the `Promise` rejects.
|
|
139
147
|
*/
|
|
140
148
|
locatorFor(...queries) {
|
|
141
149
|
return this.locatorFactory.locatorFor(...queries);
|
|
@@ -143,6 +151,21 @@ class ComponentHarness {
|
|
|
143
151
|
/**
|
|
144
152
|
* Creates an asynchronous locator function that can be used to find a `ComponentHarness` instance
|
|
145
153
|
* or element under the host element of this `ComponentHarness`.
|
|
154
|
+
*
|
|
155
|
+
* For example, given the following DOM and assuming `DivHarness.hostSelector` is `'div'`
|
|
156
|
+
*
|
|
157
|
+
* ```html
|
|
158
|
+
* <div id="d1"></div><div id="d2"></div>
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* then we expect:
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* await ch.locatorForOptional(DivHarness, 'div')() // Gets a `DivHarness` instance for #d1
|
|
165
|
+
* await ch.locatorForOptional('div', DivHarness)() // Gets a `TestElement` instance for #d1
|
|
166
|
+
* await ch.locatorForOptional('span')() // Gets `null`
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
146
169
|
* @param queries A list of queries specifying which harnesses and elements to search for:
|
|
147
170
|
* - A `string` searches for elements matching the CSS selector specified by the string.
|
|
148
171
|
* - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
|
|
@@ -154,12 +177,6 @@ class ComponentHarness {
|
|
|
154
177
|
* order in the DOM, and second by order in the queries list. If no matches are found, the
|
|
155
178
|
* `Promise` is resolved with `null`. The type that the `Promise` resolves to is a union of all
|
|
156
179
|
* result types for each query or null.
|
|
157
|
-
*
|
|
158
|
-
* e.g. Given the following DOM: `<div id="d1" /><div id="d2" />`, and assuming
|
|
159
|
-
* `DivHarness.hostSelector === 'div'`:
|
|
160
|
-
* - `await ch.locatorForOptional(DivHarness, 'div')()` gets a `DivHarness` instance for `#d1`
|
|
161
|
-
* - `await ch.locatorForOptional('div', DivHarness)()` gets a `TestElement` instance for `#d1`
|
|
162
|
-
* - `await ch.locatorForOptional('span')()` gets `null`.
|
|
163
180
|
*/
|
|
164
181
|
locatorForOptional(...queries) {
|
|
165
182
|
return this.locatorFactory.locatorForOptional(...queries);
|
|
@@ -167,6 +184,27 @@ class ComponentHarness {
|
|
|
167
184
|
/**
|
|
168
185
|
* Creates an asynchronous locator function that can be used to find `ComponentHarness` instances
|
|
169
186
|
* or elements under the host element of this `ComponentHarness`.
|
|
187
|
+
*
|
|
188
|
+
* For example, given the following DOM and assuming `DivHarness.hostSelector` is `'div'` and
|
|
189
|
+
* `IdIsD1Harness.hostSelector` is `'#d1'`
|
|
190
|
+
*
|
|
191
|
+
* ```html
|
|
192
|
+
* <div id="d1"></div><div id="d2"></div>
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* then we expect:
|
|
196
|
+
*
|
|
197
|
+
* ```ts
|
|
198
|
+
* // Gets [DivHarness for #d1, TestElement for #d1, DivHarness for #d2, TestElement for #d2]
|
|
199
|
+
* await ch.locatorForAll(DivHarness, 'div')()
|
|
200
|
+
* // Gets [TestElement for #d1, TestElement for #d2]
|
|
201
|
+
* await ch.locatorForAll('div', '#d1')()
|
|
202
|
+
* // Gets [DivHarness for #d1, IdIsD1Harness for #d1, DivHarness for #d2]
|
|
203
|
+
* await ch.locatorForAll(DivHarness, IdIsD1Harness)()
|
|
204
|
+
* // Gets []
|
|
205
|
+
* await ch.locatorForAll('span')()
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
170
208
|
* @param queries A list of queries specifying which harnesses and elements to search for:
|
|
171
209
|
* - A `string` searches for elements matching the CSS selector specified by the string.
|
|
172
210
|
* - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
|
|
@@ -180,25 +218,6 @@ class ComponentHarness {
|
|
|
180
218
|
* an element matches multiple `string` selectors, only one `TestElement` instance is returned
|
|
181
219
|
* for that element. The type that the `Promise` resolves to is an array where each element is
|
|
182
220
|
* the union of all result types for each query.
|
|
183
|
-
*
|
|
184
|
-
* e.g. Given the following DOM: `<div id="d1" /><div id="d2" />`, and assuming
|
|
185
|
-
* `DivHarness.hostSelector === 'div'` and `IdIsD1Harness.hostSelector === '#d1'`:
|
|
186
|
-
* - `await ch.locatorForAll(DivHarness, 'div')()` gets `[
|
|
187
|
-
* DivHarness, // for #d1
|
|
188
|
-
* TestElement, // for #d1
|
|
189
|
-
* DivHarness, // for #d2
|
|
190
|
-
* TestElement // for #d2
|
|
191
|
-
* ]`
|
|
192
|
-
* - `await ch.locatorForAll('div', '#d1')()` gets `[
|
|
193
|
-
* TestElement, // for #d1
|
|
194
|
-
* TestElement // for #d2
|
|
195
|
-
* ]`
|
|
196
|
-
* - `await ch.locatorForAll(DivHarness, IdIsD1Harness)()` gets `[
|
|
197
|
-
* DivHarness, // for #d1
|
|
198
|
-
* IdIsD1Harness, // for #d1
|
|
199
|
-
* DivHarness // for #d2
|
|
200
|
-
* ]`
|
|
201
|
-
* - `await ch.locatorForAll('span')()` gets `[]`.
|
|
202
221
|
*/
|
|
203
222
|
locatorForAll(...queries) {
|
|
204
223
|
return this.locatorFactory.locatorForAll(...queries);
|
|
@@ -224,21 +243,56 @@ class ComponentHarness {
|
|
|
224
243
|
* of the harness may want to access other harnesses within the `<ng-content>` of the component.
|
|
225
244
|
*/
|
|
226
245
|
class ContentContainerComponentHarness extends ComponentHarness {
|
|
246
|
+
/**
|
|
247
|
+
* Gets a `HarnessLoader` that searches for harnesses under the first element matching the given
|
|
248
|
+
* selector within the current harness's content.
|
|
249
|
+
* @param selector The selector for an element in the component's content.
|
|
250
|
+
* @returns A `HarnessLoader` that searches for harnesses under the given selector.
|
|
251
|
+
*/
|
|
227
252
|
async getChildLoader(selector) {
|
|
228
253
|
return (await this.getRootHarnessLoader()).getChildLoader(selector);
|
|
229
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Gets a list of `HarnessLoader` for each element matching the given selector under the current
|
|
257
|
+
* harness's cotnent that searches for harnesses under that element.
|
|
258
|
+
* @param selector The selector for elements in the component's content.
|
|
259
|
+
* @returns A list of `HarnessLoader` for each element matching the given selector.
|
|
260
|
+
*/
|
|
230
261
|
async getAllChildLoaders(selector) {
|
|
231
262
|
return (await this.getRootHarnessLoader()).getAllChildLoaders(selector);
|
|
232
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Gets the first matching harness for the given query within the current harness's content.
|
|
266
|
+
* @param query The harness query to search for.
|
|
267
|
+
* @returns The first harness matching the given query.
|
|
268
|
+
* @throws If no matching harness is found.
|
|
269
|
+
*/
|
|
233
270
|
async getHarness(query) {
|
|
234
271
|
return (await this.getRootHarnessLoader()).getHarness(query);
|
|
235
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Gets the first matching harness for the given query within the current harness's content.
|
|
275
|
+
* @param query The harness query to search for.
|
|
276
|
+
* @returns The first harness matching the given query, or null if none is found.
|
|
277
|
+
*/
|
|
236
278
|
async getHarnessOrNull(query) {
|
|
237
279
|
return (await this.getRootHarnessLoader()).getHarnessOrNull(query);
|
|
238
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Gets all matching harnesses for the given query within the current harness's content.
|
|
283
|
+
* @param query The harness query to search for.
|
|
284
|
+
* @returns The list of harness matching the given query.
|
|
285
|
+
*/
|
|
239
286
|
async getAllHarnesses(query) {
|
|
240
287
|
return (await this.getRootHarnessLoader()).getAllHarnesses(query);
|
|
241
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Checks whether there is a matching harnesses for the given query within the current harness's
|
|
291
|
+
* content.
|
|
292
|
+
*
|
|
293
|
+
* @param query The harness query to search for.
|
|
294
|
+
* @returns Whetehr there is matching harnesses for the given query.
|
|
295
|
+
*/
|
|
242
296
|
async hasHarness(query) {
|
|
243
297
|
return (await this.getRootHarnessLoader()).hasHarness(query);
|
|
244
298
|
}
|
|
@@ -251,8 +305,8 @@ class ContentContainerComponentHarness extends ComponentHarness {
|
|
|
251
305
|
}
|
|
252
306
|
}
|
|
253
307
|
/**
|
|
254
|
-
* A class used to associate a ComponentHarness class with
|
|
255
|
-
* filter instances of the class.
|
|
308
|
+
* A class used to associate a ComponentHarness class with predicate functions that can be used to
|
|
309
|
+
* filter instances of the class to be matched.
|
|
256
310
|
*/
|
|
257
311
|
class HarnessPredicate {
|
|
258
312
|
harnessType;
|
|
@@ -425,7 +479,7 @@ function _restoreSelector(selector, placeholders) {
|
|
|
425
479
|
*/
|
|
426
480
|
class HarnessEnvironment {
|
|
427
481
|
rawRootElement;
|
|
428
|
-
|
|
482
|
+
/** The root element of this `HarnessEnvironment` as a `TestElement`. */
|
|
429
483
|
get rootElement() {
|
|
430
484
|
this._rootElement = this._rootElement || this.createTestElement(this.rawRootElement);
|
|
431
485
|
return this._rootElement;
|
|
@@ -434,68 +488,217 @@ class HarnessEnvironment {
|
|
|
434
488
|
this._rootElement = element;
|
|
435
489
|
}
|
|
436
490
|
_rootElement;
|
|
437
|
-
constructor(
|
|
491
|
+
constructor(
|
|
492
|
+
/** The native root element of this `HarnessEnvironment`. */
|
|
493
|
+
rawRootElement) {
|
|
438
494
|
this.rawRootElement = rawRootElement;
|
|
439
495
|
}
|
|
440
|
-
|
|
496
|
+
/** Gets a locator factory rooted at the document root. */
|
|
441
497
|
documentRootLocatorFactory() {
|
|
442
498
|
return this.createEnvironment(this.getDocumentRoot());
|
|
443
499
|
}
|
|
444
|
-
|
|
500
|
+
/**
|
|
501
|
+
* Creates an asynchronous locator function that can be used to find a `ComponentHarness` instance
|
|
502
|
+
* or element under the root element of this `HarnessEnvironment`.
|
|
503
|
+
*
|
|
504
|
+
* For example, given the following DOM and assuming `DivHarness.hostSelector` is `'div'`
|
|
505
|
+
*
|
|
506
|
+
* ```html
|
|
507
|
+
* <div id="d1"></div><div id="d2"></div>
|
|
508
|
+
* ```
|
|
509
|
+
*
|
|
510
|
+
* then we expect:
|
|
511
|
+
*
|
|
512
|
+
* ```ts
|
|
513
|
+
* await lf.locatorFor(DivHarness, 'div')() // Gets a `DivHarness` instance for #d1
|
|
514
|
+
* await lf.locatorFor('div', DivHarness)() // Gets a `TestElement` instance for #d1
|
|
515
|
+
* await lf.locatorFor('span')() // Throws because the `Promise` rejects
|
|
516
|
+
* ```
|
|
517
|
+
*
|
|
518
|
+
* @param queries A list of queries specifying which harnesses and elements to search for:
|
|
519
|
+
* - A `string` searches for elements matching the CSS selector specified by the string.
|
|
520
|
+
* - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
|
|
521
|
+
* given class.
|
|
522
|
+
* - A `HarnessPredicate` searches for `ComponentHarness` instances matching the given
|
|
523
|
+
* predicate.
|
|
524
|
+
* @return An asynchronous locator function that searches for and returns a `Promise` for the
|
|
525
|
+
* first element or harness matching the given search criteria. Matches are ordered first by
|
|
526
|
+
* order in the DOM, and second by order in the queries list. If no matches are found, the
|
|
527
|
+
* `Promise` rejects. The type that the `Promise` resolves to is a union of all result types for
|
|
528
|
+
* each query.
|
|
529
|
+
*/
|
|
445
530
|
locatorFor(...queries) {
|
|
446
531
|
return () => _assertResultFound(this._getAllHarnessesAndTestElements(queries), _getDescriptionForLocatorForQueries(queries));
|
|
447
532
|
}
|
|
448
|
-
|
|
533
|
+
/**
|
|
534
|
+
* Creates an asynchronous locator function that can be used to find a `ComponentHarness` instance
|
|
535
|
+
* or element under the root element of this `HarnessEnvironmnet`.
|
|
536
|
+
*
|
|
537
|
+
* For example, given the following DOM and assuming `DivHarness.hostSelector` is `'div'`
|
|
538
|
+
*
|
|
539
|
+
* ```html
|
|
540
|
+
* <div id="d1"></div><div id="d2"></div>
|
|
541
|
+
* ```
|
|
542
|
+
*
|
|
543
|
+
* then we expect:
|
|
544
|
+
*
|
|
545
|
+
* ```ts
|
|
546
|
+
* await lf.locatorForOptional(DivHarness, 'div')() // Gets a `DivHarness` instance for #d1
|
|
547
|
+
* await lf.locatorForOptional('div', DivHarness)() // Gets a `TestElement` instance for #d1
|
|
548
|
+
* await lf.locatorForOptional('span')() // Gets `null`
|
|
549
|
+
* ```
|
|
550
|
+
*
|
|
551
|
+
* @param queries A list of queries specifying which harnesses and elements to search for:
|
|
552
|
+
* - A `string` searches for elements matching the CSS selector specified by the string.
|
|
553
|
+
* - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
|
|
554
|
+
* given class.
|
|
555
|
+
* - A `HarnessPredicate` searches for `ComponentHarness` instances matching the given
|
|
556
|
+
* predicate.
|
|
557
|
+
* @return An asynchronous locator function that searches for and returns a `Promise` for the
|
|
558
|
+
* first element or harness matching the given search criteria. Matches are ordered first by
|
|
559
|
+
* order in the DOM, and second by order in the queries list. If no matches are found, the
|
|
560
|
+
* `Promise` is resolved with `null`. The type that the `Promise` resolves to is a union of all
|
|
561
|
+
* result types for each query or null.
|
|
562
|
+
*/
|
|
449
563
|
locatorForOptional(...queries) {
|
|
450
564
|
return async () => (await this._getAllHarnessesAndTestElements(queries))[0] || null;
|
|
451
565
|
}
|
|
452
|
-
|
|
566
|
+
/**
|
|
567
|
+
* Creates an asynchronous locator function that can be used to find `ComponentHarness` instances
|
|
568
|
+
* or elements under the root element of this `HarnessEnvironment`.
|
|
569
|
+
*
|
|
570
|
+
* For example, given the following DOM and assuming `DivHarness.hostSelector` is `'div'` and
|
|
571
|
+
* `IdIsD1Harness.hostSelector` is `'#d1'`
|
|
572
|
+
*
|
|
573
|
+
* ```html
|
|
574
|
+
* <div id="d1"></div><div id="d2"></div>
|
|
575
|
+
* ```
|
|
576
|
+
*
|
|
577
|
+
* then we expect:
|
|
578
|
+
*
|
|
579
|
+
* ```ts
|
|
580
|
+
* // Gets [DivHarness for #d1, TestElement for #d1, DivHarness for #d2, TestElement for #d2]
|
|
581
|
+
* await lf.locatorForAll(DivHarness, 'div')()
|
|
582
|
+
* // Gets [TestElement for #d1, TestElement for #d2]
|
|
583
|
+
* await lf.locatorForAll('div', '#d1')()
|
|
584
|
+
* // Gets [DivHarness for #d1, IdIsD1Harness for #d1, DivHarness for #d2]
|
|
585
|
+
* await lf.locatorForAll(DivHarness, IdIsD1Harness)()
|
|
586
|
+
* // Gets []
|
|
587
|
+
* await lf.locatorForAll('span')()
|
|
588
|
+
* ```
|
|
589
|
+
*
|
|
590
|
+
* @param queries A list of queries specifying which harnesses and elements to search for:
|
|
591
|
+
* - A `string` searches for elements matching the CSS selector specified by the string.
|
|
592
|
+
* - A `ComponentHarness` constructor searches for `ComponentHarness` instances matching the
|
|
593
|
+
* given class.
|
|
594
|
+
* - A `HarnessPredicate` searches for `ComponentHarness` instances matching the given
|
|
595
|
+
* predicate.
|
|
596
|
+
* @return An asynchronous locator function that searches for and returns a `Promise` for all
|
|
597
|
+
* elements and harnesses matching the given search criteria. Matches are ordered first by
|
|
598
|
+
* order in the DOM, and second by order in the queries list. If an element matches more than
|
|
599
|
+
* one `ComponentHarness` class, the locator gets an instance of each for the same element. If
|
|
600
|
+
* an element matches multiple `string` selectors, only one `TestElement` instance is returned
|
|
601
|
+
* for that element. The type that the `Promise` resolves to is an array where each element is
|
|
602
|
+
* the union of all result types for each query.
|
|
603
|
+
*/
|
|
453
604
|
locatorForAll(...queries) {
|
|
454
605
|
return () => this._getAllHarnessesAndTestElements(queries);
|
|
455
606
|
}
|
|
456
|
-
|
|
607
|
+
/** @return A `HarnessLoader` rooted at the root element of this `HarnessEnvironment`. */
|
|
457
608
|
async rootHarnessLoader() {
|
|
458
609
|
return this;
|
|
459
610
|
}
|
|
460
|
-
|
|
611
|
+
/**
|
|
612
|
+
* Gets a `HarnessLoader` instance for an element under the root of this `HarnessEnvironment`.
|
|
613
|
+
* @param selector The selector for the root element.
|
|
614
|
+
* @return A `HarnessLoader` rooted at the first element matching the given selector.
|
|
615
|
+
* @throws If no matching element is found for the given selector.
|
|
616
|
+
*/
|
|
461
617
|
async harnessLoaderFor(selector) {
|
|
462
618
|
return this.createEnvironment(await _assertResultFound(this.getAllRawElements(selector), [
|
|
463
619
|
_getDescriptionForHarnessLoaderQuery(selector),
|
|
464
620
|
]));
|
|
465
621
|
}
|
|
466
|
-
|
|
622
|
+
/**
|
|
623
|
+
* Gets a `HarnessLoader` instance for an element under the root of this `HarnessEnvironment`.
|
|
624
|
+
* @param selector The selector for the root element.
|
|
625
|
+
* @return A `HarnessLoader` rooted at the first element matching the given selector, or null if
|
|
626
|
+
* no matching element is found.
|
|
627
|
+
*/
|
|
467
628
|
async harnessLoaderForOptional(selector) {
|
|
468
629
|
const elements = await this.getAllRawElements(selector);
|
|
469
630
|
return elements[0] ? this.createEnvironment(elements[0]) : null;
|
|
470
631
|
}
|
|
471
|
-
|
|
632
|
+
/**
|
|
633
|
+
* Gets a list of `HarnessLoader` instances, one for each matching element.
|
|
634
|
+
* @param selector The selector for the root element.
|
|
635
|
+
* @return A list of `HarnessLoader`, one rooted at each element matching the given selector.
|
|
636
|
+
*/
|
|
472
637
|
async harnessLoaderForAll(selector) {
|
|
473
638
|
const elements = await this.getAllRawElements(selector);
|
|
474
639
|
return elements.map(element => this.createEnvironment(element));
|
|
475
640
|
}
|
|
476
|
-
|
|
641
|
+
/**
|
|
642
|
+
* Searches for an instance of the component corresponding to the given harness type under the
|
|
643
|
+
* `HarnessEnvironment`'s root element, and returns a `ComponentHarness` for that instance. If
|
|
644
|
+
* multiple matching components are found, a harness for the first one is returned. If no matching
|
|
645
|
+
* component is found, an error is thrown.
|
|
646
|
+
* @param query A query for a harness to create
|
|
647
|
+
* @return An instance of the given harness type
|
|
648
|
+
* @throws If a matching component instance can't be found.
|
|
649
|
+
*/
|
|
477
650
|
getHarness(query) {
|
|
478
651
|
return this.locatorFor(query)();
|
|
479
652
|
}
|
|
480
|
-
|
|
653
|
+
/**
|
|
654
|
+
* Searches for an instance of the component corresponding to the given harness type under the
|
|
655
|
+
* `HarnessEnvironment`'s root element, and returns a `ComponentHarness` for that instance. If
|
|
656
|
+
* multiple matching components are found, a harness for the first one is returned. If no matching
|
|
657
|
+
* component is found, null is returned.
|
|
658
|
+
* @param query A query for a harness to create
|
|
659
|
+
* @return An instance of the given harness type (or null if not found).
|
|
660
|
+
*/
|
|
481
661
|
getHarnessOrNull(query) {
|
|
482
662
|
return this.locatorForOptional(query)();
|
|
483
663
|
}
|
|
484
|
-
|
|
664
|
+
/**
|
|
665
|
+
* Searches for all instances of the component corresponding to the given harness type under the
|
|
666
|
+
* `HarnessEnvironment`'s root element, and returns a list `ComponentHarness` for each instance.
|
|
667
|
+
* @param query A query for a harness to create
|
|
668
|
+
* @return A list instances of the given harness type.
|
|
669
|
+
*/
|
|
485
670
|
getAllHarnesses(query) {
|
|
486
671
|
return this.locatorForAll(query)();
|
|
487
672
|
}
|
|
488
|
-
|
|
673
|
+
/**
|
|
674
|
+
* Searches for an instance of the component corresponding to the given harness type under the
|
|
675
|
+
* `HarnessEnvironment`'s root element, and returns a boolean indicating if any were found.
|
|
676
|
+
* @param query A query for a harness to create
|
|
677
|
+
* @return A boolean indicating if an instance was found.
|
|
678
|
+
*/
|
|
489
679
|
async hasHarness(query) {
|
|
490
680
|
return (await this.locatorForOptional(query)()) !== null;
|
|
491
681
|
}
|
|
492
|
-
|
|
682
|
+
/**
|
|
683
|
+
* Searches for an element with the given selector under the evironment's root element,
|
|
684
|
+
* and returns a `HarnessLoader` rooted at the matching element. If multiple elements match the
|
|
685
|
+
* selector, the first is used. If no elements match, an error is thrown.
|
|
686
|
+
* @param selector The selector for the root element of the new `HarnessLoader`
|
|
687
|
+
* @return A `HarnessLoader` rooted at the element matching the given selector.
|
|
688
|
+
* @throws If a matching element can't be found.
|
|
689
|
+
*/
|
|
493
690
|
async getChildLoader(selector) {
|
|
494
691
|
return this.createEnvironment(await _assertResultFound(this.getAllRawElements(selector), [
|
|
495
692
|
_getDescriptionForHarnessLoaderQuery(selector),
|
|
496
693
|
]));
|
|
497
694
|
}
|
|
498
|
-
|
|
695
|
+
/**
|
|
696
|
+
* Searches for all elements with the given selector under the environment's root element,
|
|
697
|
+
* and returns an array of `HarnessLoader`s, one for each matching element, rooted at that
|
|
698
|
+
* element.
|
|
699
|
+
* @param selector The selector for the root element of the new `HarnessLoader`
|
|
700
|
+
* @return A list of `HarnessLoader`s, one for each matching element, rooted at that element.
|
|
701
|
+
*/
|
|
499
702
|
async getAllChildLoaders(selector) {
|
|
500
703
|
return (await this.getAllRawElements(selector)).map(e => this.createEnvironment(e));
|
|
501
704
|
}
|