UNPKG

@angular/material

Version:
1 lines 10.2 kB
{"version":3,"file":"testing.mjs","sources":["../../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/src/material/dialog/testing/dialog-harness.ts","../../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/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.dev/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 '../../dialog';\n\n/** Selectors for different sections of the mat-dialog that can contain user content. */\nexport enum MatDialogSection {\n TITLE = '.mat-mdc-dialog-title',\n CONTENT = '.mat-mdc-dialog-content',\n ACTIONS = '.mat-mdc-dialog-actions',\n}\n\n/** Harness for interacting with a standard `MatDialog` in tests. */\nexport class MatDialogHarness\n // @breaking-change 14.0.0 change generic type to MatDialogSection.\n extends ContentContainerComponentHarness<MatDialogSection | string>\n{\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<T extends MatDialogHarness>(\n this: ComponentHarnessConstructor<T>,\n options: DialogHarnessFilters = {},\n ): HarnessPredicate<T> {\n return new HarnessPredicate(this, options);\n }\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 the 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 * @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.dev/license\n */\n\nimport {ComponentType} from '@angular/cdk/overlay';\nimport {\n ChangeDetectionStrategy,\n Component,\n NgModule,\n NgZone,\n OnDestroy,\n ViewEncapsulation,\n inject,\n} from '@angular/core';\nimport {MatDialog, MatDialogConfig, MatDialogModule, MatDialogRef} from '../../dialog';\nimport {NoopAnimationsModule} from '@angular/platform-browser/animations';\nimport {Subscription} from 'rxjs';\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<T = unknown, R = unknown> implements OnDestroy {\n dialog = inject(MatDialog);\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 private readonly _ngZone = inject(NgZone);\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 MatTestDialogOpener.component = component;\n MatTestDialogOpener.config = config;\n return MatTestDialogOpener as ComponentType<MatTestDialogOpener<T, R>>;\n }\n\n constructor(...args: unknown[]);\n\n constructor() {\n if (!MatTestDialogOpener.component) {\n throw new Error(`MatTestDialogOpener does not have a component provided.`);\n }\n\n this.dialogRef = this._ngZone.run(() =>\n this.dialog.open<T, R>(\n MatTestDialogOpener.component as ComponentType<T>,\n MatTestDialogOpener.config || {},\n ),\n );\n this._afterClosedSubscription = this.dialogRef.afterClosed().subscribe(result => {\n this.closedResult = result;\n });\n }\n\n ngOnDestroy() {\n this._afterClosedSubscription.unsubscribe();\n MatTestDialogOpener.component = undefined;\n MatTestDialogOpener.config = undefined;\n }\n}\n\n@NgModule({\n imports: [MatDialogModule, NoopAnimationsModule, MatTestDialogOpener],\n})\nexport class MatTestDialogOpenerModule {}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAiBA;IACY,iBAIX;AAJD,CAAA,UAAY,gBAAgB,EAAA;AAC1B,IAAA,gBAAA,CAAA,OAAA,CAAA,GAAA,uBAA+B,CAAA;AAC/B,IAAA,gBAAA,CAAA,SAAA,CAAA,GAAA,yBAAmC,CAAA;AACnC,IAAA,gBAAA,CAAA,SAAA,CAAA,GA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