UNPKG

@angular/material

Version:
104 lines (99 loc) 4.12 kB
import { __awaiter } from 'tslib'; import { ContentContainerComponentHarness, HarnessPredicate } from '@angular/cdk/testing'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; /** Harness for interacting with a MDC-based mat-button in tests. */ class MatButtonHarness extends ContentContainerComponentHarness { /** * Gets a `HarnessPredicate` that can be used to search for a button with specific attributes. * @param options Options for narrowing the search: * - `selector` finds a button whose host element matches the given selector. * - `text` finds a button with specific text content. * - `variant` finds buttons matching a specific variant. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options) .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text)) .addOption('variant', options.variant, (harness, variant) => HarnessPredicate.stringMatches(harness.getVariant(), variant)); } click(...args) { return __awaiter(this, void 0, void 0, function* () { return (yield this.host()).click(...args); }); } /** Gets a boolean promise indicating if the button is disabled. */ isDisabled() { return __awaiter(this, void 0, void 0, function* () { const disabled = (yield this.host()).getAttribute('disabled'); return coerceBooleanProperty(yield disabled); }); } /** Gets a promise for the button's label text. */ getText() { return __awaiter(this, void 0, void 0, function* () { return (yield this.host()).text(); }); } /** Focuses the button and returns a void promise that indicates when the action is complete. */ focus() { return __awaiter(this, void 0, void 0, function* () { return (yield this.host()).focus(); }); } /** Blurs the button and returns a void promise that indicates when the action is complete. */ blur() { return __awaiter(this, void 0, void 0, function* () { return (yield this.host()).blur(); }); } /** Whether the button is focused. */ isFocused() { return __awaiter(this, void 0, void 0, function* () { return (yield this.host()).isFocused(); }); } /** Gets the variant of the button. */ getVariant() { return __awaiter(this, void 0, void 0, function* () { const host = yield this.host(); if ((yield host.getAttribute('mat-raised-button')) != null) { return 'raised'; } else if ((yield host.getAttribute('mat-flat-button')) != null) { return 'flat'; } else if ((yield host.getAttribute('mat-icon-button')) != null) { return 'icon'; } else if ((yield host.getAttribute('mat-stroked-button')) != null) { return 'stroked'; } else if ((yield host.getAttribute('mat-fab')) != null) { return 'fab'; } else if ((yield host.getAttribute('mat-mini-fab')) != null) { return 'mini-fab'; } return 'basic'; }); } } // TODO(jelbourn) use a single class, like `.mat-button-base` MatButtonHarness.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 { MatButtonHarness }; //# sourceMappingURL=testing.mjs.map