@angular/material
Version:
Angular Material
121 lines (116 loc) • 4.58 kB
JavaScript
import { __extends, __awaiter, __generator } from 'tslib';
import { HarnessPredicate, ComponentHarness } 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. */
var MatButtonHarness = /** @class */ (function (_super) {
__extends(MatButtonHarness, _super);
function MatButtonHarness() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* 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.
*/
MatButtonHarness.with = function (options) {
if (options === void 0) { options = {}; }
return new HarnessPredicate(MatButtonHarness, options)
.addOption('text', options.text, function (harness, text) { return HarnessPredicate.stringMatches(harness.getText(), text); });
};
/** Clicks the button. */
MatButtonHarness.prototype.click = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.host()];
case 1: return [2 /*return*/, (_a.sent()).click()];
}
});
});
};
/** Whether the button is disabled. */
MatButtonHarness.prototype.isDisabled = function () {
return __awaiter(this, void 0, void 0, function () {
var disabled, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this.host()];
case 1:
disabled = (_b.sent()).getAttribute('disabled');
_a = coerceBooleanProperty;
return [4 /*yield*/, disabled];
case 2: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
}
});
});
};
/** Gets the button's label text. */
MatButtonHarness.prototype.getText = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.host()];
case 1: return [2 /*return*/, (_a.sent()).text()];
}
});
});
};
/** Focuses the button. */
MatButtonHarness.prototype.focus = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.host()];
case 1: return [2 /*return*/, (_a.sent()).focus()];
}
});
});
};
/** Blurs the button. */
MatButtonHarness.prototype.blur = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.host()];
case 1: return [2 /*return*/, (_a.sent()).blur()];
}
});
});
};
// 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-stroked-button]',
'[mat-fab]',
'[mat-mini-fab]',
].join(',');
return MatButtonHarness;
}(ComponentHarness));
/**
* @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.js.map