@@ -32,8 +32,8 @@ describe('CdkTable', () => {
32
32
let component : any ;
33
33
let tableElement : HTMLElement ;
34
34
35
- function createComponent < T > ( componentType : Type < T > , declarations : any [ ] = [ ] ) :
36
- ComponentFixture < T > {
35
+ function createComponent < T > (
36
+ componentType : Type < T > , declarations : any [ ] = [ ] ) : ComponentFixture < T > {
37
37
TestBed . configureTestingModule ( {
38
38
imports : [ CdkTableModule , BidiModule ] ,
39
39
declarations : [ componentType , ...declarations ] ,
@@ -306,28 +306,6 @@ describe('CdkTable', () => {
306
306
] ) ;
307
307
} ) ;
308
308
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
-
331
309
it ( 'should be able to project a caption' , fakeAsync ( ( ) => {
332
310
setupTableTestApp ( NativeHtmlTableWithCaptionApp ) ;
333
311
fixture . detectChanges ( ) ;
@@ -447,8 +425,7 @@ describe('CdkTable', () => {
447
425
it ( 'should throw an error if the data source is not valid' , ( ) => {
448
426
component . dataSource = { invalid : 'dataSource' } ;
449
427
450
- expect ( ( ) => fixture . detectChanges ( ) )
451
- . toThrowError ( getTableUnknownDataSourceError ( ) . message ) ;
428
+ expect ( ( ) => fixture . detectChanges ( ) ) . toThrowError ( getTableUnknownDataSourceError ( ) . message ) ;
452
429
} ) ;
453
430
454
431
it ( 'should throw an error if the data source is not valid' , ( ) => {
@@ -526,8 +503,7 @@ describe('CdkTable', () => {
526
503
const rowGroups : HTMLElement [ ] = Array . from ( thisTableElement . querySelectorAll ( 'thead, tfoot' ) ) ;
527
504
expect ( rowGroups . length ) . toBe ( 2 , 'Expected table to have a thead and tfoot' ) ;
528
505
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`' ) ;
531
507
}
532
508
} ) ;
533
509
@@ -566,15 +542,15 @@ describe('CdkTable', () => {
566
542
} ) ;
567
543
568
544
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
+ } ) ) ;
578
554
579
555
it ( 'should throw an error if the row definitions are missing' , ( ) => {
580
556
expect ( ( ) => createComponent ( MissingAllRowDefsCdkTableApp ) . detectChanges ( ) )
@@ -660,18 +636,18 @@ describe('CdkTable', () => {
660
636
} ) ;
661
637
662
638
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
+ } ) ) ;
675
651
676
652
it ( 'should fail when multiple rows match data without multiTemplateDataRows' , fakeAsync ( ( ) => {
677
653
let whenFixture = createComponent ( WhenRowMultipleDefaultsCdkTableApp ) ;
@@ -717,40 +693,40 @@ describe('CdkTable', () => {
717
693
} ) ;
718
694
719
695
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
+ } ) ;
754
730
} ) ;
755
731
} ) ;
756
732
@@ -774,8 +750,7 @@ describe('CdkTable', () => {
774
750
} ) ;
775
751
}
776
752
777
- function expectStickyStyles (
778
- element : any , zIndex : string , directions : PositionDirections = { } ) {
753
+ function expectStickyStyles ( element : any , zIndex : string , directions : PositionDirections = { } ) {
779
754
expect ( element . style . position ) . toContain ( 'sticky' ) ;
780
755
expect ( element . style . zIndex ) . toBe ( zIndex , `Expected zIndex to be ${ zIndex } ` ) ;
781
756
@@ -820,8 +795,8 @@ describe('CdkTable', () => {
820
795
821
796
expectStickyStyles ( headerRows [ 0 ] , '100' , { top : '0px' } ) ;
822
797
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' } ) ;
825
800
826
801
component . stickyHeaders = [ ] ;
827
802
fixture . detectChanges ( ) ;
@@ -832,8 +807,8 @@ describe('CdkTable', () => {
832
807
component . stickyFooters = [ 'footer-1' , 'footer-3' ] ;
833
808
fixture . detectChanges ( ) ;
834
809
835
- expectStickyStyles ( footerRows [ 0 ] , '10' ,
836
- { bottom : footerRows [ 1 ] . getBoundingClientRect ( ) . height + 'px' } ) ;
810
+ expectStickyStyles (
811
+ footerRows [ 0 ] , '10' , { bottom : footerRows [ 1 ] . getBoundingClientRect ( ) . height + 'px' } ) ;
837
812
expectNoStickyStyles ( [ footerRows [ 1 ] ] ) ;
838
813
expectStickyStyles ( footerRows [ 2 ] , '10' , { bottom : '0px' } ) ;
839
814
@@ -1200,8 +1175,8 @@ describe('CdkTable', () => {
1200
1175
mutateData ( ) ;
1201
1176
1202
1177
// 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 } ) ) ;
1205
1180
1206
1181
// Expect that all the rows are considered new since their references are all different
1207
1182
const changedRows = getRows ( tableElement ) ;
@@ -1217,8 +1192,8 @@ describe('CdkTable', () => {
1217
1192
1218
1193
// Change each item reference to show that the trackby is checking the item properties.
1219
1194
// 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 } ) ) ;
1222
1197
1223
1198
// Expect that the first and second rows were swapped and that the last row is new
1224
1199
const changedRows = getRows ( tableElement ) ;
@@ -1234,8 +1209,8 @@ describe('CdkTable', () => {
1234
1209
1235
1210
// Change each item reference to show that the trackby is checking the index.
1236
1211
// 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 } ) ) ;
1239
1214
1240
1215
// Expect first two to be the same since they were swapped but indicies are consistent.
1241
1216
// The third element was removed and caught by the table so it was removed before another
@@ -1256,8 +1231,8 @@ describe('CdkTable', () => {
1256
1231
1257
1232
// Change each item reference to show that the trackby is checking the index.
1258
1233
// 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 } ) ) ;
1261
1236
1262
1237
// Expect the rows were given the right implicit data even though the rows were not moved.
1263
1238
fixture . detectChanges ( ) ;
@@ -1396,13 +1371,19 @@ interface TestData {
1396
1371
class FakeDataSource extends DataSource < TestData > {
1397
1372
isConnected = false ;
1398
1373
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
+ }
1401
1380
_dataChange = new BehaviorSubject < TestData [ ] > ( [ ] ) ;
1402
1381
1403
1382
constructor ( ) {
1404
1383
super ( ) ;
1405
- for ( let i = 0 ; i < 3 ; i ++ ) { this . addData ( ) ; }
1384
+ for ( let i = 0 ; i < 3 ; i ++ ) {
1385
+ this . addData ( ) ;
1386
+ }
1406
1387
}
1407
1388
1408
1389
connect ( collectionViewer : CollectionViewer ) {
@@ -1436,7 +1417,7 @@ class BooleanDataSource extends DataSource<boolean> {
1436
1417
return this . _dataChange ;
1437
1418
}
1438
1419
1439
- disconnect ( ) { }
1420
+ disconnect ( ) { }
1440
1421
}
1441
1422
1442
1423
@Component ( {
@@ -1561,40 +1542,14 @@ class NullDataCdkTableApp {
1561
1542
<td cdk-footer-cell *cdkFooterCellDef> second-footer </td>
1562
1543
</ng-container>
1563
1544
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>
1593
1549
</cdk-table>
1594
1550
`
1595
1551
} )
1596
1552
class MultipleHeaderFooterRowsCdkTableApp {
1597
- showAlternativeHeadersAndFooters = false ;
1598
1553
}
1599
1554
1600
1555
@Component ( {
@@ -1656,7 +1611,9 @@ class WhenRowCdkTableApp {
1656
1611
isIndex1 = ( index : number , _rowData : TestData ) => index == 1 ;
1657
1612
hasC3 = ( _index : number , rowData : TestData ) => rowData . c == 'c_3' ;
1658
1613
1659
- constructor ( ) { this . dataSource . addData ( ) ; }
1614
+ constructor ( ) {
1615
+ this . dataSource . addData ( ) ;
1616
+ }
1660
1617
1661
1618
@ViewChild ( CdkTable ) table : CdkTable < TestData > ;
1662
1619
@@ -2030,7 +1987,9 @@ class MissingColumnDefAfterRenderCdkTableApp implements AfterViewInit {
2030
1987
displayedColumns : string [ ] = [ ] ;
2031
1988
2032
1989
ngAfterViewInit ( ) {
2033
- setTimeout ( ( ) => { this . displayedColumns = [ 'column_a' ] ; } , 0 ) ;
1990
+ setTimeout ( ( ) => {
1991
+ this . displayedColumns = [ 'column_a' ] ;
1992
+ } , 0 ) ;
2034
1993
}
2035
1994
}
2036
1995
0 commit comments