{"version":3,"file":"testing.mjs","sources":["../../../../../../../src/material/select/testing/select-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 {\n BaseHarnessFilters,\n ComponentHarness,\n ComponentHarnessConstructor,\n HarnessPredicate,\n parallel,\n} from '@angular/cdk/testing';\nimport {\n MatOptionHarness,\n MatOptgroupHarness,\n OptionHarnessFilters,\n OptgroupHarnessFilters,\n} from '@angular/material/core/testing';\nimport {MatFormFieldControlHarness} from '@angular/material/form-field/testing/control';\nimport {SelectHarnessFilters} from './select-harness-filters';\n\nexport abstract class _MatSelectHarnessBase<\n OptionType extends ComponentHarnessConstructor & {\n with: (options?: OptionFilters) => HarnessPredicate ;\n },\n Option extends ComponentHarness & {click(): Promise},\n OptionFilters extends BaseHarnessFilters,\n OptionGroupType extends ComponentHarnessConstructor & {\n with: (options?: OptionGroupFilters) => HarnessPredicate;\n },\n OptionGroup extends ComponentHarness,\n OptionGroupFilters extends BaseHarnessFilters,\n> extends MatFormFieldControlHarness {\n protected abstract _prefix: string;\n protected abstract _optionClass: OptionType;\n protected abstract _optionGroupClass: OptionGroupType;\n private _documentRootLocator = this.documentRootLocatorFactory();\n private _backdrop = this._documentRootLocator.locatorFor('.cdk-overlay-backdrop');\n\n /** Gets a boolean promise indicating if the select is disabled. */\n async isDisabled(): Promise {\n return (await this.host()).hasClass(`${this._prefix}-select-disabled`);\n }\n\n /** Gets a boolean promise indicating if the select is valid. */\n async isValid(): Promise {\n return !(await (await this.host()).hasClass('ng-invalid'));\n }\n\n /** Gets a boolean promise indicating if the select is required. */\n async isRequired(): Promise {\n return (await this.host()).hasClass(`${this._prefix}-select-required`);\n }\n\n /** Gets a boolean promise indicating if the select is empty (no value is selected). */\n async isEmpty(): Promise {\n return (await this.host()).hasClass(`${this._prefix}-select-empty`);\n }\n\n /** Gets a boolean promise indicating if the select is in multi-selection mode. */\n async isMultiple(): Promise {\n return (await this.host()).hasClass(`${this._prefix}-select-multiple`);\n }\n\n /** Gets a promise for the select's value text. */\n async getValueText(): Promise {\n const value = await this.locatorFor(`.${this._prefix}-select-value`)();\n return value.text();\n }\n\n /** Focuses the select and returns a void promise that indicates when the action is complete. */\n async focus(): Promise {\n return (await this.host()).focus();\n }\n\n /** Blurs the select and returns a void promise that indicates when the action is complete. */\n async blur(): Promise {\n return (await this.host()).blur();\n }\n\n /** Whether the select is focused. */\n async isFocused(): Promise {\n return (await this.host()).isFocused();\n }\n\n /** Gets the options inside the select panel. */\n async getOptions(filter?: Omit): Promise {\n return this._documentRootLocator.locatorForAll(\n this._optionClass.with({\n ...(filter || {}),\n ancestor: await this._getPanelSelector(),\n } as OptionFilters),\n )();\n }\n\n /** Gets the groups of options inside the panel. */\n async getOptionGroups(filter?: Omit): Promise {\n return this._documentRootLocator.locatorForAll(\n this._optionGroupClass.with({\n ...(filter || {}),\n ancestor: await this._getPanelSelector(),\n } as OptionGroupFilters),\n )() as Promise;\n }\n\n /** Gets whether the select is open. */\n async isOpen(): Promise {\n return !!(await this._documentRootLocator.locatorForOptional(await this._getPanelSelector())());\n }\n\n /** Opens the select's panel. */\n async open(): Promise {\n if (!(await this.isOpen())) {\n const trigger = await this.locatorFor(`.${this._prefix}-select-trigger`)();\n return trigger.click();\n }\n }\n\n /**\n * Clicks the options that match the passed-in filter. If the select is in multi-selection\n * mode all options will be clicked, otherwise the harness will pick the first matching option.\n */\n async clickOptions(filter?: OptionFilters): Promise {\n await this.open();\n\n const [isMultiple, options] = await parallel(() => [\n this.isMultiple(),\n this.getOptions(filter),\n ]);\n\n if (options.length === 0) {\n throw Error('Select does not have options matching the specified filter');\n }\n\n if (isMultiple) {\n await parallel(() => options.map(option => option.click()));\n } else {\n await options[0].click();\n }\n }\n\n /** Closes the select's panel. */\n async close(): Promise {\n if (await this.isOpen()) {\n // This is the most consistent way that works both in both single and multi-select modes,\n // but it assumes that only one overlay is open at a time. We should be able to make it\n // a bit more precise after #16645 where we can dispatch an ESCAPE press to the host instead.\n return (await this._backdrop()).click();\n }\n }\n\n /** Gets the selector that should be used to find this select's panel. */\n private async _getPanelSelector(): Promise {\n const id = await (await this.host()).getAttribute('id');\n return `#${id}-panel`;\n }\n}\n\n/** Harness for interacting with an MDC-based mat-select in tests. */\nexport class MatSelectHarness extends _MatSelectHarnessBase<\n typeof MatOptionHarness,\n MatOptionHarness,\n OptionHarnessFilters,\n typeof MatOptgroupHarness,\n MatOptgroupHarness,\n OptgroupHarnessFilters\n> {\n static hostSelector = '.mat-mdc-select';\n protected _prefix = 'mat-mdc';\n protected _optionClass = MatOptionHarness;\n protected _optionGroupClass = MatOptgroupHarness;\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a select with specific attributes.\n * @param options Options for filtering which select instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(\n this: ComponentHarnessConstructor,\n options: SelectHarnessFilters = {},\n ): HarnessPredicate {\n return new HarnessPredicate(this, options).addOption(\n 'disabled',\n options.disabled,\n async (harness, disabled) => {\n return (await harness.isDisabled()) === disabled;\n },\n );\n }\n}\n"],"names":[],"mappings":";;;;AAwBM,MAAgB,qBAWpB,SAAQ,0BAA0B,CAAA;AAXpC,IAAA,WAAA,GAAA;;AAeU,QAAA,IAAA,CAAA,oBAAoB,GAAG,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACzD,IAAS,CAAA,SAAA,GAAG,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC;KAuHnF;;AApHC,IAAA,MAAM,UAAU,GAAA;AACd,QAAA,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA,gBAAA,CAAkB,CAAC,CAAC;KACxE;;AAGD,IAAA,MAAM,OAAO,GAAA;AACX,QAAA,OAAO,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAA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