/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/material/datepicker/testing/datepicker-input-harness-base.ts
101 строка
3 KB
Dragon Wrangler
feat(material/testing): Extend Angular harness testing functionality (#30960)
14 май 2025, 19:37
Не верифицирован
14 май 2025, 19:37
4de7c0f
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {ComponentHarnessConstructor, HarnessPredicate} from '@angular/cdk/testing'; import {MatFormFieldControlHarnessBase} from '@angular/material/form-field/testing/control'; import {DatepickerInputHarnessFilters} from './datepicker-harness-filters'; /** Sets up the filter predicates for a datepicker input harness. */ export function getInputPredicate<T extends MatDatepickerInputHarnessBase>( type: ComponentHarnessConstructor<T>, options: DatepickerInputHarnessFilters, ): HarnessPredicate<T> { return new HarnessPredicate(type, options) .addOption('value', options.value, (harness, value) => { return HarnessPredicate.stringMatches(harness.getValue(), value); }) .addOption('placeholder', options.placeholder, (harness, placeholder) => { return HarnessPredicate.stringMatches(harness.getPlaceholder(), placeholder); }) .addOption('label', options.label, (harness, label) => { return HarnessPredicate.stringMatches(harness.getLabel(), label); }); } /** Base class for datepicker input harnesses. */ export abstract class MatDatepickerInputHarnessBase extends MatFormFieldControlHarnessBase { /** Whether the input is disabled. */ async isDisabled(): Promise<boolean> { return (await this.host()).getProperty<boolean>('disabled'); } /** Whether the input is required. */ async isRequired(): Promise<boolean> { return (await this.host()).getProperty<boolean>('required'); } /** Gets the value of the input. */ async getValue(): Promise<string> { // The "value" property of the native input is always defined. return await (await this.host()).getProperty<string>('value'); } /** * Sets the value of the input. The value will be set by simulating * keypresses that correspond to the given value. */ async setValue(newValue: string): Promise<void> { const inputEl = await this.host(); await inputEl.clear(); // We don't want to send keys for the value if the value is an empty // string in order to clear the value. Sending keys with an empty string // still results in unnecessary focus events. if (newValue) { await inputEl.sendKeys(newValue); } await inputEl.dispatchEvent('change'); } /** Gets the placeholder of the input. */ async getPlaceholder(): Promise<string> { return await (await this.host()).getProperty<string>('placeholder'); } /** * Focuses the input and returns a promise that indicates when the * action is complete. */ async focus(): Promise<void> { return (await this.host()).focus(); } /** * Blurs the input and returns a promise that indicates when the * action is complete. */ async blur(): Promise<void> { return (await this.host()).blur(); } /** Whether the input is focused. */ async isFocused(): Promise<boolean> { return (await this.host()).isFocused(); } /** Gets the formatted minimum date for the input's value. */ async getMin(): Promise<string | null> { return (await this.host()).getAttribute('min'); } /** Gets the formatted maximum date for the input's value. */ async getMax(): Promise<string | null> { return (await this.host()).getAttribute('max'); } }