1 | {"version":3,"file":"icon__testing.js","sources":["../../../../../../src/material/icon/testing/icon-harness.ts","../../../../../../src/material/icon/testing/icon-harness-filters.ts","../../../../../../src/material/icon/testing/fake-icon-registry.ts","../../../../../../src/material/icon/testing/public-api.ts","../../../../../../src/material/icon/testing/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';\nimport {IconHarnessFilters, IconType} from './icon-harness-filters';\n\n\n/** Harness for interacting with a standard mat-icon in tests. */\nexport class MatIconHarness extends ComponentHarness {\n /** The selector for the host element of a `MatIcon` instance. */\n static hostSelector = '.mat-icon';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatIconHarness` that meets\n * certain criteria.\n * @param options Options for filtering which icon instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: IconHarnessFilters = {}): HarnessPredicate<MatIconHarness> {\n return new HarnessPredicate(MatIconHarness, options)\n .addOption('type', options.type,\n async (harness, type) => (await harness.getType()) === type)\n .addOption('name', options.name,\n (harness, text) => HarnessPredicate.stringMatches(harness.getName(), text))\n .addOption('namespace', options.namespace,\n (harness, text) => HarnessPredicate.stringMatches(harness.getNamespace(), text));\n }\n\n /** Gets the type of the icon. */\n async getType(): Promise<IconType> {\n const type = await (await this.host()).getAttribute('data-mat-icon-type');\n return type === 'svg' ? IconType.SVG : IconType.FONT;\n }\n\n /** Gets the name of the icon. */\n async getName(): Promise<string | null> {\n const host = await this.host();\n const nameFromDom = await host.getAttribute('data-mat-icon-name');\n\n // If we managed to figure out the name from the attribute, use it.\n if (nameFromDom) {\n return nameFromDom;\n }\n\n // Some icons support defining the icon as a ligature.\n // As a fallback, try to extract it from the DOM text.\n if (await this.getType() === IconType.FONT) {\n return host.text();\n }\n\n return null;\n }\n\n /** Gets the namespace of the icon. */\n async getNamespace(): Promise<string | null> {\n return (await this.host()).getAttribute('data-mat-icon-namespace');\n }\n\n /** Gets whether the icon is inline. */\n async isInline(): Promise<boolean> {\n return (await this.host()).hasClass('mat-icon-inline');\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {BaseHarnessFilters} from '@angular/cdk/testing';\n\n/** Possible types of icons. */\nexport const enum IconType {SVG, FONT}\n\n/** A set of criteria that can be used to filter a list of `MatIconHarness` instances. */\nexport interface IconHarnessFilters extends BaseHarnessFilters {\n /** Filters based on the typef of the icon. */\n type?: IconType;\n /** Filters based on the name of the icon. */\n name?: string | RegExp;\n /** Filters based on the namespace of the icon. */\n namespace?: string | null | RegExp;\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Injectable, NgModule, OnDestroy} from '@angular/core';\nimport {MatIconRegistry} from '@angular/material/icon';\nimport {Observable, of as observableOf} from 'rxjs';\n\ntype PublicApi<T> = {\n [K in keyof T]: T[K] extends (...x: any[]) => T ? (...x: any[]) => PublicApi<T> : T[K]\n};\n\n/**\n * A null icon registry that must be imported to allow disabling of custom\n * icons.\n */\n@Injectable()\nexport class FakeMatIconRegistry implements PublicApi<MatIconRegistry>, OnDestroy {\n addSvgIcon(): this {\n return this;\n }\n\n addSvgIconLiteral(): this {\n return this;\n }\n\n addSvgIconInNamespace(): this {\n return this;\n }\n\n addSvgIconLiteralInNamespace(): this {\n return this;\n }\n\n addSvgIconSet(): this {\n return this;\n }\n\n addSvgIconSetLiteral(): this {\n return this;\n }\n\n addSvgIconSetInNamespace(): this {\n return this;\n }\n\n addSvgIconSetLiteralInNamespace(): this {\n return this;\n }\n\n registerFontClassAlias(): this {\n return this;\n }\n\n classNameForFontAlias(alias: string): string {\n return alias;\n }\n\n getDefaultFontSetClass() {\n return 'material-icons';\n }\n\n getSvgIconFromUrl(): Observable<SVGElement> {\n return observableOf(this._generateEmptySvg());\n }\n\n getNamedSvgIcon(): Observable<SVGElement> {\n return observableOf(this._generateEmptySvg());\n }\n\n setDefaultFontSetClass(): this {\n return this;\n }\n\n addSvgIconResolver(): this {\n return this;\n }\n\n ngOnDestroy() { }\n\n private _generateEmptySvg(): SVGElement {\n const emptySvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n emptySvg.classList.add('fake-testing-svg');\n // Emulate real icon characteristics from `MatIconRegistry` so size remains consistent in tests.\n emptySvg.setAttribute('fit', '');\n emptySvg.setAttribute('height', '100%');\n emptySvg.setAttribute('width', '100%');\n emptySvg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n emptySvg.setAttribute('focusable', 'false');\n return emptySvg;\n }\n}\n\n/** Import this module in tests to install the null icon registry. */\n@NgModule({\n providers: [{provide: MatIconRegistry, useClass: FakeMatIconRegistry}]\n})\nexport class MatIconTestingModule {\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './icon-harness';\nexport * from './icon-harness-filters';\nexport * from './fake-icon-registry';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["observableOf"],"mappings":";;;;;;AAAA;;;;;;;AAYA;MACa,cAAe,SAAQ,gBAAgB;;;;;;;IAUlD,OAAO,IAAI,CAAC,UAA8B,EAAE;QAC1C,OAAO,IAAI,gBAAgB,CAAC,cAAc,EAAE,OAAO,CAAC;aAC/C,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,EAC3B,CAAO,OAAO,EAAE,IAAI,oDAAK,OAAA,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,MAAM,IAAI,CAAA,GAAA,CAAC;aAC/D,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,EAC3B,CAAC,OAAO,EAAE,IAAI,KA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