index.d.ts 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { BaseHarnessFilters, ContentContainerComponentHarness, ComponentHarnessConstructor, HarnessPredicate, HarnessLoader } from '@angular/cdk/testing';
  2. /** A set of criteria that can be used to filter a list of `MatMenuHarness` instances. */
  3. interface MenuHarnessFilters extends BaseHarnessFilters {
  4. /** Only find instances whose trigger text matches the given value. */
  5. triggerText?: string | RegExp;
  6. }
  7. /** A set of criteria that can be used to filter a list of `MatMenuItemHarness` instances. */
  8. interface MenuItemHarnessFilters extends BaseHarnessFilters {
  9. /** Only find instances whose text matches the given value. */
  10. text?: string | RegExp;
  11. /** Only find instances that have a sub-menu. */
  12. hasSubmenu?: boolean;
  13. }
  14. /** Harness for interacting with a mat-menu in tests. */
  15. declare class MatMenuHarness extends ContentContainerComponentHarness<string> {
  16. private _documentRootLocator;
  17. /** The selector for the host element of a `MatMenu` instance. */
  18. static hostSelector: string;
  19. /**
  20. * Gets a `HarnessPredicate` that can be used to search for a menu with specific attributes.
  21. * @param options Options for filtering which menu instances are considered a match.
  22. * @return a `HarnessPredicate` configured with the given options.
  23. */
  24. static with<T extends MatMenuHarness>(this: ComponentHarnessConstructor<T>, options?: MenuHarnessFilters): HarnessPredicate<T>;
  25. /** Whether the menu is disabled. */
  26. isDisabled(): Promise<boolean>;
  27. /** Whether the menu is open. */
  28. isOpen(): Promise<boolean>;
  29. /** Gets the text of the menu's trigger element. */
  30. getTriggerText(): Promise<string>;
  31. /** Focuses the menu. */
  32. focus(): Promise<void>;
  33. /** Blurs the menu. */
  34. blur(): Promise<void>;
  35. /** Whether the menu is focused. */
  36. isFocused(): Promise<boolean>;
  37. /** Opens the menu. */
  38. open(): Promise<void>;
  39. /** Closes the menu. */
  40. close(): Promise<void>;
  41. /**
  42. * Gets a list of `MatMenuItemHarness` representing the items in the menu.
  43. * @param filters Optionally filters which menu items are included.
  44. */
  45. getItems(filters?: Omit<MenuItemHarnessFilters, 'ancestor'>): Promise<MatMenuItemHarness[]>;
  46. /**
  47. * Clicks an item in the menu, and optionally continues clicking items in subsequent sub-menus.
  48. * @param itemFilter A filter used to represent which item in the menu should be clicked. The
  49. * first matching menu item will be clicked.
  50. * @param subItemFilters A list of filters representing the items to click in any subsequent
  51. * sub-menus. The first item in the sub-menu matching the corresponding filter in
  52. * `subItemFilters` will be clicked.
  53. */
  54. clickItem(itemFilter: Omit<MenuItemHarnessFilters, 'ancestor'>, ...subItemFilters: Omit<MenuItemHarnessFilters, 'ancestor'>[]): Promise<void>;
  55. protected getRootHarnessLoader(): Promise<HarnessLoader>;
  56. /** Gets the menu panel associated with this menu. */
  57. private _getMenuPanel;
  58. /** Gets the id of the menu panel associated with this menu. */
  59. private _getPanelId;
  60. }
  61. declare class MatMenuItemHarness extends ContentContainerComponentHarness<string> {
  62. /** The selector for the host element of a `MatMenuItem` instance. */
  63. static hostSelector: string;
  64. /**
  65. * Gets a `HarnessPredicate` that can be used to search for a menu item with specific attributes.
  66. * @param options Options for filtering which menu item instances are considered a match.
  67. * @return a `HarnessPredicate` configured with the given options.
  68. */
  69. static with<T extends MatMenuItemHarness>(this: ComponentHarnessConstructor<T>, options?: MenuItemHarnessFilters): HarnessPredicate<T>;
  70. /** Whether the menu is disabled. */
  71. isDisabled(): Promise<boolean>;
  72. /** Gets the text of the menu item. */
  73. getText(): Promise<string>;
  74. /** Focuses the menu item. */
  75. focus(): Promise<void>;
  76. /** Blurs the menu item. */
  77. blur(): Promise<void>;
  78. /** Whether the menu item is focused. */
  79. isFocused(): Promise<boolean>;
  80. /** Clicks the menu item. */
  81. click(): Promise<void>;
  82. /** Whether this item has a submenu. */
  83. hasSubmenu(): Promise<boolean>;
  84. /** Gets the submenu associated with this menu item, or null if none. */
  85. getSubmenu(): Promise<MatMenuHarness | null>;
  86. }
  87. export { MatMenuHarness, MatMenuItemHarness };
  88. export type { MenuHarnessFilters, MenuItemHarnessFilters };