@@ -907,10 +907,10 @@ describe('StackRouter', () => {
907907 } ,
908908 state
909909 ) ;
910- expect ( state2 && state2 . index ) . toEqual ( 1 ) ;
911- expect ( state2 && state2 . routes [ 1 ] . routeName ) . toEqual ( 'Bar' ) ;
912- expect ( state2 && state2 . routes [ 1 ] . params ) . toEqual ( { name : 'Zoom' } ) ;
913- expect ( state2 && state2 . routes . length ) . toEqual ( 2 ) ;
910+ expect ( state2 . index ) . toEqual ( 1 ) ;
911+ expect ( state2 . routes [ 1 ] . routeName ) . toEqual ( 'Bar' ) ;
912+ expect ( state2 . routes [ 1 ] . params ) . toEqual ( { name : 'Zoom' } ) ;
913+ expect ( state2 . routes . length ) . toEqual ( 2 ) ;
914914 const state3 = router . getStateForAction (
915915 { type : NavigationActions . BACK , immediate : true } ,
916916 state2
@@ -1059,13 +1059,69 @@ describe('StackRouter', () => {
10591059 const state3 = router . getStateForAction (
10601060 {
10611061 type : StackActions . COMPLETE_TRANSITION ,
1062+ toChildKey : state2 . routes [ 1 ] . key ,
10621063 } ,
10631064 state2
10641065 ) ;
10651066 expect ( state3 && state3 . index ) . toEqual ( 1 ) ;
10661067 expect ( state3 && state3 . isTransitioning ) . toEqual ( false ) ;
10671068 } ) ;
10681069
1070+ test ( 'Completion action does not work with incorrect key' , ( ) => {
1071+ const FooScreen = ( ) => < div /> ;
1072+ const router = StackRouter ( {
1073+ Foo : {
1074+ screen : FooScreen ,
1075+ } ,
1076+ Bar : {
1077+ screen : FooScreen ,
1078+ } ,
1079+ } ) ;
1080+ const state = {
1081+ key : 'StackKey' ,
1082+ index : 1 ,
1083+ isTransitioning : true ,
1084+ routes : [ { key : 'a' , routeName : 'Foo' } , { key : 'b' , routeName : 'Foo' } ] ,
1085+ } ;
1086+ const outputState = router . getStateForAction (
1087+ {
1088+ type : StackActions . COMPLETE_TRANSITION ,
1089+ toChildKey : state . routes [ state . index ] . key ,
1090+ key : 'not StackKey' ,
1091+ } ,
1092+ state
1093+ ) ;
1094+ expect ( outputState . isTransitioning ) . toEqual ( true ) ;
1095+ } ) ;
1096+
1097+ test ( 'Completion action does not work with incorrect toChildKey' , ( ) => {
1098+ const FooScreen = ( ) => < div /> ;
1099+ const router = StackRouter ( {
1100+ Foo : {
1101+ screen : FooScreen ,
1102+ } ,
1103+ Bar : {
1104+ screen : FooScreen ,
1105+ } ,
1106+ } ) ;
1107+ const state = {
1108+ key : 'StackKey' ,
1109+ index : 1 ,
1110+ isTransitioning : true ,
1111+ routes : [ { key : 'a' , routeName : 'Foo' } , { key : 'b' , routeName : 'Foo' } ] ,
1112+ } ;
1113+ const outputState = router . getStateForAction (
1114+ {
1115+ type : StackActions . COMPLETE_TRANSITION ,
1116+ // for this action to toggle isTransitioning, toChildKey should be state.routes[state.index].key,
1117+ toChildKey : 'incorrect' ,
1118+ key : 'StackKey' ,
1119+ } ,
1120+ state
1121+ ) ;
1122+ expect ( outputState . isTransitioning ) . toEqual ( true ) ;
1123+ } ) ;
1124+
10691125 test ( 'Back action parent is prioritized over inactive child routers' , ( ) => {
10701126 const Bar = ( ) => < div /> ;
10711127 Bar . router = StackRouter ( {
@@ -1842,14 +1898,15 @@ describe('StackRouter', () => {
18421898 } ,
18431899 state
18441900 ) ;
1845- expect ( state2 && state2 . index ) . toEqual ( 0 ) ;
1846- expect ( state2 && state2 . isTransitioning ) . toEqual ( false ) ;
1847- expect ( state2 && state2 . routes [ 0 ] . index ) . toEqual ( 1 ) ;
1848- expect ( state2 && state2 . routes [ 0 ] . isTransitioning ) . toEqual ( true ) ;
1901+ expect ( state2 . index ) . toEqual ( 0 ) ;
1902+ expect ( state2 . isTransitioning ) . toEqual ( false ) ;
1903+ expect ( state2 . routes [ 0 ] . index ) . toEqual ( 1 ) ;
1904+ expect ( state2 . routes [ 0 ] . isTransitioning ) . toEqual ( true ) ;
18491905 expect ( ! ! key ) . toEqual ( true ) ;
18501906 const state3 = router . getStateForAction (
18511907 {
18521908 type : StackActions . COMPLETE_TRANSITION ,
1909+ toChildKey : state2 . routes [ 0 ] . routes [ 1 ] . key ,
18531910 } ,
18541911 state2
18551912 ) ;
0 commit comments