@angular/material
Version:
Angular Material
111 lines (105 loc) • 4.18 kB
JavaScript
import { ContentContainerComponentHarness, TestKey, 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
*/
/** Base class for the `MatDialogHarness` implementation. */
class _MatDialogHarnessBase extends
// @breaking-change 14.0.0 change generic type to MatDialogSection.
ContentContainerComponentHarness {
constructor() {
super(...arguments);
this._title = this.locatorForOptional(".mat-dialog-title" /* TITLE */);
this._content = this.locatorForOptional(".mat-dialog-content" /* CONTENT */);
this._actions = this.locatorForOptional(".mat-dialog-actions" /* ACTIONS */);
}
/** Gets the id of the dialog. */
async getId() {
const id = await (await this.host()).getAttribute('id');
// In case no id has been specified, the "id" property always returns
// an empty string. To make this method more explicit, we return null.
return id !== '' ? id : null;
}
/** Gets the role of the dialog. */
async getRole() {
return (await this.host()).getAttribute('role');
}
/** Gets the value of the dialog's "aria-label" attribute. */
async getAriaLabel() {
return (await this.host()).getAttribute('aria-label');
}
/** Gets the value of the dialog's "aria-labelledby" attribute. */
async getAriaLabelledby() {
return (await this.host()).getAttribute('aria-labelledby');
}
/** Gets the value of the dialog's "aria-describedby" attribute. */
async getAriaDescribedby() {
return (await this.host()).getAttribute('aria-describedby');
}
/**
* Closes the dialog by pressing escape.
*
* Note: this method does nothing if `disableClose` has been set to `true` for the dialog.
*/
async close() {
await (await this.host()).sendKeys(TestKey.ESCAPE);
}
/** Gets te dialog's text. */
async getText() {
return (await this.host()).text();
}
/** Gets the dialog's title text. This only works if the dialog is using mat-dialog-title. */
async getTitleText() {
return (await this._title())?.text() ?? '';
}
/** Gets the dialog's content text. This only works if the dialog is using mat-dialog-content. */
async getContentText() {
return (await this._content())?.text() ?? '';
}
/** Gets the dialog's actions text. This only works if the dialog is using mat-dialog-actions. */
async getActionsText() {
return (await this._actions())?.text() ?? '';
}
}
/** Harness for interacting with a standard `MatDialog` in tests. */
class MatDialogHarness extends _MatDialogHarnessBase {
/**
* Gets a `HarnessPredicate` that can be used to search for a `MatDialogHarness` that meets
* certain criteria.
* @param options Options for filtering which dialog instances are considered a match.
* @return a `HarnessPredicate` configured with the given options.
*/
static with(options = {}) {
return new HarnessPredicate(MatDialogHarness, options);
}
}
// Developers can provide a custom component or template for the
// dialog. The canonical dialog parent is the "MatDialogContainer".
/** The selector for the host element of a `MatDialog` instance. */
MatDialogHarness.hostSelector = '.mat-dialog-container';
/**
* @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 { MatDialogHarness, _MatDialogHarnessBase };
//# sourceMappingURL=testing.mjs.map