Skip to content

Commit 1b1a569

Browse files
andrewseguinjelbourn
authored andcommitted
test(table): remove redundant test (#15273)
1 parent 140c4e0 commit 1b1a569

File tree

1 file changed

+92
-133
lines changed

1 file changed

+92
-133
lines changed

src/cdk/table/table.spec.ts

Lines changed: 92 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe('CdkTable', () => {
3232
let component: any;
3333
let tableElement: HTMLElement;
3434

35-
function createComponent<T>(componentType: Type<T>, declarations: any[] = []):
36-
ComponentFixture<T> {
35+
function createComponent<T>(
36+
componentType: Type<T>, declarations: any[] = []): ComponentFixture<T> {
3737
TestBed.configureTestingModule({
3838
imports: [CdkTableModule, BidiModule],
3939
declarations: [componentType, ...declarations],
@@ -306,28 +306,6 @@ describe('CdkTable', () => {
306306
]);
307307
});
308308

309-
it('should be able to render and change multiple header and footer rows', () => {
310-
setupTableTestApp(MultipleHeaderFooterRowsCdkTableApp);
311-
fixture.detectChanges();
312-
313-
expectTableToMatchContent(tableElement, [
314-
['first-header'],
315-
['second-header'],
316-
['first-footer'],
317-
['second-footer'],
318-
]);
319-
320-
component.showAlternativeHeadersAndFooters = true;
321-
fixture.detectChanges();
322-
323-
expectTableToMatchContent(tableElement, [
324-
['first-header'],
325-
['second-header'],
326-
['first-footer'],
327-
['second-footer'],
328-
]);
329-
});
330-
331309
it('should be able to project a caption', fakeAsync(() => {
332310
setupTableTestApp(NativeHtmlTableWithCaptionApp);
333311
fixture.detectChanges();
@@ -447,8 +425,7 @@ describe('CdkTable', () => {
447425
it('should throw an error if the data source is not valid', () => {
448426
component.dataSource = {invalid: 'dataSource'};
449427

450-
expect(() => fixture.detectChanges())
451-
.toThrowError(getTableUnknownDataSourceError().message);
428+
expect(() => fixture.detectChanges()).toThrowError(getTableUnknownDataSourceError().message);
452429
});
453430

454431
it('should throw an error if the data source is not valid', () => {
@@ -526,8 +503,7 @@ describe('CdkTable', () => {
526503
const rowGroups: HTMLElement[] = Array.from(thisTableElement.querySelectorAll('thead, tfoot'));
527504
expect(rowGroups.length).toBe(2, 'Expected table to have a thead and tfoot');
528505
for (const group of rowGroups) {
529-
expect(group.style.display)
530-
.toBe('none', 'Expected thead and tfoot to be `display: none`');
506+
expect(group.style.display).toBe('none', 'Expected thead and tfoot to be `display: none`');
531507
}
532508
});
533509

@@ -566,15 +542,15 @@ describe('CdkTable', () => {
566542
});
567543

568544
it('should throw an error if a column definition is requested but not defined after render',
569-
fakeAsync(() => {
570-
const columnDefinitionMissingAfterRenderFixture =
571-
createComponent(MissingColumnDefAfterRenderCdkTableApp);
572-
expect(() => {
573-
columnDefinitionMissingAfterRenderFixture.detectChanges();
574-
flush();
575-
columnDefinitionMissingAfterRenderFixture.detectChanges();
576-
}).toThrowError(getTableUnknownColumnError('column_a').message);
577-
}));
545+
fakeAsync(() => {
546+
const columnDefinitionMissingAfterRenderFixture =
547+
createComponent(MissingColumnDefAfterRenderCdkTableApp);
548+
expect(() => {
549+
columnDefinitionMissingAfterRenderFixture.detectChanges();
550+
flush();
551+
columnDefinitionMissingAfterRenderFixture.detectChanges();
552+
}).toThrowError(getTableUnknownColumnError('column_a').message);
553+
}));
578554

579555
it('should throw an error if the row definitions are missing', () => {
580556
expect(() => createComponent(MissingAllRowDefsCdkTableApp).detectChanges())
@@ -660,18 +636,18 @@ describe('CdkTable', () => {
660636
});
661637

662638
it('should error if there is row data that does not have a matching row template',
663-
fakeAsync(() => {
664-
const whenRowWithoutDefaultFixture = createComponent(WhenRowWithoutDefaultCdkTableApp);
665-
const data = whenRowWithoutDefaultFixture.componentInstance.dataSource.data;
666-
expect(() => {
667-
try {
668-
whenRowWithoutDefaultFixture.detectChanges();
669-
flush();
670-
} catch {
671-
flush();
672-
}
673-
}).toThrowError(getTableMissingMatchingRowDefError(data[0]).message);
674-
}));
639+
fakeAsync(() => {
640+
const whenRowWithoutDefaultFixture = createComponent(WhenRowWithoutDefaultCdkTableApp);
641+
const data = whenRowWithoutDefaultFixture.componentInstance.dataSource.data;
642+
expect(() => {
643+
try {
644+
whenRowWithoutDefaultFixture.detectChanges();
645+
flush();
646+
} catch {
647+
flush();
648+
}
649+
}).toThrowError(getTableMissingMatchingRowDefError(data[0]).message);
650+
}));
675651

676652
it('should fail when multiple rows match data without multiTemplateDataRows', fakeAsync(() => {
677653
let whenFixture = createComponent(WhenRowMultipleDefaultsCdkTableApp);
@@ -717,40 +693,40 @@ describe('CdkTable', () => {
717693
});
718694

719695
it('should have the correct data and row indicies when data contains multiple instances of ' +
720-
'the same object instance', () => {
721-
setupTableTestApp(WhenRowCdkTableApp);
722-
component.multiTemplateDataRows = true;
723-
component.showIndexColumns();
724-
725-
const obj = {value: true};
726-
component.dataSource.data = [obj, obj, obj, obj];
727-
fixture.detectChanges();
728-
729-
expectTableToMatchContent(tableElement, [
730-
['Index', 'Data Index', 'Render Index'],
731-
['', '0', '0'],
732-
['', '1', '1'],
733-
['', '1', '2'],
734-
['', '2', '3'],
735-
['', '3', '4'],
736-
]);
737-
738-
// Push unique data on the front and add another obj to the array
739-
component.dataSource.data = [{value: false}, obj, obj, obj, obj, obj];
740-
fixture.detectChanges();
741-
742-
expectTableToMatchContent(tableElement, [
743-
['Index', 'Data Index', 'Render Index'],
744-
['', '0', '0'],
745-
['', '1', '1'],
746-
['', '1', '2'],
747-
['', '2', '3'],
748-
['', '3', '4'],
749-
['', '4', '5'],
750-
['', '5', '6'],
751-
]);
752-
753-
});
696+
'the same object instance',
697+
() => {
698+
setupTableTestApp(WhenRowCdkTableApp);
699+
component.multiTemplateDataRows = true;
700+
component.showIndexColumns();
701+
702+
const obj = {value: true};
703+
component.dataSource.data = [obj, obj, obj, obj];
704+
fixture.detectChanges();
705+
706+
expectTableToMatchContent(tableElement, [
707+
['Index', 'Data Index', 'Render Index'],
708+
['', '0', '0'],
709+
['', '1', '1'],
710+
['', '1', '2'],
711+
['', '2', '3'],
712+
['', '3', '4'],
713+
]);
714+
715+
// Push unique data on the front and add another obj to the array
716+
component.dataSource.data = [{value: false}, obj, obj, obj, obj, obj];
717+
fixture.detectChanges();
718+
719+
expectTableToMatchContent(tableElement, [
720+
['Index', 'Data Index', 'Render Index'],
721+
['', '0', '0'],
722+
['', '1', '1'],
723+
['', '1', '2'],
724+
['', '2', '3'],
725+
['', '3', '4'],
726+
['', '4', '5'],
727+
['', '5', '6'],
728+
]);
729+
});
754730
});
755731
});
756732

@@ -774,8 +750,7 @@ describe('CdkTable', () => {
774750
});
775751
}
776752

777-
function expectStickyStyles(
778-
element: any, zIndex: string, directions: PositionDirections = {}) {
753+
function expectStickyStyles(element: any, zIndex: string, directions: PositionDirections = {}) {
779754
expect(element.style.position).toContain('sticky');
780755
expect(element.style.zIndex).toBe(zIndex, `Expected zIndex to be ${zIndex}`);
781756

@@ -820,8 +795,8 @@ describe('CdkTable', () => {
820795

821796
expectStickyStyles(headerRows[0], '100', {top: '0px'});
822797
expectNoStickyStyles([headerRows[1]]);
823-
expectStickyStyles(headerRows[2], '100',
824-
{top: headerRows[0].getBoundingClientRect().height + 'px'});
798+
expectStickyStyles(
799+
headerRows[2], '100', {top: headerRows[0].getBoundingClientRect().height + 'px'});
825800

826801
component.stickyHeaders = [];
827802
fixture.detectChanges();
@@ -832,8 +807,8 @@ describe('CdkTable', () => {
832807
component.stickyFooters = ['footer-1', 'footer-3'];
833808
fixture.detectChanges();
834809

835-
expectStickyStyles(footerRows[0], '10',
836-
{bottom: footerRows[1].getBoundingClientRect().height + 'px'});
810+
expectStickyStyles(
811+
footerRows[0], '10', {bottom: footerRows[1].getBoundingClientRect().height + 'px'});
837812
expectNoStickyStyles([footerRows[1]]);
838813
expectStickyStyles(footerRows[2], '10', {bottom: '0px'});
839814

@@ -1200,8 +1175,8 @@ describe('CdkTable', () => {
12001175
mutateData();
12011176

12021177
// Change each item reference to show that the trackby is not checking the item properties.
1203-
component.dataSource.data = component.dataSource.data
1204-
.map((item: TestData) => ({a: item.a, b: item.b, c: item.c}));
1178+
component.dataSource.data =
1179+
component.dataSource.data.map((item: TestData) => ({a: item.a, b: item.b, c: item.c}));
12051180

12061181
// Expect that all the rows are considered new since their references are all different
12071182
const changedRows = getRows(tableElement);
@@ -1217,8 +1192,8 @@ describe('CdkTable', () => {
12171192

12181193
// Change each item reference to show that the trackby is checking the item properties.
12191194
// Otherwise this would cause them all to be removed/added.
1220-
component.dataSource.data = component.dataSource.data
1221-
.map((item: TestData) => ({a: item.a, b: item.b, c: item.c}));
1195+
component.dataSource.data =
1196+
component.dataSource.data.map((item: TestData) => ({a: item.a, b: item.b, c: item.c}));
12221197

12231198
// Expect that the first and second rows were swapped and that the last row is new
12241199
const changedRows = getRows(tableElement);
@@ -1234,8 +1209,8 @@ describe('CdkTable', () => {
12341209

12351210
// Change each item reference to show that the trackby is checking the index.
12361211
// Otherwise this would cause them all to be removed/added.
1237-
component.dataSource.data = component.dataSource.data
1238-
.map((item: TestData) => ({a: item.a, b: item.b, c: item.c}));
1212+
component.dataSource.data =
1213+
component.dataSource.data.map((item: TestData) => ({a: item.a, b: item.b, c: item.c}));
12391214

12401215
// Expect first two to be the same since they were swapped but indicies are consistent.
12411216
// The third element was removed and caught by the table so it was removed before another
@@ -1256,8 +1231,8 @@ describe('CdkTable', () => {
12561231

12571232
// Change each item reference to show that the trackby is checking the index.
12581233
// Otherwise this would cause them all to be removed/added.
1259-
component.dataSource.data = component.dataSource.data
1260-
.map((item: TestData) => ({a: item.a, b: item.b, c: item.c}));
1234+
component.dataSource.data =
1235+
component.dataSource.data.map((item: TestData) => ({a: item.a, b: item.b, c: item.c}));
12611236

12621237
// Expect the rows were given the right implicit data even though the rows were not moved.
12631238
fixture.detectChanges();
@@ -1396,13 +1371,19 @@ interface TestData {
13961371
class FakeDataSource extends DataSource<TestData> {
13971372
isConnected = false;
13981373

1399-
get data() { return this._dataChange.getValue(); }
1400-
set data(data: TestData[]) { this._dataChange.next(data); }
1374+
get data() {
1375+
return this._dataChange.getValue();
1376+
}
1377+
set data(data: TestData[]) {
1378+
this._dataChange.next(data);
1379+
}
14011380
_dataChange = new BehaviorSubject<TestData[]>([]);
14021381

14031382
constructor() {
14041383
super();
1405-
for (let i = 0; i < 3; i++) { this.addData(); }
1384+
for (let i = 0; i < 3; i++) {
1385+
this.addData();
1386+
}
14061387
}
14071388

14081389
connect(collectionViewer: CollectionViewer) {
@@ -1436,7 +1417,7 @@ class BooleanDataSource extends DataSource<boolean> {
14361417
return this._dataChange;
14371418
}
14381419

1439-
disconnect() { }
1420+
disconnect() {}
14401421
}
14411422

14421423
@Component({
@@ -1561,40 +1542,14 @@ class NullDataCdkTableApp {
15611542
<td cdk-footer-cell *cdkFooterCellDef> second-footer </td>
15621543
</ng-container>
15631544
1564-
<ng-container *ngIf="!showAlternativeHeadersAndFooters">
1565-
<tr cdk-header-row *cdkHeaderRowDef="['first-header']"></tr>
1566-
<tr cdk-header-row *cdkHeaderRowDef="['second-header']"></tr>
1567-
<tr cdk-footer-row *cdkFooterRowDef="['first-footer']"></tr>
1568-
<tr cdk-footer-row *cdkFooterRowDef="['second-footer']"></tr>
1569-
</ng-container>
1570-
1571-
<ng-container cdkColumnDef="alt-first-header">
1572-
<th cdk-header-cell *cdkHeaderCellDef> alt-first-header </th>
1573-
</ng-container>
1574-
1575-
<ng-container cdkColumnDef="alt-second-header">
1576-
<th cdk-header-cell *cdkHeaderCellDef> alt-second-header </th>
1577-
</ng-container>
1578-
1579-
<ng-container cdkColumnDef="alt-first-footer">
1580-
<td cdk-footer-cell *cdkFooterCellDef> alt-first-footer </td>
1581-
</ng-container>
1582-
1583-
<ng-container cdkColumnDef="alt-second-footer">
1584-
<td cdk-footer-cell *cdkFooterCellDef> alt-second-footer </td>
1585-
</ng-container>
1586-
1587-
<ng-container *ngIf="showAlternativeHeadersAndFooters">
1588-
<tr cdk-header-row *cdkHeaderRowDef="['alt-first-header']"></tr>
1589-
<tr cdk-header-row *cdkHeaderRowDef="['alt-second-header']"></tr>
1590-
<tr cdk-footer-row *cdkFooterRowDef="['alt-first-footer']"></tr>
1591-
<tr cdk-footer-row *cdkFooterRowDef="['alt-second-footer']"></tr>
1592-
</ng-container>
1545+
<tr cdk-header-row *cdkHeaderRowDef="['first-header']"></tr>
1546+
<tr cdk-header-row *cdkHeaderRowDef="['second-header']"></tr>
1547+
<tr cdk-footer-row *cdkFooterRowDef="['first-footer']"></tr>
1548+
<tr cdk-footer-row *cdkFooterRowDef="['second-footer']"></tr>
15931549
</cdk-table>
15941550
`
15951551
})
15961552
class MultipleHeaderFooterRowsCdkTableApp {
1597-
showAlternativeHeadersAndFooters = false;
15981553
}
15991554

16001555
@Component({
@@ -1656,7 +1611,9 @@ class WhenRowCdkTableApp {
16561611
isIndex1 = (index: number, _rowData: TestData) => index == 1;
16571612
hasC3 = (_index: number, rowData: TestData) => rowData.c == 'c_3';
16581613

1659-
constructor() { this.dataSource.addData(); }
1614+
constructor() {
1615+
this.dataSource.addData();
1616+
}
16601617

16611618
@ViewChild(CdkTable) table: CdkTable<TestData>;
16621619

@@ -2030,7 +1987,9 @@ class MissingColumnDefAfterRenderCdkTableApp implements AfterViewInit {
20301987
displayedColumns: string[] = [];
20311988

20321989
ngAfterViewInit() {
2033-
setTimeout(() => { this.displayedColumns = ['column_a']; }, 0);
1990+
setTimeout(() => {
1991+
this.displayedColumns = ['column_a'];
1992+
}, 0);
20341993
}
20351994
}
20361995

0 commit comments

Comments
 (0)