@@ -12,6 +12,12 @@ namespace Xamarin.Forms.Core.UnitTests
12
12
[ TestFixture ]
13
13
public class ShellNavigatingTests : ShellTestBase
14
14
{
15
+ [ TearDown ]
16
+ public override void TearDown ( )
17
+ {
18
+ base . TearDown ( ) ;
19
+ Routing . Clear ( ) ;
20
+ }
15
21
16
22
[ Test ]
17
23
public void CancelNavigation ( )
@@ -637,6 +643,296 @@ public async Task InitialNavigatingArgs()
637
643
null , "//item" ) ;
638
644
}
639
645
646
+
647
+ [ TestCase ( true , 2 ) ]
648
+ [ TestCase ( false , 2 ) ]
649
+ [ TestCase ( true , 3 ) ]
650
+ [ TestCase ( false , 3 ) ]
651
+ public async Task ShellItemContentRouteWithGlobalRouteRelative ( bool modal , int depth )
652
+ {
653
+ var shell = new Shell ( ) ;
654
+ var item1 = CreateShellItem < FlyoutItem > ( asImplicit : true , shellItemRoute : "animals" , shellContentRoute : "monkeys" ) ;
655
+
656
+ string route = "monkeys/details" ;
657
+
658
+ if ( depth == 3 )
659
+ {
660
+ route = "animals/monkeys/details" ;
661
+ }
662
+
663
+ if ( modal )
664
+ Routing . RegisterRoute ( route , typeof ( ShellModalTests . ModalTestPage ) ) ;
665
+ else
666
+ Routing . RegisterRoute ( route , typeof ( ContentPage ) ) ;
667
+
668
+ shell . Items . Add ( item1 ) ;
669
+
670
+ await shell . GoToAsync ( "details" ) ;
671
+ Assert . That ( shell . CurrentState . Location . ToString ( ) , Is . EqualTo ( "//animals/monkeys/details" ) ) ;
672
+ }
673
+
674
+ [ TestCase ( true ) ]
675
+ [ TestCase ( false ) ]
676
+ public async Task GotoSameGlobalRoutesCollapsesUriCorrectly ( bool modal )
677
+ {
678
+ var shell = new Shell ( ) ;
679
+ var item1 = CreateShellItem < FlyoutItem > ( asImplicit : true , shellItemRoute : "animals" , shellContentRoute : "monkeys" ) ;
680
+
681
+ if ( modal )
682
+ Routing . RegisterRoute ( "details" , typeof ( ShellModalTests . ModalTestPage ) ) ;
683
+ else
684
+ Routing . RegisterRoute ( "details" , typeof ( ContentPage ) ) ;
685
+
686
+ shell . Items . Add ( item1 ) ;
687
+
688
+ await shell . GoToAsync ( "details" ) ;
689
+ await shell . GoToAsync ( "details" ) ;
690
+ Assert . That ( shell . CurrentState . Location . ToString ( ) , Is . EqualTo ( "//animals/monkeys/details/details" ) ) ;
691
+ }
692
+
693
+ [ Test ]
694
+ public async Task ShellSectionWithGlobalRouteAbsolute ( )
695
+ {
696
+ var shell = new Shell ( ) ;
697
+ var item1 = CreateShellItem ( asImplicit : true , shellContentRoute : "rootlevelcontent1" , shellSectionRoute : "section1" ) ;
698
+
699
+ Routing . RegisterRoute ( "edit" , typeof ( ContentPage ) ) ;
700
+
701
+ shell . Items . Add ( item1 ) ;
702
+
703
+ var request = ShellUriHandler . GetNavigationRequest ( shell , CreateUri ( "//rootlevelcontent1/edit" ) ) ;
704
+
705
+ Assert . AreEqual ( 1 , request . Request . GlobalRoutes . Count ) ;
706
+ Assert . AreEqual ( "edit" , request . Request . GlobalRoutes . First ( ) ) ;
707
+ }
708
+
709
+ [ Test ]
710
+ public async Task ShellSectionWithRelativeEdit ( )
711
+ {
712
+ var shell = new Shell ( ) ;
713
+ var item1 = CreateShellItem ( asImplicit : true , shellContentRoute : "rootlevelcontent1" , shellSectionRoute : "section1" ) ;
714
+ var editShellContent = CreateShellContent ( shellContentRoute : "edit" ) ;
715
+
716
+
717
+ item1 . Items [ 0 ] . Items . Add ( editShellContent ) ;
718
+ shell . Items . Add ( item1 ) ;
719
+
720
+ await shell . GoToAsync ( "//rootlevelcontent1" ) ;
721
+ var location = shell . CurrentState . FullLocation ;
722
+ await shell . NavigationManager . GoToAsync ( "edit" , false , true ) ;
723
+
724
+ Assert . AreEqual ( editShellContent , shell . CurrentItem . CurrentItem . CurrentItem ) ;
725
+ }
726
+
727
+
728
+ [ Test ]
729
+ public async Task ShellContentOnlyWithGlobalEdit ( )
730
+ {
731
+ var shell = new Shell ( ) ;
732
+ var item1 = CreateShellItem ( asImplicit : true , shellContentRoute : "rootlevelcontent1" ) ;
733
+ var item2 = CreateShellItem ( asImplicit : true , shellContentRoute : "rootlevelcontent2" ) ;
734
+
735
+ shell . Items . Add ( item1 ) ;
736
+ shell . Items . Add ( item2 ) ;
737
+
738
+ Routing . RegisterRoute ( "//rootlevelcontent1/edit" , typeof ( ContentPage ) ) ;
739
+ await shell . GoToAsync ( "//rootlevelcontent1/edit" ) ;
740
+ }
741
+
742
+
743
+ [ Test ]
744
+ public async Task RouteWithGlobalPageRoute ( )
745
+ {
746
+
747
+ var shell = new Shell ( ) ;
748
+ var item1 = CreateShellItem ( asImplicit : true , shellItemRoute : "animals" , shellSectionRoute : "domestic" , shellContentRoute : "dogs" ) ;
749
+ var item2 = CreateShellItem ( asImplicit : true , shellItemRoute : "animals" , shellSectionRoute : "domestic" , shellContentRoute : "cats" ) ;
750
+
751
+ shell . Items . Add ( item1 ) ;
752
+ shell . Items . Add ( item2 ) ;
753
+
754
+ Routing . RegisterRoute ( "catdetails" , typeof ( ContentPage ) ) ;
755
+ await shell . GoToAsync ( "//cats/catdetails?name=3" ) ;
756
+
757
+ Assert . AreEqual ( "//animals/domestic/cats/catdetails" , shell . CurrentState . Location . ToString ( ) ) ;
758
+ }
759
+
760
+ [ Test ]
761
+ public async Task AbsoluteRoutingToPage ( )
762
+ {
763
+
764
+ var shell = new Shell ( ) ;
765
+ var item1 = CreateShellItem ( asImplicit : true , shellItemRoute : "animals" , shellSectionRoute : "domestic" , shellContentRoute : "dogs" ) ;
766
+ shell . Items . Add ( item1 ) ;
767
+
768
+ Routing . RegisterRoute ( "catdetails" , typeof ( ContentPage ) ) ;
769
+
770
+ Assert . That ( async ( ) => await shell . GoToAsync ( $ "//catdetails") , Throws . Exception ) ;
771
+ }
772
+
773
+ [ Test ]
774
+ public async Task LocationRemovesImplicit ( )
775
+ {
776
+
777
+ var shell = new Shell ( ) ;
778
+ var item1 = CreateShellItem ( asImplicit : true , shellContentRoute : "rootlevelcontent1" ) ;
779
+
780
+ shell . Items . Add ( item1 ) ;
781
+
782
+ Assert . AreEqual ( "//rootlevelcontent1" , shell . CurrentState . Location . ToString ( ) ) ;
783
+ }
784
+
785
+ [ Test ]
786
+ public async Task GlobalNavigateTwice ( )
787
+ {
788
+
789
+ var shell = new Shell ( ) ;
790
+ var item1 = CreateShellItem ( asImplicit : true , shellContentRoute : "rootlevelcontent1" ) ;
791
+
792
+ shell . Items . Add ( item1 ) ;
793
+ Routing . RegisterRoute ( "cat" , typeof ( ContentPage ) ) ;
794
+ Routing . RegisterRoute ( "details" , typeof ( ContentPage ) ) ;
795
+
796
+ await shell . GoToAsync ( "cat" ) ;
797
+ await shell . GoToAsync ( "details" ) ;
798
+
799
+ Assert . AreEqual ( "//rootlevelcontent1/cat/details" , shell . CurrentState . Location . ToString ( ) ) ;
800
+ await shell . GoToAsync ( "//rootlevelcontent1/details" ) ;
801
+ Assert . AreEqual ( "//rootlevelcontent1/details" , shell . CurrentState . Location . ToString ( ) ) ;
802
+ }
803
+
804
+ [ Test ]
805
+ public async Task GlobalRoutesRegisteredHierarchicallyNavigateCorrectly ( )
806
+ {
807
+ Routing . RegisterRoute ( "first" , typeof ( TestPage1 ) ) ;
808
+ Routing . RegisterRoute ( "first/second" , typeof ( TestPage2 ) ) ;
809
+ Routing . RegisterRoute ( "first/second/third" , typeof ( TestPage3 ) ) ;
810
+ var shell = new TestShell (
811
+ CreateShellItem ( shellContentRoute : "MainPage" )
812
+ ) ;
813
+
814
+ await shell . GoToAsync ( "//MainPage/first/second" ) ;
815
+
816
+ Assert . AreEqual ( typeof ( TestPage1 ) , shell . Navigation . NavigationStack [ 1 ] . GetType ( ) ) ;
817
+ Assert . AreEqual ( typeof ( TestPage2 ) , shell . Navigation . NavigationStack [ 2 ] . GetType ( ) ) ;
818
+
819
+ await shell . GoToAsync ( "//MainPage/first/second/third" ) ;
820
+
821
+ Assert . AreEqual ( typeof ( TestPage1 ) , shell . Navigation . NavigationStack [ 1 ] . GetType ( ) ) ;
822
+ Assert . AreEqual ( typeof ( TestPage2 ) , shell . Navigation . NavigationStack [ 2 ] . GetType ( ) ) ;
823
+ Assert . AreEqual ( typeof ( TestPage3 ) , shell . Navigation . NavigationStack [ 3 ] . GetType ( ) ) ;
824
+ }
825
+
826
+ [ Test ]
827
+ public async Task GlobalRoutesRegisteredHierarchicallyNavigateCorrectlyVariation ( )
828
+ {
829
+ Routing . RegisterRoute ( "monkeys/monkeyDetails" , typeof ( TestPage1 ) ) ;
830
+ Routing . RegisterRoute ( "monkeyDetails/monkeygenome" , typeof ( TestPage2 ) ) ;
831
+ var shell = new TestShell (
832
+ CreateShellItem ( shellContentRoute : "monkeys" , shellItemRoute : "animals2" ) ,
833
+ CreateShellItem ( shellContentRoute : "monkeys" , shellItemRoute : "animals" )
834
+ ) ;
835
+
836
+ await shell . GoToAsync ( "//animals/monkeys/monkeyDetails?id=123" ) ;
837
+ await shell . GoToAsync ( "monkeygenome" ) ;
838
+ Assert . AreEqual ( "//animals/monkeys/monkeyDetails/monkeygenome" , shell . CurrentState . Location . ToString ( ) ) ;
839
+ }
840
+
841
+ [ Test ]
842
+ public async Task GlobalRoutesRegisteredHierarchicallyWithDoublePop ( )
843
+ {
844
+ Routing . RegisterRoute ( "monkeys/monkeyDetails" , typeof ( TestPage1 ) ) ;
845
+ Routing . RegisterRoute ( "monkeyDetails/monkeygenome" , typeof ( TestPage2 ) ) ;
846
+ var shell = new TestShell (
847
+ CreateShellItem ( shellContentRoute : "monkeys" , shellItemRoute : "animals2" ) ,
848
+ CreateShellItem ( shellContentRoute : "monkeys" , shellItemRoute : "animals" )
849
+ ) ;
850
+
851
+ await shell . GoToAsync ( "//animals/monkeys/monkeyDetails?id=123" ) ;
852
+ await shell . GoToAsync ( "monkeygenome" ) ;
853
+ await shell . GoToAsync ( "../.." ) ;
854
+ Assert . AreEqual ( "//animals/monkeys" , shell . CurrentState . Location . ToString ( ) ) ;
855
+ }
856
+
857
+ [ Test ]
858
+ public async Task GlobalRoutesRegisteredHierarchicallyWithDoubleSplash ( )
859
+ {
860
+ Routing . RegisterRoute ( "//animals/monkeys/monkeyDetails" , typeof ( TestPage1 ) ) ;
861
+ var shell = new TestShell (
862
+ CreateShellItem ( shellContentRoute : "monkeys" , shellItemRoute : "animals" )
863
+ ) ;
864
+
865
+ await shell . GoToAsync ( "//animals/monkeys/monkeyDetails?id=123" ) ;
866
+ Assert . AreEqual ( "//animals/monkeys/monkeyDetails" , shell . CurrentState . Location . ToString ( ) ) ;
867
+ }
868
+
869
+
870
+ [ Test ]
871
+ public async Task RemovePageWithNestedRoutes ( )
872
+ {
873
+ Routing . RegisterRoute ( "monkeys/monkeyDetails" , typeof ( TestPage1 ) ) ;
874
+ Routing . RegisterRoute ( "monkeyDetails/monkeygenome" , typeof ( TestPage2 ) ) ;
875
+ var shell = new TestShell (
876
+ CreateShellItem ( shellContentRoute : "monkeys" , shellItemRoute : "animals" )
877
+ ) ;
878
+
879
+ await shell . GoToAsync ( "//animals/monkeys/monkeyDetails" ) ;
880
+ await shell . GoToAsync ( "monkeygenome" ) ;
881
+ shell . Navigation . RemovePage ( shell . Navigation . NavigationStack [ 1 ] ) ;
882
+ await shell . Navigation . PopAsync ( ) ;
883
+ }
884
+
885
+ [ Test ]
886
+ public async Task GlobalRoutesRegisteredHierarchicallyNavigateCorrectlyWithAdditionalItems ( )
887
+ {
888
+ Routing . RegisterRoute ( "monkeys/monkeyDetails" , typeof ( TestPage1 ) ) ;
889
+ Routing . RegisterRoute ( "monkeyDetails/monkeygenome" , typeof ( TestPage2 ) ) ;
890
+ var shell = new TestShell (
891
+ CreateShellItem ( shellContentRoute : "cats" , shellSectionRoute : "domestic" , shellItemRoute : "animals" )
892
+ ) ;
893
+
894
+ shell . Items [ 0 ] . Items . Add ( CreateShellContent ( shellContentRoute : "monkeys" ) ) ;
895
+ shell . Items [ 0 ] . Items . Add ( CreateShellContent ( shellContentRoute : "elephants" ) ) ;
896
+ shell . Items [ 0 ] . Items . Add ( CreateShellContent ( shellContentRoute : "bears" ) ) ;
897
+ shell . Items [ 0 ] . Items [ 0 ] . Items . Add ( CreateShellContent ( shellContentRoute : "dogs" ) ) ;
898
+ shell . Items . Add ( CreateShellContent ( shellContentRoute : "about" ) ) ;
899
+ await shell . GoToAsync ( "//animals/monkeys/monkeyDetails?id=123" ) ;
900
+ await shell . GoToAsync ( "monkeygenome" ) ;
901
+ Assert . AreEqual ( "//animals/monkeys/monkeyDetails/monkeygenome" , shell . CurrentState . Location . ToString ( ) ) ;
902
+ }
903
+
904
+ [ Test ]
905
+ public async Task GoBackFromRouteWithMultiplePaths ( )
906
+ {
907
+ Routing . RegisterRoute ( "monkeys/monkeyDetails" , typeof ( TestPage1 ) ) ;
908
+
909
+ var shell = new TestShell (
910
+ CreateShellItem ( )
911
+ ) ;
912
+
913
+ await shell . GoToAsync ( "monkeys/monkeyDetails" ) ;
914
+ await shell . GoToAsync ( "monkeys/monkeyDetails" ) ;
915
+ await shell . Navigation . PopAsync ( ) ;
916
+ await shell . Navigation . PopAsync ( ) ;
917
+ }
918
+
919
+
920
+ [ Test ]
921
+ public async Task GoBackFromRouteWithMultiplePathsHierarchical ( )
922
+ {
923
+ Routing . RegisterRoute ( "monkeys/monkeyDetails" , typeof ( TestPage1 ) ) ;
924
+ Routing . RegisterRoute ( "monkeyDetails/monkeygenome" , typeof ( TestPage2 ) ) ;
925
+
926
+ var shell = new TestShell (
927
+ CreateShellItem ( )
928
+ ) ;
929
+
930
+ await shell . GoToAsync ( "monkeys/monkeyDetails" ) ;
931
+ await shell . GoToAsync ( "monkeygenome" ) ;
932
+ await shell . Navigation . PopAsync ( ) ;
933
+ await shell . Navigation . PopAsync ( ) ;
934
+ }
935
+
640
936
public class NavigationMonitoringTab : Tab
641
937
{
642
938
public List < string > NavigationsFired = new List < string > ( ) ;
0 commit comments