index.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import * as _angular_cdk_testing from '@angular/cdk/testing';
  2. import { BaseHarnessFilters, ContentContainerComponentHarness, HarnessPredicate, ComponentHarness } from '@angular/cdk/testing';
  3. /** A set of criteria that can be used to filter a list of tree harness instances */
  4. interface TreeHarnessFilters extends BaseHarnessFilters {
  5. }
  6. /** A set of criteria that can be used to filter a list of node harness instances. */
  7. interface TreeNodeHarnessFilters extends BaseHarnessFilters {
  8. /** Only find instances whose text matches the given value. */
  9. text?: string | RegExp;
  10. /** Only find instances whose disabled state matches the given value. */
  11. disabled?: boolean;
  12. /** Only find instances whose expansion state matches the given value. */
  13. expanded?: boolean;
  14. /** Only find instances whose level matches the given value. */
  15. level?: number;
  16. }
  17. /** Harness for interacting with a standard Angular Material tree node. */
  18. declare class MatTreeNodeHarness extends ContentContainerComponentHarness<string> {
  19. /** The selector of the host element of a `MatTreeNode` instance. */
  20. static hostSelector: string;
  21. _toggle: () => Promise<_angular_cdk_testing.TestElement | null>;
  22. /**
  23. * Gets a `HarnessPredicate` that can be used to search for a tree node with specific attributes.
  24. * @param options Options for narrowing the search
  25. * @return a `HarnessPredicate` configured with the given options.
  26. */
  27. static with(options?: TreeNodeHarnessFilters): HarnessPredicate<MatTreeNodeHarness>;
  28. /** Whether the tree node is expanded. */
  29. isExpanded(): Promise<boolean>;
  30. /** Whether the tree node is expandable. */
  31. isExpandable(): Promise<boolean>;
  32. /** Whether the tree node is disabled. */
  33. isDisabled(): Promise<boolean>;
  34. /** Gets the level of the tree node. Note that this gets the aria-level and is 1 indexed. */
  35. getLevel(): Promise<number>;
  36. /** Gets the tree node's text. */
  37. getText(): Promise<string>;
  38. /** Toggles node between expanded/collapsed. Only works when node is not disabled. */
  39. toggle(): Promise<void>;
  40. /** Expands the node if it is collapsed. Only works when node is not disabled. */
  41. expand(): Promise<void>;
  42. /** Collapses the node if it is expanded. Only works when node is not disabled. */
  43. collapse(): Promise<void>;
  44. }
  45. type TextTree = {
  46. text?: string;
  47. children?: TextTree[];
  48. };
  49. /** Harness for interacting with a standard mat-tree in tests. */
  50. declare class MatTreeHarness extends ComponentHarness {
  51. /** The selector for the host element of a `MatTableHarness` instance. */
  52. static hostSelector: string;
  53. /**
  54. * Gets a `HarnessPredicate` that can be used to search for a tree with specific attributes.
  55. * @param options Options for narrowing the search
  56. * @return a `HarnessPredicate` configured with the given options.
  57. */
  58. static with(options?: TreeHarnessFilters): HarnessPredicate<MatTreeHarness>;
  59. /** Gets all of the nodes in the tree. */
  60. getNodes(filter?: TreeNodeHarnessFilters): Promise<MatTreeNodeHarness[]>;
  61. /**
  62. * Gets an object representation for the visible tree structure
  63. * If a node is under an unexpanded node it will not be included.
  64. * Eg.
  65. * Tree (all nodes expanded):
  66. * `
  67. * <mat-tree>
  68. * <mat-tree-node>Node 1<mat-tree-node>
  69. * <mat-nested-tree-node>
  70. * Node 2
  71. * <mat-nested-tree-node>
  72. * Node 2.1
  73. * <mat-tree-node>
  74. * Node 2.1.1
  75. * <mat-tree-node>
  76. * <mat-nested-tree-node>
  77. * <mat-tree-node>
  78. * Node 2.2
  79. * <mat-tree-node>
  80. * <mat-nested-tree-node>
  81. * </mat-tree>`
  82. *
  83. * Tree structure:
  84. * {
  85. * children: [
  86. * {
  87. * text: 'Node 1',
  88. * children: [
  89. * {
  90. * text: 'Node 2',
  91. * children: [
  92. * {
  93. * text: 'Node 2.1',
  94. * children: [{text: 'Node 2.1.1'}]
  95. * },
  96. * {text: 'Node 2.2'}
  97. * ]
  98. * }
  99. * ]
  100. * }
  101. * ]
  102. * };
  103. */
  104. getTreeStructure(): Promise<TextTree>;
  105. /**
  106. * Recursively collect the structured text of the tree nodes.
  107. * @param nodes A list of tree nodes
  108. * @param level The level of nodes that are being accounted for during this iteration
  109. * @param parentExpanded Whether the parent of the first node in param nodes is expanded
  110. */
  111. private _getTreeStructure;
  112. private _addChildToNode;
  113. }
  114. export { MatTreeHarness, MatTreeNodeHarness };
  115. export type { TextTree, TreeHarnessFilters, TreeNodeHarnessFilters };