UNPKG

10.2 kBSource Map (JSON)View Raw
1{"version":3,"file":"testing.mjs","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","../../../../../../../src/material/icon/testing/testing_public_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/** 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, async (harness, type) => (await harness.getType()) === type)\n .addOption('name', options.name, (harness, text) =>\n HarnessPredicate.stringMatches(harness.getName(), text),\n )\n .addOption('namespace', options.namespace, (harness, text) =>\n HarnessPredicate.stringMatches(harness.getNamespace(), text),\n );\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 {\n SVG,\n FONT,\n}\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 * @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 * @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 './public-api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["observableOf"],"mappings":";;;;;;AAAA;;;;;;AAMG;AAKH;AACM,MAAO,cAAe,SAAQ,gBAAgB,CAAA;AAIlD;;;;;AAKG;AACH,IAAA,OAAO,IAAI,CAAC,OAAA,GAA8B,EAAE,EAAA;AAC1C,QAAA,OAAO,IAAI,gBAAgB,CAAC,cAAc,EAAE,OAAO,CAAC;aAC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