/** * @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 */ import { ContentContainerComponentHarness, HarnessPredicate } from '@angular/cdk/testing'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; /** * Harness for interacting with a standard mat-button in tests. * @deprecated Use `MatButtonHarness` from `@angular/material/button/testing` instead. See https://material.angular.io/guide/mdc-migration for information about migrating. * @breaking-change 17.0.0 */ export class MatLegacyButtonHarness extends ContentContainerComponentHarness { // TODO(jelbourn) use a single class, like `.mat-button-base` /** The selector for the host element of a button instance. */ static { this.hostSelector = `[mat-button], [mat-raised-button], [mat-flat-button], [mat-icon-button], [mat-stroked-button], [mat-fab], [mat-mini-fab]`; } /** * Gets a `HarnessPredicate` that can be used to search for a button harness that meets * certain criteria. * @param options Options for filtering which button instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(MatLegacyButtonHarness, options) .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text)) .addOption('variant', options.variant, (harness, variant) => HarnessPredicate.stringMatches(harness.getVariant(), variant)) .addOption('disabled', options.disabled, async (harness, disabled) => { return (await harness.isDisabled()) === disabled; }); } async click(...args) { return (await this.host()).click(...args); } /** Whether the button is disabled. */ async isDisabled() { const disabled = (await this.host()).getAttribute('disabled'); return coerceBooleanProperty(await disabled); } /** Gets the button's label text. */ async getText() { return (await this.host()).text(); } /** Focuses the button. */ async focus() { return (await this.host()).focus(); } /** Blurs the button. */ async blur() { return (await this.host()).blur(); } /** Whether the button is focused. */ async isFocused() { return (await this.host()).isFocused(); } /** Gets the variant of the button. */ async getVariant() { const host = await this.host(); if ((await host.getAttribute('mat-raised-button')) != null) { return 'raised'; } else if ((await host.getAttribute('mat-flat-button')) != null) { return 'flat'; } else if ((await host.getAttribute('mat-icon-button')) != null) { return 'icon'; } else if ((await host.getAttribute('mat-stroked-button')) != null) { return 'stroked'; } else if ((await host.getAttribute('mat-fab')) != null) { return 'fab'; } else if ((await host.getAttribute('mat-mini-fab')) != null) { return 'mini-fab'; } return 'basic'; } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnV0dG9uLWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvbGVnYWN5LWJ1dHRvbi90ZXN0aW5nL2J1dHRvbi1oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBQyxnQ0FBZ0MsRUFBRSxnQkFBZ0IsRUFBQyxNQUFNLHNCQUFzQixDQUFDO0FBQ3hGLE9BQU8sRUFBQyxxQkFBcUIsRUFBQyxNQUFNLHVCQUF1QixDQUFDO0FBRzVEOzs7O0dBSUc7QUFDSCxNQUFNLE9BQU8sc0JBQXVCLFNBQVEsZ0NBQWdDO0lBQzFFLDZEQUE2RDtJQUM3RCw4REFBOEQ7YUFDdkQsaUJBQVksR0FBRzt5RUFDaUQsQ0FBQztJQUV4RTs7Ozs7T0FLRztJQUNILE1BQU0sQ0FBQyxJQUFJLENBQUMsVUFBZ0MsRUFBRTtRQUM1QyxPQUFPLElBQUksZ0JBQWdCLENBQUMsc0JBQXNCLEVBQUUsT0FBTyxDQUFDO2FBQ3pELFNBQVMsQ0FBQyxNQUFNLEVBQUUsT0FBTyxDQUFDLElBQUksRUFBRSxDQUFDLE9BQU8sRUFBRSxJQUFJLEVBQUUsRUFBRSxDQUNqRCxnQkFBZ0IsQ0FBQyxhQUFhLENBQUMsT0FBTyxDQUFDLE9BQU8sRUFBRSxFQUFFLElBQUksQ0FBQyxDQUN4RDthQUNBLFNBQVMsQ0FBQyxTQUFTLEVBQUUsT0FBTyxDQUFDLE9BQU8sRUFBRSxDQUFDLE9BQU8sRUFBRSxPQUFPLEVBQUUsRUFBRSxDQUMxR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