7
7
*/
8
8
9
9
import { DefaultIterableDiffer , DefaultIterableDifferFactory } from '@angular/core/src/change_detection/differs/default_iterable_differ' ;
10
- import { beforeEach , describe , expect , it } from '@angular/core/testing/src/testing_internal' ;
11
10
12
11
import { TestIterable } from '../../change_detection/iterable' ;
13
12
import { iterableChangesAsString } from '../../change_detection/util' ;
@@ -28,7 +27,7 @@ class ComplexItem {
28
27
export function main ( ) {
29
28
describe ( 'iterable differ' , function ( ) {
30
29
describe ( 'DefaultIterableDiffer' , function ( ) {
31
- let differ : any /** TODO #9100 */ ;
30
+ let differ : DefaultIterableDiffer < any > ;
32
31
33
32
beforeEach ( ( ) => { differ = new DefaultIterableDiffer ( ) ; } ) ;
34
33
@@ -41,7 +40,7 @@ export function main() {
41
40
} ) ;
42
41
43
42
it ( 'should support iterables' , ( ) => {
44
- const l = new TestIterable ( ) ;
43
+ const l : any = new TestIterable ( ) ;
45
44
46
45
differ . check ( l ) ;
47
46
expect ( differ . toString ( ) ) . toEqual ( iterableChangesAsString ( { collection : [ ] } ) ) ;
@@ -64,7 +63,7 @@ export function main() {
64
63
} ) ;
65
64
66
65
it ( 'should detect additions' , ( ) => {
67
- const l : any [ ] /** TODO #9100 */ = [ ] ;
66
+ const l : any [ ] = [ ] ;
68
67
differ . check ( l ) ;
69
68
expect ( differ . toString ( ) ) . toEqual ( iterableChangesAsString ( { collection : [ ] } ) ) ;
70
69
@@ -144,7 +143,7 @@ export function main() {
144
143
} ) ;
145
144
146
145
it ( 'should detect changes in list' , ( ) => {
147
- const l : any [ ] /** TODO #9100 */ = [ ] ;
146
+ const l : any [ ] = [ ] ;
148
147
differ . check ( l ) ;
149
148
150
149
l . push ( 'a' ) ;
@@ -192,19 +191,7 @@ export function main() {
192
191
} ) ) ;
193
192
} ) ;
194
193
195
- it ( 'should test string by value rather than by reference (Dart)' , ( ) => {
196
- const l = [ 'a' , 'boo' ] ;
197
- differ . check ( l ) ;
198
-
199
- const b = 'b' ;
200
- const oo = 'oo' ;
201
- l [ 1 ] = b + oo ;
202
- differ . check ( l ) ;
203
- expect ( differ . toString ( ) )
204
- . toEqual ( iterableChangesAsString ( { collection : [ 'a' , 'boo' ] , previous : [ 'a' , 'boo' ] } ) ) ;
205
- } ) ;
206
-
207
- it ( 'should ignore [NaN] != [NaN] (JS)' , ( ) => {
194
+ it ( 'should ignore [NaN] != [NaN]' , ( ) => {
208
195
const l = [ NaN ] ;
209
196
differ . check ( l ) ;
210
197
differ . check ( l ) ;
@@ -294,6 +281,22 @@ export function main() {
294
281
} ) ) ;
295
282
} ) ;
296
283
284
+ // https://github.com/angular/angular/issues/17852
285
+ it ( 'support re-insertion' , ( ) => {
286
+ const l = [ 'a' , '*' , '*' , 'd' , '-' , '-' , '-' , 'e' ] ;
287
+ differ . check ( l ) ;
288
+ l [ 1 ] = 'b' ;
289
+ l [ 5 ] = 'c' ;
290
+ differ . check ( l ) ;
291
+ expect ( differ . toString ( ) ) . toEqual ( iterableChangesAsString ( {
292
+ collection : [ 'a' , 'b[null->1]' , '*[1->2]' , 'd' , '-' , 'c[null->5]' , '-[5->6]' , 'e' ] ,
293
+ previous : [ 'a' , '*[1->2]' , '*[2->null]' , 'd' , '-' , '-[5->6]' , '-[6->null]' , 'e' ] ,
294
+ additions : [ 'b[null->1]' , 'c[null->5]' ] ,
295
+ moves : [ '*[1->2]' , '-[5->6]' ] ,
296
+ removals : [ '*[2->null]' , '-[6->null]' ] ,
297
+ } ) ) ;
298
+ } ) ;
299
+
297
300
describe ( 'forEachOperation' , ( ) => {
298
301
function stringifyItemChange ( record : any , p : number , c : number , originalIndex : number ) {
299
302
const suffix = originalIndex == null ? '' : ' [o=' + originalIndex + ']' ;
@@ -329,8 +332,8 @@ export function main() {
329
332
const startData = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
330
333
const endData = [ 6 , 2 , 7 , 0 , 4 , 8 ] ;
331
334
332
- differ = differ . diff ( startData ) ;
333
- differ = differ . diff ( endData ) ;
335
+ differ = differ . diff ( startData ) ! ;
336
+ differ = differ . diff ( endData ) ! ;
334
337
335
338
const operations : string [ ] = [ ] ;
336
339
differ . forEachOperation ( ( item : any , prev : number , next : number ) => {
@@ -352,12 +355,12 @@ export function main() {
352
355
const startData = [ 0 , 1 , 2 , 3 ] ;
353
356
const endData = [ 2 , 1 ] ;
354
357
355
- differ = differ . diff ( startData ) ;
356
- differ = differ . diff ( endData ) ;
358
+ differ = differ . diff ( startData ) ! ;
359
+ differ = differ . diff ( endData ) ! ;
357
360
358
361
const operations : string [ ] = [ ] ;
359
362
differ . forEachOperation ( ( item : any , prev : number , next : number ) => {
360
- const value = modifyArrayUsingOperation ( startData , endData , prev , next ) ;
363
+ modifyArrayUsingOperation ( startData , endData , prev , next ) ;
361
364
operations . push ( stringifyItemChange ( item , prev , next , item . previousIndex ) ) ;
362
365
} ) ;
363
366
@@ -372,12 +375,12 @@ export function main() {
372
375
const startData = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
373
376
const endData = [ 3 , 6 , 4 , 9 , 1 , 2 ] ;
374
377
375
- differ = differ . diff ( startData ) ;
376
- differ = differ . diff ( endData ) ;
378
+ differ = differ . diff ( startData ) ! ;
379
+ differ = differ . diff ( endData ) ! ;
377
380
378
381
const operations : string [ ] = [ ] ;
379
382
differ . forEachOperation ( ( item : any , prev : number , next : number ) => {
380
- const value = modifyArrayUsingOperation ( startData , endData , prev , next ) ;
383
+ modifyArrayUsingOperation ( startData , endData , prev , next ) ;
381
384
operations . push ( stringifyItemChange ( item , prev , next , item . previousIndex ) ) ;
382
385
} ) ;
383
386
@@ -393,12 +396,12 @@ export function main() {
393
396
const startData = [ 0 , 1 , 2 , 3 , 4 ] ;
394
397
const endData = [ 4 , 1 , 2 , 3 , 0 , 5 ] ;
395
398
396
- differ = differ . diff ( startData ) ;
397
- differ = differ . diff ( endData ) ;
399
+ differ = differ . diff ( startData ) ! ;
400
+ differ = differ . diff ( endData ) ! ;
398
401
399
402
const operations : string [ ] = [ ] ;
400
403
differ . forEachOperation ( ( item : any , prev : number , next : number ) => {
401
- const value = modifyArrayUsingOperation ( startData , endData , prev , next ) ;
404
+ modifyArrayUsingOperation ( startData , endData , prev , next ) ;
402
405
operations . push ( stringifyItemChange ( item , prev , next , item . previousIndex ) ) ;
403
406
} ) ;
404
407
@@ -414,12 +417,12 @@ export function main() {
414
417
const startData = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ;
415
418
const endData = [ 10 , 11 , 1 , 5 , 7 , 8 , 0 , 5 , 3 , 6 ] ;
416
419
417
- differ = differ . diff ( startData ) ;
418
- differ = differ . diff ( endData ) ;
420
+ differ = differ . diff ( startData ) ! ;
421
+ differ = differ . diff ( endData ) ! ;
419
422
420
423
const operations : string [ ] = [ ] ;
421
424
differ . forEachOperation ( ( item : any , prev : number , next : number ) => {
422
- const value = modifyArrayUsingOperation ( startData , endData , prev , next ) ;
425
+ modifyArrayUsingOperation ( startData , endData , prev , next ) ;
423
426
operations . push ( stringifyItemChange ( item , prev , next , item . previousIndex ) ) ;
424
427
} ) ;
425
428
@@ -440,8 +443,8 @@ export function main() {
440
443
const startData = [ 1 , 2 , 3 , 4 ] ;
441
444
const endData = [ 5 , 6 , 7 , 8 ] ;
442
445
443
- differ = differ . diff ( startData ) ;
444
- differ = differ . diff ( endData ) ;
446
+ differ = differ . diff ( startData ) ! ;
447
+ differ = differ . diff ( endData ) ! ;
445
448
446
449
const operations : string [ ] = [ ] ;
447
450
differ . forEachOperation ( ( item : any , prev : number , next : number ) => {
@@ -465,7 +468,7 @@ export function main() {
465
468
466
469
it ( 'should treat null as an empty list' , ( ) => {
467
470
differ . diff ( [ 'a' , 'b' ] ) ;
468
- expect ( differ . diff ( null ) . toString ( ) ) . toEqual ( iterableChangesAsString ( {
471
+ expect ( differ . diff ( null ! ) ! . toString ( ) ) . toEqual ( iterableChangesAsString ( {
469
472
previous : [ 'a[0->null]' , 'b[1->null]' ] ,
470
473
removals : [ 'a[0->null]' , 'b[1->null]' ]
471
474
} ) ) ;
@@ -478,7 +481,7 @@ export function main() {
478
481
} ) ;
479
482
480
483
describe ( 'trackBy function by id' , function ( ) {
481
- let differ : any /** TODO #9100 */ ;
484
+ let differ : any ;
482
485
483
486
const trackByItemId = ( index : number , item : any ) : any => item . id ;
484
487
@@ -565,8 +568,9 @@ export function main() {
565
568
} ) ) ;
566
569
} ) ;
567
570
} ) ;
571
+
568
572
describe ( 'trackBy function by index' , function ( ) {
569
- let differ : any /** TODO #9100 */ ;
573
+ let differ : DefaultIterableDiffer < string > ;
570
574
571
575
const trackByIndex = ( index : number , item : any ) : number => index ;
572
576
@@ -584,9 +588,6 @@ export function main() {
584
588
identityChanges : [ 'h' ]
585
589
} ) ) ;
586
590
} ) ;
587
-
588
591
} ) ;
589
-
590
-
591
592
} ) ;
592
593
}
0 commit comments