index.d.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { BaseHarnessFilters, ContentContainerComponentHarness, ComponentHarnessConstructor, HarnessPredicate, ComponentHarness } from '@angular/cdk/testing';
  2. /** A set of criteria that can be used to filter a list of cell harness instances. */
  3. interface CellHarnessFilters extends BaseHarnessFilters {
  4. /** Only find instances whose text matches the given value. */
  5. text?: string | RegExp;
  6. /** Only find instances whose column name matches the given value. */
  7. columnName?: string | RegExp;
  8. }
  9. /** A set of criteria that can be used to filter a list of row harness instances. */
  10. interface RowHarnessFilters extends BaseHarnessFilters {
  11. }
  12. /** A set of criteria that can be used to filter a list of table harness instances. */
  13. interface TableHarnessFilters extends BaseHarnessFilters {
  14. }
  15. declare abstract class _MatCellHarnessBase extends ContentContainerComponentHarness {
  16. /** Gets the cell's text. */
  17. getText(): Promise<string>;
  18. /** Gets the name of the column that the cell belongs to. */
  19. getColumnName(): Promise<string>;
  20. protected static _getCellPredicate<T extends MatCellHarness>(type: ComponentHarnessConstructor<T>, options: CellHarnessFilters): HarnessPredicate<T>;
  21. }
  22. /** Harness for interacting with an Angular Material table cell. */
  23. declare class MatCellHarness extends _MatCellHarnessBase {
  24. /** The selector for the host element of a `MatCellHarness` instance. */
  25. static hostSelector: string;
  26. /**
  27. * Gets a `HarnessPredicate` that can be used to search for a table cell with specific attributes.
  28. * @param options Options for narrowing the search
  29. * @return a `HarnessPredicate` configured with the given options.
  30. */
  31. static with(options?: CellHarnessFilters): HarnessPredicate<MatCellHarness>;
  32. }
  33. /** Harness for interacting with an Angular Material table header cell. */
  34. declare class MatHeaderCellHarness extends _MatCellHarnessBase {
  35. /** The selector for the host element of a `MatHeaderCellHarness` instance. */
  36. static hostSelector: string;
  37. /**
  38. * Gets a `HarnessPredicate` that can be used to search for a table header cell with specific
  39. * attributes.
  40. * @param options Options for narrowing the search
  41. * @return a `HarnessPredicate` configured with the given options.
  42. */
  43. static with(options?: CellHarnessFilters): HarnessPredicate<MatHeaderCellHarness>;
  44. }
  45. /** Harness for interacting with an Angular Material table footer cell. */
  46. declare class MatFooterCellHarness extends _MatCellHarnessBase {
  47. /** The selector for the host element of a `MatFooterCellHarness` instance. */
  48. static hostSelector: string;
  49. /**
  50. * Gets a `HarnessPredicate` that can be used to search for a table footer cell with specific
  51. * attributes.
  52. * @param options Options for narrowing the search
  53. * @return a `HarnessPredicate` configured with the given options.
  54. */
  55. static with(options?: CellHarnessFilters): HarnessPredicate<MatFooterCellHarness>;
  56. }
  57. /** Text extracted from a table row organized by columns. */
  58. interface MatRowHarnessColumnsText {
  59. [columnName: string]: string;
  60. }
  61. declare abstract class _MatRowHarnessBase<CellType extends ComponentHarnessConstructor<Cell> & {
  62. with: (options?: CellHarnessFilters) => HarnessPredicate<Cell>;
  63. }, Cell extends _MatCellHarnessBase> extends ComponentHarness {
  64. protected abstract _cellHarness: CellType;
  65. /** Gets a list of `MatCellHarness` for all cells in the row. */
  66. getCells(filter?: CellHarnessFilters): Promise<Cell[]>;
  67. /** Gets the text of the cells in the row. */
  68. getCellTextByIndex(filter?: CellHarnessFilters): Promise<string[]>;
  69. /** Gets the text inside the row organized by columns. */
  70. getCellTextByColumnName(): Promise<MatRowHarnessColumnsText>;
  71. }
  72. /** Harness for interacting with an Angular Material table row. */
  73. declare class MatRowHarness extends _MatRowHarnessBase<typeof MatCellHarness, MatCellHarness> {
  74. /** The selector for the host element of a `MatRowHarness` instance. */
  75. static hostSelector: string;
  76. protected _cellHarness: typeof MatCellHarness;
  77. /**
  78. * Gets a `HarnessPredicate` that can be used to search for a table row with specific attributes.
  79. * @param options Options for narrowing the search
  80. * @return a `HarnessPredicate` configured with the given options.
  81. */
  82. static with<T extends MatRowHarness>(this: ComponentHarnessConstructor<T>, options?: RowHarnessFilters): HarnessPredicate<T>;
  83. }
  84. /** Harness for interacting with an Angular Material table header row. */
  85. declare class MatHeaderRowHarness extends _MatRowHarnessBase<typeof MatHeaderCellHarness, MatHeaderCellHarness> {
  86. /** The selector for the host element of a `MatHeaderRowHarness` instance. */
  87. static hostSelector: string;
  88. protected _cellHarness: typeof MatHeaderCellHarness;
  89. /**
  90. * Gets a `HarnessPredicate` that can be used to search for a table header row with specific
  91. * attributes.
  92. * @param options Options for narrowing the search
  93. * @return a `HarnessPredicate` configured with the given options.
  94. */
  95. static with<T extends MatHeaderRowHarness>(this: ComponentHarnessConstructor<T>, options?: RowHarnessFilters): HarnessPredicate<T>;
  96. }
  97. /** Harness for interacting with an Angular Material table footer row. */
  98. declare class MatFooterRowHarness extends _MatRowHarnessBase<typeof MatFooterCellHarness, MatFooterCellHarness> {
  99. /** The selector for the host element of a `MatFooterRowHarness` instance. */
  100. static hostSelector: string;
  101. protected _cellHarness: typeof MatFooterCellHarness;
  102. /**
  103. * Gets a `HarnessPredicate` that can be used to search for a table footer row cell with specific
  104. * attributes.
  105. * @param options Options for narrowing the search
  106. * @return a `HarnessPredicate` configured with the given options.
  107. */
  108. static with<T extends MatFooterRowHarness>(this: ComponentHarnessConstructor<T>, options?: RowHarnessFilters): HarnessPredicate<T>;
  109. }
  110. /** Text extracted from a table organized by columns. */
  111. interface MatTableHarnessColumnsText {
  112. [columnName: string]: {
  113. text: string[];
  114. headerText: string[];
  115. footerText: string[];
  116. };
  117. }
  118. /** Harness for interacting with a mat-table in tests. */
  119. declare class MatTableHarness extends ContentContainerComponentHarness<string> {
  120. /** The selector for the host element of a `MatTableHarness` instance. */
  121. static hostSelector: string;
  122. _headerRowHarness: typeof MatHeaderRowHarness;
  123. _rowHarness: typeof MatRowHarness;
  124. private _footerRowHarness;
  125. /**
  126. * Gets a `HarnessPredicate` that can be used to search for a table with specific attributes.
  127. * @param options Options for narrowing the search
  128. * @return a `HarnessPredicate` configured with the given options.
  129. */
  130. static with<T extends MatTableHarness>(this: ComponentHarnessConstructor<T>, options?: TableHarnessFilters): HarnessPredicate<T>;
  131. /** Gets all the header rows in a table. */
  132. getHeaderRows(filter?: RowHarnessFilters): Promise<MatHeaderRowHarness[]>;
  133. /** Gets all the regular data rows in a table. */
  134. getRows(filter?: RowHarnessFilters): Promise<MatRowHarness[]>;
  135. /** Gets all the footer rows in a table. */
  136. getFooterRows(filter?: RowHarnessFilters): Promise<MatFooterRowHarness[]>;
  137. /** Gets the text inside the entire table organized by rows. */
  138. getCellTextByIndex(): Promise<string[][]>;
  139. /** Gets the text inside the entire table organized by columns. */
  140. getCellTextByColumnName(): Promise<MatTableHarnessColumnsText>;
  141. }
  142. export { MatCellHarness, MatFooterCellHarness, MatFooterRowHarness, MatHeaderCellHarness, MatHeaderRowHarness, MatRowHarness, MatTableHarness, _MatCellHarnessBase, _MatRowHarnessBase };
  143. export type { CellHarnessFilters, MatRowHarnessColumnsText, MatTableHarnessColumnsText, RowHarnessFilters, TableHarnessFilters };