UNPKG

@angular/material

Version:
177 lines (169 loc) 6.66 kB
import { ComponentHarness, 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-toggle in tests. */ class MatButtonToggleHarness extends ComponentHarness { constructor() { super(...arguments); this._label = this.locatorFor('.mat-button-toggle-label-content'); this._button = this.locatorFor('.mat-button-toggle-button'); } /** * Gets a `HarnessPredicate` that can be used to search for a `MatButtonToggleHarness` that meets * certain criteria. * @param options Options for filtering which button toggle instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(MatButtonToggleHarness, options) .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text)) .addOption('name', options.name, (harness, name) => HarnessPredicate.stringMatches(harness.getName(), name)) .addOption('checked', options.checked, async (harness, checked) => (await harness.isChecked()) === checked); } /** Gets a boolean promise indicating if the button toggle is checked. */ async isChecked() { const checked = (await this._button()).getAttribute('aria-pressed'); return coerceBooleanProperty(await checked); } /** Gets a boolean promise indicating if the button toggle is disabled. */ async isDisabled() { const disabled = (await this._button()).getAttribute('disabled'); return coerceBooleanProperty(await disabled); } /** Gets a promise for the button toggle's name. */ async getName() { return (await this._button()).getAttribute('name'); } /** Gets a promise for the button toggle's aria-label. */ async getAriaLabel() { return (await this._button()).getAttribute('aria-label'); } /** Gets a promise for the button toggles's aria-labelledby. */ async getAriaLabelledby() { return (await this._button()).getAttribute('aria-labelledby'); } /** Gets a promise for the button toggle's text. */ async getText() { return (await this._label()).text(); } /** Gets the appearance that the button toggle is using. */ async getAppearance() { const host = await this.host(); const className = 'mat-button-toggle-appearance-standard'; return (await host.hasClass(className)) ? 'standard' : 'legacy'; } /** Focuses the toggle. */ async focus() { return (await this._button()).focus(); } /** Blurs the toggle. */ async blur() { return (await this._button()).blur(); } /** Whether the toggle is focused. */ async isFocused() { return (await this._button()).isFocused(); } /** Toggle the checked state of the buttons toggle. */ async toggle() { return (await this._button()).click(); } /** * Puts the button toggle in a checked state by toggling it if it's * currently unchecked, or doing nothing if it is already checked. */ async check() { if (!(await this.isChecked())) { await this.toggle(); } } /** * Puts the button toggle in an unchecked state by toggling it if it's * currently checked, or doing nothing if it's already unchecked. */ async uncheck() { if (await this.isChecked()) { await this.toggle(); } } } /** The selector for the host element of a `MatButton` instance. */ MatButtonToggleHarness.hostSelector = '.mat-button-toggle'; /** * @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 */ /** Harness for interacting with a standard mat-button-toggle in tests. */ class MatButtonToggleGroupHarness extends ComponentHarness { /** * Gets a `HarnessPredicate` that can be used to search for a `MatButtonToggleGroupHarness` * that meets certain criteria. * @param options Options for filtering which button toggle instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(MatButtonToggleGroupHarness, options); } /** * Gets the button toggles that are inside the group. * @param filter Optionally filters which toggles are included. */ async getToggles(filter = {}) { return this.locatorForAll(MatButtonToggleHarness.with(filter))(); } /** Gets whether the button toggle group is disabled. */ async isDisabled() { return (await (await this.host()).getAttribute('aria-disabled')) === 'true'; } /** Gets whether the button toggle group is laid out vertically. */ async isVertical() { return (await this.host()).hasClass('mat-button-toggle-vertical'); } /** Gets the appearance that the group is using. */ async getAppearance() { const host = await this.host(); const className = 'mat-button-toggle-group-appearance-standard'; return (await host.hasClass(className)) ? 'standard' : 'legacy'; } } /** The selector for the host element of a `MatButton` instance. */ MatButtonToggleGroupHarness.hostSelector = '.mat-button-toggle-group'; /** * @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 */ /** * @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 { MatButtonToggleGroupHarness, MatButtonToggleHarness }; //# sourceMappingURL=testing.mjs.map