Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fix additional scenarios with nested defined routes (#13648)
Browse files Browse the repository at this point in the history
* Fix additional scenarios with nested defined routes

* - pick better starting point for uri matching

* - fix merge

* - formating changes and more accurate test fix
  • Loading branch information
PureWeen committed Feb 9, 2021
1 parent 053ede6 commit cc0caa6
Show file tree
Hide file tree
Showing 2 changed files with 264 additions and 110 deletions.
65 changes: 64 additions & 1 deletion Xamarin.Forms.Core.UnitTests/ShellNavigatingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,6 @@ public async Task GoBackFromRouteWithMultiplePaths()
await shell.Navigation.PopAsync();
}


[Test]
public async Task GoBackFromRouteWithMultiplePathsHierarchical()
{
Expand All @@ -933,6 +932,70 @@ public async Task GoBackFromRouteWithMultiplePathsHierarchical()
await shell.Navigation.PopAsync();
}

[Test]
public async Task HierarchicalNavigation()
{
Routing.RegisterRoute("page1/page2", typeof(ShellTestPage));
var shell = new TestShell(
CreateShellItem(shellSectionRoute: "page1")
);

await shell.GoToAsync($"page1/page2?{nameof(ShellTestPage.SomeQueryParameter)}=1");

Assert.AreEqual("1", ((ShellTestPage)shell.CurrentPage).SomeQueryParameter);
}

[Test]
public async Task HierarchicalNavigationMultipleRoutes()
{
Routing.RegisterRoute("page1/page2", typeof(ShellTestPage));
Routing.RegisterRoute("page1/page2/page3", typeof(TestPage1));
var shell = new TestShell(
CreateShellItem(shellSectionRoute: "page1")
);

await shell.GoToAsync($"page1/page2?{nameof(ShellTestPage.SomeQueryParameter)}=1");

Assert.AreEqual("1", ((ShellTestPage)shell.CurrentPage).SomeQueryParameter);
await shell.GoToAsync($"page1/page2/page3");

Assert.IsTrue(shell.CurrentPage is TestPage1);
Assert.IsTrue(shell.Navigation.NavigationStack[1] is ShellTestPage);
}

[Test]
public async Task HierarchicalNavigationMultipleRoutesVariation1()
{
Routing.RegisterRoute("page1/page2", typeof(ShellTestPage));
Routing.RegisterRoute("page1/page2/page3", typeof(TestPage1));
var shell = new TestShell(
CreateShellItem(shellSectionRoute: "page1")
);

await shell.GoToAsync($"page1/page2/page3");

Assert.IsTrue(shell.CurrentPage is TestPage1);
Assert.IsTrue(shell.Navigation.NavigationStack[1] is ShellTestPage);
}

[Test]
public async Task HierarchicalNavigationWithBackNavigation()
{
Routing.RegisterRoute("page1/page2", typeof(ShellTestPage));
Routing.RegisterRoute("page1/page2/page3", typeof(TestPage1));
var shell = new TestShell(
CreateShellItem(shellSectionRoute: "page1")
);

await shell.GoToAsync($"page1/page2");
await shell.GoToAsync($"page1/page2/page3");
Assert.IsTrue(shell.CurrentPage is TestPage1);
await shell.GoToAsync($"..");
Assert.IsTrue(shell.CurrentPage is ShellTestPage);
await shell.GoToAsync($"..");
Assert.IsTrue(shell.CurrentPage is ContentPage);
}

public class NavigationMonitoringTab : Tab
{
public List<string> NavigationsFired = new List<string>();
Expand Down
Loading

0 comments on commit cc0caa6

Please sign in to comment.