@@ -146,14 +146,14 @@ describe('CdkTable', () => {
146
146
expect ( changedRows [ 2 ] . getAttribute ( 'initialIndex' ) ) . toBe ( null ) ;
147
147
} ) ;
148
148
149
- describe ( 'should properly use trackBy when diffing to add/remove/move rows ' , ( ) => {
149
+ describe ( 'with trackBy' , ( ) => {
150
150
151
151
afterEach ( ( ) => {
152
152
// Resetting the static value of the trackby function for TrackByCdkTableApp
153
- TrackByCdkTableApp . TRACK_BY = 'reference' ;
153
+ TrackByCdkTableApp . trackBy = 'reference' ;
154
154
} ) ;
155
155
156
- function createComponent ( ) {
156
+ function createTestComponentWithTrackyByTable ( ) {
157
157
fixture = TestBed . createComponent ( TrackByCdkTableApp ) ;
158
158
159
159
component = fixture . componentInstance ;
@@ -177,7 +177,7 @@ describe('CdkTable', () => {
177
177
}
178
178
179
179
// Swap first two elements, remove the third, add new data
180
- function changeData ( ) {
180
+ function mutateData ( ) {
181
181
// Swap first and second data in data array
182
182
const copiedData = component . dataSource . data . slice ( ) ;
183
183
const temp = copiedData [ 0 ] ;
@@ -192,9 +192,9 @@ describe('CdkTable', () => {
192
192
component . dataSource . addData ( ) ;
193
193
}
194
194
195
- it ( 'with reference-based trackBy' , ( ) => {
196
- createComponent ( ) ;
197
- changeData ( ) ;
195
+ it ( 'should add/remove/move rows with reference-based trackBy' , ( ) => {
196
+ createTestComponentWithTrackyByTable ( ) ;
197
+ mutateData ( ) ;
198
198
199
199
// Expect that the first and second rows were swapped and that the last row is new
200
200
const changedRows = getRows ( tableElement ) ;
@@ -204,9 +204,9 @@ describe('CdkTable', () => {
204
204
expect ( changedRows [ 2 ] . getAttribute ( 'initialIndex' ) ) . toBe ( null ) ;
205
205
} ) ;
206
206
207
- it ( 'with changed references without property-based trackBy' , ( ) => {
208
- createComponent ( ) ;
209
- changeData ( ) ;
207
+ it ( 'should add/remove/move rows with changed references without property-based trackBy' , ( ) => {
208
+ createTestComponentWithTrackyByTable ( ) ;
209
+ mutateData ( ) ;
210
210
211
211
// Change each item reference to show that the trackby is not checking the item properties.
212
212
component . dataSource . data = component . dataSource . data
@@ -220,10 +220,10 @@ describe('CdkTable', () => {
220
220
expect ( changedRows [ 2 ] . getAttribute ( 'initialIndex' ) ) . toBe ( null ) ;
221
221
} ) ;
222
222
223
- it ( 'with changed references with property-based trackBy' , ( ) => {
224
- TrackByCdkTableApp . TRACK_BY = 'propertyA' ;
225
- createComponent ( ) ;
226
- changeData ( ) ;
223
+ it ( 'should add/remove/move rows with changed references with property-based trackBy' , ( ) => {
224
+ TrackByCdkTableApp . trackBy = 'propertyA' ;
225
+ createTestComponentWithTrackyByTable ( ) ;
226
+ mutateData ( ) ;
227
227
228
228
// Change each item reference to show that the trackby is checking the item properties.
229
229
// Otherwise this would cause them all to be removed/added.
@@ -238,10 +238,10 @@ describe('CdkTable', () => {
238
238
expect ( changedRows [ 2 ] . getAttribute ( 'initialIndex' ) ) . toBe ( null ) ;
239
239
} ) ;
240
240
241
- it ( 'with changed references with index-based trackBy' , ( ) => {
242
- TrackByCdkTableApp . TRACK_BY = 'index' ;
243
- createComponent ( ) ;
244
- changeData ( ) ;
241
+ it ( 'should add/remove/move rows with changed references with index-based trackBy' , ( ) => {
242
+ TrackByCdkTableApp . trackBy = 'index' ;
243
+ createTestComponentWithTrackyByTable ( ) ;
244
+ mutateData ( ) ;
245
245
246
246
// Change each item reference to show that the trackby is checking the index.
247
247
// Otherwise this would cause them all to be removed/added.
@@ -539,15 +539,15 @@ class DynamicDataSourceCdkTableApp {
539
539
`
540
540
} )
541
541
class TrackByCdkTableApp {
542
- static TRACK_BY : 'reference' | 'propertyA' | 'index' = 'reference' ;
542
+ static trackBy : 'reference' | 'propertyA' | 'index' = 'reference' ;
543
543
544
544
dataSource : FakeDataSource = new FakeDataSource ( ) ;
545
545
columnsToRender = [ 'column_a' , 'column_b' ] ;
546
546
547
547
@ViewChild ( CdkTable ) table : CdkTable < TestData > ;
548
548
549
549
trackBy ( index : number , item : TestData ) {
550
- switch ( TrackByCdkTableApp . TRACK_BY ) {
550
+ switch ( TrackByCdkTableApp . trackBy ) {
551
551
case 'reference' : return item ;
552
552
case 'propertyA' : return item . a ;
553
553
case 'index' : return index ;
0 commit comments