@@ -1453,6 +1453,117 @@ const DEFAULT_COMPONENT_ID = '1';
1453
1453
. toBeTruthy ( ) ;
1454
1454
} ) ;
1455
1455
1456
+ it ( 'should retain state styles when the underlying DOM structure changes even if there are no insert/remove animations' ,
1457
+ ( ) => {
1458
+ @Component ( {
1459
+ selector : 'ani-cmp' ,
1460
+ template : `
1461
+ <div class="item" *ngFor="let item of items" [@color]="colorExp">
1462
+ {{ item }}
1463
+ </div>
1464
+ ` ,
1465
+ animations : [ trigger ( 'color' , [ state ( 'green' , style ( { backgroundColor : 'green' } ) ) ] ) ]
1466
+ } )
1467
+ class Cmp {
1468
+ public colorExp = 'green' ;
1469
+ public items = [ 0 , 1 , 2 , 3 ] ;
1470
+
1471
+ reorder ( ) {
1472
+ const temp = this . items [ 0 ] ;
1473
+ this . items [ 0 ] = this . items [ 1 ] ;
1474
+ this . items [ 1 ] = temp ;
1475
+ }
1476
+ }
1477
+
1478
+ TestBed . configureTestingModule ( { declarations : [ Cmp ] } ) ;
1479
+
1480
+ const fixture = TestBed . createComponent ( Cmp ) ;
1481
+ const cmp = fixture . componentInstance ;
1482
+ fixture . detectChanges ( ) ;
1483
+
1484
+ let elements : HTMLElement [ ] = fixture . nativeElement . querySelectorAll ( '.item' ) ;
1485
+ assertBackgroundColor ( elements [ 0 ] , 'green' ) ;
1486
+ assertBackgroundColor ( elements [ 1 ] , 'green' ) ;
1487
+ assertBackgroundColor ( elements [ 2 ] , 'green' ) ;
1488
+ assertBackgroundColor ( elements [ 3 ] , 'green' ) ;
1489
+
1490
+ elements [ 0 ] . title = '0a' ;
1491
+ elements [ 1 ] . title = '1a' ;
1492
+
1493
+ cmp . reorder ( ) ;
1494
+ fixture . detectChanges ( ) ;
1495
+
1496
+ elements = fixture . nativeElement . querySelectorAll ( '.item' ) ;
1497
+ assertBackgroundColor ( elements [ 0 ] , 'green' ) ;
1498
+ assertBackgroundColor ( elements [ 1 ] , 'green' ) ;
1499
+ assertBackgroundColor ( elements [ 2 ] , 'green' ) ;
1500
+ assertBackgroundColor ( elements [ 3 ] , 'green' ) ;
1501
+
1502
+ function assertBackgroundColor ( element : HTMLElement , color : string ) {
1503
+ expect ( element . style . getPropertyValue ( 'background-color' ) ) . toEqual ( color ) ;
1504
+ }
1505
+ } ) ;
1506
+
1507
+ it ( 'should retain state styles when the underlying DOM structure changes even if there are insert/remove animations' ,
1508
+ ( ) => {
1509
+ @Component ( {
1510
+ selector : 'ani-cmp' ,
1511
+ template : `
1512
+ <div class="item" *ngFor="let item of items" [@color]="colorExp">
1513
+ {{ item }}
1514
+ </div>
1515
+ ` ,
1516
+ animations : [ trigger (
1517
+ 'color' ,
1518
+ [
1519
+ transition ( '* => *' , animate ( 500 ) ) ,
1520
+ state ( 'green' , style ( { backgroundColor : 'green' } ) )
1521
+ ] ) ]
1522
+ } )
1523
+ class Cmp {
1524
+ public colorExp = 'green' ;
1525
+ public items = [ 0 , 1 , 2 , 3 ] ;
1526
+
1527
+ reorder ( ) {
1528
+ const temp = this . items [ 0 ] ;
1529
+ this . items [ 0 ] = this . items [ 1 ] ;
1530
+ this . items [ 1 ] = temp ;
1531
+ }
1532
+ }
1533
+
1534
+ TestBed . configureTestingModule ( { declarations : [ Cmp ] } ) ;
1535
+
1536
+ const fixture = TestBed . createComponent ( Cmp ) ;
1537
+ const cmp = fixture . componentInstance ;
1538
+ fixture . detectChanges ( ) ;
1539
+
1540
+ getLog ( ) . forEach ( p => p . finish ( ) ) ;
1541
+
1542
+ let elements : HTMLElement [ ] = fixture . nativeElement . querySelectorAll ( '.item' ) ;
1543
+ assertBackgroundColor ( elements [ 0 ] , 'green' ) ;
1544
+ assertBackgroundColor ( elements [ 1 ] , 'green' ) ;
1545
+ assertBackgroundColor ( elements [ 2 ] , 'green' ) ;
1546
+ assertBackgroundColor ( elements [ 3 ] , 'green' ) ;
1547
+
1548
+ elements [ 0 ] . title = '0a' ;
1549
+ elements [ 1 ] . title = '1a' ;
1550
+
1551
+ cmp . reorder ( ) ;
1552
+ fixture . detectChanges ( ) ;
1553
+
1554
+ getLog ( ) . forEach ( p => p . finish ( ) ) ;
1555
+
1556
+ elements = fixture . nativeElement . querySelectorAll ( '.item' ) ;
1557
+ assertBackgroundColor ( elements [ 0 ] , 'green' ) ;
1558
+ assertBackgroundColor ( elements [ 1 ] , 'green' ) ;
1559
+ assertBackgroundColor ( elements [ 2 ] , 'green' ) ;
1560
+ assertBackgroundColor ( elements [ 3 ] , 'green' ) ;
1561
+
1562
+ function assertBackgroundColor ( element : HTMLElement , color : string ) {
1563
+ expect ( element . style . getPropertyValue ( 'background-color' ) ) . toEqual ( color ) ;
1564
+ }
1565
+ } ) ;
1566
+
1456
1567
it ( 'should animate removals of nodes to the `void` state for each animation trigger, but treat all auto styles as pre styles' ,
1457
1568
( ) => {
1458
1569
@Component ( {
0 commit comments