@angular/material
Version:
Angular Material
139 lines (131 loc) • 5.09 kB
JavaScript
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
*/
/**
* Harness for interacting with a `mat-option` in tests.
* @deprecated Use `MatOptionHarness` from `@angular/material/core/testing` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
* @breaking-change 17.0.0
*/
class MatLegacyOptionHarness extends ComponentHarness {
constructor() {
super(...arguments);
/** Element containing the option's text. */
this._text = this.locatorFor('.mat-option-text');
}
/**
* Gets a `HarnessPredicate` that can be used to search for a `MatOptionsHarness` that meets
* certain criteria.
* @param options Options for filtering which option instances are considered a match.
* @return a `HarnessPredicate` configured with the given options.
*/
static with(options = {}) {
return new HarnessPredicate(MatLegacyOptionHarness, options)
.addOption('text', options.text, async (harness, title) => HarnessPredicate.stringMatches(await harness.getText(), title))
.addOption('isSelected', options.isSelected, async (harness, isSelected) => (await harness.isSelected()) === isSelected);
}
/** Clicks the option. */
async click() {
return (await this.host()).click();
}
/** Gets the option's label text. */
async getText() {
return (await this._text()).text();
}
/** Gets whether the option is disabled. */
async isDisabled() {
return (await this.host()).hasClass('mat-option-disabled');
}
/** Gets whether the option is selected. */
async isSelected() {
return (await this.host()).hasClass('mat-selected');
}
/** Gets whether the option is active. */
async isActive() {
return (await this.host()).hasClass('mat-active');
}
/** Gets whether the option is in multiple selection mode. */
async isMultiple() {
return (await this.host()).hasClass('mat-option-multiple');
}
}
/** Selector used to locate option instances. */
MatLegacyOptionHarness.hostSelector = '.mat-option';
/**
* @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 `mat-optgroup` in tests.
* @deprecated Use `MatOptgroupHarness` from `@angular/material/core/testing` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
* @breaking-change 17.0.0
*/
class MatLegacyOptgroupHarness extends ComponentHarness {
constructor() {
super(...arguments);
this._label = this.locatorFor('.mat-optgroup-label');
}
/**
* Gets a `HarnessPredicate` that can be used to search for a `MatOptgroupHarness` that meets
* certain criteria.
* @param options Options for filtering which option instances are considered a match.
* @return a `HarnessPredicate` configured with the given options.
*/
static with(options = {}) {
return new HarnessPredicate(MatLegacyOptgroupHarness, options).addOption('labelText', options.labelText, async (harness, title) => HarnessPredicate.stringMatches(await harness.getLabelText(), title));
}
/** Gets the option group's label text. */
async getLabelText() {
return (await this._label()).text();
}
/** Gets whether the option group is disabled. */
async isDisabled() {
return (await this.host()).hasClass('mat-optgroup-disabled');
}
/**
* Gets the options that are inside the group.
* @param filter Optionally filters which options are included.
*/
async getOptions(filter = {}) {
return this.locatorForAll(MatLegacyOptionHarness.with(filter))();
}
}
/** Selector used to locate option group instances. */
MatLegacyOptgroupHarness.hostSelector = '.mat-optgroup';
/**
* @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 { MatLegacyOptgroupHarness, MatLegacyOptionHarness };
//# sourceMappingURL=testing.mjs.map