/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { parallel } from './change-detection'; import { ComponentHarness, HarnessPredicate, } from './component-harness'; /** * Base harness environment class that can be extended to allow `ComponentHarness`es to be used in * different test environments (e.g. testbed, protractor, etc.). This class implements the * functionality of both a `HarnessLoader` and `LocatorFactory`. This class is generic on the raw * element type, `E`, used by the particular test environment. */ export class HarnessEnvironment { // Implemented as part of the `LocatorFactory` interface. get rootElement() { this._rootElement = this._rootElement || this.createTestElement(this.rawRootElement); return this._rootElement; } set rootElement(element) { this._rootElement = element; } constructor(rawRootElement) { this.rawRootElement = rawRootElement; } // Implemented as part of the `LocatorFactory` interface. documentRootLocatorFactory() { return this.createEnvironment(this.getDocumentRoot()); } // Implemented as part of the `LocatorFactory` interface. locatorFor(...queries) { return () => _assertResultFound(this._getAllHarnessesAndTestElements(queries), _getDescriptionForLocatorForQueries(queries)); } // Implemented as part of the `LocatorFactory` interface. locatorForOptional(...queries) { return async () => (await this._getAllHarnessesAndTestElements(queries))[0] || null; } // Implemented as part of the `LocatorFactory` interface. locatorForAll(...queries) { return () => this._getAllHarnessesAndTestElements(queries); } // Implemented as part of the `LocatorFactory` interface. async rootHarnessLoader() { return this; } // Implemented as part of the `LocatorFactory` interface. async harnessLoaderFor(selector) { return this.createEnvironment(await _assertResultFound(this.getAllRawElements(selector), [ _getDescriptionForHarnessLoaderQuery(selector), ])); } // Implemented as part of the `LocatorFactory` interface. async harnessLoaderForOptional(selector) { const elements = await this.getAllRawElements(selector); return elements[0] ? this.createEnvironment(elements[0]) : null; } // Implemented as part of the `LocatorFactory` interface. async harnessLoaderForAll(selector) { const elements = await this.getAllRawElements(selector); return elements.map(element => this.createEnvironment(element)); } // Implemented as part of the `HarnessLoader` interface. getHarness(query) { return this.locatorFor(query)(); } // Implemented as part of the `HarnessLoader` interface. getHarnessOrNull(query) { return this.locatorForOptional(query)(); } // Implemented as part of the `HarnessLoader` interface. getAllHarnesses(query) { return this.locatorForAll(query)(); } // Implemented as part of the `HarnessLoader` interface. async hasHarness(query) { return (await this.locatorForOptional(query)()) !== null; } // Implemented as part of the `HarnessLoader` interface. async getChildLoader(selector) { return this.createEnvironment(await _assertResultFound(this.getAllRawElements(selector), [ _getDescriptionForHarnessLoaderQuery(selector), ])); } // Implemented as part of the `HarnessLoader` interface. async getAllChildLoaders(selector) { return (await this.getAllRawElements(selector)).map(e => this.createEnvironment(e)); } /** Creates a `ComponentHarness` for the given harness type with the given raw host element. */ createComponentHarness(harnessType, element) { return new harnessType(this.createEnvironment(element)); } /** * Matches the given raw elements with the given list of element and harness queries to produce a * list of matched harnesses and test elements. */ async _getAllHarnessesAndTestElements(queries) { if (!queries.length) { throw Error('CDK Component harness query must contain at least one element.'); } const { allQueries, harnessQueries, elementQueries, harnessTypes } = _parseQueries(queries); // Combine all of the queries into one large comma-delimited selector and use it to get all raw // elements matching any of the individual queries. const rawElements = await this.getAllRawElements([...elementQueries, ...harnessQueries.map(predicate => predicate.getSelector())].join(',')); // If every query is searching for the same harness subclass, we know every result corresponds // to an instance of that subclass. Likewise, if every query is for a `TestElement`, we know // every result corresponds to a `TestElement`. Otherwise we need to verify which result was // found by which selector so it can be matched to the appropriate instance. const skipSelectorCheck = (elementQueries.length === 0 && harnessTypes.size === 1) || harnessQueries.length === 0; const perElementMatches = await parallel(() => rawElements.map(async (rawElement) => { const testElement = this.createTestElement(rawElement); const allResultsForElement = await parallel( // For each query, get `null` if it doesn't match, or a `TestElement` or // `ComponentHarness` as appropriate if it does match. This gives us everything that // matches the current raw element, but it may contain duplicate entries (e.g. // multiple `TestElement` or multiple `ComponentHarness` of the same type). () => allQueries.map(query => this._getQueryResultForElement(query, rawElement, testElement, skipSelectorCheck))); return _removeDuplicateQueryResults(allResultsForElement); })); return [].concat(...perElementMatches); } /** * Check whether the given query matches the given element, if it does return the matched * `TestElement` or `ComponentHarness`, if it does not, return null. In cases where the caller * knows for sure that the query matches the element's selector, `skipSelectorCheck` can be used * to skip verification and optimize performance. */ async _getQueryResultForElement(query, rawElement, testElement, skipSelectorCheck = false) { if (typeof query === 'string') { return skipSelectorCheck || (await testElement.matchesSelector(query)) ? testElement : null; } if (skipSelectorCheck || (await testElement.matchesSelector(query.getSelector()))) { const harness = this.createComponentHarness(query.harnessType, rawElement); return (await query.evaluate(harness)) ? harness : null; } return null; } } /** * Parses a list of queries in the format accepted by the `locatorFor*` methods into an easier to * work with format. */ function _parseQueries(queries) { const allQueries = []; const harnessQueries = []; const elementQueries = []; const harnessTypes = new Set(); for (const query of queries) { if (typeof query === 'string') { allQueries.push(query); elementQueries.push(query); } else { const predicate = query instanceof HarnessPredicate ? query : new HarnessPredicate(query, {}); allQueries.push(predicate); harnessQueries.push(predicate); harnessTypes.add(predicate.harnessType); } } return { allQueries, harnessQueries, elementQueries, harnessTypes }; } /** * Removes duplicate query results for a particular element. (e.g. multiple `TestElement` * instances or multiple instances of the same `ComponentHarness` class. */ async function _removeDuplicateQueryResults(results) { let testElementMatched = false; let matchedHarnessTypes = new Set(); const dedupedMatches = []; for (const result of results) { if (!result) { continue; } if (result instanceof ComponentHarness) { if (!matchedHarnessTypes.has(result.constructor)) { matchedHarnessTypes.add(result.constructor); dedupedMatches.push(result); } } else if (!testElementMatched) { testElementMatched = true; dedupedMatches.push(result); } } return dedupedMatches; } /** Verifies that there is at least one result in an array. */ async function _assertResultFound(results, queryDescriptions) { const result = (await results)[0]; if (result == undefined) { throw Error(`Failed to find element matching one of the following queries:\n` + queryDescriptions.map(desc => `(${desc})`).join(',\n')); } return result; } /** Gets a list of description strings from a list of queries. */ function _getDescriptionForLocatorForQueries(queries) { return queries.map(query => typeof query === 'string' ? _getDescriptionForTestElementQuery(query) : _getDescriptionForComponentHarnessQuery(query)); } /** Gets a description string for a `ComponentHarness` query. */ function _getDescriptionForComponentHarnessQuery(query) { const harnessPredicate = query instanceof HarnessPredicate ? query : new HarnessPredicate(query, {}); const { name, hostSelector } = harnessPredicate.harnessType; const description = `${name} with host element matching selector: "${hostSelector}"`; const constraints = harnessPredicate.getDescription(); return (description + (constraints ? ` satisfying the constraints: ${harnessPredicate.getDescription()}` : '')); } /** Gets a description string for a `TestElement` query. */ function _getDescriptionForTestElementQuery(selector) { return `TestElement for element matching selector: "${selector}"`; } /** Gets a description string for a `HarnessLoader` query. */ function _getDescriptionForHarnessLoaderQuery(selector) { return `HarnessLoader for element matching selector: "${selector}"`; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGFybmVzcy1lbnZpcm9ubWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvdGVzdGluZy9oYXJuZXNzLWVudmlyb25tZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBQyxRQUFRLEVBQUMsTUFBTSxvQkFBb0IsQ0FBQztBQUM1QyxPQUFPLEVBRUwsZ0JBQWdCLEVBR2hCLGdCQUFnQixHQUlqQixNQUFNLHFCQUFxQixDQUFDO0FBcUI3Qjs7Ozs7R0FLRztBQUNILE1BQU0sT0FBZ0Isa0JBQWtCO0lBQ3RDLHlEQUF5RDtJQUN6RCxJQUFJLFdBQVc7UUFDYixJQUFJLENBQUMsWUFBWSxHQUFHLElBQUksQ0FBQyxZQUFZLElBQUksSUFBSSxDQUFDLGlCQUFpQixDQUFDLElBQUksQ0FBQyxjQUFjLENBQUMsQ0FBQztRQUNyRixPQUFPLElBQUksQ0FBQyxZQUFZLENBQUM7SUFDM0IsQ0FBQztJQUNELElBQUksV0FBVyxDQUFDLE9BQW9CO1FBQ2xDLElBQUksQ0FBQyxZQUFZLEdBQUcsT0FBTyxDQUFDO0lBQzlCLENBQUM7SUFHRCxZQUFnQyxjQUFpQjtRQUFqQixtQkFBYyxHQUFkLGNBQWMsQ0FBRztJQUFHLENBQUM7SU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