@angular/material
Version:
Angular Material
293 lines (286 loc) • 14.2 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('tslib'), require('@angular/cdk/coercion'), require('@angular/cdk/testing')) :
typeof define === 'function' && define.amd ? define('@angular/material/checkbox/testing', ['exports', 'tslib', '@angular/cdk/coercion', '@angular/cdk/testing'], factory) :
(global = global || self, factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.checkbox = global.ng.material.checkbox || {}, global.ng.material.checkbox.testing = {}), global.tslib, global.ng.cdk.coercion, global.ng.cdk.testing));
}(this, (function (exports, tslib, coercion, testing) { 'use strict';
/**
* @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-checkbox in tests. */
var MatCheckboxHarness = /** @class */ (function (_super) {
tslib.__extends(MatCheckboxHarness, _super);
function MatCheckboxHarness() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._label = _this.locatorFor('.mat-checkbox-label');
_this._input = _this.locatorFor('input');
_this._inputContainer = _this.locatorFor('.mat-checkbox-inner-container');
return _this;
}
/**
* Gets a `HarnessPredicate` that can be used to search for a `MatCheckboxHarness` that meets
* certain criteria.
* @param options Options for filtering which checkbox instances are considered a match.
* @return a `HarnessPredicate` configured with the given options.
*/
MatCheckboxHarness.with = function (options) {
var _this = this;
if (options === void 0) { options = {}; }
return new testing.HarnessPredicate(MatCheckboxHarness, options)
.addOption('label', options.label, function (harness, label) { return testing.HarnessPredicate.stringMatches(harness.getLabelText(), label); })
// We want to provide a filter option for "name" because the name of the checkbox is
// only set on the underlying input. This means that it's not possible for developers
// to retrieve the harness of a specific checkbox with name through a CSS selector.
.addOption('name', options.name, function (harness, name) { return tslib.__awaiter(_this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, harness.getName()];
case 1: return [2 /*return*/, (_a.sent()) === name];
}
}); }); });
};
/** Whether the checkbox is checked. */
MatCheckboxHarness.prototype.isChecked = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
var checked, _a;
return tslib.__generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this._input()];
case 1:
checked = (_b.sent()).getProperty('checked');
_a = coercion.coerceBooleanProperty;
return [4 /*yield*/, checked];
case 2: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
}
});
});
};
/** Whether the checkbox is in an indeterminate state. */
MatCheckboxHarness.prototype.isIndeterminate = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
var indeterminate, _a;
return tslib.__generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this._input()];
case 1:
indeterminate = (_b.sent()).getProperty('indeterminate');
_a = coercion.coerceBooleanProperty;
return [4 /*yield*/, indeterminate];
case 2: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
}
});
});
};
/** Whether the checkbox is disabled. */
MatCheckboxHarness.prototype.isDisabled = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
var disabled, _a;
return tslib.__generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this._input()];
case 1:
disabled = (_b.sent()).getAttribute('disabled');
_a = coercion.coerceBooleanProperty;
return [4 /*yield*/, disabled];
case 2: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
}
});
});
};
/** Whether the checkbox is required. */
MatCheckboxHarness.prototype.isRequired = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
var required, _a;
return tslib.__generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this._input()];
case 1:
required = (_b.sent()).getProperty('required');
_a = coercion.coerceBooleanProperty;
return [4 /*yield*/, required];
case 2: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
}
});
});
};
/** Whether the checkbox is valid. */
MatCheckboxHarness.prototype.isValid = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
var invalid;
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.host()];
case 1:
invalid = (_a.sent()).hasClass('ng-invalid');
return [4 /*yield*/, invalid];
case 2: return [2 /*return*/, !(_a.sent())];
}
});
});
};
/** Gets the checkbox's name. */
MatCheckboxHarness.prototype.getName = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._input()];
case 1: return [2 /*return*/, (_a.sent()).getAttribute('name')];
}
});
});
};
/** Gets the checkbox's value. */
MatCheckboxHarness.prototype.getValue = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._input()];
case 1: return [2 /*return*/, (_a.sent()).getProperty('value')];
}
});
});
};
/** Gets the checkbox's aria-label. */
MatCheckboxHarness.prototype.getAriaLabel = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._input()];
case 1: return [2 /*return*/, (_a.sent()).getAttribute('aria-label')];
}
});
});
};
/** Gets the checkbox's aria-labelledby. */
MatCheckboxHarness.prototype.getAriaLabelledby = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._input()];
case 1: return [2 /*return*/, (_a.sent()).getAttribute('aria-labelledby')];
}
});
});
};
/** Gets the checkbox's label text. */
MatCheckboxHarness.prototype.getLabelText = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._label()];
case 1: return [2 /*return*/, (_a.sent()).text()];
}
});
});
};
/** Focuses the checkbox. */
MatCheckboxHarness.prototype.focus = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._input()];
case 1: return [2 /*return*/, (_a.sent()).focus()];
}
});
});
};
/** Blurs the checkbox. */
MatCheckboxHarness.prototype.blur = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._input()];
case 1: return [2 /*return*/, (_a.sent()).blur()];
}
});
});
};
/**
* Toggles the checked state of the checkbox.
*
* Note: This attempts to toggle the checkbox as a user would, by clicking it. Therefore if you
* are using `MAT_CHECKBOX_CLICK_ACTION` to change the behavior on click, calling this method
* might not have the expected result.
*/
MatCheckboxHarness.prototype.toggle = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._inputContainer()];
case 1: return [2 /*return*/, (_a.sent()).click()];
}
});
});
};
/**
* Puts the checkbox in a checked state by toggling it if it is currently unchecked, or doing
* nothing if it is already checked.
*
* Note: This attempts to check the checkbox as a user would, by clicking it. Therefore if you
* are using `MAT_CHECKBOX_CLICK_ACTION` to change the behavior on click, calling this method
* might not have the expected result.
*/
MatCheckboxHarness.prototype.check = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.isChecked()];
case 1:
if (!!(_a.sent())) return [3 /*break*/, 3];
return [4 /*yield*/, this.toggle()];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
};
/**
* Puts the checkbox in an unchecked state by toggling it if it is currently checked, or doing
* nothing if it is already unchecked.
*
* Note: This attempts to uncheck the checkbox as a user would, by clicking it. Therefore if you
* are using `MAT_CHECKBOX_CLICK_ACTION` to change the behavior on click, calling this method
* might not have the expected result.
*/
MatCheckboxHarness.prototype.uncheck = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.isChecked()];
case 1:
if (!_a.sent()) return [3 /*break*/, 3];
return [4 /*yield*/, this.toggle()];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
};
/** The selector for the host element of a `MatCheckbox` instance. */
MatCheckboxHarness.hostSelector = 'mat-checkbox';
return MatCheckboxHarness;
}(testing.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
*/
exports.MatCheckboxHarness = MatCheckboxHarness;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=material-checkbox-testing.umd.js.map