{"version":3,"file":"testing.mjs","sources":["../../../../../../../src/material/checkbox/testing/checkbox-harness.ts","../../../../../../../src/material/checkbox/testing/public-api.ts","../../../../../../../src/material/checkbox/testing/index.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  AsyncFactoryFn,\n  ComponentHarness,\n  ComponentHarnessConstructor,\n  HarnessPredicate,\n  TestElement,\n} from '@angular/cdk/testing';\nimport {CheckboxHarnessFilters} from './checkbox-harness-filters';\nimport {coerceBooleanProperty} from '@angular/cdk/coercion';\n\nexport abstract class _MatCheckboxHarnessBase extends ComponentHarness {\n  protected abstract _input: AsyncFactoryFn<TestElement>;\n  protected abstract _label: AsyncFactoryFn<TestElement>;\n\n  /** Whether the checkbox is checked. */\n  async isChecked(): Promise<boolean> {\n    const checked = (await this._input()).getProperty<boolean>('checked');\n    return coerceBooleanProperty(await checked);\n  }\n\n  /** Whether the checkbox is in an indeterminate state. */\n  async isIndeterminate(): Promise<boolean> {\n    const indeterminate = (await this._input()).getProperty<string>('indeterminate');\n    return coerceBooleanProperty(await indeterminate);\n  }\n\n  /** Whether the checkbox is disabled. */\n  async isDisabled(): Promise<boolean> {\n    const disabled = (await this._input()).getAttribute('disabled');\n    return coerceBooleanProperty(await disabled);\n  }\n\n  /** Whether the checkbox is required. */\n  async isRequired(): Promise<boolean> {\n    const required = (await this._input()).getProperty<boolean>('required');\n    return coerceBooleanProperty(await required);\n  }\n\n  /** Whether the checkbox is valid. */\n  async isValid(): Promise<boolean> {\n    const invalid = (await this.host()).hasClass('ng-invalid');\n    return !(await invalid);\n  }\n\n  /** Gets the checkbox's name. */\n  async getName(): Promise<string | null> {\n    return (await this._input()).getAttribute('name');\n  }\n\n  /** Gets the checkbox's value. */\n  async getValue(): Promise<string | null> {\n    return (await this._input()).getProperty<string | null>('value');\n  }\n\n  /** Gets the checkbox's aria-label. */\n  async getAriaLabel(): Promise<string | null> {\n    return (await this._input()).getAttribute('aria-label');\n  }\n\n  /** Gets the checkbox's aria-labelledby. */\n  async getAriaLabelledby(): Promise<string | null> {\n    return (await this._input()).getAttribute('aria-labelledby');\n  }\n\n  /** Gets the checkbox's label text. */\n  async getLabelText(): Promise<string> {\n    return (await this._label()).text();\n  }\n\n  /** Focuses the checkbox. */\n  async focus(): Promise<void> {\n    return (await this._input()).focus();\n  }\n\n  /** Blurs the checkbox. */\n  async blur(): Promise<void> {\n    return (await this._input()).blur();\n  }\n\n  /** Whether the checkbox is focused. */\n  async isFocused(): Promise<boolean> {\n    return (await this._input()).isFocused();\n  }\n\n  /**\n   * Toggles the checked state of the checkbox.\n   *\n   * Note: This attempts to toggle the checkbox as a user would, by clicking it. Therefore if you\n   * are using `MAT_CHECKBOX_DEFAULT_OPTIONS` to change the behavior on click, calling this method\n   * might not have the expected result.\n   */\n  abstract toggle(): Promise<void>;\n\n  /**\n   * Puts the checkbox in a checked state by toggling it if it is currently unchecked, or doing\n   * nothing if it is already checked.\n   *\n   * Note: This attempts to check the checkbox as a user would, by clicking it. Therefore if you\n   * are using `MAT_CHECKBOX_DEFAULT_OPTIONS` to change the behavior on click, calling this method\n   * might not have the expected result.\n   */\n  async check(): Promise<void> {\n    if (!(await this.isChecked())) {\n      await this.toggle();\n    }\n  }\n\n  /**\n   * Puts the checkbox in an unchecked state by toggling it if it is currently checked, or doing\n   * nothing if it is already unchecked.\n   *\n   * Note: This attempts to uncheck the checkbox as a user would, by clicking it. Therefore if you\n   * are using `MAT_CHECKBOX_DEFAULT_OPTIONS` to change the behavior on click, calling this method\n   * might not have the expected result.\n   */\n  async uncheck(): Promise<void> {\n    if (await this.isChecked()) {\n      await this.toggle();\n    }\n  }\n}\n\n/** Harness for interacting with a MDC-based mat-checkbox in tests. */\nexport class MatCheckboxHarness extends _MatCheckboxHarnessBase {\n  static hostSelector = '.mat-mdc-checkbox';\n\n  /**\n   * Gets a `HarnessPredicate` that can be used to search for a checkbox with specific attributes.\n   * @param options Options for narrowing the search:\n   *   - `selector` finds a checkbox whose host element matches the given selector.\n   *   - `label` finds a checkbox with specific label text.\n   *   - `name` finds a checkbox with specific name.\n   * @return a `HarnessPredicate` configured with the given options.\n   */\n  static with<T extends MatCheckboxHarness>(\n    this: ComponentHarnessConstructor<T>,\n    options: CheckboxHarnessFilters = {},\n  ): HarnessPredicate<T> {\n    return (\n      new HarnessPredicate(this, options)\n        .addOption('label', options.label, (harness, label) =>\n          HarnessPredicate.stringMatches(harness.getLabelText(), label),\n        )\n        // We want to provide a filter option for \"name\" because the name of the checkbox is\n        // only set on the underlying input. This means that it's not possible for developers\n        // to retrieve the harness of a specific checkbox with name through a CSS selector.\n        .addOption(\n          'name',\n          options.name,\n          async (harness, name) => (await harness.getName()) === name,\n        )\n        .addOption(\n          'checked',\n          options.checked,\n          async (harness, checked) => (await harness.isChecked()) == checked,\n        )\n        .addOption('disabled', options.disabled, async (harness, disabled) => {\n          return (await harness.isDisabled()) === disabled;\n        })\n    );\n  }\n\n  protected _input = this.locatorFor('input');\n  protected _label = this.locatorFor('label');\n  private _inputContainer = this.locatorFor('.mdc-checkbox');\n\n  async toggle(): Promise<void> {\n    const elToClick = (await this.isDisabled()) ? this._inputContainer() : this._input();\n    return (await elToClick).click();\n  }\n}\n","/**\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\nexport * from './checkbox-harness';\nexport {CheckboxHarnessFilters} from './checkbox-harness-filters';\n","/**\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\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAkBM,MAAgB,uBAAwB,SAAQ,gBAAgB,CAAA;;IAK9D,SAAS,GAAA;;AACb,YAAA,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,EA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