6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { ComponentHarness , HarnessPredicate , parallel } from '@angular/cdk/testing' ;
10
- import { RowHarnessFilters , CellHarnessFilters } from './ table-harness-filters ' ;
9
+ import { HarnessPredicate } from '@angular/cdk/testing' ;
10
+ import { _MatRowHarnessBase , RowHarnessFilters } from '@angular/material/ table/testing ' ;
11
11
import { MatCellHarness , MatHeaderCellHarness , MatFooterCellHarness } from './cell-harness' ;
12
12
13
- /** Text extracted from a table row organized by columns. */
14
- export interface MatRowHarnessColumnsText {
15
- [ columnName : string ] : string ;
16
- }
17
-
18
13
/** Harness for interacting with an MDC-based Angular Material table row. */
19
- export class MatRowHarness extends ComponentHarness {
14
+ export class MatRowHarness extends _MatRowHarnessBase < typeof MatCellHarness , MatCellHarness > {
20
15
/** The selector for the host element of a `MatRowHarness` instance. */
21
16
static hostSelector = '.mat-mdc-row' ;
17
+ protected _cellHarness = MatCellHarness ;
22
18
23
19
/**
24
20
* Gets a `HarnessPredicate` that can be used to search for a table row with specific attributes.
@@ -28,27 +24,14 @@ export class MatRowHarness extends ComponentHarness {
28
24
static with ( options : RowHarnessFilters = { } ) : HarnessPredicate < MatRowHarness > {
29
25
return new HarnessPredicate ( MatRowHarness , options ) ;
30
26
}
31
-
32
- /** Gets a list of `MatCellHarness` for all cells in the row. */
33
- async getCells ( filter : CellHarnessFilters = { } ) : Promise < MatCellHarness [ ] > {
34
- return this . locatorForAll ( MatCellHarness . with ( filter ) ) ( ) ;
35
- }
36
-
37
- /** Gets the text of the cells in the row. */
38
- async getCellTextByIndex ( filter : CellHarnessFilters = { } ) : Promise < string [ ] > {
39
- return getCellTextByIndex ( this , filter ) ;
40
- }
41
-
42
- /** Gets the text inside the row organized by columns. */
43
- async getCellTextByColumnName ( ) : Promise < MatRowHarnessColumnsText > {
44
- return getCellTextByColumnName ( this ) ;
45
- }
46
27
}
47
28
48
29
/** Harness for interacting with an MDC-based Angular Material table header row. */
49
- export class MatHeaderRowHarness extends ComponentHarness {
30
+ export class MatHeaderRowHarness extends _MatRowHarnessBase <
31
+ typeof MatHeaderCellHarness , MatHeaderCellHarness > {
50
32
/** The selector for the host element of a `MatHeaderRowHarness` instance. */
51
33
static hostSelector = '.mat-mdc-header-row' ;
34
+ protected _cellHarness = MatHeaderCellHarness ;
52
35
53
36
/**
54
37
* Gets a `HarnessPredicate` that can be used to search for
@@ -59,28 +42,15 @@ export class MatHeaderRowHarness extends ComponentHarness {
59
42
static with ( options : RowHarnessFilters = { } ) : HarnessPredicate < MatHeaderRowHarness > {
60
43
return new HarnessPredicate ( MatHeaderRowHarness , options ) ;
61
44
}
62
-
63
- /** Gets a list of `MatHeaderCellHarness` for all cells in the row. */
64
- async getCells ( filter : CellHarnessFilters = { } ) : Promise < MatHeaderCellHarness [ ] > {
65
- return this . locatorForAll ( MatHeaderCellHarness . with ( filter ) ) ( ) ;
66
- }
67
-
68
- /** Gets the text of the cells in the header row. */
69
- async getCellTextByIndex ( filter : CellHarnessFilters = { } ) : Promise < string [ ] > {
70
- return getCellTextByIndex ( this , filter ) ;
71
- }
72
-
73
- /** Gets the text inside the header row organized by columns. */
74
- async getCellTextByColumnName ( ) : Promise < MatRowHarnessColumnsText > {
75
- return getCellTextByColumnName ( this ) ;
76
- }
77
45
}
78
46
79
47
80
48
/** Harness for interacting with an MDC-based Angular Material table footer row. */
81
- export class MatFooterRowHarness extends ComponentHarness {
49
+ export class MatFooterRowHarness extends _MatRowHarnessBase <
50
+ typeof MatFooterCellHarness , MatFooterCellHarness > {
82
51
/** The selector for the host element of a `MatFooterRowHarness` instance. */
83
52
static hostSelector = '.mat-mdc-footer-row' ;
53
+ protected _cellHarness = MatFooterCellHarness ;
84
54
85
55
/**
86
56
* Gets a `HarnessPredicate` that can be used to search for
@@ -91,39 +61,4 @@ export class MatFooterRowHarness extends ComponentHarness {
91
61
static with ( options : RowHarnessFilters = { } ) : HarnessPredicate < MatFooterRowHarness > {
92
62
return new HarnessPredicate ( MatFooterRowHarness , options ) ;
93
63
}
94
-
95
- /** Gets a list of `MatFooterCellHarness` for all cells in the row. */
96
- async getCells ( filter : CellHarnessFilters = { } ) : Promise < MatFooterCellHarness [ ] > {
97
- return this . locatorForAll ( MatFooterCellHarness . with ( filter ) ) ( ) ;
98
- }
99
-
100
- /** Gets the text of the cells in the footer row. */
101
- async getCellTextByIndex ( filter : CellHarnessFilters = { } ) : Promise < string [ ] > {
102
- return getCellTextByIndex ( this , filter ) ;
103
- }
104
-
105
- /** Gets the text inside the footer row organized by columns. */
106
- async getCellTextByColumnName ( ) : Promise < MatRowHarnessColumnsText > {
107
- return getCellTextByColumnName ( this ) ;
108
- }
109
- }
110
-
111
-
112
- async function getCellTextByIndex ( harness : {
113
- getCells : ( filter ?: CellHarnessFilters ) => Promise < MatCellHarness [ ] >
114
- } , filter : CellHarnessFilters ) : Promise < string [ ] > {
115
- const cells = await harness . getCells ( filter ) ;
116
- return parallel ( ( ) => cells . map ( cell => cell . getText ( ) ) ) ;
117
- }
118
-
119
- async function getCellTextByColumnName ( harness : {
120
- getCells : ( ) => Promise < MatCellHarness [ ] >
121
- } ) : Promise < MatRowHarnessColumnsText > {
122
- const output : MatRowHarnessColumnsText = { } ;
123
- const cells = await harness . getCells ( ) ;
124
- const cellsData = await parallel ( ( ) => cells . map ( cell => {
125
- return parallel ( ( ) => [ cell . getColumnName ( ) , cell . getText ( ) ] ) ;
126
- } ) ) ;
127
- cellsData . forEach ( ( [ columnName , text ] ) => output [ columnName ] = text ) ;
128
- return output ;
129
64
}
0 commit comments