{"version":3,"file":"testing.mjs","sources":["../../../../../../../src/material/snack-bar/testing/snack-bar-harness.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, parallel} from '@angular/cdk/testing';\nimport {AriaLivePoliteness} from '@angular/cdk/a11y';\nimport {SnackBarHarnessFilters} from './snack-bar-harness-filters';\n\nexport abstract class _MatSnackBarHarnessBase extends ContentContainerComponentHarness {\n protected abstract _messageSelector: string;\n protected abstract _actionButtonSelector: string;\n\n private _snackBarLiveRegion = this.locatorFor('[aria-live]');\n\n /**\n * Gets the role of the snack-bar. The role of a snack-bar is determined based\n * on the ARIA politeness specified in the snack-bar config.\n * @deprecated Use `getAriaLive` instead.\n * @breaking-change 13.0.0\n */\n async getRole(): Promise<'alert' | 'status' | null> {\n return (await this.host()).getAttribute('role') as Promise<'alert' | 'status' | null>;\n }\n\n /**\n * Gets the aria-live of the snack-bar's live region. The aria-live of a snack-bar is\n * determined based on the ARIA politeness specified in the snack-bar config.\n */\n async getAriaLive(): Promise {\n return (await this._snackBarLiveRegion()).getAttribute(\n 'aria-live',\n ) as Promise;\n }\n\n /**\n * Whether the snack-bar has an action. Method cannot be used for snack-bar's with custom content.\n */\n async hasAction(): Promise {\n await this._assertContentAnnotated();\n return (await this._getActionButton()) !== null;\n }\n\n /**\n * Gets the description of the snack-bar. Method cannot be used for snack-bar's without action or\n * with custom content.\n */\n async getActionDescription(): Promise {\n await this._assertHasAction();\n return (await this._getActionButton())!.text();\n }\n\n /**\n * Dismisses the snack-bar by clicking the action button. Method cannot be used for snack-bar's\n * without action or with custom content.\n */\n async dismissWithAction(): Promise {\n await this._assertHasAction();\n await (await this._getActionButton())!.click();\n }\n\n /**\n * Gets the message of the snack-bar. Method cannot be used for snack-bar's with custom content.\n */\n async getMessage(): Promise {\n await this._assertContentAnnotated();\n return (await this.locatorFor(this._messageSelector)()).text();\n }\n\n /** Gets whether the snack-bar has been dismissed. */\n async isDismissed(): Promise {\n // We consider the snackbar dismissed if it's not in the DOM. We can assert that the\n // element isn't in the DOM by seeing that its width and height are zero.\n\n const host = await this.host();\n const [exit, dimensions] = await parallel(() => [\n // The snackbar container is marked with the \"exit\" attribute after it has been dismissed\n // but before the animation has finished (after which it's removed from the DOM).\n host.getAttribute('mat-exit'),\n host.getDimensions(),\n ]);\n\n return exit != null || (!!dimensions && dimensions.height === 0 && dimensions.width === 0);\n }\n\n /**\n * Asserts that the current snack-bar has annotated content. Promise reject\n * if content is not annotated.\n */\n protected abstract _assertContentAnnotated(): Promise;\n\n /**\n * Asserts that the current snack-bar has an action defined. Otherwise the\n * promise will reject.\n */\n protected async _assertHasAction(): Promise {\n await this._assertContentAnnotated();\n if (!(await this.hasAction())) {\n throw Error('Method cannot be used for a snack-bar without an action.');\n }\n }\n\n /** Gets the simple snack bar action button. */\n private async _getActionButton() {\n return this.locatorForOptional(this._actionButtonSelector)();\n }\n}\n\n/** Harness for interacting with an MDC-based mat-snack-bar in tests. */\nexport class MatSnackBarHarness extends _MatSnackBarHarnessBase {\n // Developers can provide a custom component or template for the\n // snackbar. The canonical snack-bar parent is the \"MatSnackBarContainer\".\n /** The selector for the host element of a `MatSnackBar` instance. */\n static hostSelector = '.mat-mdc-snack-bar-container:not([mat-exit])';\n protected override _messageSelector = '.mdc-snackbar__label';\n protected override _actionButtonSelector = '.mat-mdc-snack-bar-action';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatSnackBarHarness` that meets\n * certain criteria.\n * @param options Options for filtering which snack bar instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: SnackBarHarnessFilters = {}): HarnessPredicate {\n return new HarnessPredicate(MatSnackBarHarness, options);\n }\n\n /**\n * Asserts that the current snack-bar has annotated content. Promise reject\n * if content is not annotated.\n */\n protected override async _assertContentAnnotated() {}\n}\n"],"names":[],"mappings":";;AAYM,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