@angular/material
Version:
Angular Material
1 lines • 8.31 kB
Source Map (JSON)
{"version":3,"file":"_input-harness-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/input/testing/input-harness.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.dev/license\n */\n\nimport {HarnessPredicate, parallel} from '@angular/cdk/testing';\nimport {MatFormFieldControlHarnessBase} from '@angular/material/form-field/testing/control';\nimport {coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {InputHarnessFilters} from './input-harness-filters';\n\n/** Harness for interacting with a standard Material inputs in tests. */\nexport class MatInputHarness extends MatFormFieldControlHarnessBase {\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 .addOption('label', options.label, (harness, label) => {\n return HarnessPredicate.stringMatches(harness.getLabel(), label);\n });\n }\n\n /** Whether the input is disabled. */\n async isDisabled(): Promise<boolean> {\n const host = await this.host();\n const disabled = await host.getAttribute('disabled');\n\n if (disabled !== null) {\n return coerceBooleanProperty(disabled);\n }\n\n return (await host.getAttribute('aria-disabled')) === 'true';\n }\n\n /** Whether the input is required. */\n async isRequired(): Promise<boolean> {\n return (await this.host()).getProperty<boolean>('required');\n }\n\n /** Whether the input is readonly. */\n async isReadonly(): Promise<boolean> {\n return (await this.host()).getProperty<boolean>('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<string>('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<string>('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<string>('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<string>('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 await inputEl.setInputValue(newValue);\n }\n}\n"],"names":["MatInputHarness","MatFormFieldControlHarnessBase","hostSelector","with","options","HarnessPredicate","addOption","value","harness","stringMatches","getValue","placeholder","getPlaceholder","label","getLabel","isDisabled","host","disabled","getAttribute","coerceBooleanProperty","isRequired","getProperty","isReadonly","getName","getType","nativePlaceholder","fallback","parallel","getId","focus","blur","isFocused","setValue","newValue","inputEl","clear","sendKeys","setInputValue"],"mappings":";;;;AAcM,MAAOA,eAAgB,SAAQC,8BAA8B,CAAA;EAIjE,OAAOC,YAAY,GAAG,iEAAiE;AAQvF,EAAA,OAAOC,IAAIA,CAACC,OAAA,GAA+B,EAAE,EAAA;IAC3C,OAAO,IAAIC,gBAAgB,CAACL,eAAe,EAAEI,OAAO,CAAA,CACjDE,SAAS,CAAC,OAAO,EAAEF,OAAO,CAACG,KAAK,EAAE,CAACC,OAAO,EAAED,KAAK,KAAI;MACpD,OAAOF,gBAAgB,CAACI,aAAa,CAACD,OAAO,CAACE,QAAQ,EAAE,EAAEH,KAAK,CAAC;AAClE,KAAC,CAAA,CACAD,SAAS,CAAC,aAAa,EAAEF,OAAO,CAACO,WAAW,EAAE,CAACH,OAAO,EAAEG,WAAW,KAAI;MACtE,OAAON,gBAAgB,CAACI,aAAa,CAACD,OAAO,CAACI,cAAc,EAAE,EAAED,WAAW,CAAC;AAC9E,KAAC,CAAA,CACAL,SAAS,CAAC,OAAO,EAAEF,OAAO,CAACS,KAAK,EAAE,CAACL,OAAO,EAAEK,KAAK,KAAI;MACpD,OAAOR,gBAAgB,CAACI,aAAa,CAACD,OAAO,CAACM,QAAQ,EAAE,EAAED,KAAK,CAAC;AAClE,KAAC,CAAC;AACN;EAGA,MAAME,UAAUA,GAAA;AACd,IAAA,MAAMC,IAAI,GAAG,MAAM,IAAI,CAACA,IAAI,EAAE;IAC9B,MAAMC,QAAQ,GAAG,MAAMD,IAAI,CAACE,YAAY,CAAC,UAAU,CAAC;IAEpD,IAAID,QAAQ,KAAK,IAAI,EAAE;MACrB,OAAOE,qBAAqB,CAACF,QA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