{"version":3,"file":"ngx-com-components-code-block-testing.mjs","sources":["../../../projects/com/components/code-block/testing/code-block.harness.ts","../../../projects/com/components/code-block/testing/index.ts","../../../projects/com/components/code-block/testing/ngx-com-components-code-block-testing.ts"],"sourcesContent":["import {\n  ComponentHarness,\n  HarnessPredicate,\n} from '@angular/cdk/testing';\nimport type { BaseHarnessFilters } from '@angular/cdk/testing';\n\n/** Harness filters for ComCodeBlockHarness. */\nexport interface ComCodeBlockHarnessFilters extends BaseHarnessFilters {\n  /** Filter by the code block's language label. */\n  language?: string | RegExp;\n}\n\n/**\n * Harness for interacting with a ComCodeBlock in tests.\n */\nexport class ComCodeBlockHarness extends ComponentHarness {\n  static hostSelector = 'com-code-block';\n\n  private readonly codeElement = this.locatorFor('code');\n  private readonly preElement = this.locatorFor('pre');\n  private readonly copyButton = this.locatorFor('button[type=\"button\"]');\n\n  /**\n   * Gets a HarnessPredicate for matching code blocks.\n   * @param options Filter options.\n   */\n  static with(options: ComCodeBlockHarnessFilters = {}): HarnessPredicate<ComCodeBlockHarness> {\n    return new HarnessPredicate(ComCodeBlockHarness, options)\n      .addOption('language', options.language, async (harness, language) => {\n        const lang = await harness.getLanguage();\n        if (lang === null) {\n          return false;\n        }\n        return HarnessPredicate.stringMatches(lang, language);\n      });\n  }\n\n  /** Gets the code text content. */\n  async getCode(): Promise<string> {\n    const codeEl = await this.codeElement();\n    return codeEl.text();\n  }\n\n  /**\n   * Gets the language label.\n   * Returns `null` if no language is set.\n   */\n  async getLanguage(): Promise<string | null> {\n    const preEl = await this.preElement();\n    const ariaLabel = await preEl.getAttribute('aria-label');\n    if (!ariaLabel || ariaLabel === 'Code') {\n      return null;\n    }\n    // aria-label follows the pattern \"{language} code\"\n    return ariaLabel.replace(/ code$/, '');\n  }\n\n  /** Clicks the copy button to copy code to clipboard. */\n  async copyToClipboard(): Promise<void> {\n    const button = await this.copyButton();\n    return button.click();\n  }\n\n  /** Whether the copy button is currently showing the \"Copied\" state. */\n  async isCopied(): Promise<boolean> {\n    const label = await this.getCopyButtonLabel();\n    return label === 'Copied';\n  }\n\n  /** Gets the copy button's aria-label. */\n  async getCopyButtonLabel(): Promise<string> {\n    const button = await this.copyButton();\n    const label = await button.getAttribute('aria-label');\n    return label ?? '';\n  }\n\n  /** Whether the code block is disabled (copy button is disabled). */\n  async isDisabled(): Promise<boolean> {\n    const button = await this.copyButton();\n    return button.getProperty<boolean>('disabled');\n  }\n\n  /** Whether the code block host is focused. */\n  async isFocused(): Promise<boolean> {\n    const host = await this.host();\n    return host.isFocused();\n  }\n\n  /** Focuses the code block host element. */\n  async focus(): Promise<void> {\n    const host = await this.host();\n    return host.focus();\n  }\n\n  /** Blurs the code block host element. */\n  async blur(): Promise<void> {\n    const host = await this.host();\n    return host.blur();\n  }\n}\n","// Testing utilities for the code-block component\n\nexport { ComCodeBlockHarness } from './code-block.harness';\n\nexport type { ComCodeBlockHarnessFilters } from './code-block.harness';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAYA;;AAEG;AACG,MAAO,mBAAoB,SAAQ,gBAAgB,CAAA;AACvD,IAAA,OAAO,YAAY,GAAG,gBAAgB;AAErB,IAAA,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;AACrC,IAAA,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;AACnC,IAAA,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,uBAAuB,CAAC;AAEtE;;;AAGG;AACH,IAAA,OAAO,IAAI,CAAC,OAAA,GAAsC,EAAE,EAAA;AAClD,QAAA,OAAO,IAAI,gBAAgB,CAAC,mBAAmB,EAAE,OAAO;AACrD,aAAA,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,OAAO,EAAE,QAAQ,KAAI;AACnE,YAAA,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE;AACxC,YAAA,IAAI,IAAI,KAAK,IAAI,EA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