Skip to content

Commit b00b75f

Browse files
committed
reverse table/testing => legacy-table/testing dependency
1 parent 12f453f commit b00b75f

File tree

11 files changed

+278
-287
lines changed

11 files changed

+278
-287
lines changed

src/material/legacy-table/testing/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ts_library(
1010
),
1111
deps = [
1212
"//src/cdk/testing",
13+
"//src/material/table/testing",
1314
],
1415
)
1516

src/material/legacy-table/testing/cell-harness.ts

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {
10-
HarnessPredicate,
11-
ComponentHarnessConstructor,
12-
ContentContainerComponentHarness,
13-
} from '@angular/cdk/testing';
14-
import {LegacyCellHarnessFilters} from './table-harness-filters';
9+
import {HarnessPredicate} from '@angular/cdk/testing';
10+
import {_MatCellHarnessBase, CellHarnessFilters} from '@angular/material/table/testing';
1511

1612
/** Harness for interacting with a standard Angular Material table cell. */
17-
export class MatLegacyCellHarness extends ContentContainerComponentHarness {
13+
export class MatLegacyCellHarness extends _MatCellHarnessBase {
1814
/** The selector for the host element of a `MatCellHarness` instance. */
1915
static hostSelector = '.mat-cell';
2016

@@ -23,81 +19,39 @@ export class MatLegacyCellHarness extends ContentContainerComponentHarness {
2319
* @param options Options for narrowing the search
2420
* @return a `HarnessPredicate` configured with the given options.
2521
*/
26-
static with(options: LegacyCellHarnessFilters = {}): HarnessPredicate<MatLegacyCellHarness> {
27-
return MatLegacyCellHarness._getCellPredicate(MatLegacyCellHarness, options);
28-
}
29-
30-
/** Gets the cell's text. */
31-
async getText(): Promise<string> {
32-
return (await this.host()).text();
33-
}
34-
35-
/** Gets the name of the column that the cell belongs to. */
36-
async getColumnName(): Promise<string> {
37-
const host = await this.host();
38-
const classAttribute = await host.getAttribute('class');
39-
40-
if (classAttribute) {
41-
const prefix = 'mat-column-';
42-
const name = classAttribute
43-
.split(' ')
44-
.map(c => c.trim())
45-
.find(c => c.startsWith(prefix));
46-
47-
if (name) {
48-
return name.split(prefix)[1];
49-
}
50-
}
51-
52-
throw Error('Could not determine column name of cell.');
53-
}
54-
55-
protected static _getCellPredicate<T extends MatLegacyCellHarness>(
56-
type: ComponentHarnessConstructor<T>,
57-
options: LegacyCellHarnessFilters,
58-
): HarnessPredicate<T> {
59-
return new HarnessPredicate(type, options)
60-
.addOption('text', options.text, (harness, text) =>
61-
HarnessPredicate.stringMatches(harness.getText(), text),
62-
)
63-
.addOption('columnName', options.columnName, (harness, name) =>
64-
HarnessPredicate.stringMatches(harness.getColumnName(), name),
65-
);
22+
static with(options: CellHarnessFilters = {}): HarnessPredicate<MatLegacyCellHarness> {
23+
return _MatCellHarnessBase._getCellPredicate(MatLegacyCellHarness, options);
6624
}
6725
}
6826

6927
/** Harness for interacting with a standard Angular Material table header cell. */
70-
export class MatLegacyHeaderCellHarness extends MatLegacyCellHarness {
28+
export class MatLegacyHeaderCellHarness extends _MatCellHarnessBase {
7129
/** The selector for the host element of a `MatHeaderCellHarness` instance. */
72-
static override hostSelector = '.mat-header-cell';
30+
static hostSelector = '.mat-header-cell';
7331

7432
/**
7533
* Gets a `HarnessPredicate` that can be used to search for
7634
* a table header cell with specific attributes.
7735
* @param options Options for narrowing the search
7836
* @return a `HarnessPredicate` configured with the given options.
7937
*/
80-
static override with(
81-
options: LegacyCellHarnessFilters = {},
82-
): HarnessPredicate<MatLegacyHeaderCellHarness> {
83-
return MatLegacyHeaderCellHarness._getCellPredicate(MatLegacyHeaderCellHarness, options);
38+
static with(options: CellHarnessFilters = {}): HarnessPredicate<MatLegacyHeaderCellHarness> {
39+
return _MatCellHarnessBase._getCellPredicate(MatLegacyHeaderCellHarness, options);
8440
}
8541
}
8642

8743
/** Harness for interacting with a standard Angular Material table footer cell. */
88-
export class MatLegacyFooterCellHarness extends MatLegacyCellHarness {
44+
export class MatLegacyFooterCellHarness extends _MatCellHarnessBase {
8945
/** The selector for the host element of a `MatFooterCellHarness` instance. */
90-
static override hostSelector = '.mat-footer-cell';
46+
static hostSelector = '.mat-footer-cell';
9147

9248
/**
9349
* Gets a `HarnessPredicate` that can be used to search for
9450
* a table footer cell with specific attributes.
9551
* @param options Options for narrowing the search
9652
* @return a `HarnessPredicate` configured with the given options.
9753
*/
98-
static override with(
99-
options: LegacyCellHarnessFilters = {},
100-
): HarnessPredicate<MatLegacyFooterCellHarness> {
101-
return MatLegacyFooterCellHarness._getCellPredicate(MatLegacyFooterCellHarness, options);
54+
static with(options: CellHarnessFilters = {}): HarnessPredicate<MatLegacyFooterCellHarness> {
55+
return _MatCellHarnessBase._getCellPredicate(MatLegacyFooterCellHarness, options);
10256
}
10357
}

src/material/legacy-table/testing/public-api.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@
99
export * from './table-harness';
1010
export * from './row-harness';
1111
export * from './cell-harness';
12-
export * from './table-harness-filters';
12+
export {
13+
CellHarnessFilters as LegacyCellHarnessFilters,
14+
RowHarnessFilters as LegacyRowHarnessFilters,
15+
TableHarnessFilters as LegacyTableHarnessFilters,
16+
MatRowHarnessColumnsText as MatLegacyRowHarnessColumnsText,
17+
MatTableHarnessColumnsText as MatLegacyTableHarnessColumnsText,
18+
_MatCellHarnessBase as _MatLegacyCellHarnessBase,
19+
_MatRowHarnessBase as _MatLegacyRowHarnessBase,
20+
_MatTableHarnessBase as _MatLegacyTableHarnessBase,
21+
} from '@angular/material/table/testing';

src/material/legacy-table/testing/row-harness.ts

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,16 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {
10-
ComponentHarness,
11-
ComponentHarnessConstructor,
12-
HarnessPredicate,
13-
parallel,
14-
} from '@angular/cdk/testing';
15-
import {LegacyRowHarnessFilters, LegacyCellHarnessFilters} from './table-harness-filters';
9+
import {HarnessPredicate} from '@angular/cdk/testing';
1610
import {
1711
MatLegacyCellHarness,
18-
MatLegacyHeaderCellHarness,
1912
MatLegacyFooterCellHarness,
13+
MatLegacyHeaderCellHarness,
2014
} from './cell-harness';
21-
22-
/** Text extracted from a table row organized by columns. */
23-
export interface MatLegacyRowHarnessColumnsText {
24-
[columnName: string]: string;
25-
}
26-
27-
export abstract class _MatLegacyRowHarnessBase<
28-
CellType extends ComponentHarnessConstructor<Cell> & {
29-
with: (options?: LegacyCellHarnessFilters) => HarnessPredicate<Cell>;
30-
},
31-
Cell extends ComponentHarness & {getText(): Promise<string>; getColumnName(): Promise<string>},
32-
> extends ComponentHarness {
33-
protected abstract _cellHarness: CellType;
34-
35-
/** Gets a list of `MatCellHarness` for all cells in the row. */
36-
async getCells(filter: LegacyCellHarnessFilters = {}): Promise<Cell[]> {
37-
return this.locatorForAll(this._cellHarness.with(filter))();
38-
}
39-
40-
/** Gets the text of the cells in the row. */
41-
async getCellTextByIndex(filter: LegacyCellHarnessFilters = {}): Promise<string[]> {
42-
const cells = await this.getCells(filter);
43-
return parallel(() => cells.map(cell => cell.getText()));
44-
}
45-
46-
/** Gets the text inside the row organized by columns. */
47-
async getCellTextByColumnName(): Promise<MatLegacyRowHarnessColumnsText> {
48-
const output: MatLegacyRowHarnessColumnsText = {};
49-
const cells = await this.getCells();
50-
const cellsData = await parallel(() =>
51-
cells.map(cell => {
52-
return parallel(() => [cell.getColumnName(), cell.getText()]);
53-
}),
54-
);
55-
cellsData.forEach(([columnName, text]) => (output[columnName] = text));
56-
return output;
57-
}
58-
}
15+
import {_MatRowHarnessBase, RowHarnessFilters} from '@angular/material/table/testing';
5916

6017
/** Harness for interacting with a standard Angular Material table row. */
61-
export class MatLegacyRowHarness extends _MatLegacyRowHarnessBase<
18+
export class MatLegacyRowHarness extends _MatRowHarnessBase<
6219
typeof MatLegacyCellHarness,
6320
MatLegacyCellHarness
6421
> {
@@ -71,13 +28,13 @@ export class MatLegacyRowHarness extends _MatLegacyRowHarnessBase<
7128
* @param options Options for narrowing the search
7229
* @return a `HarnessPredicate` configured with the given options.
7330
*/
74-
static with(options: LegacyRowHarnessFilters = {}): HarnessPredicate<MatLegacyRowHarness> {
31+
static with(options: RowHarnessFilters = {}): HarnessPredicate<MatLegacyRowHarness> {
7532
return new HarnessPredicate(MatLegacyRowHarness, options);
7633
}
7734
}
7835

7936
/** Harness for interacting with a standard Angular Material table header row. */
80-
export class MatLegacyHeaderRowHarness extends _MatLegacyRowHarnessBase<
37+
export class MatLegacyHeaderRowHarness extends _MatRowHarnessBase<
8138
typeof MatLegacyHeaderCellHarness,
8239
MatLegacyHeaderCellHarness
8340
> {
@@ -91,13 +48,13 @@ export class MatLegacyHeaderRowHarness extends _MatLegacyRowHarnessBase<
9148
* @param options Options for narrowing the search
9249
* @return a `HarnessPredicate` configured with the given options.
9350
*/
94-
static with(options: LegacyRowHarnessFilters = {}): HarnessPredicate<MatLegacyHeaderRowHarness> {
51+
static with(options: RowHarnessFilters = {}): HarnessPredicate<MatLegacyHeaderRowHarness> {
9552
return new HarnessPredicate(MatLegacyHeaderRowHarness, options);
9653
}
9754
}
9855

9956
/** Harness for interacting with a standard Angular Material table footer row. */
100-
export class MatLegacyFooterRowHarness extends _MatLegacyRowHarnessBase<
57+
export class MatLegacyFooterRowHarness extends _MatRowHarnessBase<
10158
typeof MatLegacyFooterCellHarness,
10259
MatLegacyFooterCellHarness
10360
> {
@@ -111,7 +68,7 @@ export class MatLegacyFooterRowHarness extends _MatLegacyRowHarnessBase<
11168
* @param options Options for narrowing the search
11269
* @return a `HarnessPredicate` configured with the given options.
11370
*/
114-
static with(options: LegacyRowHarnessFilters = {}): HarnessPredicate<MatLegacyFooterRowHarness> {
71+
static with(options: RowHarnessFilters = {}): HarnessPredicate<MatLegacyFooterRowHarness> {
11572
return new HarnessPredicate(MatLegacyFooterRowHarness, options);
11673
}
11774
}

src/material/legacy-table/testing/table-harness.ts

Lines changed: 10 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -6,111 +6,20 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {HarnessPredicate} from '@angular/cdk/testing';
910
import {
10-
ComponentHarness,
11-
ComponentHarnessConstructor,
12-
ContentContainerComponentHarness,
13-
HarnessPredicate,
14-
parallel,
15-
} from '@angular/cdk/testing';
16-
import {LegacyTableHarnessFilters, LegacyRowHarnessFilters} from './table-harness-filters';
17-
import {
18-
MatLegacyRowHarness,
19-
MatLegacyHeaderRowHarness,
2011
MatLegacyFooterRowHarness,
21-
MatLegacyRowHarnessColumnsText,
12+
MatLegacyHeaderRowHarness,
13+
MatLegacyRowHarness,
2214
} from './row-harness';
23-
24-
/** Text extracted from a table organized by columns. */
25-
export interface MatLegacyTableHarnessColumnsText {
26-
[columnName: string]: {
27-
text: string[];
28-
headerText: string[];
29-
footerText: string[];
30-
};
31-
}
32-
33-
interface RowBase extends ComponentHarness {
34-
getCellTextByColumnName(): Promise<MatLegacyRowHarnessColumnsText>;
35-
getCellTextByIndex(): Promise<string[]>;
36-
}
37-
38-
export abstract class _MatLegacyTableHarnessBase<
39-
HeaderRowType extends ComponentHarnessConstructor<HeaderRow> & {
40-
with: (options?: LegacyRowHarnessFilters) => HarnessPredicate<HeaderRow>;
41-
},
42-
HeaderRow extends RowBase,
43-
RowType extends ComponentHarnessConstructor<Row> & {
44-
with: (options?: LegacyRowHarnessFilters) => HarnessPredicate<Row>;
45-
},
46-
Row extends RowBase,
47-
FooterRowType extends ComponentHarnessConstructor<FooterRow> & {
48-
with: (options?: LegacyRowHarnessFilters) => HarnessPredicate<FooterRow>;
49-
},
50-
FooterRow extends RowBase,
51-
> extends ContentContainerComponentHarness<string> {
52-
protected abstract _headerRowHarness: HeaderRowType;
53-
protected abstract _rowHarness: RowType;
54-
protected abstract _footerRowHarness: FooterRowType;
55-
56-
/** Gets all of the header rows in a table. */
57-
async getHeaderRows(filter: LegacyRowHarnessFilters = {}): Promise<HeaderRow[]> {
58-
return this.locatorForAll(this._headerRowHarness.with(filter))();
59-
}
60-
61-
/** Gets all of the regular data rows in a table. */
62-
async getRows(filter: LegacyRowHarnessFilters = {}): Promise<Row[]> {
63-
return this.locatorForAll(this._rowHarness.with(filter))();
64-
}
65-
66-
/** Gets all of the footer rows in a table. */
67-
async getFooterRows(filter: LegacyRowHarnessFilters = {}): Promise<FooterRow[]> {
68-
return this.locatorForAll(this._footerRowHarness.with(filter))();
69-
}
70-
71-
/** Gets the text inside the entire table organized by rows. */
72-
async getCellTextByIndex(): Promise<string[][]> {
73-
const rows = await this.getRows();
74-
return parallel(() => rows.map(row => row.getCellTextByIndex()));
75-
}
76-
77-
/** Gets the text inside the entire table organized by columns. */
78-
async getCellTextByColumnName(): Promise<MatLegacyTableHarnessColumnsText> {
79-
const [headerRows, footerRows, dataRows] = await parallel(() => [
80-
this.getHeaderRows(),
81-
this.getFooterRows(),
82-
this.getRows(),
83-
]);
84-
85-
const text: MatLegacyTableHarnessColumnsText = {};
86-
const [headerData, footerData, rowsData] = await parallel(() => [
87-
parallel(() => headerRows.map(row => row.getCellTextByColumnName())),
88-
parallel(() => footerRows.map(row => row.getCellTextByColumnName())),
89-
parallel(() => dataRows.map(row => row.getCellTextByColumnName())),
90-
]);
91-
92-
rowsData.forEach(data => {
93-
Object.keys(data).forEach(columnName => {
94-
const cellText = data[columnName];
95-
96-
if (!text[columnName]) {
97-
text[columnName] = {
98-
headerText: getCellTextsByColumn(headerData, columnName),
99-
footerText: getCellTextsByColumn(footerData, columnName),
100-
text: [],
101-
};
102-
}
103-
104-
text[columnName].text.push(cellText);
105-
});
106-
});
107-
108-
return text;
109-
}
110-
}
15+
import {
16+
_MatTableHarnessBase,
17+
MatRowHarnessColumnsText,
18+
TableHarnessFilters,
19+
} from '@angular/material/table/testing';
11120

11221
/** Harness for interacting with a standard mat-table in tests. */
113-
export class MatLegacyTableHarness extends _MatLegacyTableHarnessBase<
22+
export class MatLegacyTableHarness extends _MatTableHarnessBase<
11423
typeof MatLegacyHeaderRowHarness,
11524
MatLegacyHeaderRowHarness,
11625
typeof MatLegacyRowHarness,
@@ -129,25 +38,7 @@ export class MatLegacyTableHarness extends _MatLegacyTableHarnessBase<
12938
* @param options Options for narrowing the search
13039
* @return a `HarnessPredicate` configured with the given options.
13140
*/
132-
static with(options: LegacyTableHarnessFilters = {}): HarnessPredicate<MatLegacyTableHarness> {
41+
static with(options: TableHarnessFilters = {}): HarnessPredicate<MatLegacyTableHarness> {
13342
return new HarnessPredicate(MatLegacyTableHarness, options);
13443
}
13544
}
136-
137-
/** Extracts the text of cells only under a particular column. */
138-
function getCellTextsByColumn(
139-
rowsData: MatLegacyRowHarnessColumnsText[],
140-
column: string,
141-
): string[] {
142-
const columnTexts: string[] = [];
143-
144-
rowsData.forEach(data => {
145-
Object.keys(data).forEach(columnName => {
146-
if (columnName === column) {
147-
columnTexts.push(data[columnName]);
148-
}
149-
});
150-
});
151-
152-
return columnTexts;
153-
}

src/material/table/testing/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ ts_library(
1010
),
1111
deps = [
1212
"//src/cdk/testing",
13-
"//src/material/legacy-table/testing",
1413
],
1514
)
1615

0 commit comments

Comments
 (0)