@@ -143,14 +143,14 @@ describe('CdkTable', () => {
143
143
expect ( changedRows [ 2 ] . getAttribute ( 'initialIndex' ) ) . toBe ( null ) ;
144
144
} ) ;
145
145
146
- describe ( 'should properly use trackBy when diffing to add/remove/move rows ' , ( ) => {
146
+ describe ( 'with trackBy' , ( ) => {
147
147
148
148
afterEach ( ( ) => {
149
149
// Resetting the static value of the trackby function for TrackByCdkTableApp
150
- TrackByCdkTableApp . TRACK_BY = 'reference' ;
150
+ TrackByCdkTableApp . trackBy = 'reference' ;
151
151
} ) ;
152
152
153
- function createComponent ( ) {
153
+ function createTestComponentWithTrackyByTable ( ) {
154
154
fixture = TestBed . createComponent ( TrackByCdkTableApp ) ;
155
155
156
156
component = fixture . componentInstance ;
@@ -174,7 +174,7 @@ describe('CdkTable', () => {
174
174
}
175
175
176
176
// Swap first two elements, remove the third, add new data
177
- function changeData ( ) {
177
+ function mutateData ( ) {
178
178
// Swap first and second data in data array
179
179
const copiedData = component . dataSource . data . slice ( ) ;
180
180
const temp = copiedData [ 0 ] ;
@@ -189,9 +189,9 @@ describe('CdkTable', () => {
189
189
component . dataSource . addData ( ) ;
190
190
}
191
191
192
- it ( 'with reference-based trackBy' , ( ) => {
193
- createComponent ( ) ;
194
- changeData ( ) ;
192
+ it ( 'should add/remove/move rows with reference-based trackBy' , ( ) => {
193
+ createTestComponentWithTrackyByTable ( ) ;
194
+ mutateData ( ) ;
195
195
196
196
// Expect that the first and second rows were swapped and that the last row is new
197
197
const changedRows = getRows ( tableElement ) ;
@@ -201,9 +201,9 @@ describe('CdkTable', () => {
201
201
expect ( changedRows [ 2 ] . getAttribute ( 'initialIndex' ) ) . toBe ( null ) ;
202
202
} ) ;
203
203
204
- it ( 'with changed references without property-based trackBy' , ( ) => {
205
- createComponent ( ) ;
206
- changeData ( ) ;
204
+ it ( 'should add/remove/move rows with changed references without property-based trackBy' , ( ) => {
205
+ createTestComponentWithTrackyByTable ( ) ;
206
+ mutateData ( ) ;
207
207
208
208
// Change each item reference to show that the trackby is not checking the item properties.
209
209
component . dataSource . data = component . dataSource . data
@@ -217,10 +217,10 @@ describe('CdkTable', () => {
217
217
expect ( changedRows [ 2 ] . getAttribute ( 'initialIndex' ) ) . toBe ( null ) ;
218
218
} ) ;
219
219
220
- it ( 'with changed references with property-based trackBy' , ( ) => {
221
- TrackByCdkTableApp . TRACK_BY = 'propertyA' ;
222
- createComponent ( ) ;
223
- changeData ( ) ;
220
+ it ( 'should add/remove/move rows with changed references with property-based trackBy' , ( ) => {
221
+ TrackByCdkTableApp . trackBy = 'propertyA' ;
222
+ createTestComponentWithTrackyByTable ( ) ;
223
+ mutateData ( ) ;
224
224
225
225
// Change each item reference to show that the trackby is checking the item properties.
226
226
// Otherwise this would cause them all to be removed/added.
@@ -235,10 +235,10 @@ describe('CdkTable', () => {
235
235
expect ( changedRows [ 2 ] . getAttribute ( 'initialIndex' ) ) . toBe ( null ) ;
236
236
} ) ;
237
237
238
- it ( 'with changed references with index-based trackBy' , ( ) => {
239
- TrackByCdkTableApp . TRACK_BY = 'index' ;
240
- createComponent ( ) ;
241
- changeData ( ) ;
238
+ it ( 'should add/remove/move rows with changed references with index-based trackBy' , ( ) => {
239
+ TrackByCdkTableApp . trackBy = 'index' ;
240
+ createTestComponentWithTrackyByTable ( ) ;
241
+ mutateData ( ) ;
242
242
243
243
// Change each item reference to show that the trackby is checking the index.
244
244
// Otherwise this would cause them all to be removed/added.
@@ -453,15 +453,15 @@ class DynamicDataSourceCdkTableApp {
453
453
`
454
454
} )
455
455
class TrackByCdkTableApp {
456
- static TRACK_BY : 'reference' | 'propertyA' | 'index' = 'reference' ;
456
+ static trackBy : 'reference' | 'propertyA' | 'index' = 'reference' ;
457
457
458
458
dataSource : FakeDataSource = new FakeDataSource ( ) ;
459
459
columnsToRender = [ 'column_a' , 'column_b' ] ;
460
460
461
461
@ViewChild ( CdkTable ) table : CdkTable < TestData > ;
462
462
463
463
trackBy ( index : number , item : TestData ) {
464
- switch ( TrackByCdkTableApp . TRACK_BY ) {
464
+ switch ( TrackByCdkTableApp . trackBy ) {
465
465
case 'reference' : return item ;
466
466
case 'propertyA' : return item . a ;
467
467
case 'index' : return index ;
0 commit comments