index.d.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { MatFormFieldControlHarness } from './control/index.js';
  2. import { BaseHarnessFilters, ComponentHarness, ComponentHarnessConstructor, HarnessPredicate } from '@angular/cdk/testing';
  3. import { M as MatInputHarness } from '../../input-harness.d-8fkAAbu2.js';
  4. import { MatSelectHarness } from '../../select/testing/index.js';
  5. import { M as MatDatepickerInputHarness, g as MatDateRangeInputHarness } from '../../date-range-input-harness.d-CaEyN8dT.js';
  6. import '../../option-harness.d-IqsW95GR.js';
  7. import '../../core/testing/index.js';
  8. /** A set of criteria that can be used to filter a list of `MatFormFieldHarness` instances. */
  9. interface FormFieldHarnessFilters extends BaseHarnessFilters {
  10. /** Filters based on the text of the form field's floating label. */
  11. floatingLabelText?: string | RegExp;
  12. /** Filters based on whether the form field has error messages. */
  13. hasErrors?: boolean;
  14. /** Filters based on whether the form field value is valid. */
  15. isValid?: boolean;
  16. }
  17. /** A set of criteria that can be used to filter a list of error harness instances. */
  18. interface ErrorHarnessFilters extends BaseHarnessFilters {
  19. /** Only find instances whose text matches the given value. */
  20. text?: string | RegExp;
  21. }
  22. /** Harness for interacting with a `mat-error` in tests. */
  23. declare class MatErrorHarness extends ComponentHarness {
  24. static hostSelector: string;
  25. /**
  26. * Gets a `HarnessPredicate` that can be used to search for an error with specific
  27. * attributes.
  28. * @param options Options for filtering which error instances are considered a match.
  29. * @return a `HarnessPredicate` configured with the given options.
  30. */
  31. static with<T extends MatErrorHarness>(this: ComponentHarnessConstructor<T>, options?: ErrorHarnessFilters): HarnessPredicate<T>;
  32. protected static _getErrorPredicate<T extends MatErrorHarness>(type: ComponentHarnessConstructor<T>, options: ErrorHarnessFilters): HarnessPredicate<T>;
  33. /** Gets a promise for the error's label text. */
  34. getText(): Promise<string>;
  35. }
  36. /** Possible harnesses of controls which can be bound to a form-field. */
  37. type FormFieldControlHarness = MatInputHarness | MatSelectHarness | MatDatepickerInputHarness | MatDateRangeInputHarness;
  38. declare class MatFormFieldHarness extends ComponentHarness {
  39. private _prefixContainer;
  40. private _suffixContainer;
  41. private _label;
  42. private _hints;
  43. private _inputControl;
  44. private _selectControl;
  45. private _datepickerInputControl;
  46. private _dateRangeInputControl;
  47. private _textField;
  48. private _errorHarness;
  49. static hostSelector: string;
  50. /**
  51. * Gets a `HarnessPredicate` that can be used to search for a form field with specific
  52. * attributes.
  53. * @param options Options for filtering which form field instances are considered a match.
  54. * @return a `HarnessPredicate` configured with the given options.
  55. */
  56. static with<T extends MatFormFieldHarness>(this: ComponentHarnessConstructor<T>, options?: FormFieldHarnessFilters): HarnessPredicate<T>;
  57. /** Gets the appearance of the form-field. */
  58. getAppearance(): Promise<'fill' | 'outline'>;
  59. /** Whether the form-field has a label. */
  60. hasLabel(): Promise<boolean>;
  61. /** Whether the label is currently floating. */
  62. isLabelFloating(): Promise<boolean>;
  63. /** Gets the label of the form-field. */
  64. getLabel(): Promise<string | null>;
  65. /** Whether the form-field has errors. */
  66. hasErrors(): Promise<boolean>;
  67. /** Whether the form-field is disabled. */
  68. isDisabled(): Promise<boolean>;
  69. /** Whether the form-field is currently autofilled. */
  70. isAutofilled(): Promise<boolean>;
  71. /**
  72. * Gets the harness of the control that is bound to the form-field. Only
  73. * default controls such as "MatInputHarness" and "MatSelectHarness" are
  74. * supported.
  75. */
  76. getControl(): Promise<FormFieldControlHarness | null>;
  77. /**
  78. * Gets the harness of the control that is bound to the form-field. Searches
  79. * for a control that matches the specified harness type.
  80. */
  81. getControl<X extends MatFormFieldControlHarness>(type: ComponentHarnessConstructor<X>): Promise<X | null>;
  82. /**
  83. * Gets the harness of the control that is bound to the form-field. Searches
  84. * for a control that matches the specified harness predicate.
  85. */
  86. getControl<X extends MatFormFieldControlHarness>(type: HarnessPredicate<X>): Promise<X | null>;
  87. /** Gets the theme color of the form-field. */
  88. getThemeColor(): Promise<'primary' | 'accent' | 'warn'>;
  89. /** Gets error messages which are currently displayed in the form-field. */
  90. getTextErrors(): Promise<string[]>;
  91. /** Gets all of the error harnesses in the form field. */
  92. getErrors(filter?: ErrorHarnessFilters): Promise<MatErrorHarness[]>;
  93. /** Gets hint messages which are currently displayed in the form-field. */
  94. getTextHints(): Promise<string[]>;
  95. /** Gets the text inside the prefix element. */
  96. getPrefixText(): Promise<string>;
  97. /** Gets the text inside the suffix element. */
  98. getSuffixText(): Promise<string>;
  99. /**
  100. * Whether the form control has been touched. Returns "null"
  101. * if no form control is set up.
  102. */
  103. isControlTouched(): Promise<boolean | null>;
  104. /**
  105. * Whether the form control is dirty. Returns "null"
  106. * if no form control is set up.
  107. */
  108. isControlDirty(): Promise<boolean | null>;
  109. /**
  110. * Whether the form control is valid. Returns "null"
  111. * if no form control is set up.
  112. */
  113. isControlValid(): Promise<boolean | null>;
  114. /**
  115. * Whether the form control is pending validation. Returns "null"
  116. * if no form control is set up.
  117. */
  118. isControlPending(): Promise<boolean | null>;
  119. /** Checks whether the form-field control has set up a form control. */
  120. private _hasFormControl;
  121. }
  122. export { MatErrorHarness, MatFormFieldControlHarness, MatFormFieldHarness };
  123. export type { ErrorHarnessFilters, FormFieldControlHarness, FormFieldHarnessFilters };