UNPKG

@angular/material

Version:
99 lines (94 loc) 3.66 kB
import { ContentContainerComponentHarness, HarnessPredicate } from '@angular/cdk/testing'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; /** * @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-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 */ class MatLegacyButtonHarness extends ContentContainerComponentHarness { /** * 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)); } 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'; } } // TODO(jelbourn) use a single class, like `.mat-button-base` /** The selector for the host element of a button instance. */ MatLegacyButtonHarness.hostSelector = `[mat-button], [mat-raised-button], [mat-flat-button], [mat-icon-button], [mat-stroked-button], [mat-fab], [mat-mini-fab]`; /** * @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 */ export { MatLegacyButtonHarness }; //# sourceMappingURL=testing.mjs.map