UNPKG

11.7 kBSource Map (JSON)View Raw
1{"version":3,"file":"testing.mjs","sources":["../../../../../../../src/material/dialog/testing/dialog-harness.ts","../../../../../../../src/material/dialog/testing/dialog-opener.ts","../../../../../../../src/material/dialog/testing/public-api.ts","../../../../../../../src/material/dialog/testing/index.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 {ContentContainerComponentHarness, HarnessPredicate, TestKey} from '@angular/cdk/testing';\nimport {DialogRole} from '@angular/material/dialog';\nimport {DialogHarnessFilters} from './dialog-harness-filters';\n\n/** Selectors for different sections of the mat-dialog that can contain user content. */\nexport const enum MatDialogSection {\n TITLE = '.mat-dialog-title',\n CONTENT = '.mat-dialog-content',\n ACTIONS = '.mat-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<MatDialogSection | string>\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<string | null> {\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<DialogRole | null> {\n return (await this.host()).getAttribute('role') as Promise<DialogRole | null>;\n }\n\n /** Gets the value of the dialog's \"aria-label\" attribute. */\n async getAriaLabel(): Promise<string | null> {\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<string | null> {\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<string | null> {\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<void> {\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 // Developers can provide a custom component or template for the\n // dialog. The canonical dialog parent is the \"MatDialogContainer\".\n /** The selector for the host element of a `MatDialog` instance. */\n static hostSelector = '.mat-dialog-container';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatDialogHarness` that meets\n * certain criteria.\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(options: DialogHarnessFilters = {}): HarnessPredicate<MatDialogHarness> {\n return new HarnessPredicate(MatDialogHarness, 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 Directive,\n Component,\n NgModule,\n OnDestroy,\n ViewEncapsulation,\n} from '@angular/core';\nimport {\n _MatDialogBase,\n _MatDialogContainerBase,\n MatDialog,\n MatDialogConfig,\n MatDialogContainer,\n MatDialogModule,\n MatDialogRef,\n} from '@angular/material/dialog';\nimport {Subscription} from 'rxjs';\nimport {NoopAnimationsModule} from '@angular/platform-browser/animations';\n\n/** Base class for a component that immediately opens a dialog when created. */\n@Directive()\nexport class _MatTestDialogOpenerBase<C extends _MatDialogContainerBase, T, R>\n implements OnDestroy\n{\n /** Component that should be opened with the MatDialog `open` method. */\n protected static component: ComponentType<unknown> | 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<T, R>;\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<C>) {\n if (!_MatTestDialogOpenerBase.component) {\n throw new Error(`MatTestDialogOpener does not have a component provided.`);\n }\n\n this.dialogRef = this.dialog.open<T, R>(\n _MatTestDialogOpenerBase.component as ComponentType<T>,\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 created. */\n@Component({\n selector: 'mat-test-dialog-opener',\n template: '',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n})\nexport class MatTestDialogOpener<T = unknown, R = unknown> 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<T = unknown, R = unknown>(\n component: ComponentType<T>,\n config?: MatDialogConfig,\n ) {\n _MatTestDialogOpenerBase.component = component;\n _MatTestDialogOpenerBase.config = config;\n return MatTestDialogOpener as ComponentType<MatTestDialogOpener<T, R>>;\n }\n}\n\n@NgModule({\n declarations: [MatTestDialogOpener],\n imports: [MatDialogModule, NoopAnimationsModule],\n})\nexport class MatTestDialogOpenerModule {}\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\nexport * from './dialog-harness';\nexport * from './dialog-harness-filters';\nexport * from './dialog-opener';\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\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAmBA;MACa,qBAAqB;AAChC;AACA,SAAQ,gCAA2D,CAAA;AAFrE,IAAA,WAAA,GAAA;;QAIY,IAAA,CAAA,MAAM,GAAG,IAAI,CAAC,kBAAkB,kDAAwB,CAAC;QACzD,IAAA,CAAA,QAAQ,GAAG,IAAI,CAAC,kBAAkB,sDAA0B,CAAC;QAC7D,IAAA,CAAA,QAAQ,GAAG,IAAI,CAAC,kBAAkB,sDAA0B,CAAC;KA0DxE;;IAvDO,KAAK,GAAA;;AACT,YAAA,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;;;YAGxD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;SAC9B,CAAA,CAAA;AAAA,KAAA;;IAGK,OAAO,GAAA;;AACX,YAAA,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,YAAY,CAAC,MAAM,CAA+B,CAAC;SAC/E,CAAA,CAAA;AAAA,KAAA;;IAGK,YAAY,GAAA;;AAChB,YAAA,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;SACvD,CAAA,CAAA;AAAA,KAAA;;IAGK,iBAAiB,GAAA;;AACrB,YAAA,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC;SAC5D,CAAA,CAAA;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