index.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. import { BaseHarnessFilters, ComponentHarness, HarnessPredicate, ContentContainerComponentHarness, ComponentHarnessConstructor } from '@angular/cdk/testing';
  2. import { DividerHarnessFilters, MatDividerHarness } from '../../divider/testing/index.js';
  3. import { M as MatListOptionTogglePosition } from '../../list-option-types.d-77dQtwu8.js';
  4. interface ListHarnessFilters extends BaseHarnessFilters {
  5. }
  6. interface ActionListHarnessFilters extends BaseHarnessFilters {
  7. }
  8. interface NavListHarnessFilters extends BaseHarnessFilters {
  9. }
  10. interface SelectionListHarnessFilters extends BaseHarnessFilters {
  11. }
  12. interface BaseListItemHarnessFilters extends BaseHarnessFilters {
  13. title?: string | RegExp;
  14. secondaryText?: string | RegExp | null;
  15. tertiaryText?: string | RegExp | null;
  16. fullText?: string | RegExp;
  17. /**
  18. * @deprecated Use the `fullText` filter instead.
  19. * @breaking-change 16.0.0
  20. */
  21. text?: string | RegExp;
  22. }
  23. interface ListItemHarnessFilters extends BaseListItemHarnessFilters {
  24. }
  25. interface ActionListItemHarnessFilters extends BaseListItemHarnessFilters {
  26. }
  27. interface NavListItemHarnessFilters extends BaseListItemHarnessFilters {
  28. href?: string | RegExp | null;
  29. activated?: boolean;
  30. }
  31. interface ListOptionHarnessFilters extends BaseListItemHarnessFilters {
  32. selected?: boolean;
  33. }
  34. interface SubheaderHarnessFilters extends BaseHarnessFilters {
  35. text?: string | RegExp;
  36. }
  37. /** Harness for interacting with a list subheader. */
  38. declare class MatSubheaderHarness extends ComponentHarness {
  39. static hostSelector: string;
  40. static with(options?: SubheaderHarnessFilters): HarnessPredicate<MatSubheaderHarness>;
  41. /** Gets the full text content of the list item (including text from any font icons). */
  42. getText(): Promise<string>;
  43. }
  44. /** Selectors for the various list item sections that may contain user content. */
  45. declare enum MatListItemSection {
  46. CONTENT = ".mdc-list-item__content"
  47. }
  48. /** Enum describing the possible variants of a list item. */
  49. declare enum MatListItemType {
  50. ONE_LINE_ITEM = 0,
  51. TWO_LINE_ITEM = 1,
  52. THREE_LINE_ITEM = 2
  53. }
  54. /**
  55. * Shared behavior among the harnesses for the various `MatListItem` flavors.
  56. * @docs-private
  57. */
  58. declare abstract class MatListItemHarnessBase extends ContentContainerComponentHarness<MatListItemSection> {
  59. private _lines;
  60. private _primaryText;
  61. private _avatar;
  62. private _icon;
  63. private _unscopedTextContent;
  64. /** Gets the type of the list item, currently describing how many lines there are. */
  65. getType(): Promise<MatListItemType>;
  66. /**
  67. * Gets the full text content of the list item, excluding text
  68. * from icons and avatars.
  69. *
  70. * @deprecated Use the `getFullText` method instead.
  71. * @breaking-change 16.0.0
  72. */
  73. getText(): Promise<string>;
  74. /**
  75. * Gets the full text content of the list item, excluding text
  76. * from icons and avatars.
  77. */
  78. getFullText(): Promise<string>;
  79. /** Gets the title of the list item. */
  80. getTitle(): Promise<string>;
  81. /** Whether the list item is disabled. */
  82. isDisabled(): Promise<boolean>;
  83. /**
  84. * Gets the secondary line text of the list item. Null if the list item
  85. * does not have a secondary line.
  86. */
  87. getSecondaryText(): Promise<string | null>;
  88. /**
  89. * Gets the tertiary line text of the list item. Null if the list item
  90. * does not have a tertiary line.
  91. */
  92. getTertiaryText(): Promise<string | null>;
  93. /** Whether this list item has an avatar. */
  94. hasAvatar(): Promise<boolean>;
  95. /** Whether this list item has an icon. */
  96. hasIcon(): Promise<boolean>;
  97. }
  98. /** Represents a section of a list falling under a specific header. */
  99. interface ListSection<I> {
  100. /** The heading for this list section. `undefined` if there is no heading. */
  101. heading?: string;
  102. /** The items in this list section. */
  103. items: I[];
  104. }
  105. /**
  106. * Shared behavior among the harnesses for the various `MatList` flavors.
  107. * @template T A constructor type for a list item harness type used by this list harness.
  108. * @template C The list item harness type that `T` constructs.
  109. * @template F The filter type used filter list item harness of type `C`.
  110. * @docs-private
  111. */
  112. declare abstract class MatListHarnessBase<T extends ComponentHarnessConstructor<C> & {
  113. with: (options?: F) => HarnessPredicate<C>;
  114. }, C extends ComponentHarness, F extends BaseListItemHarnessFilters> extends ComponentHarness {
  115. protected _itemHarness: T;
  116. /**
  117. * Gets a list of harnesses representing the items in this list.
  118. * @param filters Optional filters used to narrow which harnesses are included
  119. * @return The list of items matching the given filters.
  120. */
  121. getItems(filters?: F): Promise<C[]>;
  122. /**
  123. * Gets a list of `ListSection` representing the list items grouped by subheaders. If the list has
  124. * no subheaders it is represented as a single `ListSection` with an undefined `heading` property.
  125. * @param filters Optional filters used to narrow which list item harnesses are included
  126. * @return The list of items matching the given filters, grouped into sections by subheader.
  127. */
  128. getItemsGroupedBySubheader(filters?: F): Promise<ListSection<C>[]>;
  129. /**
  130. * Gets a list of sub-lists representing the list items grouped by dividers. If the list has no
  131. * dividers it is represented as a list with a single sub-list.
  132. * @param filters Optional filters used to narrow which list item harnesses are included
  133. * @return The list of items matching the given filters, grouped into sub-lists by divider.
  134. */
  135. getItemsGroupedByDividers(filters?: F): Promise<C[][]>;
  136. /**
  137. * Gets a list of harnesses representing all of the items, subheaders, and dividers
  138. * (in the order they appear in the list). Use `instanceof` to check which type of harness a given
  139. * item is.
  140. * @param filters Optional filters used to narrow which list items, subheaders, and dividers are
  141. * included. A value of `false` for the `item`, `subheader`, or `divider` properties indicates
  142. * that the respective harness type should be omitted completely.
  143. * @return The list of harnesses representing the items, subheaders, and dividers matching the
  144. * given filters.
  145. */
  146. getItemsWithSubheadersAndDividers(filters: {
  147. item: false;
  148. subheader: false;
  149. divider: false;
  150. }): Promise<[]>;
  151. getItemsWithSubheadersAndDividers(filters: {
  152. item?: F | false;
  153. subheader: false;
  154. divider: false;
  155. }): Promise<C[]>;
  156. getItemsWithSubheadersAndDividers(filters: {
  157. item: false;
  158. subheader?: SubheaderHarnessFilters | false;
  159. divider: false;
  160. }): Promise<MatSubheaderHarness[]>;
  161. getItemsWithSubheadersAndDividers(filters: {
  162. item: false;
  163. subheader: false;
  164. divider?: DividerHarnessFilters | false;
  165. }): Promise<MatDividerHarness[]>;
  166. getItemsWithSubheadersAndDividers(filters: {
  167. item?: F | false;
  168. subheader?: SubheaderHarnessFilters | false;
  169. divider: false;
  170. }): Promise<(C | MatSubheaderHarness)[]>;
  171. getItemsWithSubheadersAndDividers(filters: {
  172. item?: F | false;
  173. subheader: false;
  174. divider?: false | DividerHarnessFilters;
  175. }): Promise<(C | MatDividerHarness)[]>;
  176. getItemsWithSubheadersAndDividers(filters: {
  177. item: false;
  178. subheader?: false | SubheaderHarnessFilters;
  179. divider?: false | DividerHarnessFilters;
  180. }): Promise<(MatSubheaderHarness | MatDividerHarness)[]>;
  181. getItemsWithSubheadersAndDividers(filters?: {
  182. item?: F | false;
  183. subheader?: SubheaderHarnessFilters | false;
  184. divider?: DividerHarnessFilters | false;
  185. }): Promise<(C | MatSubheaderHarness | MatDividerHarness)[]>;
  186. }
  187. /** Harness for interacting with a action-list in tests. */
  188. declare class MatActionListHarness extends MatListHarnessBase<typeof MatActionListItemHarness, MatActionListItemHarness, ActionListItemHarnessFilters> {
  189. /** The selector for the host element of a `MatActionList` instance. */
  190. static hostSelector: string;
  191. /**
  192. * Gets a `HarnessPredicate` that can be used to search for an action list with specific
  193. * attributes.
  194. * @param options Options for filtering which action list instances are considered a match.
  195. * @return a `HarnessPredicate` configured with the given options.
  196. */
  197. static with<T extends MatActionListHarness>(this: ComponentHarnessConstructor<T>, options?: ActionListHarnessFilters): HarnessPredicate<T>;
  198. _itemHarness: typeof MatActionListItemHarness;
  199. }
  200. /** Harness for interacting with an action list item. */
  201. declare class MatActionListItemHarness extends MatListItemHarnessBase {
  202. /** The selector for the host element of a `MatListItem` instance. */
  203. static hostSelector: string;
  204. /**
  205. * Gets a `HarnessPredicate` that can be used to search for a list item with specific
  206. * attributes.
  207. * @param options Options for filtering which action list item instances are considered a match.
  208. * @return a `HarnessPredicate` configured with the given options.
  209. */
  210. static with<T extends MatActionListItemHarness>(this: ComponentHarnessConstructor<T>, options?: ActionListItemHarnessFilters): HarnessPredicate<T>;
  211. /** Clicks on the action list item. */
  212. click(): Promise<void>;
  213. /** Focuses the action list item. */
  214. focus(): Promise<void>;
  215. /** Blurs the action list item. */
  216. blur(): Promise<void>;
  217. /** Whether the action list item is focused. */
  218. isFocused(): Promise<boolean>;
  219. }
  220. /** Harness for interacting with a list in tests. */
  221. declare class MatListHarness extends MatListHarnessBase<typeof MatListItemHarness, MatListItemHarness, ListItemHarnessFilters> {
  222. /** The selector for the host element of a `MatList` instance. */
  223. static hostSelector: string;
  224. /**
  225. * Gets a `HarnessPredicate` that can be used to search for a list with specific attributes.
  226. * @param options Options for filtering which list instances are considered a match.
  227. * @return a `HarnessPredicate` configured with the given options.
  228. */
  229. static with<T extends MatListHarness>(this: ComponentHarnessConstructor<T>, options?: ListHarnessFilters): HarnessPredicate<T>;
  230. _itemHarness: typeof MatListItemHarness;
  231. }
  232. /** Harness for interacting with a list item. */
  233. declare class MatListItemHarness extends MatListItemHarnessBase {
  234. /** The selector for the host element of a `MatListItem` instance. */
  235. static hostSelector: string;
  236. /**
  237. * Gets a `HarnessPredicate` that can be used to search for a list item with specific attributes.
  238. * @param options Options for filtering which list item instances are considered a match.
  239. * @return a `HarnessPredicate` configured with the given options.
  240. */
  241. static with<T extends MatListItemHarness>(this: ComponentHarnessConstructor<T>, options?: ListItemHarnessFilters): HarnessPredicate<T>;
  242. }
  243. /** Harness for interacting with a mat-nav-list in tests. */
  244. declare class MatNavListHarness extends MatListHarnessBase<typeof MatNavListItemHarness, MatNavListItemHarness, NavListItemHarnessFilters> {
  245. /** The selector for the host element of a `MatNavList` instance. */
  246. static hostSelector: string;
  247. /**
  248. * Gets a `HarnessPredicate` that can be used to search for a nav list with specific
  249. * attributes.
  250. * @param options Options for filtering which nav list instances are considered a match.
  251. * @return a `HarnessPredicate` configured with the given options.
  252. */
  253. static with<T extends MatNavListHarness>(this: ComponentHarnessConstructor<T>, options?: NavListHarnessFilters): HarnessPredicate<T>;
  254. _itemHarness: typeof MatNavListItemHarness;
  255. }
  256. /** Harness for interacting with a nav-list item. */
  257. declare class MatNavListItemHarness extends MatListItemHarnessBase {
  258. /** The selector for the host element of a `MatListItem` instance. */
  259. static hostSelector: string;
  260. /**
  261. * Gets a `HarnessPredicate` that can be used to search for a nav list item with specific
  262. * attributes.
  263. * @param options Options for filtering which nav list item instances are considered a match.
  264. * @return a `HarnessPredicate` configured with the given options.
  265. */
  266. static with<T extends MatNavListItemHarness>(this: ComponentHarnessConstructor<T>, options?: NavListItemHarnessFilters): HarnessPredicate<T>;
  267. /** Gets the href for this nav list item. */
  268. getHref(): Promise<string | null>;
  269. /** Clicks on the nav list item. */
  270. click(): Promise<void>;
  271. /** Focuses the nav list item. */
  272. focus(): Promise<void>;
  273. /** Blurs the nav list item. */
  274. blur(): Promise<void>;
  275. /** Whether the nav list item is focused. */
  276. isFocused(): Promise<boolean>;
  277. /** Whether the list item is activated. Should only be used for nav list items. */
  278. isActivated(): Promise<boolean>;
  279. }
  280. /** Harness for interacting with a selection-list in tests. */
  281. declare class MatSelectionListHarness extends MatListHarnessBase<typeof MatListOptionHarness, MatListOptionHarness, ListOptionHarnessFilters> {
  282. /** The selector for the host element of a `MatSelectionList` instance. */
  283. static hostSelector: string;
  284. /**
  285. * Gets a `HarnessPredicate` that can be used to search for a selection list with specific
  286. * attributes.
  287. * @param options Options for filtering which selection list instances are considered a match.
  288. * @return a `HarnessPredicate` configured with the given options.
  289. */
  290. static with<T extends MatSelectionListHarness>(this: ComponentHarnessConstructor<T>, options?: SelectionListHarnessFilters): HarnessPredicate<T>;
  291. _itemHarness: typeof MatListOptionHarness;
  292. /** Whether the selection list is disabled. */
  293. isDisabled(): Promise<boolean>;
  294. /**
  295. * Selects all items matching any of the given filters.
  296. * @param filters Filters that specify which items should be selected.
  297. */
  298. selectItems(...filters: ListOptionHarnessFilters[]): Promise<void>;
  299. /**
  300. * Deselects all items matching any of the given filters.
  301. * @param filters Filters that specify which items should be deselected.
  302. */
  303. deselectItems(...filters: ListItemHarnessFilters[]): Promise<void>;
  304. /** Gets all items matching the given list of filters. */
  305. private _getItems;
  306. }
  307. /** Harness for interacting with a list option. */
  308. declare class MatListOptionHarness extends MatListItemHarnessBase {
  309. /** The selector for the host element of a `MatListOption` instance. */
  310. static hostSelector: string;
  311. /**
  312. * Gets a `HarnessPredicate` that can be used to search for a list option with specific
  313. * attributes.
  314. * @param options Options for filtering which list option instances are considered a match.
  315. * @return a `HarnessPredicate` configured with the given options.
  316. */
  317. static with<T extends MatListOptionHarness>(this: ComponentHarnessConstructor<T>, options?: ListOptionHarnessFilters): HarnessPredicate<T>;
  318. private _beforeCheckbox;
  319. private _beforeRadio;
  320. /** Gets the position of the checkbox relative to the list option content. */
  321. getCheckboxPosition(): Promise<MatListOptionTogglePosition>;
  322. /** Gets the position of the radio relative to the list option content. */
  323. getRadioPosition(): Promise<MatListOptionTogglePosition>;
  324. /** Whether the list option is selected. */
  325. isSelected(): Promise<boolean>;
  326. /** Focuses the list option. */
  327. focus(): Promise<void>;
  328. /** Blurs the list option. */
  329. blur(): Promise<void>;
  330. /** Whether the list option is focused. */
  331. isFocused(): Promise<boolean>;
  332. /** Toggles the checked state of the checkbox. */
  333. toggle(): Promise<void>;
  334. /**
  335. * Puts the list option in a checked state by toggling it if it is currently
  336. * unchecked, or doing nothing if it is already checked.
  337. */
  338. select(): Promise<void>;
  339. /**
  340. * Puts the list option in an unchecked state by toggling it if it is currently
  341. * checked, or doing nothing if it is already unchecked.
  342. */
  343. deselect(): Promise<void>;
  344. }
  345. export { MatActionListHarness, MatActionListItemHarness, MatListHarness, MatListItemHarness, MatListItemSection, MatListItemType, MatListOptionHarness, MatNavListHarness, MatNavListItemHarness, MatSelectionListHarness, MatSubheaderHarness };
  346. export type { ActionListHarnessFilters, ActionListItemHarnessFilters, BaseListItemHarnessFilters, ListHarnessFilters, ListItemHarnessFilters, ListOptionHarnessFilters, NavListHarnessFilters, NavListItemHarnessFilters, SelectionListHarnessFilters, SubheaderHarnessFilters };