You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
183 lines
6.8 KiB
183 lines
6.8 KiB
import { __awaiter } from 'tslib';
|
|
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
|
import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
|
|
|
|
/**
|
|
* @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
|
|
*/
|
|
class _MatCheckboxHarnessBase extends ComponentHarness {
|
|
/** Whether the checkbox is checked. */
|
|
isChecked() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const checked = (yield this._input()).getProperty('checked');
|
|
return coerceBooleanProperty(yield checked);
|
|
});
|
|
}
|
|
/** Whether the checkbox is in an indeterminate state. */
|
|
isIndeterminate() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const indeterminate = (yield this._input()).getProperty('indeterminate');
|
|
return coerceBooleanProperty(yield indeterminate);
|
|
});
|
|
}
|
|
/** Whether the checkbox is disabled. */
|
|
isDisabled() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const disabled = (yield this._input()).getAttribute('disabled');
|
|
return coerceBooleanProperty(yield disabled);
|
|
});
|
|
}
|
|
/** Whether the checkbox is required. */
|
|
isRequired() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const required = (yield this._input()).getProperty('required');
|
|
return coerceBooleanProperty(yield required);
|
|
});
|
|
}
|
|
/** Whether the checkbox is valid. */
|
|
isValid() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const invalid = (yield this.host()).hasClass('ng-invalid');
|
|
return !(yield invalid);
|
|
});
|
|
}
|
|
/** Gets the checkbox's name. */
|
|
getName() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return (yield this._input()).getAttribute('name');
|
|
});
|
|
}
|
|
/** Gets the checkbox's value. */
|
|
getValue() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return (yield this._input()).getProperty('value');
|
|
});
|
|
}
|
|
/** Gets the checkbox's aria-label. */
|
|
getAriaLabel() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return (yield this._input()).getAttribute('aria-label');
|
|
});
|
|
}
|
|
/** Gets the checkbox's aria-labelledby. */
|
|
getAriaLabelledby() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return (yield this._input()).getAttribute('aria-labelledby');
|
|
});
|
|
}
|
|
/** Gets the checkbox's label text. */
|
|
getLabelText() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return (yield this._label()).text();
|
|
});
|
|
}
|
|
/** Focuses the checkbox. */
|
|
focus() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return (yield this._input()).focus();
|
|
});
|
|
}
|
|
/** Blurs the checkbox. */
|
|
blur() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return (yield this._input()).blur();
|
|
});
|
|
}
|
|
/** Whether the checkbox is focused. */
|
|
isFocused() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return (yield this._input()).isFocused();
|
|
});
|
|
}
|
|
/**
|
|
* 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_DEFAULT_OPTIONS` to change the behavior on click, calling this method
|
|
* might not have the expected result.
|
|
*/
|
|
check() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
if (!(yield this.isChecked())) {
|
|
yield this.toggle();
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* 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_DEFAULT_OPTIONS` to change the behavior on click, calling this method
|
|
* might not have the expected result.
|
|
*/
|
|
uncheck() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
if (yield this.isChecked()) {
|
|
yield this.toggle();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
/** Harness for interacting with a standard mat-checkbox in tests. */
|
|
class MatCheckboxHarness extends _MatCheckboxHarnessBase {
|
|
constructor() {
|
|
super(...arguments);
|
|
this._input = this.locatorFor('input');
|
|
this._label = this.locatorFor('.mat-checkbox-label');
|
|
this._inputContainer = this.locatorFor('.mat-checkbox-inner-container');
|
|
}
|
|
/**
|
|
* 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.
|
|
*/
|
|
static with(options = {}) {
|
|
return new HarnessPredicate(MatCheckboxHarness, options)
|
|
.addOption('label', options.label, (harness, label) => 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, (harness, name) => __awaiter(this, void 0, void 0, function* () { return (yield harness.getName()) === name; }));
|
|
}
|
|
toggle() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return (yield this._inputContainer()).click();
|
|
});
|
|
}
|
|
}
|
|
/** The selector for the host element of a `MatCheckbox` instance. */
|
|
MatCheckboxHarness.hostSelector = '.mat-checkbox';
|
|
|
|
/**
|
|
* @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 { MatCheckboxHarness, _MatCheckboxHarnessBase };
|
|
//# sourceMappingURL=testing.js.map
|