@@ -1414,7 +1414,7 @@ scenarios.forEach(function(scenario) {
1414
1414
} ) ;
1415
1415
1416
1416
test ( 'abort route events' , function ( assert ) {
1417
- assert . expect ( 20 ) ;
1417
+ assert . expect ( 19 ) ;
1418
1418
map ( assert , function ( match ) {
1419
1419
match ( '/' ) . to ( 'index' ) ;
1420
1420
match ( '/posts' , function ( match ) {
@@ -1465,7 +1465,6 @@ scenarios.forEach(function(scenario) {
1465
1465
} else if ( aborted ) {
1466
1466
assert . equal ( transition . isAborted , true ) ;
1467
1467
assert . equal ( transition . to , transition . from ) ;
1468
- assert . equal ( transition . to , transition . from ) ;
1469
1468
assert . equal ( transition . to ! . localName , 'index' ) ;
1470
1469
} else {
1471
1470
assert . equal ( transition . to ! . localName , 'post' ) ;
@@ -1501,6 +1500,107 @@ scenarios.forEach(function(scenario) {
1501
1500
} ) ;
1502
1501
} ) ;
1503
1502
1503
+ test ( 'always has a transition through the substates' , function ( assert ) {
1504
+ map ( assert , function ( match ) {
1505
+ match ( '/' ) . to ( 'index' ) ;
1506
+ match ( '/posts' , function ( match ) {
1507
+ match ( '/:id' ) . to ( 'post' ) ;
1508
+ match ( '/details' ) . to ( 'postDetails' ) ;
1509
+ } ) ;
1510
+ match ( '/foo' , function ( match ) {
1511
+ match ( '/' ) . to ( 'foo' , function ( match ) {
1512
+ match ( '/bar' ) . to ( 'bar' ) ;
1513
+ } ) ;
1514
+ } ) ;
1515
+ match ( '/err' ) . to ( 'fooError' ) ;
1516
+ } ) ;
1517
+
1518
+ let enterSubstate = false ;
1519
+ let initial = true ;
1520
+ let isAborted = false ;
1521
+ let errorHandled = false ;
1522
+ let enteredWillChange = 0 ;
1523
+ let enteredDidChange = 0 ;
1524
+
1525
+ routes = {
1526
+ post : createHandler ( 'post' , {
1527
+ beforeModel ( transition : Transition ) {
1528
+ isAborted = true ;
1529
+ transition . abort ( ) ;
1530
+ enterSubstate = true ;
1531
+ router . intermediateTransitionTo ( 'fooError' ) ;
1532
+ } ,
1533
+ } ) ,
1534
+ foo : createHandler ( 'foo' ) ,
1535
+ } ;
1536
+
1537
+ router . transitionDidError = ( error : TransitionError , transition : Transition ) => {
1538
+ if ( error . wasAborted || transition . isAborted ) {
1539
+ return logAbort ( transition ) ;
1540
+ } else {
1541
+ transition . trigger ( false , 'error' , error . error , transition , error . route ) ;
1542
+ if ( errorHandled ) {
1543
+ transition . rollback ( ) ;
1544
+ router . routeDidChange ( transition ) ;
1545
+ return transition ;
1546
+ } else {
1547
+ transition . abort ( ) ;
1548
+ return error . error ;
1549
+ }
1550
+ }
1551
+ } ;
1552
+
1553
+ router . routeWillChange = ( transition : Transition ) => {
1554
+ enteredWillChange ++ ;
1555
+ if ( initial ) {
1556
+ assert . equal ( transition . to ! . localName , 'index' , 'initial' ) ;
1557
+ assert . equal ( transition . from ! , null , 'initial' ) ;
1558
+ assert . equal ( transition . to ! . parent , null , 'initial' ) ;
1559
+ } else if ( isAborted ) {
1560
+ assert . equal ( transition . to ! . localName , 'index' , 'aborted' ) ;
1561
+ assert . equal ( isPresent ( transition . from ) && transition . from ! . localName , 'index' , 'aborted' ) ;
1562
+ } else if ( enterSubstate ) {
1563
+ assert . equal ( transition . to ! . localName , 'fooError' , 'substate' ) ;
1564
+ assert . equal ( isPresent ( transition . from ) && transition . from ! . localName , 'index' , 'substate' ) ;
1565
+ assert . equal ( transition . to ! . parent ! . localName , 'foo' , 'substate' ) ;
1566
+ } else {
1567
+ assert . equal ( transition . to ! . localName , 'post' , 'to post' ) ;
1568
+ assert . equal ( isPresent ( transition . from ) && transition . from ! . localName , 'index' , 'to post' ) ;
1569
+ assert . equal ( transition . to ! . parent , null , 'to post' ) ;
1570
+ }
1571
+ } ;
1572
+
1573
+ router . routeDidChange = ( transition : Transition ) => {
1574
+ enteredDidChange ++ ;
1575
+ if ( initial ) {
1576
+ assert . equal ( transition . to ! . localName , 'index' , 'initial' ) ;
1577
+ assert . equal ( transition . from ! , null , 'initial' ) ;
1578
+ initial = false ;
1579
+ } else if ( isAborted ) {
1580
+ assert . equal ( transition . to ! . localName , 'index' , 'aborted' ) ;
1581
+ assert . equal ( isPresent ( transition . from ) && transition . from ! . localName , 'index' , 'aborted' ) ;
1582
+ isAborted = false ;
1583
+ } else {
1584
+ assert . equal ( transition . to ! . localName , 'bar' ) ;
1585
+ assert . equal ( isPresent ( transition . from ) && transition . from ! . localName , 'index' ) ;
1586
+ }
1587
+ } ;
1588
+
1589
+ router
1590
+ . transitionTo ( '/' )
1591
+ . then ( ( ) => {
1592
+ return router . transitionTo ( '/posts/1' ) ;
1593
+ } )
1594
+ . catch ( ( err : any ) => {
1595
+ assert . equal ( err . name , 'TransitionAborted' ) ;
1596
+ return router . activeTransition as any ;
1597
+ } )
1598
+ . finally ( ( ) => {
1599
+ assert . equal ( enteredWillChange , 4 ) ;
1600
+ assert . equal ( enteredDidChange , 2 ) ;
1601
+ } ) ;
1602
+ } ) ;
1603
+
1504
1604
test ( 'error route events' , function ( assert ) {
1505
1605
map ( assert , function ( match ) {
1506
1606
match ( '/' ) . to ( 'index' ) ;
@@ -1555,6 +1655,7 @@ scenarios.forEach(function(scenario) {
1555
1655
transition . trigger ( false , 'error' , error . error , transition , error . route ) ;
1556
1656
if ( errorHandled ) {
1557
1657
transition . rollback ( ) ;
1658
+ router . toInfos ( transition , router . state ! . routeInfos , true ) ;
1558
1659
router . routeDidChange ( transition ) ;
1559
1660
return transition ;
1560
1661
} else {
0 commit comments