{"version":3,"file":"autocomplete-testing.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/autocomplete/testing/autocomplete-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.dev/license\n */\n\nimport {coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {\n  ComponentHarness,\n  ComponentHarnessConstructor,\n  HarnessPredicate,\n  TestElement,\n} from '@angular/cdk/testing';\nimport {\n  MatOptgroupHarness,\n  MatOptionHarness,\n  OptgroupHarnessFilters,\n  OptionHarnessFilters,\n} from '../../core/testing';\nimport {AutocompleteHarnessFilters} from './autocomplete-harness-filters';\n\nexport class MatAutocompleteHarness extends ComponentHarness {\n  private _documentRootLocator = this.documentRootLocatorFactory();\n\n  /** The selector for the host element of a `MatAutocomplete` instance. */\n  static hostSelector = '.mat-mdc-autocomplete-trigger';\n\n  /**\n   * Gets a `HarnessPredicate` that can be used to search for an autocomplete with specific\n   * attributes.\n   * @param options Options for filtering which autocomplete instances are considered a match.\n   * @return a `HarnessPredicate` configured with the given options.\n   */\n  static with<T extends MatAutocompleteHarness>(\n    this: ComponentHarnessConstructor<T>,\n    options: AutocompleteHarnessFilters = {},\n  ): HarnessPredicate<T> {\n    return new HarnessPredicate(this, options)\n      .addOption('value', options.value, (harness, value) =>\n        HarnessPredicate.stringMatches(harness.getValue(), value),\n      )\n      .addOption('disabled', options.disabled, async (harness, disabled) => {\n        return (await harness.isDisabled()) === disabled;\n      });\n  }\n\n  /** Gets the value of the autocomplete input. */\n  async getValue(): Promise<string> {\n    return (await this.host()).getProperty<string>('value');\n  }\n\n  /** Whether the autocomplete input is disabled. */\n  async isDisabled(): Promise<boolean> {\n    const disabled = (await this.host()).getAttribute('disabled');\n    return coerceBooleanProperty(await disabled);\n  }\n\n  /** Focuses the autocomplete input. */\n  async focus(): Promise<void> {\n    return (await this.host()).focus();\n  }\n\n  /** Blurs the autocomplete input. */\n  async blur(): Promise<void> {\n    return (await this.host()).blur();\n  }\n\n  /** Whether the autocomplete input is focused. */\n  async isFocused(): Promise<boolean> {\n    return (await this.host()).isFocused();\n  }\n\n  /** Enters text into the autocomplete. */\n  async enterText(value: string): Promise<void> {\n    return (await this.host()).sendKeys(value);\n  }\n\n  /** Clears the input value. */\n  async clear(): Promise<void> {\n    return (await this.host()).clear();\n  }\n\n  /** Gets the options inside the autocomplete panel. */\n  async getOptions(filters?: Omit<OptionHarnessFilters, 'ancestor'>): Promise<MatOptionHarness[]> {\n    if (!(await this.isOpen())) {\n      throw new Error('Unable to retrieve options for autocomplete. Autocomplete panel is closed.');\n    }\n\n    return this._documentRootLocator.locatorForAll(\n      MatOptionHarness.with({\n        ...(filters || {}),\n        ancestor: await this._getPanelSelector(),\n      } as OptionHarnessFilters),\n    )();\n  }\n\n  /** Gets the option groups inside the autocomplete panel. */\n  async getOptionGroups(\n    filters?: Omit<OptgroupHarnessFilters, 'ancestor'>,\n  ): Promise<MatOptgroupHarness[]> {\n    if (!(await this.isOpen())) {\n      throw new Error(\n        'Unable to retrieve option groups for autocomplete. Autocomplete panel is closed.',\n      );\n    }\n\n    return this._documentRootLocator.locatorForAll(\n      MatOptgroupHarness.with({\n        ...(filters || {}),\n        ancestor: await this._getPanelSelector(),\n      } as OptgroupHarnessFilters),\n    )();\n  }\n\n  /** Selects the first option matching the given filters. */\n  async selectOption(filters: OptionHarnessFilters): Promise<void> {\n    await this.focus(); // Focus the input to make sure the autocomplete panel is shown.\n    const options = await this.getOptions(filters);\n    if (!options.length) {\n      throw Error(`Could not find a mat-option matching ${JSON.stringify(filters)}`);\n    }\n    await options[0].click();\n  }\n\n  /** Whether the autocomplete is open. */\n  async isOpen(): Promise<boolean> {\n    const panel = await this._getPanel();\n    return !!panel && (await panel.hasClass(`mat-mdc-autocomplete-visible`));\n  }\n\n  /** Gets the panel associated with this autocomplete trigger. */\n  private async _getPanel(): Promise<TestElement | null> {\n    // Technically this is static, but it needs to be in a\n    // function, because the autocomplete's panel ID can changed.\n    return this._documentRootLocator.locatorForOptional(await this._getPanelSelector())();\n  }\n\n  /** Gets the selector that can be used to find the autocomplete trigger's panel. */\n  protected async _getPanelSelector(): Promise<string> {\n    return `#${await (await this.host()).getAttribute('aria-controls')}`;\n  }\n}\n"],"names":["MatAutocompleteHarness","ComponentHarness","_documentRootLocator","documentRootLocatorFactory","hostSelector","with","options","HarnessPredicate","addOption","value","harness","stringMatches","getValue","disabled","isDisabled","host","getProperty","getAttribute","coerceBooleanProperty","focus","blur","isFocused","enterText","sendKeys","clear","getOptions","filters","isOpen","Error","locatorForAll","MatOptionHarness","ancestor","_getPanelSelector","getOptionGroups","MatOptgroupHarness","selectOption","length","JSON","stringify","click","panel","_getPanel","hasClass","locatorForOptional"],"mappings":";;;;;AAuBM,MAAOA,sBAAuB,SAAQC,gBAAgB,CAAA;AAClDC,EAAAA,oBAAoB,GAAG,IAAI,CAACC,0BAA0B,EAAE;EAGhE,OAAOC,YAAY,GAAG,+BAA+B;AAQrD,EAAA,OAAOC,IAAIA,CAETC,OAAA,GAAsC,EAAE,EAAA;IAExC,OAAO,IAAIC,gBAAgB,CAAC,IAAI,EAAED,OAAO,CAAA,CACtCE,SAAS,CAAC,OAAO,EAAEF,OAAO,CAACG,KAAK,EAAE,CAACC,OAAO,EAAED,KAAK,KAChDF,gBAAgB,CAACI,aAAa,CAACD,OAAO,CAACE,QAAQ,EAAE,EAAEH,KAAK,CAAC,CAAA,CAE1DD,SAAS,CAAC,UAAU,EAAEF,OAAO,CAACO,QAAQ,EAAE,OAAOH,OAAO,EAAEG,QAAQ,KAAI;MACnE,OAAO,CAAC,MAAMH,OAAO,CAACI,UAAU,EAAE,MAAMD,QAAQ;AAClD,IAAA,CAAC,CAAC;AACN,EAAA;EAGA,MAAMD,QAAQA,GAAA;IACZ,OAAO,CAAC,MAAM,IAAI,CAACG,IAAI,EAAE,EAAEC,WAAW,CAAS,OAAO,CAAC;AAC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