@angular/material
Version:
Angular Material
78 lines (72 loc) • 2.7 kB
JavaScript
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. */
class MatButtonHarness extends ContentContainerComponentHarness {
/**
* Gets a `HarnessPredicate` that can be used to search for a `MatButtonHarness` 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(MatButtonHarness, options).addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
}
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();
}
}
// TODO(jelbourn) use a single class, like `.mat-button-base`
/** The selector for the host element of a `MatButton` instance. */
MatButtonHarness.hostSelector = `[mat-button], [mat-raised-button], [mat-flat-button], [mat-icon-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
*/
/**
* @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