date-range-input-harness.d-CaEyN8dT.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
  2. import { MatFormFieldControlHarness } from './form-field/testing/control/index.js';
  3. /** A set of criteria that can be used to filter a list of datepicker input instances. */
  4. interface DatepickerInputHarnessFilters extends BaseHarnessFilters {
  5. /** Filters based on the value of the input. */
  6. value?: string | RegExp;
  7. /** Filters based on the placeholder text of the input. */
  8. placeholder?: string | RegExp;
  9. }
  10. /** A set of criteria that can be used to filter a list of datepicker toggle instances. */
  11. interface DatepickerToggleHarnessFilters extends BaseHarnessFilters {
  12. }
  13. /** A set of criteria that can be used to filter a list of calendar instances. */
  14. interface CalendarHarnessFilters extends BaseHarnessFilters {
  15. }
  16. /** A set of criteria that can be used to filter a list of calendar cell instances. */
  17. interface CalendarCellHarnessFilters extends BaseHarnessFilters {
  18. /** Filters based on the text of the cell. */
  19. text?: string | RegExp;
  20. /** Filters based on whether the cell is selected. */
  21. selected?: boolean;
  22. /** Filters based on whether the cell is activated using keyboard navigation */
  23. active?: boolean;
  24. /** Filters based on whether the cell is disabled. */
  25. disabled?: boolean;
  26. /** Filters based on whether the cell represents today's date. */
  27. today?: boolean;
  28. /** Filters based on whether the cell is inside of the main range. */
  29. inRange?: boolean;
  30. /** Filters based on whether the cell is inside of the comparison range. */
  31. inComparisonRange?: boolean;
  32. /** Filters based on whether the cell is inside of the preview range. */
  33. inPreviewRange?: boolean;
  34. }
  35. /** A set of criteria that can be used to filter a list of date range input instances. */
  36. interface DateRangeInputHarnessFilters extends BaseHarnessFilters {
  37. /** Filters based on the value of the input. */
  38. value?: string | RegExp;
  39. }
  40. /** Base class for datepicker input harnesses. */
  41. declare abstract class MatDatepickerInputHarnessBase extends MatFormFieldControlHarness {
  42. /** Whether the input is disabled. */
  43. isDisabled(): Promise<boolean>;
  44. /** Whether the input is required. */
  45. isRequired(): Promise<boolean>;
  46. /** Gets the value of the input. */
  47. getValue(): Promise<string>;
  48. /**
  49. * Sets the value of the input. The value will be set by simulating
  50. * keypresses that correspond to the given value.
  51. */
  52. setValue(newValue: string): Promise<void>;
  53. /** Gets the placeholder of the input. */
  54. getPlaceholder(): Promise<string>;
  55. /**
  56. * Focuses the input and returns a promise that indicates when the
  57. * action is complete.
  58. */
  59. focus(): Promise<void>;
  60. /**
  61. * Blurs the input and returns a promise that indicates when the
  62. * action is complete.
  63. */
  64. blur(): Promise<void>;
  65. /** Whether the input is focused. */
  66. isFocused(): Promise<boolean>;
  67. /** Gets the formatted minimum date for the input's value. */
  68. getMin(): Promise<string | null>;
  69. /** Gets the formatted maximum date for the input's value. */
  70. getMax(): Promise<string | null>;
  71. }
  72. /** Harness for interacting with a standard Material calendar cell in tests. */
  73. declare class MatCalendarCellHarness extends ComponentHarness {
  74. static hostSelector: string;
  75. /** Reference to the inner content element inside the cell. */
  76. private _content;
  77. /**
  78. * Gets a `HarnessPredicate` that can be used to search for a `MatCalendarCellHarness`
  79. * that meets certain criteria.
  80. * @param options Options for filtering which cell instances are considered a match.
  81. * @return a `HarnessPredicate` configured with the given options.
  82. */
  83. static with(options?: CalendarCellHarnessFilters): HarnessPredicate<MatCalendarCellHarness>;
  84. /** Gets the text of the calendar cell. */
  85. getText(): Promise<string>;
  86. /** Gets the aria-label of the calendar cell. */
  87. getAriaLabel(): Promise<string>;
  88. /** Whether the cell is selected. */
  89. isSelected(): Promise<boolean>;
  90. /** Whether the cell is disabled. */
  91. isDisabled(): Promise<boolean>;
  92. /** Whether the cell is currently activated using keyboard navigation. */
  93. isActive(): Promise<boolean>;
  94. /** Whether the cell represents today's date. */
  95. isToday(): Promise<boolean>;
  96. /** Selects the calendar cell. Won't do anything if the cell is disabled. */
  97. select(): Promise<void>;
  98. /** Hovers over the calendar cell. */
  99. hover(): Promise<void>;
  100. /** Moves the mouse away from the calendar cell. */
  101. mouseAway(): Promise<void>;
  102. /** Focuses the calendar cell. */
  103. focus(): Promise<void>;
  104. /** Removes focus from the calendar cell. */
  105. blur(): Promise<void>;
  106. /** Whether the cell is the start of the main range. */
  107. isRangeStart(): Promise<boolean>;
  108. /** Whether the cell is the end of the main range. */
  109. isRangeEnd(): Promise<boolean>;
  110. /** Whether the cell is part of the main range. */
  111. isInRange(): Promise<boolean>;
  112. /** Whether the cell is the start of the comparison range. */
  113. isComparisonRangeStart(): Promise<boolean>;
  114. /** Whether the cell is the end of the comparison range. */
  115. isComparisonRangeEnd(): Promise<boolean>;
  116. /** Whether the cell is inside of the comparison range. */
  117. isInComparisonRange(): Promise<boolean>;
  118. /** Whether the cell is the start of the preview range. */
  119. isPreviewRangeStart(): Promise<boolean>;
  120. /** Whether the cell is the end of the preview range. */
  121. isPreviewRangeEnd(): Promise<boolean>;
  122. /** Whether the cell is inside of the preview range. */
  123. isInPreviewRange(): Promise<boolean>;
  124. /** Returns whether the cell has a particular CSS class-based state. */
  125. private _hasState;
  126. }
  127. /** Possible views of a `MatCalendarHarness`. */
  128. declare enum CalendarView {
  129. MONTH = 0,
  130. YEAR = 1,
  131. MULTI_YEAR = 2
  132. }
  133. /** Harness for interacting with a standard Material calendar in tests. */
  134. declare class MatCalendarHarness extends ComponentHarness {
  135. static hostSelector: string;
  136. /** Queries for the calendar's period toggle button. */
  137. private _periodButton;
  138. /**
  139. * Gets a `HarnessPredicate` that can be used to search for a `MatCalendarHarness`
  140. * that meets certain criteria.
  141. * @param options Options for filtering which calendar instances are considered a match.
  142. * @return a `HarnessPredicate` configured with the given options.
  143. */
  144. static with(options?: CalendarHarnessFilters): HarnessPredicate<MatCalendarHarness>;
  145. /**
  146. * Gets a list of cells inside the calendar.
  147. * @param filter Optionally filters which cells are included.
  148. */
  149. getCells(filter?: CalendarCellHarnessFilters): Promise<MatCalendarCellHarness[]>;
  150. /** Gets the current view that is being shown inside the calendar. */
  151. getCurrentView(): Promise<CalendarView>;
  152. /** Gets the label of the current calendar view. */
  153. getCurrentViewLabel(): Promise<string>;
  154. /** Changes the calendar view by clicking on the view toggle button. */
  155. changeView(): Promise<void>;
  156. /** Goes to the next page of the current view (e.g. next month when inside the month view). */
  157. next(): Promise<void>;
  158. /**
  159. * Goes to the previous page of the current view
  160. * (e.g. previous month when inside the month view).
  161. */
  162. previous(): Promise<void>;
  163. /**
  164. * Selects a cell in the current calendar view.
  165. * @param filter An optional filter to apply to the cells. The first cell matching the filter
  166. * will be selected.
  167. */
  168. selectCell(filter?: CalendarCellHarnessFilters): Promise<void>;
  169. }
  170. /** Interface for a test harness that can open and close a calendar. */
  171. interface DatepickerTrigger {
  172. isCalendarOpen(): Promise<boolean>;
  173. openCalendar(): Promise<void>;
  174. closeCalendar(): Promise<void>;
  175. hasCalendar(): Promise<boolean>;
  176. getCalendar(filter?: CalendarHarnessFilters): Promise<MatCalendarHarness>;
  177. }
  178. /** Base class for harnesses that can trigger a calendar. */
  179. declare abstract class DatepickerTriggerHarnessBase extends ComponentHarness implements DatepickerTrigger {
  180. /** Whether the trigger is disabled. */
  181. abstract isDisabled(): Promise<boolean>;
  182. /** Whether the calendar associated with the trigger is open. */
  183. abstract isCalendarOpen(): Promise<boolean>;
  184. /** Opens the calendar associated with the trigger. */
  185. protected abstract _openCalendar(): Promise<void>;
  186. /** Opens the calendar if the trigger is enabled and it has a calendar. */
  187. openCalendar(): Promise<void>;
  188. /** Closes the calendar if it is open. */
  189. closeCalendar(): Promise<void>;
  190. /** Gets whether there is a calendar associated with the trigger. */
  191. hasCalendar(): Promise<boolean>;
  192. /**
  193. * Gets the `MatCalendarHarness` that is associated with the trigger.
  194. * @param filter Optionally filters which calendar is included.
  195. */
  196. getCalendar(filter?: CalendarHarnessFilters): Promise<MatCalendarHarness>;
  197. }
  198. /** Harness for interacting with a standard Material datepicker inputs in tests. */
  199. declare class MatDatepickerInputHarness extends MatDatepickerInputHarnessBase implements DatepickerTrigger {
  200. static hostSelector: string;
  201. /**
  202. * Gets a `HarnessPredicate` that can be used to search for a `MatDatepickerInputHarness`
  203. * that meets certain criteria.
  204. * @param options Options for filtering which input instances are considered a match.
  205. * @return a `HarnessPredicate` configured with the given options.
  206. */
  207. static with(options?: DatepickerInputHarnessFilters): HarnessPredicate<MatDatepickerInputHarness>;
  208. /** Gets whether the calendar associated with the input is open. */
  209. isCalendarOpen(): Promise<boolean>;
  210. /** Opens the calendar associated with the input. */
  211. openCalendar(): Promise<void>;
  212. /** Closes the calendar associated with the input. */
  213. closeCalendar(): Promise<void>;
  214. /** Whether a calendar is associated with the input. */
  215. hasCalendar(): Promise<boolean>;
  216. /**
  217. * Gets the `MatCalendarHarness` that is associated with the trigger.
  218. * @param filter Optionally filters which calendar is included.
  219. */
  220. getCalendar(filter?: CalendarHarnessFilters): Promise<MatCalendarHarness>;
  221. }
  222. /** Harness for interacting with a standard Material date range start input in tests. */
  223. declare class MatStartDateHarness extends MatDatepickerInputHarnessBase {
  224. static hostSelector: string;
  225. /**
  226. * Gets a `HarnessPredicate` that can be used to search for a `MatStartDateHarness`
  227. * that meets certain criteria.
  228. * @param options Options for filtering which input instances are considered a match.
  229. * @return a `HarnessPredicate` configured with the given options.
  230. */
  231. static with(options?: DatepickerInputHarnessFilters): HarnessPredicate<MatStartDateHarness>;
  232. }
  233. /** Harness for interacting with a standard Material date range end input in tests. */
  234. declare class MatEndDateHarness extends MatDatepickerInputHarnessBase {
  235. static hostSelector: string;
  236. /**
  237. * Gets a `HarnessPredicate` that can be used to search for a `MatEndDateHarness`
  238. * that meets certain criteria.
  239. * @param options Options for filtering which input instances are considered a match.
  240. * @return a `HarnessPredicate` configured with the given options.
  241. */
  242. static with(options?: DatepickerInputHarnessFilters): HarnessPredicate<MatEndDateHarness>;
  243. }
  244. /** Harness for interacting with a standard Material date range input in tests. */
  245. declare class MatDateRangeInputHarness extends DatepickerTriggerHarnessBase {
  246. static hostSelector: string;
  247. /**
  248. * Gets a `HarnessPredicate` that can be used to search for a `MatDateRangeInputHarness`
  249. * that meets certain criteria.
  250. * @param options Options for filtering which input instances are considered a match.
  251. * @return a `HarnessPredicate` configured with the given options.
  252. */
  253. static with(options?: DateRangeInputHarnessFilters): HarnessPredicate<MatDateRangeInputHarness>;
  254. /** Gets the combined value of the start and end inputs, including the separator. */
  255. getValue(): Promise<string>;
  256. /** Gets the inner start date input inside the range input. */
  257. getStartInput(): Promise<MatStartDateHarness>;
  258. /** Gets the inner start date input inside the range input. */
  259. getEndInput(): Promise<MatEndDateHarness>;
  260. /** Gets the separator text between the values of the two inputs. */
  261. getSeparator(): Promise<string>;
  262. /** Gets whether the range input is disabled. */
  263. isDisabled(): Promise<boolean>;
  264. /** Gets whether the range input is required. */
  265. isRequired(): Promise<boolean>;
  266. /** Opens the calendar associated with the input. */
  267. isCalendarOpen(): Promise<boolean>;
  268. protected _openCalendar(): Promise<void>;
  269. }
  270. export { DatepickerTriggerHarnessBase as D, MatDatepickerInputHarness as M, MatStartDateHarness as e, MatEndDateHarness as f, MatDateRangeInputHarness as g, CalendarView as h, MatCalendarHarness as i, MatCalendarCellHarness as j };
  271. export type { CalendarHarnessFilters as C, DatepickerToggleHarnessFilters as a, DatepickerInputHarnessFilters as b, CalendarCellHarnessFilters as c, DateRangeInputHarnessFilters as d };