/** * @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 */ import { ContentContainerComponentHarness, HarnessPredicate, TestKey, } from '@angular/cdk/testing'; /** Base class for the `MatDialogHarness` implementation. */ export class _MatDialogHarnessBase // @breaking-change 14.0.0 change generic type to MatDialogSection. extends ContentContainerComponentHarness { constructor() { super(...arguments); this._title = this.locatorForOptional(".mat-mdc-dialog-title" /* MatDialogSection.TITLE */); this._content = this.locatorForOptional(".mat-mdc-dialog-content" /* MatDialogSection.CONTENT */); this._actions = this.locatorForOptional(".mat-mdc-dialog-actions" /* MatDialogSection.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. */ export class MatDialogHarness extends _MatDialogHarnessBase { /** The selector for the host element of a `MatDialog` instance. */ static { this.hostSelector = '.mat-mdc-dialog-container'; } /** * Gets a `HarnessPredicate` that can be used to search for a dialog with specific attributes. * @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(this, options); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGlhbG9nLWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvZGlhbG9nL3Rlc3RpbmcvZGlhbG9nLWhhcm5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUVMLGdDQUFnQyxFQUNoQyxnQkFBZ0IsRUFDaEIsT0FBTyxHQUNSLE1BQU0sc0JBQXNCLENBQUM7QUFXOUIsNERBQTREO0FBQzVELE1BQU0sT0FBTyxxQkFBcUI7QUFDaEMsbUVBQW1FO0FBQ25FLFNBQVEsZ0NBQTJEO0lBRnJFOztRQUlZLFdBQU0sR0FBRyxJQUFJLENBQUMsa0JBQWtCLHNEQUF3QixDQUFDO1FBQ3pELGFBQVEsR0FBRyxJQUFJLENBQUMsa0JBQWtCLDBEQUEwQixDQUFDO1FBQzdELGFBQVEsR0FBRyxJQUFJLENBQUMsa0JBQWtCLDBEQUEwQixDQUFDO0lBMER6RSxDQUFDO0lBeERDLGlDQUFpQztJQUNqQyxLQUFLLENBQUMsS0FBSztRQUNULE1BQU0sRUFBRSxHQUFHLE1BQU0sQ0FBQyxNQUFNLElBQUksQ0FBQyxJQUFJLEVBQUUsQ0FBQyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUN4RCxxRUFBcUU7UUFDckUsc0VBQXNFO1FBQ3RFLE9BQU8sRUFBRSxLQUFLLEVBQUUsQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLENBQUMsQ0FBQ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