{"version":3,"file":"testing.mjs","sources":["../../../../../../../src/material/dialog/testing/dialog-harness.ts","../../../../../../../src/material/dialog/testing/dialog-opener.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {\n ComponentHarnessConstructor,\n ContentContainerComponentHarness,\n HarnessPredicate,\n TestKey,\n} from '@angular/cdk/testing';\nimport {DialogHarnessFilters} from './dialog-harness-filters';\nimport {DialogRole} from '@angular/material/dialog';\n\n/** Selectors for different sections of the mat-dialog that can contain user content. */\nexport const enum MatDialogSection {\n TITLE = '.mat-mdc-dialog-title',\n CONTENT = '.mat-mdc-dialog-content',\n ACTIONS = '.mat-mdc-dialog-actions',\n}\n\n/** Base class for the `MatDialogHarness` implementation. */\nexport class _MatDialogHarnessBase\n // @breaking-change 14.0.0 change generic type to MatDialogSection.\n extends ContentContainerComponentHarness\n{\n protected _title = this.locatorForOptional(MatDialogSection.TITLE);\n protected _content = this.locatorForOptional(MatDialogSection.CONTENT);\n protected _actions = this.locatorForOptional(MatDialogSection.ACTIONS);\n\n /** Gets the id of the dialog. */\n async getId(): Promise {\n const id = await (await this.host()).getAttribute('id');\n // In case no id has been specified, the \"id\" property always returns\n // an empty string. To make this method more explicit, we return null.\n return id !== '' ? id : null;\n }\n\n /** Gets the role of the dialog. */\n async getRole(): Promise {\n return (await this.host()).getAttribute('role') as Promise;\n }\n\n /** Gets the value of the dialog's \"aria-label\" attribute. */\n async getAriaLabel(): Promise {\n return (await this.host()).getAttribute('aria-label');\n }\n\n /** Gets the value of the dialog's \"aria-labelledby\" attribute. */\n async getAriaLabelledby(): Promise {\n return (await this.host()).getAttribute('aria-labelledby');\n }\n\n /** Gets the value of the dialog's \"aria-describedby\" attribute. */\n async getAriaDescribedby(): Promise {\n return (await this.host()).getAttribute('aria-describedby');\n }\n\n /**\n * Closes the dialog by pressing escape.\n *\n * Note: this method does nothing if `disableClose` has been set to `true` for the dialog.\n */\n async close(): Promise {\n await (await this.host()).sendKeys(TestKey.ESCAPE);\n }\n\n /** Gets te dialog's text. */\n async getText() {\n return (await this.host()).text();\n }\n\n /** Gets the dialog's title text. This only works if the dialog is using mat-dialog-title. */\n async getTitleText() {\n return (await this._title())?.text() ?? '';\n }\n\n /** Gets the dialog's content text. This only works if the dialog is using mat-dialog-content. */\n async getContentText() {\n return (await this._content())?.text() ?? '';\n }\n\n /** Gets the dialog's actions text. This only works if the dialog is using mat-dialog-actions. */\n async getActionsText() {\n return (await this._actions())?.text() ?? '';\n }\n}\n\n/** Harness for interacting with a standard `MatDialog` in tests. */\nexport class MatDialogHarness extends _MatDialogHarnessBase {\n /** The selector for the host element of a `MatDialog` instance. */\n static hostSelector = '.mat-mdc-dialog-container';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a dialog with specific attributes.\n * @param options Options for filtering which dialog instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(\n this: ComponentHarnessConstructor,\n options: DialogHarnessFilters = {},\n ): HarnessPredicate {\n return new HarnessPredicate(this, options);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {ComponentType} from '@angular/cdk/overlay';\nimport {\n ChangeDetectionStrategy,\n Component,\n Directive,\n NgModule,\n OnDestroy,\n ViewEncapsulation,\n} from '@angular/core';\nimport {\n MatDialog,\n MatDialogConfig,\n MatDialogContainer,\n MatDialogModule,\n _MatDialogBase,\n _MatDialogContainerBase,\n MatDialogRef,\n} from '@angular/material/dialog';\nimport {NoopAnimationsModule} from '@angular/platform-browser/animations';\nimport {Subscription} from 'rxjs';\n\n/** Base class for a component that immediately opens a dialog when created. */\n@Directive()\nexport class _MatTestDialogOpenerBase\n implements OnDestroy\n{\n /** Component that should be opened with the MatDialog `open` method. */\n protected static component: ComponentType | undefined;\n\n /** Config that should be provided to the MatDialog `open` method. */\n protected static config: MatDialogConfig | undefined;\n\n /** MatDialogRef returned from the MatDialog `open` method. */\n dialogRef: MatDialogRef;\n\n /** Data passed to the `MatDialog` close method. */\n closedResult: R | undefined;\n\n private readonly _afterClosedSubscription: Subscription;\n\n constructor(public dialog: _MatDialogBase) {\n if (!_MatTestDialogOpenerBase.component) {\n throw new Error(`MatTestDialogOpener does not have a component provided.`);\n }\n\n this.dialogRef = this.dialog.open(\n _MatTestDialogOpenerBase.component as ComponentType,\n _MatTestDialogOpenerBase.config || {},\n );\n this._afterClosedSubscription = this.dialogRef.afterClosed().subscribe(result => {\n this.closedResult = result;\n });\n }\n\n ngOnDestroy() {\n this._afterClosedSubscription.unsubscribe();\n _MatTestDialogOpenerBase.component = undefined;\n _MatTestDialogOpenerBase.config = undefined;\n }\n}\n\n/** Test component that immediately opens a dialog when bootstrapped. */\n@Component({\n selector: 'mat-test-dialog-opener',\n template: '',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n})\nexport class MatTestDialogOpener extends _MatTestDialogOpenerBase<\n MatDialogContainer,\n T,\n R\n> {\n constructor(dialog: MatDialog) {\n super(dialog);\n }\n\n /** Static method that prepares this class to open the provided component. */\n static withComponent(\n component: ComponentType,\n config?: MatDialogConfig,\n ) {\n _MatTestDialogOpenerBase.component = component;\n _MatTestDialogOpenerBase.config = config;\n return MatTestDialogOpener as ComponentType>;\n }\n}\n\n@NgModule({\n declarations: [MatTestDialogOpener],\n imports: [MatDialogModule, NoopAnimationsModule],\n})\nexport class MatTestDialogOpenerModule {}\n"],"names":[],"mappings":";;;;;;AAwBA;MACa,qBAAqB;AAChC;AACA,SAAQ,gCAA2D,CAAA;AAFrE,IAAA,WAAA,GAAA;;AAIY,QAAA,IAAA,CAAA,MAAM,GAAG,IAAI,CAAC,kBAAkB,sDAAwB,CAAC;AACzD,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,CAAC,kBAAkB,0DAA0B,CAAC;AAC7D,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