@angular/material
Version:
Angular Material
1 lines • 11.5 kB
Source Map (JSON)
{"version":3,"file":"dialog-testing.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/dialog/testing/dialog-harness.ts","../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/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 {Subscription} from 'rxjs';\nimport {AnimationsConfig, MATERIAL_ANIMATIONS} from '@angular/material/core';\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 const config = {...(MatTestDialogOpener.config || {})};\n config.enterAnimationDuration = 0;\n config.exitAnimationDuration = 0;\n return this.dialog.open<T, R>(MatTestDialogOpener.component as ComponentType<T>, config);\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, MatTestDialogOpener],\n providers: [\n {\n provide: MATERIAL_ANIMATIONS,\n useValue: {\n animationsDisabled: true,\n } as AnimationsConfig,\n },\n ],\n})\nexport class MatTestDialogOpenerModule {}\n"],"names":["MatDialogSection","MatDialogHarness","ContentContainerComponentHarness","hostSelector","with","options","HarnessPredicate","_title","locatorForOptional","TITLE","_content","CONTENT","_actions","ACTIONS","getId","id","host","getAttribute","getRole","getAriaLabel","getAriaLabelledby","getAriaDescribedby","close","sendKeys","TestKey","ESCAPE","getText","text","getTitleText","getContentText","getActionsText","MatTestDialogOpener","dialog","inject","MatDialog","component","config","dialogRef","closedResult","_afterClosedSubscription","_ngZone","NgZone","withComponent","MatTestDialogOpener_1","constructor","Error","run","enterAnimationDuration","exitAnimationDuration","open","afterClosed","subscribe","result","ngOnDestroy","unsubscribe","undefined","__decorate","Component","selector","template","changeDetection","ChangeDetectionStrategy","OnPush","encapsulation","ViewEncapsulation","None","MatTestDialogOpenerModule","NgModule","imports","MatDialogModule","providers","provide","MATERIAL_ANIMATIONS","useValue","animationsDisabled"],"mappings":";;;;;;;;;;;;;;;;;;IAkBYA;AAAZ,CAAA,UAAYA,gBAAgB,EAAA;AAC1BA,EAAAA,gBAAA,CAAA,OAAA,CAAA,GAAA,uBAA+B;AAC/BA,EAAAA,gBAAA,CAAA,SAAA,CAAA,GAAA,yBAAmC;AACnCA,EAAAA,gBAAA,CAAA,SAAA,CAAA,GAAA,yBAAmC;AACrC,CAAC,EAJWA,gBAAgB,KAAhBA,gBAAgB,GAI3B,EAAA,CAAA,CAAA;MAGYC,gBAAgB,SAEnBC,gCAA2D,CAAA;EAGnE,OAAOC,YAAY,GAAG,2BAA2B;AAOjD,EAAA,OAAOC,IAAIA,CAETC,OAAA,GAAgC,EAAE,EAAA;AAElC,IAAA,OAAO,IAAIC,gBAAgB,CAAC,IAAI,EAAED,OAAO,CAAC;AAC5C;EAEUE,MAAM,GAAG,IAAI,CAACC,kBAAkB,CAACR,gBAAgB,CAACS,KAAK,CAAC;EACxDC,QAAQ,GAAG,IAAI,CAACF,kBAAkB,CAACR,gBAAgB,CAACW,OAAO,CAAC;EAC5DC,QAAQ,GAAG,IAAI,CAACJ,kBAAkB,CAACR,gBAAgB,CAACa,OAAO,CAAC;EAGtE,MAAMC,KAAKA,GAAA;AACT,IAAA,MAAMC,EAAE,GAAG,MAAM,CA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