{"version":3,"file":"testing.mjs","sources":["../../../../../../../src/material/slide-toggle/testing/slide-toggle-harness.ts","../../../../../../../src/material/slide-toggle/testing/public-api.ts","../../../../../../../src/material/slide-toggle/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 {coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {SlideToggleHarnessFilters} from './slide-toggle-harness-filters';\n\nexport abstract class _MatSlideToggleHarnessBase extends ComponentHarness {\n  private _label = this.locatorFor('label');\n  protected abstract _nativeElement: AsyncFactoryFn<TestElement>;\n\n  /** Toggle the checked state of the slide-toggle. */\n  abstract toggle(): Promise<void>;\n\n  /** Whether the slide-toggle is checked. */\n  abstract isChecked(): Promise<boolean>;\n\n  /** Whether the slide-toggle is disabled. */\n  async isDisabled(): Promise<boolean> {\n    const disabled = (await this._nativeElement()).getAttribute('disabled');\n    return coerceBooleanProperty(await disabled);\n  }\n\n  /** Whether the slide-toggle is required. */\n  async isRequired(): Promise<boolean> {\n    const required = (await this._nativeElement()).getAttribute('required');\n    return coerceBooleanProperty(await required);\n  }\n\n  /** Whether the slide-toggle 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 slide-toggle's name. */\n  async getName(): Promise<string | null> {\n    return (await this._nativeElement()).getAttribute('name');\n  }\n\n  /** Gets the slide-toggle's aria-label. */\n  async getAriaLabel(): Promise<string | null> {\n    return (await this._nativeElement()).getAttribute('aria-label');\n  }\n\n  /** Gets the slide-toggle's aria-labelledby. */\n  async getAriaLabelledby(): Promise<string | null> {\n    return (await this._nativeElement()).getAttribute('aria-labelledby');\n  }\n\n  /** Gets the slide-toggle's label text. */\n  async getLabelText(): Promise<string> {\n    return (await this._label()).text();\n  }\n\n  /** Focuses the slide-toggle. */\n  async focus(): Promise<void> {\n    return (await this._nativeElement()).focus();\n  }\n\n  /** Blurs the slide-toggle. */\n  async blur(): Promise<void> {\n    return (await this._nativeElement()).blur();\n  }\n\n  /** Whether the slide-toggle is focused. */\n  async isFocused(): Promise<boolean> {\n    return (await this._nativeElement()).isFocused();\n  }\n\n  /**\n   * Puts the slide-toggle in a checked state by toggling it if it is currently unchecked, or doing\n   * nothing if it is already checked.\n   */\n  async check(): Promise<void> {\n    if (!(await this.isChecked())) {\n      await this.toggle();\n    }\n  }\n\n  /**\n   * Puts the slide-toggle in an unchecked state by toggling it if it is currently checked, or doing\n   * nothing if it is already unchecked.\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-slide-toggle in tests. */\nexport class MatSlideToggleHarness extends _MatSlideToggleHarnessBase {\n  protected _nativeElement = this.locatorFor('button');\n  static hostSelector = '.mat-mdc-slide-toggle';\n\n  /**\n   * Gets a `HarnessPredicate` that can be used to search for a slide-toggle w/ specific attributes.\n   * @param options Options for narrowing the search:\n   *   - `selector` finds a slide-toggle whose host element matches the given selector.\n   *   - `label` finds a slide-toggle with specific label text.\n   * @return a `HarnessPredicate` configured with the given options.\n   */\n  static with<T extends MatSlideToggleHarness>(\n    this: ComponentHarnessConstructor<T>,\n    options: SlideToggleHarnessFilters = {},\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 slide-toggle 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(\n          'disabled',\n          options.disabled,\n          async (harness, disabled) => (await harness.isDisabled()) == disabled,\n        )\n    );\n  }\n\n  async toggle(): Promise<void> {\n    return (await this._nativeElement()).click();\n  }\n\n  override async isRequired(): Promise<boolean> {\n    const ariaRequired = await (await this._nativeElement()).getAttribute('aria-required');\n    return ariaRequired === 'true';\n  }\n\n  async isChecked(): Promise<boolean> {\n    const checked = (await this._nativeElement()).getAttribute('aria-checked');\n    return coerceBooleanProperty(await checked);\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 './slide-toggle-harness';\nexport * from './slide-toggle-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,0BAA2B,SAAQ,gBAAgB,CAAA;AAAzE,IAAA,WAAA,GAAA;;QACU,IAAA,CAAA,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;KAiF3C;;IAvEO,UAAU,GAAA;;AACd,YAAA,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAI,CAAC,cAAc,EAAE,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;AACxE,YAAA,OAAO,qBAAqB,CAAC,MAAM,QAAQ,CAAC,CAAC;SAC9C,CAAA,CAAA;AAAA,KAAA;;IAGK,UAAU,GAAA;;AACd,YAAA,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAI,CAAC,cAAc,EAAE,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;AACxE,YAAA,OAAO,qBAAqB,CAAC,MAAM,QAAQ,CAAC,CAAC;SAC9C,CAAA,CAAA;AAAA,KAAA;;IAGK,OAAO,GAAA;;AACX,YAAA,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