1 | import { __awaiter } from 'tslib';
|
---|
2 | import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
|
---|
3 | import { Injectable, NgModule } from '@angular/core';
|
---|
4 | import { MatIconRegistry } from '@angular/material/icon';
|
---|
5 | import { of } from 'rxjs';
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * @license
|
---|
9 | * Copyright Google LLC All Rights Reserved.
|
---|
10 | *
|
---|
11 | * Use of this source code is governed by an MIT-style license that can be
|
---|
12 | * found in the LICENSE file at https://angular.io/license
|
---|
13 | */
|
---|
14 | /** Harness for interacting with a standard mat-icon in tests. */
|
---|
15 | class MatIconHarness extends ComponentHarness {
|
---|
16 | /**
|
---|
17 | * Gets a `HarnessPredicate` that can be used to search for a `MatIconHarness` that meets
|
---|
18 | * certain criteria.
|
---|
19 | * @param options Options for filtering which icon instances are considered a match.
|
---|
20 | * @return a `HarnessPredicate` configured with the given options.
|
---|
21 | */
|
---|
22 | static with(options = {}) {
|
---|
23 | return new HarnessPredicate(MatIconHarness, options)
|
---|
24 | .addOption('type', options.type, (harness, type) => __awaiter(this, void 0, void 0, function* () { return (yield harness.getType()) === type; }))
|
---|
25 | .addOption('name', options.name, (harness, text) => HarnessPredicate.stringMatches(harness.getName(), text))
|
---|
26 | .addOption('namespace', options.namespace, (harness, text) => HarnessPredicate.stringMatches(harness.getNamespace(), text));
|
---|
27 | }
|
---|
28 | /** Gets the type of the icon. */
|
---|
29 | getType() {
|
---|
30 | return __awaiter(this, void 0, void 0, function* () {
|
---|
31 | const type = yield (yield this.host()).getAttribute('data-mat-icon-type');
|
---|
32 | return type === 'svg' ? 0 /* SVG */ : 1 /* FONT */;
|
---|
33 | });
|
---|
34 | }
|
---|
35 | /** Gets the name of the icon. */
|
---|
36 | getName() {
|
---|
37 | return __awaiter(this, void 0, void 0, function* () {
|
---|
38 | const host = yield this.host();
|
---|
39 | const nameFromDom = yield host.getAttribute('data-mat-icon-name');
|
---|
40 | // If we managed to figure out the name from the attribute, use it.
|
---|
41 | if (nameFromDom) {
|
---|
42 | return nameFromDom;
|
---|
43 | }
|
---|
44 | // Some icons support defining the icon as a ligature.
|
---|
45 | // As a fallback, try to extract it from the DOM text.
|
---|
46 | if ((yield this.getType()) === 1 /* FONT */) {
|
---|
47 | return host.text();
|
---|
48 | }
|
---|
49 | return null;
|
---|
50 | });
|
---|
51 | }
|
---|
52 | /** Gets the namespace of the icon. */
|
---|
53 | getNamespace() {
|
---|
54 | return __awaiter(this, void 0, void 0, function* () {
|
---|
55 | return (yield this.host()).getAttribute('data-mat-icon-namespace');
|
---|
56 | });
|
---|
57 | }
|
---|
58 | /** Gets whether the icon is inline. */
|
---|
59 | isInline() {
|
---|
60 | return __awaiter(this, void 0, void 0, function* () {
|
---|
61 | return (yield this.host()).hasClass('mat-icon-inline');
|
---|
62 | });
|
---|
63 | }
|
---|
64 | }
|
---|
65 | /** The selector for the host element of a `MatIcon` instance. */
|
---|
66 | MatIconHarness.hostSelector = '.mat-icon';
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * @license
|
---|
70 | * Copyright Google LLC All Rights Reserved.
|
---|
71 | *
|
---|
72 | * Use of this source code is governed by an MIT-style license that can be
|
---|
73 | * found in the LICENSE file at https://angular.io/license
|
---|
74 | */
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * @license
|
---|
78 | * Copyright Google LLC All Rights Reserved.
|
---|
79 | *
|
---|
80 | * Use of this source code is governed by an MIT-style license that can be
|
---|
81 | * found in the LICENSE file at https://angular.io/license
|
---|
82 | */
|
---|
83 | /**
|
---|
84 | * A null icon registry that must be imported to allow disabling of custom
|
---|
85 | * icons.
|
---|
86 | */
|
---|
87 | class FakeMatIconRegistry {
|
---|
88 | addSvgIcon() {
|
---|
89 | return this;
|
---|
90 | }
|
---|
91 | addSvgIconLiteral() {
|
---|
92 | return this;
|
---|
93 | }
|
---|
94 | addSvgIconInNamespace() {
|
---|
95 | return this;
|
---|
96 | }
|
---|
97 | addSvgIconLiteralInNamespace() {
|
---|
98 | return this;
|
---|
99 | }
|
---|
100 | addSvgIconSet() {
|
---|
101 | return this;
|
---|
102 | }
|
---|
103 | addSvgIconSetLiteral() {
|
---|
104 | return this;
|
---|
105 | }
|
---|
106 | addSvgIconSetInNamespace() {
|
---|
107 | return this;
|
---|
108 | }
|
---|
109 | addSvgIconSetLiteralInNamespace() {
|
---|
110 | return this;
|
---|
111 | }
|
---|
112 | registerFontClassAlias() {
|
---|
113 | return this;
|
---|
114 | }
|
---|
115 | classNameForFontAlias(alias) {
|
---|
116 | return alias;
|
---|
117 | }
|
---|
118 | getDefaultFontSetClass() {
|
---|
119 | return 'material-icons';
|
---|
120 | }
|
---|
121 | getSvgIconFromUrl() {
|
---|
122 | return of(this._generateEmptySvg());
|
---|
123 | }
|
---|
124 | getNamedSvgIcon() {
|
---|
125 | return of(this._generateEmptySvg());
|
---|
126 | }
|
---|
127 | setDefaultFontSetClass() {
|
---|
128 | return this;
|
---|
129 | }
|
---|
130 | addSvgIconResolver() {
|
---|
131 | return this;
|
---|
132 | }
|
---|
133 | ngOnDestroy() { }
|
---|
134 | _generateEmptySvg() {
|
---|
135 | const emptySvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
---|
136 | emptySvg.classList.add('fake-testing-svg');
|
---|
137 | // Emulate real icon characteristics from `MatIconRegistry` so size remains consistent in tests.
|
---|
138 | emptySvg.setAttribute('fit', '');
|
---|
139 | emptySvg.setAttribute('height', '100%');
|
---|
140 | emptySvg.setAttribute('width', '100%');
|
---|
141 | emptySvg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
|
---|
142 | emptySvg.setAttribute('focusable', 'false');
|
---|
143 | return emptySvg;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | FakeMatIconRegistry.decorators = [
|
---|
147 | { type: Injectable }
|
---|
148 | ];
|
---|
149 | /** Import this module in tests to install the null icon registry. */
|
---|
150 | class MatIconTestingModule {
|
---|
151 | }
|
---|
152 | MatIconTestingModule.decorators = [
|
---|
153 | { type: NgModule, args: [{
|
---|
154 | providers: [{ provide: MatIconRegistry, useClass: FakeMatIconRegistry }]
|
---|
155 | },] }
|
---|
156 | ];
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * @license
|
---|
160 | * Copyright Google LLC All Rights Reserved.
|
---|
161 | *
|
---|
162 | * Use of this source code is governed by an MIT-style license that can be
|
---|
163 | * found in the LICENSE file at https://angular.io/license
|
---|
164 | */
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Generated bundle index. Do not edit.
|
---|
168 | */
|
---|
169 |
|
---|
170 | export { FakeMatIconRegistry, MatIconHarness, MatIconTestingModule };
|
---|
171 | //# sourceMappingURL=testing.js.map
|
---|