You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

179 lines
6.3 KiB

import { __awaiter } from 'tslib';
import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
import { Injectable, NgModule } from '@angular/core';
import { MatIconRegistry } from '@angular/material/icon';
import { of } from 'rxjs';
/**
* @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
*/
/** Harness for interacting with a standard mat-icon in tests. */
import * as ɵngcc0 from '@angular/core';
class MatIconHarness extends ComponentHarness {
/**
* Gets a `HarnessPredicate` that can be used to search for a `MatIconHarness` that meets
* certain criteria.
* @param options Options for filtering which icon instances are considered a match.
* @return a `HarnessPredicate` configured with the given options.
*/
static with(options = {}) {
return new HarnessPredicate(MatIconHarness, options)
.addOption('type', options.type, (harness, type) => __awaiter(this, void 0, void 0, function* () { return (yield harness.getType()) === type; }))
.addOption('name', options.name, (harness, text) => HarnessPredicate.stringMatches(harness.getName(), text))
.addOption('namespace', options.namespace, (harness, text) => HarnessPredicate.stringMatches(harness.getNamespace(), text));
}
/** Gets the type of the icon. */
getType() {
return __awaiter(this, void 0, void 0, function* () {
const type = yield (yield this.host()).getAttribute('data-mat-icon-type');
return type === 'svg' ? 0 /* SVG */ : 1 /* FONT */;
});
}
/** Gets the name of the icon. */
getName() {
return __awaiter(this, void 0, void 0, function* () {
const host = yield this.host();
const nameFromDom = yield host.getAttribute('data-mat-icon-name');
// If we managed to figure out the name from the attribute, use it.
if (nameFromDom) {
return nameFromDom;
}
// Some icons support defining the icon as a ligature.
// As a fallback, try to extract it from the DOM text.
if ((yield this.getType()) === 1 /* FONT */) {
return host.text();
}
return null;
});
}
/** Gets the namespace of the icon. */
getNamespace() {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.host()).getAttribute('data-mat-icon-namespace');
});
}
/** Gets whether the icon is inline. */
isInline() {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.host()).hasClass('mat-icon-inline');
});
}
}
/** The selector for the host element of a `MatIcon` instance. */
MatIconHarness.hostSelector = '.mat-icon';
/**
* @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
*/
/**
* @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
*/
/**
* A null icon registry that must be imported to allow disabling of custom
* icons.
*/
class FakeMatIconRegistry {
addSvgIcon() {
return this;
}
addSvgIconLiteral() {
return this;
}
addSvgIconInNamespace() {
return this;
}
addSvgIconLiteralInNamespace() {
return this;
}
addSvgIconSet() {
return this;
}
addSvgIconSetLiteral() {
return this;
}
addSvgIconSetInNamespace() {
return this;
}
addSvgIconSetLiteralInNamespace() {
return this;
}
registerFontClassAlias() {
return this;
}
classNameForFontAlias(alias) {
return alias;
}
getDefaultFontSetClass() {
return 'material-icons';
}
getSvgIconFromUrl() {
return of(this._generateEmptySvg());
}
getNamedSvgIcon() {
return of(this._generateEmptySvg());
}
setDefaultFontSetClass() {
return this;
}
addSvgIconResolver() {
return this;
}
ngOnDestroy() { }
_generateEmptySvg() {
const emptySvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
emptySvg.classList.add('fake-testing-svg');
// Emulate real icon characteristics from `MatIconRegistry` so size remains consistent in tests.
emptySvg.setAttribute('fit', '');
emptySvg.setAttribute('height', '100%');
emptySvg.setAttribute('width', '100%');
emptySvg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
emptySvg.setAttribute('focusable', 'false');
return emptySvg;
}
}
FakeMatIconRegistry.ɵfac = function FakeMatIconRegistry_Factory(t) { return new (t || FakeMatIconRegistry)(); };
FakeMatIconRegistry.ɵprov = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjectable({ token: FakeMatIconRegistry, factory: FakeMatIconRegistry.ɵfac });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(FakeMatIconRegistry, [{
type: Injectable
}], null, null); })();
/** Import this module in tests to install the null icon registry. */
class MatIconTestingModule {
}
MatIconTestingModule.ɵfac = function MatIconTestingModule_Factory(t) { return new (t || MatIconTestingModule)(); };
MatIconTestingModule.ɵmod = /*@__PURE__*/ ɵngcc0.ɵɵdefineNgModule({ type: MatIconTestingModule });
MatIconTestingModule.ɵinj = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjector({ providers: [{ provide: MatIconRegistry, useClass: FakeMatIconRegistry }] });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(MatIconTestingModule, [{
type: NgModule,
args: [{
providers: [{ provide: MatIconRegistry, useClass: FakeMatIconRegistry }]
}]
}], null, null); })();
/**
* @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
*/
/**
* Generated bundle index. Do not edit.
*/
export { FakeMatIconRegistry, MatIconHarness, MatIconTestingModule };
//# sourceMappingURL=testing.js.map