@@ -586,6 +586,7 @@ describe('Ionic View Service', function() {
586
586
rootScope . $apply ( ) ;
587
587
expect ( viewService . getCurrentStateName ( ) ) . toEqual ( 'tabs.tab1view1' ) ;
588
588
registerData = viewService . register ( tab1view1Scope ) ;
589
+ var tab1view1ViewId = registerData . viewId ;
589
590
expect ( registerData . navAction ) . toEqual ( 'moveBack' ) ;
590
591
expect ( registerData . navDirection ) . toEqual ( null ) ;
591
592
@@ -613,6 +614,7 @@ describe('Ionic View Service', function() {
613
614
expect ( rootScope . $viewHistory . histories [ tab1Scope . $historyId ] . cursor ) . toEqual ( 1 ) ;
614
615
expect ( registerData . navAction ) . toEqual ( 'newView' ) ;
615
616
expect ( registerData . navDirection ) . toEqual ( 'forward' ) ;
617
+ expect ( rootScope . $viewHistory . views [ tab1view2ViewId ] . backViewId ) . toEqual ( tab1view1ViewId ) ;
616
618
617
619
// go to view 1 in tab 2
618
620
tab2view1Scope = { $parent : tab2Scope } ;
@@ -621,7 +623,7 @@ describe('Ionic View Service', function() {
621
623
registerData = viewService . register ( tab2view1Scope ) ;
622
624
expect ( viewService . getCurrentStateName ( ) ) . toEqual ( 'tabs.tab2view1' ) ;
623
625
expect ( rootScope . $viewHistory . histories [ tab2Scope . $historyId ] . cursor ) . toEqual ( 0 ) ;
624
- expect ( registerData . navAction ) . toEqual ( 'newView ' ) ;
626
+ expect ( registerData . navAction ) . toEqual ( 'moveBack ' ) ;
625
627
expect ( registerData . navDirection ) . toEqual ( null ) ;
626
628
currentView = viewService . getCurrentView ( ) ;
627
629
expect ( currentView . backViewId ) . toEqual ( tab1view2ViewId ) ;
@@ -688,6 +690,75 @@ describe('Ionic View Service', function() {
688
690
expect ( currentView . viewId ) . toEqual ( currentViewId ) ;
689
691
} ) ) ;
690
692
693
+ it ( 'should go one level in tab1, visit tab2, go to tab2 page2, visit, tab1, tab3, history still page 2 tab2' , inject ( function ( $location , $state ) {
694
+ var tab1Container = { } ;
695
+ var tab2Container = { } ;
696
+ var tab3Container = { } ;
697
+ viewService . registerHistory ( tab1Container ) ;
698
+ viewService . registerHistory ( tab2Container ) ;
699
+ viewService . registerHistory ( tab3Container ) ;
700
+
701
+ // register tab1, view1
702
+ $state . go ( 'tabs.tab1view1' ) ;
703
+ rootScope . $apply ( ) ;
704
+ var tab1view1Reg = viewService . register ( tab1Container ) ;
705
+ expect ( tab1view1Reg . navAction ) . toEqual ( 'initialView' ) ;
706
+ expect ( rootScope . $viewHistory . histories [ tab1Container . $historyId ] . cursor ) . toEqual ( 0 ) ;
707
+
708
+ // register tab2, view1
709
+ $state . go ( 'tabs.tab2view1' ) ;
710
+ rootScope . $apply ( ) ;
711
+ var tab2view1Reg = viewService . register ( tab2Container ) ;
712
+ expect ( tab2view1Reg . navAction ) . toEqual ( 'newView' ) ;
713
+ expect ( rootScope . $viewHistory . histories [ tab1Container . $historyId ] . stack [ 0 ] . forwardViewId ) . toEqual ( tab2view1Reg . viewId ) ;
714
+ expect ( rootScope . $viewHistory . histories [ tab2Container . $historyId ] . cursor ) . toEqual ( 0 ) ;
715
+
716
+ // register tab2, view2
717
+ $state . go ( 'tabs.tab2view2' ) ;
718
+ rootScope . $apply ( ) ;
719
+ var tab2view2Reg = viewService . register ( tab2Container ) ;
720
+ expect ( tab2view2Reg . navAction ) . toEqual ( 'newView' ) ;
721
+ expect ( rootScope . $viewHistory . histories [ tab2Container . $historyId ] . cursor ) . toEqual ( 1 ) ;
722
+ expect ( rootScope . $viewHistory . histories [ tab2Container . $historyId ] . stack . length ) . toEqual ( 2 ) ;
723
+
724
+ // register tab1, view1
725
+ $state . go ( 'tabs.tab1view1' ) ;
726
+ rootScope . $apply ( ) ;
727
+ tab1view1Reg = viewService . register ( tab1Container ) ;
728
+ expect ( tab1view1Reg . navAction ) . toEqual ( 'moveBack' ) ;
729
+ expect ( tab1view1Reg . navDirection ) . toEqual ( null ) ;
730
+ expect ( rootScope . $viewHistory . histories [ tab2Container . $historyId ] . cursor ) . toEqual ( 1 ) ;
731
+ expect ( rootScope . $viewHistory . histories [ tab2Container . $historyId ] . stack . length ) . toEqual ( 2 ) ;
732
+
733
+ // register tab3, view1
734
+ $state . go ( 'tabs.tab3view1' ) ;
735
+ rootScope . $apply ( ) ;
736
+ var tab3view1Reg = viewService . register ( tab3Container ) ;
737
+ expect ( tab3view1Reg . navAction ) . toEqual ( 'newView' ) ;
738
+ expect ( tab3view1Reg . navDirection ) . toEqual ( null ) ;
739
+
740
+ expect ( rootScope . $viewHistory . histories [ tab2Container . $historyId ] . cursor ) . toEqual ( 1 ) ;
741
+ expect ( rootScope . $viewHistory . histories [ tab2Container . $historyId ] . stack . length ) . toEqual ( 2 ) ;
742
+
743
+
744
+ var tab2Hist = viewService . _getHistory ( tab2Container ) ;
745
+ var currentStateId = viewService . getCurrentStateId ( )
746
+ currentView = viewService . getCurrentView ( ) ;
747
+ expect ( currentView ) . toBeDefined ( ) ;
748
+ expect ( currentView . historyId ) . not . toEqual ( tab2Hist . historyId ) ;
749
+ expect ( tab2Hist . cursor ) . toEqual ( 1 ) ;
750
+ expect ( tab2Hist . stack . length ) . toEqual ( 2 ) ;
751
+ expect ( tab2Hist . cursor ) . toBeLessThan ( tab2Hist . stack . length ) ;
752
+
753
+ // register tab2, view2
754
+ $state . go ( 'tabs.tab2view2' ) ;
755
+ rootScope . $apply ( ) ;
756
+ var tab2view2RegAgain = viewService . register ( tab2Container ) ;
757
+ expect ( tab2view2RegAgain . historyId ) . toEqual ( tab2view2Reg . historyId ) ;
758
+ expect ( rootScope . $viewHistory . histories [ tab2Container . $historyId ] . cursor ) . toEqual ( 1 ) ;
759
+ expect ( rootScope . $viewHistory . histories [ tab2Container . $historyId ] . stack . length ) . toEqual ( 2 ) ;
760
+ } ) ) ;
761
+
691
762
it ( 'should init root viewHistory data' , inject ( function ( ) {
692
763
expect ( rootScope . $viewHistory . backView ) . toEqual ( null ) ;
693
764
expect ( rootScope . $viewHistory . currentView ) . toEqual ( null ) ;
0 commit comments