1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { __awaiter } from "tslib";
|
---|
9 | import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
|
---|
10 | /** Harness for interacting with a standard mat-icon in tests. */
|
---|
11 | export class MatIconHarness extends ComponentHarness {
|
---|
12 | /**
|
---|
13 | * Gets a `HarnessPredicate` that can be used to search for a `MatIconHarness` that meets
|
---|
14 | * certain criteria.
|
---|
15 | * @param options Options for filtering which icon instances are considered a match.
|
---|
16 | * @return a `HarnessPredicate` configured with the given options.
|
---|
17 | */
|
---|
18 | static with(options = {}) {
|
---|
19 | return new HarnessPredicate(MatIconHarness, options)
|
---|
20 | .addOption('type', options.type, (harness, type) => __awaiter(this, void 0, void 0, function* () { return (yield harness.getType()) === type; }))
|
---|
21 | .addOption('name', options.name, (harness, text) => HarnessPredicate.stringMatches(harness.getName(), text))
|
---|
22 | .addOption('namespace', options.namespace, (harness, text) => HarnessPredicate.stringMatches(harness.getNamespace(), text));
|
---|
23 | }
|
---|
24 | /** Gets the type of the icon. */
|
---|
25 | getType() {
|
---|
26 | return __awaiter(this, void 0, void 0, function* () {
|
---|
27 | const type = yield (yield this.host()).getAttribute('data-mat-icon-type');
|
---|
28 | return type === 'svg' ? 0 /* SVG */ : 1 /* FONT */;
|
---|
29 | });
|
---|
30 | }
|
---|
31 | /** Gets the name of the icon. */
|
---|
32 | getName() {
|
---|
33 | return __awaiter(this, void 0, void 0, function* () {
|
---|
34 | const host = yield this.host();
|
---|
35 | const nameFromDom = yield host.getAttribute('data-mat-icon-name');
|
---|
36 | // If we managed to figure out the name from the attribute, use it.
|
---|
37 | if (nameFromDom) {
|
---|
38 | return nameFromDom;
|
---|
39 | }
|
---|
40 | // Some icons support defining the icon as a ligature.
|
---|
41 | // As a fallback, try to extract it from the DOM text.
|
---|
42 | if ((yield this.getType()) === 1 /* FONT */) {
|
---|
43 | return host.text();
|
---|
44 | }
|
---|
45 | return null;
|
---|
46 | });
|
---|
47 | }
|
---|
48 | /** Gets the namespace of the icon. */
|
---|
49 | getNamespace() {
|
---|
50 | return __awaiter(this, void 0, void 0, function* () {
|
---|
51 | return (yield this.host()).getAttribute('data-mat-icon-namespace');
|
---|
52 | });
|
---|
53 | }
|
---|
54 | /** Gets whether the icon is inline. */
|
---|
55 | isInline() {
|
---|
56 | return __awaiter(this, void 0, void 0, function* () {
|
---|
57 | return (yield this.host()).hasClass('mat-icon-inline');
|
---|
58 | });
|
---|
59 | }
|
---|
60 | }
|
---|
61 | /** The selector for the host element of a `MatIcon` instance. */
|
---|
62 | MatIconHarness.hostSelector = '.mat-icon';
|
---|
63 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWNvbi1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL2ljb24vdGVzdGluZy9pY29uLWhhcm5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HOztBQUVILE9BQU8sRUFBQyxnQkFBZ0IsRUFBRSxnQkFBZ0IsRUFBQyxNQUFNLHNCQUFzQixDQUFDO0FBSXhFLGlFQUFpRTtBQUNqRSxNQUFNLE9BQU8sY0FBZSxTQUFRLGdCQUFnQjtJQUlsRDs7Ozs7T0FLRztJQUNILE1BQU0sQ0FBQyxJQUFJLENBQUMsVUFBOEIsRUFBRTtRQUMxQyxPQUFPLElBQUksZ0JBQWdCLENBQUMsY0FBYyxFQUFFLE9BQU8sQ0FBQzthQUMvQyxTQUFTLENBQUMsTUFBTSxFQUFFLE9BQU8sQ0FBQyxJQUFJLEVBQzNCLENBQU8sT0FBTyxFQUFFLElBQUksRUFBRSxFQUFFLGdE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