blob: 9de9cbcdc75c56392c8b242def777ef2f216b793 [file] [log] [blame]
{"version":3,"file":"input__testing.js","sources":["../../../../../../src/material/input/testing/input-harness.ts","../../../../../../src/material/input/testing/input-harness-filters.ts","../../../../../../src/material/input/testing/native-option-harness.ts","../../../../../../src/material/input/testing/native-select-harness.ts","../../../../../../src/material/input/testing/native-select-harness-filters.ts","../../../../../../src/material/input/testing/public-api.ts","../../../../../../src/material/input/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 {HarnessPredicate, parallel} from '@angular/cdk/testing';\nimport {MatFormFieldControlHarness} from '@angular/material/form-field/testing/control';\nimport {InputHarnessFilters} from './input-harness-filters';\n\n/** Harness for interacting with a standard Material inputs in tests. */\nexport class MatInputHarness extends MatFormFieldControlHarness {\n // TODO: We do not want to handle `select` elements with `matNativeControl` because\n // not all methods of this harness work reasonably for native select elements.\n // For more details. See: https://github.com/angular/components/pull/18221.\n static hostSelector = '[matInput], input[matNativeControl], textarea[matNativeControl]';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatInputHarness` that meets\n * certain criteria.\n * @param options Options for filtering which input instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: InputHarnessFilters = {}): HarnessPredicate<MatInputHarness> {\n return new HarnessPredicate(MatInputHarness, options)\n .addOption('value', options.value, (harness, value) => {\n return HarnessPredicate.stringMatches(harness.getValue(), value);\n })\n .addOption('placeholder', options.placeholder, (harness, placeholder) => {\n return HarnessPredicate.stringMatches(harness.getPlaceholder(), placeholder);\n });\n }\n\n /** Whether the input is disabled. */\n async isDisabled(): Promise<boolean> {\n return (await this.host()).getProperty('disabled')!;\n }\n\n /** Whether the input is required. */\n async isRequired(): Promise<boolean> {\n return (await this.host()).getProperty('required')!;\n }\n\n /** Whether the input is readonly. */\n async isReadonly(): Promise<boolean> {\n return (await this.host()).getProperty('readOnly')!;\n }\n\n /** Gets the value of the input. */\n async getValue(): Promise<string> {\n // The \"value\" property of the native input is never undefined.\n return (await (await this.host()).getProperty('value'))!;\n }\n\n /** Gets the name of the input. */\n async getName(): Promise<string> {\n // The \"name\" property of the native input is never undefined.\n return (await (await this.host()).getProperty('name'))!;\n }\n\n /**\n * Gets the type of the input. Returns \"textarea\" if the input is\n * a textarea.\n */\n async getType(): Promise<string> {\n // The \"type\" property of the native input is never undefined.\n return (await (await this.host()).getProperty('type'))!;\n }\n\n /** Gets the placeholder of the input. */\n async getPlaceholder(): Promise<string> {\n const host = await this.host();\n const [nativePlaceholder, fallback] = await parallel(() => [\n host.getProperty('placeholder'),\n host.getAttribute('data-placeholder')\n ]);\n return nativePlaceholder || fallback || '';\n }\n\n /** Gets the id of the input. */\n async getId(): Promise<string> {\n // The input directive always assigns a unique id to the input in\n // case no id has been explicitly specified.\n return (await (await this.host()).getProperty('id'))!;\n }\n\n /**\n * Focuses the input and returns a promise that indicates when the\n * action is complete.\n */\n async focus(): Promise<void> {\n return (await this.host()).focus();\n }\n\n /**\n * Blurs the input and returns a promise that indicates when the\n * action is complete.\n */\n async blur(): Promise<void> {\n return (await this.host()).blur();\n }\n\n /** Whether the input is focused. */\n async isFocused(): Promise<boolean> {\n return (await this.host()).isFocused();\n }\n\n /**\n * Sets the value of the input. The value will be set by simulating\n * keypresses that correspond to the given value.\n */\n async setValue(newValue: string): Promise<void> {\n const inputEl = await this.host();\n await inputEl.clear();\n // We don't want to send keys for the value if the value is an empty\n // string in order to clear the value. Sending keys with an empty string\n // still results in unnecessary focus events.\n if (newValue) {\n await inputEl.sendKeys(newValue);\n }\n\n // Some input types won't respond to key presses (e.g. `color`) so to be sure that the\n // value is set, we also set the property after the keyboard sequence. Note that we don't\n // want to do it before, because it can cause the value to be entered twice.\n // @breaking-change 11.0.0 Remove non-null assertion once `setInputValue` is required.\n if (inputEl.setInputValue) {\n await inputEl.setInputValue(newValue);\n }\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\nimport {BaseHarnessFilters} from '@angular/cdk/testing';\n\n/** A set of criteria that can be used to filter a list of `MatInputHarness` instances. */\nexport interface InputHarnessFilters extends BaseHarnessFilters {\n /** Filters based on the value of the input. */\n value?: string | RegExp;\n /** Filters based on the placeholder text of the input. */\n placeholder?: string | RegExp;\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 {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';\nimport {NativeOptionHarnessFilters} from './native-select-harness-filters';\n\n/** Harness for interacting with a native `option` in tests. */\nexport class MatNativeOptionHarness extends ComponentHarness {\n /** Selector used to locate option instances. */\n static hostSelector = 'select[matNativeControl] option';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatNativeOptionHarness` that meets\n * certain criteria.\n * @param options Options for filtering which option instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: NativeOptionHarnessFilters = {}) {\n return new HarnessPredicate(MatNativeOptionHarness, options)\n .addOption('text', options.text,\n async (harness, title) =>\n HarnessPredicate.stringMatches(await harness.getText(), title))\n .addOption('index', options.index,\n async (harness, index) => await harness.getIndex() === index)\n .addOption('isSelected', options.isSelected,\n async (harness, isSelected) => await harness.isSelected() === isSelected);\n\n }\n\n /** Gets the option's label text. */\n async getText(): Promise<string> {\n return (await this.host()).getProperty('label');\n }\n\n /** Index of the option within the native `select` element. */\n async getIndex(): Promise<number> {\n return (await this.host()).getProperty('index');\n }\n\n /** Gets whether the option is disabled. */\n async isDisabled(): Promise<boolean> {\n return (await this.host()).getProperty('disabled');\n }\n\n /** Gets whether the option is selected. */\n async isSelected(): Promise<boolean> {\n return (await this.host()).getProperty('selected');\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\nimport {HarnessPredicate, parallel} from '@angular/cdk/testing';\nimport {MatFormFieldControlHarness} from '@angular/material/form-field/testing/control';\nimport {MatNativeOptionHarness} from './native-option-harness';\nimport {\n NativeOptionHarnessFilters,\n NativeSelectHarnessFilters,\n} from './native-select-harness-filters';\n\n\n/** Harness for interacting with a native `select` in tests. */\nexport class MatNativeSelectHarness extends MatFormFieldControlHarness {\n static hostSelector = 'select[matNativeControl]';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatNativeSelectHarness` that meets\n * certain criteria.\n * @param options Options for filtering which select instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: NativeSelectHarnessFilters = {}): HarnessPredicate<MatNativeSelectHarness> {\n return new HarnessPredicate(MatNativeSelectHarness, options);\n }\n\n /** Gets a boolean promise indicating if the select is disabled. */\n async isDisabled(): Promise<boolean> {\n return (await this.host()).getProperty('disabled');\n }\n\n /** Gets a boolean promise indicating if the select is required. */\n async isRequired(): Promise<boolean> {\n return (await this.host()).getProperty('required');\n }\n\n /** Gets a boolean promise indicating if the select is in multi-selection mode. */\n async isMultiple(): Promise<boolean> {\n return (await this.host()).getProperty('multiple');\n }\n\n /** Gets the name of the select. */\n async getName(): Promise<string> {\n // The \"name\" property of the native select is never undefined.\n return (await (await this.host()).getProperty('name'))!;\n }\n\n /** Gets the id of the select. */\n async getId(): Promise<string> {\n // We're guaranteed to have an id, because the `matNativeControl` always assigns one.\n return (await (await this.host()).getProperty('id'))!;\n }\n\n /** Focuses the select and returns a void promise that indicates when the action is complete. */\n async focus(): Promise<void> {\n return (await this.host()).focus();\n }\n\n /** Blurs the select and returns a void promise that indicates when the action is complete. */\n async blur(): Promise<void> {\n return (await this.host()).blur();\n }\n\n /** Whether the select is focused. */\n async isFocused(): Promise<boolean> {\n return (await this.host()).isFocused();\n }\n\n /** Gets the options inside the select panel. */\n async getOptions(filter: NativeOptionHarnessFilters = {}):\n Promise<MatNativeOptionHarness[]> {\n return this.locatorForAll(MatNativeOptionHarness.with(filter))();\n }\n\n /**\n * Selects the options that match the passed-in filter. If the select is in multi-selection\n * mode all options will be clicked, otherwise the harness will pick the first matching option.\n */\n async selectOptions(filter: NativeOptionHarnessFilters = {}): Promise<void> {\n const [isMultiple, options] = await parallel(() => {\n return [this.isMultiple(), this.getOptions(filter)];\n });\n\n if (options.length === 0) {\n throw Error('Select does not have options matching the specified filter');\n }\n\n const [host, optionIndexes] = await parallel(() => [\n this.host(),\n parallel(() => options.slice(0, isMultiple ? undefined : 1).map(option => option.getIndex()))\n ]);\n\n // @breaking-change 12.0.0 Error can be removed once `selectOptions` is a required method.\n if (!host.selectOptions) {\n throw Error('TestElement implementation does not support the selectOptions ' +\n 'method which is required for this function.');\n }\n\n await host.selectOptions(...optionIndexes);\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\nimport {BaseHarnessFilters} from '@angular/cdk/testing';\n\n/** A set of criteria that can be used to filter a list of `MatNativeSelectHarness` instances. */\nexport interface NativeSelectHarnessFilters extends BaseHarnessFilters {}\n\n/** A set of criteria that can be used to filter a list of `MatNativeOptionHarness` instances. */\nexport interface NativeOptionHarnessFilters extends BaseHarnessFilters {\n text?: string | RegExp;\n index?: number;\n isSelected?: boolean;\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 './input-harness';\nexport * from './input-harness-filters';\nexport * from './native-select-harness';\nexport * from './native-select-harness-filters';\nexport * from './native-option-harness';\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;;;;;;;AAY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