{"version":3,"file":"testing.mjs","sources":["../../../../../../../src/material/radio/testing/radio-harness.ts","../../../../../../../src/material/radio/testing/radio-harness-filters.ts","../../../../../../../src/material/radio/testing/public-api.ts","../../../../../../../src/material/radio/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 {coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {\n  AsyncFactoryFn,\n  BaseHarnessFilters,\n  ComponentHarness,\n  ComponentHarnessConstructor,\n  HarnessPredicate,\n  TestElement,\n} from '@angular/cdk/testing';\nimport {RadioButtonHarnessFilters, RadioGroupHarnessFilters} from './radio-harness-filters';\n\nexport abstract class _MatRadioGroupHarnessBase<\n  ButtonType extends (ComponentHarnessConstructor<Button> & {\n    with: (options?: ButtonFilters) => HarnessPredicate<Button>}),\n  Button extends ComponentHarness & {\n    isChecked(): Promise<boolean>, getValue(): Promise<string|null>,\n    getName(): Promise<string|null>, check(): Promise<void>\n  },\n  ButtonFilters extends BaseHarnessFilters\n> extends ComponentHarness {\n  protected abstract _buttonClass: ButtonType;\n\n  /** Gets the name of the radio-group. */\n  async getName(): Promise<string|null> {\n    const hostName = await this._getGroupNameFromHost();\n    // It's not possible to always determine the \"name\" of a radio-group by reading\n    // the attribute. This is because the radio-group does not set the \"name\" as an\n    // element attribute if the \"name\" value is set through a binding.\n    if (hostName !== null) {\n      return hostName;\n    }\n    // In case we couldn't determine the \"name\" of a radio-group by reading the\n    // \"name\" attribute, we try to determine the \"name\" of the group by going\n    // through all radio buttons.\n    const radioNames = await this._getNamesFromRadioButtons();\n    if (!radioNames.length) {\n      return null;\n    }\n    if (!this._checkRadioNamesInGroupEqual(radioNames)) {\n      throw Error('Radio buttons in radio-group have mismatching names.');\n    }\n    return radioNames[0]!;\n  }\n\n  /** Gets the id of the radio-group. */\n  async getId(): Promise<string|null> {\n    return (await this.host()).getProperty<string|null>('id');\n  }\n\n  /** Gets the checked radio-button in a radio-group. */\n  async getCheckedRadioButton(): Promise<Button|null> {\n    for (let radioButton of await this.getRadioButtons()) {\n      if (await radioButton.isChecked()) {\n        return radioButton;\n      }\n    }\n    return null;\n  }\n\n  /** Gets the checked value of the radio-group. */\n  async getCheckedValue(): Promise<string|null> {\n    const checkedRadio = await this.getCheckedRadioButton();\n    if (!checkedRadio) {\n      return null;\n    }\n    return checkedRadio.getValue();\n  }\n\n  /**\n   * Gets a list of radio buttons which are part of the radio-group.\n   * @param filter Optionally filters which radio buttons are included.\n   */\n  async getRadioButtons(filter?: ButtonFilters): Promise<Button[]> {\n    return this.locatorForAll(this._buttonClass.with(filter))();\n  }\n\n  /**\n   * Checks a radio button in this group.\n   * @param filter An optional filter to apply to the child radio buttons. The first tab matching\n   *     the filter will be selected.\n   */\n  async checkRadioButton(filter?: ButtonFilters): Promise<void> {\n    const radioButtons = await this.getRadioButtons(filter);\n    if (!radioButtons.length) {\n      throw Error(`Could not find radio button matching ${JSON.stringify(filter)}`);\n    }\n    return radioButtons[0].check();\n  }\n\n  /** Gets the name attribute of the host element. */\n  private async _getGroupNameFromHost() {\n    return (await this.host()).getAttribute('name');\n  }\n\n  /** Gets a list of the name attributes of all child radio buttons. */\n  private async _getNamesFromRadioButtons(): Promise<string[]> {\n    const groupNames: string[] = [];\n    for (let radio of await this.getRadioButtons()) {\n      const radioName = await radio.getName();\n      if (radioName !== null) {\n        groupNames.push(radioName);\n      }\n    }\n    return groupNames;\n  }\n\n  /** Checks if the specified radio names are all equal. */\n  private _checkRadioNamesInGroupEqual(radioNames: string[]): boolean {\n    let groupName: string|null = null;\n    for (let radioName of radioNames) {\n      if (groupName === null) {\n        groupName = radioName;\n      } else if (groupName !== radioName) {\n        return false;\n      }\n    }\n    return true;\n  }\n\n  /**\n   * Checks if a radio-group harness has the given name. Throws if a radio-group with\n   * matching name could be found but has mismatching radio-button names.\n   */\n  protected static async _checkRadioGroupName(\n    harness: _MatRadioGroupHarnessBase<any, any, any>, name: string) {\n    // Check if there is a radio-group which has the \"name\" attribute set\n    // to the expected group name. It's not possible to always determine\n    // the \"name\" of a radio-group by reading the attribute. This is because\n    // the radio-group does not set the \"name\" as an element attribute if the\n    // \"name\" value is set through a binding.\n    if (await harness._getGroupNameFromHost() === name) {\n      return true;\n    }\n    // Check if there is a group with radio-buttons that all have the same\n    // expected name. This implies that the group has the given name. It's\n    // not possible to always determine the name of a radio-group through\n    // the attribute because there is\n    const radioNames = await harness._getNamesFromRadioButtons();\n    if (radioNames.indexOf(name) === -1) {\n      return false;\n    }\n    if (!harness._checkRadioNamesInGroupEqual(radioNames)) {\n      throw Error(\n          `The locator found a radio-group with name \"${name}\", but some ` +\n          `radio-button's within the group have mismatching names, which is invalid.`);\n    }\n    return true;\n  }\n}\n\n/** Harness for interacting with a standard mat-radio-group in tests. */\nexport class MatRadioGroupHarness extends _MatRadioGroupHarnessBase<\n  typeof MatRadioButtonHarness,\n  MatRadioButtonHarness,\n  RadioButtonHarnessFilters\n> {\n  /** The selector for the host element of a `MatRadioGroup` instance. */\n  static hostSelector = '.mat-radio-group';\n  protected _buttonClass = MatRadioButtonHarness;\n\n  /**\n   * Gets a `HarnessPredicate` that can be used to search for a `MatRadioGroupHarness` that meets\n   * certain criteria.\n   * @param options Options for filtering which radio group instances are considered a match.\n   * @return a `HarnessPredicate` configured with the given options.\n   */\n  static with(options: RadioGroupHarnessFilters = {}): HarnessPredicate<MatRadioGroupHarness> {\n    return new HarnessPredicate(MatRadioGroupHarness, options)\n        .addOption('name', options.name, this._checkRadioGroupName);\n  }\n}\n\nexport abstract class _MatRadioButtonHarnessBase extends ComponentHarness {\n  protected abstract _textLabel: AsyncFactoryFn<TestElement>;\n  protected abstract _clickLabel: AsyncFactoryFn<TestElement>;\n  private _input = this.locatorFor('input');\n\n  /** Whether the radio-button 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 radio-button 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 radio-button is required. */\n  async isRequired(): Promise<boolean> {\n    const required = (await this._input()).getAttribute('required');\n    return coerceBooleanProperty(await required);\n  }\n\n  /** Gets the radio-button's name. */\n  async getName(): Promise<string|null> {\n    return (await this._input()).getAttribute('name');\n  }\n\n  /** Gets the radio-button's id. */\n  async getId(): Promise<string|null> {\n    return (await this.host()).getProperty<string>('id');\n  }\n\n  /**\n   * Gets the value of the radio-button. The radio-button value will be converted to a string.\n   *\n   * Note: This means that for radio-button's with an object as a value `[object Object]` is\n   * intentionally returned.\n   */\n  async getValue(): Promise<string|null> {\n    return (await this._input()).getProperty('value');\n  }\n\n  /** Gets the radio-button's label text. */\n  async getLabelText(): Promise<string> {\n    return (await this._textLabel()).text();\n  }\n\n  /** Focuses the radio-button. */\n  async focus(): Promise<void> {\n    return (await this._input()).focus();\n  }\n\n  /** Blurs the radio-button. */\n  async blur(): Promise<void> {\n    return (await this._input()).blur();\n  }\n\n  /** Whether the radio-button is focused. */\n  async isFocused(): Promise<boolean> {\n    return (await this._input()).isFocused();\n  }\n\n  /**\n   * Puts the radio-button in a checked state by clicking it if it is currently unchecked,\n   * or doing nothing if it is already checked.\n   */\n  async check(): Promise<void> {\n    if (!(await this.isChecked())) {\n      return (await this._clickLabel()).click();\n    }\n  }\n}\n\n/** Harness for interacting with a standard mat-radio-button in tests. */\nexport class MatRadioButtonHarness extends _MatRadioButtonHarnessBase {\n  /** The selector for the host element of a `MatRadioButton` instance. */\n  static hostSelector = '.mat-radio-button';\n\n  /**\n   * Gets a `HarnessPredicate` that can be used to search for a `MatRadioButtonHarness` that meets\n   * certain criteria.\n   * @param options Options for filtering which radio button instances are considered a match.\n   * @return a `HarnessPredicate` configured with the given options.\n   */\n  static with(options: RadioButtonHarnessFilters = {}): HarnessPredicate<MatRadioButtonHarness> {\n    return new HarnessPredicate(MatRadioButtonHarness, options)\n        .addOption('label', options.label,\n          (harness, label) => HarnessPredicate.stringMatches(harness.getLabelText(), label))\n        .addOption('name', options.name,\n          async (harness, name) => (await harness.getName()) === name);\n  }\n\n  protected _textLabel = this.locatorFor('.mat-radio-label-content');\n  protected _clickLabel = this.locatorFor('.mat-radio-label');\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\nimport {BaseHarnessFilters} from '@angular/cdk/testing';\n\n/** A set of criteria that can be used to filter a list of `MatRadioGroupHarness` instances. */\nexport interface RadioGroupHarnessFilters extends BaseHarnessFilters {\n  /** Only find instances whose name attribute is the given value. */\n  name?: string;\n}\n\n/** A set of criteria that can be used to filter a list of `MatRadioButtonHarness` instances. */\nexport interface RadioButtonHarnessFilters extends BaseHarnessFilters {\n  /** Only find instances whose label matches the given value. */\n  label?: string | RegExp;\n  /** Only find instances whose name attribute is the given value. */\n  name?: string;\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 './radio-harness';\nexport * from './radio-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":";;;AAAA;;;;;;;MAmBsB,yBAQpB,SAAQ,gBAAgB;;IAIxB,MAAM,OAAO;QACX,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;;;;QAIpD,IAAI,QAAQ,KAAK,IAAI,EAAE;YACrB,OAAO,QAAQ,CAAC;SACjB;;;;QAID,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,yBAAyB,EAAE,CAAC;QAC1D,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YACtB,OAA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