{"version":3,"file":"ngx-com-components-form-field-testing.mjs","sources":["../../../projects/com/components/form-field/testing/form-field.harness.ts","../../../projects/com/components/form-field/testing/index.ts","../../../projects/com/components/form-field/testing/ngx-com-components-form-field-testing.ts"],"sourcesContent":["import {\n  ComponentHarness,\n  HarnessPredicate,\n} from '@angular/cdk/testing';\nimport type { BaseHarnessFilters, TestElement } from '@angular/cdk/testing';\n\n/** Harness filters for ComFormFieldHarness. */\nexport interface ComFormFieldHarnessFilters extends BaseHarnessFilters {\n  /** Filter by the form field's label text. */\n  label?: string | RegExp;\n  /** Filter by whether the form field has errors. */\n  hasErrors?: boolean;\n  /** Filter by whether the form field is disabled. */\n  disabled?: boolean;\n  /** Filter by whether the label is floating. */\n  floatingLabel?: boolean;\n}\n\n/**\n * Harness for interacting with a ComFormField in tests.\n */\nexport class ComFormFieldHarness extends ComponentHarness {\n  static hostSelector = 'com-form-field';\n\n  private readonly label = this.locatorForOptional('[comlabel]');\n  private readonly input = this.locatorForOptional('input[cominput], textarea[cominput]');\n  private readonly hints = this.locatorForAll('[comhint]');\n  private readonly errors = this.locatorForAll('[comerror]');\n  private readonly prefix = this.locatorForOptional('[comprefix]');\n  private readonly suffix = this.locatorForOptional('[comsuffix]');\n\n  /**\n   * Gets a HarnessPredicate for matching form fields.\n   * @param options Filter options.\n   */\n  static with(options: ComFormFieldHarnessFilters = {}): HarnessPredicate<ComFormFieldHarness> {\n    return new HarnessPredicate(ComFormFieldHarness, options)\n      .addOption('label', options.label, async (harness, label) => {\n        const labelText = await harness.getLabel();\n        if (labelText === null) return false;\n        return HarnessPredicate.stringMatches(labelText, label);\n      })\n      .addOption('hasErrors', options.hasErrors, async (harness, hasErrors) => {\n        return (await harness.hasErrors()) === hasErrors;\n      })\n      .addOption('disabled', options.disabled, async (harness, disabled) => {\n        return (await harness.isDisabled()) === disabled;\n      })\n      .addOption('floatingLabel', options.floatingLabel, async (harness, floatingLabel) => {\n        return (await harness.isLabelFloating()) === floatingLabel;\n      });\n  }\n\n  /** Gets the form field's label text, or null if no label is present. */\n  async getLabel(): Promise<string | null> {\n    const labelEl = await this.label();\n    return labelEl ? labelEl.text() : null;\n  }\n\n  /** Whether the form field has a label. */\n  async hasLabel(): Promise<boolean> {\n    const labelEl = await this.label();\n    return labelEl !== null;\n  }\n\n  /** Whether the form field is disabled. */\n  async isDisabled(): Promise<boolean> {\n    const host = await this.host();\n    return (await host.getAttribute('data-disabled')) !== null;\n  }\n\n  /** Whether the form field is focused. */\n  async isFocused(): Promise<boolean> {\n    const host = await this.host();\n    return (await host.getAttribute('data-focused')) !== null;\n  }\n\n  /** Whether the form field has errors. */\n  async hasErrors(): Promise<boolean> {\n    const host = await this.host();\n    return (await host.getAttribute('data-error')) !== null;\n  }\n\n  /** Whether the label is currently floating. */\n  async isLabelFloating(): Promise<boolean> {\n    const host = await this.host();\n    return (await host.getAttribute('data-floating')) !== null;\n  }\n\n  /** Gets the text content of all visible error elements. */\n  async getTextErrors(): Promise<string[]> {\n    const errorEls = await this.errors();\n    const texts: string[] = [];\n    for (const error of errorEls) {\n      const text = await error.text();\n      if (text) {\n        texts.push(text);\n      }\n    }\n    return texts;\n  }\n\n  /** Gets the text content of all hint elements. */\n  async getTextHints(): Promise<string[]> {\n    const hintEls = await this.hints();\n    const texts: string[] = [];\n    for (const hint of hintEls) {\n      const text = await hint.text();\n      if (text) {\n        texts.push(text);\n      }\n    }\n    return texts;\n  }\n\n  /** Whether the form field has a prefix element. */\n  async hasPrefix(): Promise<boolean> {\n    const prefixEl = await this.prefix();\n    return prefixEl !== null;\n  }\n\n  /** Whether the form field has a suffix element. */\n  async hasSuffix(): Promise<boolean> {\n    const suffixEl = await this.suffix();\n    return suffixEl !== null;\n  }\n\n  /** Whether the form field's control is required. */\n  async isRequired(): Promise<boolean> {\n    const inputEl = await this.input();\n    if (inputEl) {\n      const ariaRequired = await inputEl.getAttribute('aria-required');\n      if (ariaRequired === 'true') return true;\n      const required = await inputEl.getProperty<boolean>('required');\n      if (required) return true;\n    }\n    return false;\n  }\n\n  /** Gets the form field's inner control element (input or textarea). */\n  async getControl(): Promise<TestElement | null> {\n    return this.input();\n  }\n\n  /** Focuses the form field's inner control element. */\n  async focus(): Promise<void> {\n    const inputEl = await this.input();\n    if (inputEl) {\n      return inputEl.focus();\n    }\n  }\n\n  /** Blurs the form field's inner control element. */\n  async blur(): Promise<void> {\n    const inputEl = await this.input();\n    if (inputEl) {\n      return inputEl.blur();\n    }\n  }\n}\n","// Testing utilities for the form-field component\n\nexport { ComFormFieldHarness } from './form-field.harness';\n\nexport type { ComFormFieldHarnessFilters } from './form-field.harness';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAkBA;;AAEG;AACG,MAAO,mBAAoB,SAAQ,gBAAgB,CAAA;AACvD,IAAA,OAAO,YAAY,GAAG,gBAAgB;AAErB,IAAA,KAAK,GAAG,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC;AAC7C,IAAA,KAAK,GAAG,IAAI,CAAC,kBAAkB,CAAC,qCAAqC,CAAC;AACtE,IAAA,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC;AACvC,IAAA,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC;AACzC,IAAA,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC;AAC/C,IAAA,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC;AAEhE;;;AAGG;AACH,IAAA,OAAO,IAAI,CAAC,OAAA,GAAsC,EAAE,EAAA;AAClD,QAAA,OAAO,IAAI,gBAAgB,CAAC,mBAAmB,EAAE,OAAO;AACrD,aAAA,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,OAAO,EAAE,KAAK,KAAI;AAC1D,YAAA,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE;YAC1C,IAAI,SAAS,KAAK,IAAI;AAAE,gBAA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