Example #1
0
        public async Task PushingSetsCorrectNavigationSource()
        {
            var shell = new TestShell(CreateShellItem(shellItemRoute: "item1"));

            shell.RegisterPage(nameof(PushingSetsCorrectNavigationSource));
            await shell.GoToAsync(nameof(PushingSetsCorrectNavigationSource));

            shell.TestNavigatingArgs(ShellNavigationSource.Push,
                                     "//item1", $"{nameof(PushingSetsCorrectNavigationSource)}");

            shell.TestNavigatedArgs(ShellNavigationSource.Push,
                                    "//item1", $"//item1/{nameof(PushingSetsCorrectNavigationSource)}");
        }
Example #2
0
        public async Task ChangingShellContentSetsCorrectNavigationSource()
        {
            var shell = new TestShell(
                CreateShellItem(shellContentRoute: "item1")
                );

            shell.Items[0].Items[0].Items.Add(CreateShellContent(shellContentRoute: "item2"));

            await shell.GoToAsync("//item2");

            shell.TestNavigationArgs(ShellNavigationSource.ShellContentChanged,
                                     "//item1", "//item2");
        }
Example #3
0
        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);
        }
Example #4
0
        public async Task EnsureOnAppearingFiresForLastPageOnly()
        {
            Shell         shell            = new TestShell();
            LifeCyclePage shellContentPage = new LifeCyclePage();

            shell.Items.Add(CreateShellItem(page: shellContentPage));
            await shell.GoToAsync("LifeCyclePage/LifeCyclePage");

            var page           = (LifeCyclePage)shell.GetVisiblePage();
            var nonVisiblePage = (LifeCyclePage)shell.Navigation.NavigationStack[1];

            Assert.IsFalse(nonVisiblePage.Appearing);
            Assert.IsTrue(page.Appearing);
        }
Example #5
0
        public async Task IsAppearingFiredOnLastModalPageOnly()
        {
            Shell shell = new TestShell();

            shell.Items.Add(CreateShellItem(shellItemRoute: "NewRoute", shellSectionRoute: "Section", shellContentRoute: "Content"));

            await shell.GoToAsync("ModalTestPage/ModalTestPage2");

            var page1 = (ShellLifeCycleTests.LifeCyclePage)shell.Navigation.ModalStack[0];
            var page2 = (ShellLifeCycleTests.LifeCyclePage)shell.Navigation.ModalStack[1];

            Assert.IsFalse(page1.Appearing);
            Assert.IsTrue(page2.Appearing);
        }
Example #6
0
        public async Task PoppingSamePageSetsCorrectNavigationSource()
        {
            Routing.RegisterRoute("detailspage", typeof(ContentPage));
            var shell = new TestShell(CreateShellItem(shellItemRoute: "item1"));
            await shell.GoToAsync("detailspage/detailspage");

            await shell.Navigation.PopAsync();


            shell.TestNavigatingArgs(ShellNavigationSource.Pop,
                                     "//item1/detailspage/detailspage", $"..");

            shell.TestNavigatedArgs(ShellNavigationSource.Pop,
                                    "//item1/detailspage/detailspage", $"//item1/detailspage");
        }
Example #7
0
        public async Task SwappingOutVisiblePageDoesntRevealPreviousPage()
        {
            TestShell testShell = new TestShell(
                CreateShellSection <NavigationMonitoringTab>(shellContentRoute: "rootpage")
                );


            testShell.RegisterPage("firstPage");
            testShell.RegisterPage("pageToSwapIn");

            var tab = (NavigationMonitoringTab)testShell.CurrentItem.CurrentItem;
            await testShell.GoToAsync("firstPage");

            tab.NavigationsFired.Clear();

            await testShell.GoToAsync($"../pageToSwapIn");

            Assert.That(testShell.CurrentState.Location.ToString(),
                        Is.EqualTo($"//rootpage/pageToSwapIn"));

            Assert.AreEqual("OnPushAsync", tab.NavigationsFired[0]);
            Assert.AreEqual("OnRemovePage", tab.NavigationsFired[1]);
            Assert.AreEqual(2, tab.NavigationsFired.Count);
        }
Example #8
0
        public async Task RemovePageFromNavigationSetsCorrectNavigationSource()
        {
            Routing.RegisterRoute("pagemiddle", typeof(ContentPage));
            Routing.RegisterRoute("page", typeof(ContentPage));
            var shell = new TestShell(
                CreateShellItem(shellItemRoute: "item")
                );

            await shell.GoToAsync("//item/pagemiddle/page");

            shell.Navigation.RemovePage(shell.Navigation.NavigationStack[1]);

            shell.TestNavigationArgs(ShellNavigationSource.Remove,
                                     "//item/pagemiddle/page", "//item/page");
        }
Example #9
0
        public async Task PopToRootRemovesMiddlePagesBeforePoppingVisibleModalPages()
        {
            Routing.RegisterRoute("ModalTestPage", typeof(ShellModalTests.ModalTestPage));
            TestShell testShell = new TestShell(
                CreateShellSection <NavigationMonitoringTab>(shellContentRoute: "rootpage")
                );

            var middlePage = new ContentPage();
            var tab        = (NavigationMonitoringTab)testShell.CurrentItem.CurrentItem;
            await testShell.Navigation.PushAsync(middlePage);

            await testShell.GoToAsync("ModalTestPage");

            tab.NavigationsFired.Clear();

            await testShell.GoToAsync("../..");

            Assert.That(testShell.CurrentState.Location.ToString(),
                        Is.EqualTo($"//rootpage"));

            Assert.AreEqual("OnRemovePage", tab.NavigationsFired[0]);
            Assert.AreEqual("OnPopModal", tab.NavigationsFired[1]);
            Assert.AreEqual(2, tab.NavigationsFired.Count);
        }
Example #10
0
        public async Task PoppingModalStackFiresAppearingOnRevealedModalPage()
        {
            Shell shell = new TestShell();

            shell.Items.Add(CreateShellItem(shellContentRoute: "MainContent"));

            await shell.GoToAsync($"ModalTestPage2/ModalTestPage");

            bool appearing = false;

            shell.Items[0].Items[0].Navigation.ModalStack[0].Appearing += (_, __) => appearing = true;

            await shell.Navigation.PopModalAsync();

            Assert.IsTrue(true);
        }
Example #11
0
        public async Task PagesPushToModalStack()
        {
            Routing.RegisterRoute("ContentPage", typeof(ContentPage));
            Shell shell = new TestShell();

            shell.Items.Add(CreateShellItem(shellItemRoute: "NewRoute", shellSectionRoute: "Section", shellContentRoute: "Content"));

            await shell.GoToAsync("ModalNavigationTestPage/ContentPage");

            var navStack = shell.Items[0].Items[0].Navigation;

            Assert.AreEqual(typeof(ModalTestPage), navStack.ModalStack[0].Navigation.NavigationStack[0].GetType());
            Assert.AreEqual(typeof(ContentPage), navStack.ModalStack[0].Navigation.NavigationStack[1].GetType());

            Assert.AreEqual("//NewRoute/Section/Content/ModalNavigationTestPage/ContentPage", shell.CurrentState.Location.ToString());
        }
Example #12
0
		public async Task NavigateToDefaultShellContent()
		{
			TestShell testShell = new TestShell(CreateShellItem<FlyoutItem>());
			var page = new ContentPage();

			var contentRoute = testShell.CurrentItem.CurrentItem.CurrentItem.Route;
			var pageRoute = Routing.GetRoute(page);

			await testShell.Navigation.PushAsync(new ContentPage());
			await testShell.Navigation.PushAsync(page);

			await testShell.GoToAsync($"//{contentRoute}/{pageRoute}");


			Assert.That(testShell.CurrentState.Location.ToString(),
				Is.EqualTo($"//{contentRoute}/{pageRoute}"));
		}
Example #13
0
        public async Task NavigatedFiresAfterContentIsCreatedWhenUsingTemplate()
        {
            Shell shell = new TestShell();

            FlyoutItem   flyoutItem = new FlyoutItem();
            Tab          tab        = new Tab();
            ContentPage  page       = null;
            ShellContent content    = new ShellContent()
            {
                Route           = "destination",
                ContentTemplate = new DataTemplate(() =>
                {
                    page = new ContentPage();
                    return(page);
                })
            };

            flyoutItem.Items.Add(tab);
            tab.Items.Add(content);

            shell.Items.Add(CreateShellItem());
            shell.Items.Add(flyoutItem);

            Assert.AreNotEqual(shell.CurrentItem.CurrentItem.CurrentItem, content);
            Assert.IsNull(page);

            bool navigated = false;

            shell.Navigated += (_, __) =>
            {
                Assert.IsNotNull(page);
                Assert.IsNotNull((content as IShellContentController).Page);
                navigated = true;
            };

            await shell.GoToAsync("///destination");

            // content hasn't been created yet
            Assert.IsFalse(navigated);

            var createPage = (content as IShellContentController).GetOrCreateContent();

            Assert.AreEqual(createPage, page);
            Assert.IsTrue(navigated);
        }
Example #14
0
        public async Task GetCurrentPageInModalNavigation()
        {
            Shell shell = new TestShell();

            shell.Items.Add(CreateShellItem(shellItemRoute: "NewRoute", shellSectionRoute: "Section", shellContentRoute: "Content"));

            Page page = null;

            shell.Navigated += (_, __) =>
            {
                page = shell.CurrentPage;
            };

            await shell.GoToAsync("ModalTestPage");

            Assert.IsNotNull(page);
            Assert.AreEqual(page.GetType(), typeof(ModalTestPage));
        }
Example #15
0
        public async Task OnNavigatedFiresWhenPopToRoot()
        {
            Routing.RegisterRoute("AlarmPage", typeof(LifeCyclePage));
            Routing.RegisterRoute("SoundsPage", typeof(LifeCyclePage));
            TestShell shell = new TestShell();

            var item = CreateShellItem(shellContentRoute: ContentRoute, shellSectionRoute: SectionRoute, shellItemRoute: ItemRoute);

            shell.Items.Add(item);

            await shell.GoToAsync("AlarmPage/SoundsPage");

            shell.Reset();

            await shell.Navigation.PopToRootAsync();

            shell.TestCount(1);
        }
Example #16
0
        public async Task InsertPageFromNavigationSetsCorrectNavigationSource()
        {
            Routing.RegisterRoute("pagemiddle", typeof(ContentPage));
            Routing.RegisterRoute("page", typeof(ContentPage));
            var shell = new TestShell(
                CreateShellItem(shellItemRoute: "item")
                );

            await shell.GoToAsync("//item/page");

            ContentPage contentPage = new ContentPage();

            Routing.SetRoute(contentPage, "pagemiddle");
            shell.Navigation.InsertPageBefore(contentPage, shell.Navigation.NavigationStack.Last());

            shell.TestNavigationArgs(ShellNavigationSource.Insert,
                                     "//item/page", "//item/pagemiddle/page");
        }
Example #17
0
        public async Task NavigationTaskCompletesAfterDeferralHasFinished(string testCase)
        {
            Routing.RegisterRoute(nameof(NavigationTaskCompletesAfterDeferralHasFinished), typeof(ContentPage));
            var shell = new TestShell()
            {
                Items = { CreateShellItem <FlyoutItem>() }
            };

            ShellNavigatingDeferral _token = null;

            shell.Navigating += async(_, args) =>
            {
                _token = args.GetDeferral();
                await Task.Delay(500);

                _token.Complete();
            };

            switch (testCase)
            {
            case "PopToRoot":
                await shell.Navigation.PopToRootAsync();

                break;

            case "Pop":
                await shell.Navigation.PopAsync();

                break;

            case "GoToAsync":
                await shell.GoToAsync(nameof(NavigationTaskCompletesAfterDeferralHasFinished));

                break;

            case "Push":
                await shell.Navigation.PushAsync(new ContentPage());

                break;
            }

            Assert.IsTrue(_token.IsCompleted);
        }
Example #18
0
        public async Task CanCancelGoToModalAsync()
        {
            TestShell shell = new TestShell();

            shell.Items.Add(CreateShellItem());

            shell.Navigating += async(_, args) =>
            {
                var deferral = args.GetDeferral();
                await Task.Delay(10);

                args.Cancel();
                deferral.Complete();
            };

            await shell.GoToAsync("ModalTestPage");

            Assert.AreEqual(0, shell.Navigation.ModalStack.Count);
        }
Example #19
0
        public async Task GetCurrentPageInShellNavigation()
        {
            Shell shell = new TestShell();
            var   item1 = CreateShellItem(asImplicit: true, shellContentRoute: "rootlevelcontent1");

            shell.Items.Add(item1);
            Routing.RegisterRoute("cat", typeof(ContentPage));

            Page page = null;

            shell.Navigated += (_, __) =>
            {
                page = shell.CurrentPage;
            };

            await shell.GoToAsync("cat");

            Assert.IsNotNull(page);
            Assert.AreEqual(page.GetType(), typeof(ContentPage));
            Assert.AreEqual(shell.Navigation.NavigationStack[1], page);
        }
Example #20
0
        public async Task MultiplePopsRemoveMiddlePagesBeforeFinalPop()
        {
            TestShell testShell = new TestShell(
                CreateShellSection <NavigationMonitoringTab>(shellContentRoute: "rootpage")
                );

            var pageLeftOnStack = new ContentPage();
            var tab             = (NavigationMonitoringTab)testShell.CurrentItem.CurrentItem;
            await testShell.Navigation.PushAsync(pageLeftOnStack);

            await testShell.Navigation.PushAsync(new ContentPage());

            await testShell.Navigation.PushAsync(new ContentPage());

            tab.NavigationsFired.Clear();
            await testShell.GoToAsync("../..");

            Assert.That(testShell.CurrentState.Location.ToString(),
                        Is.EqualTo($"//rootpage/{Routing.GetRoute(pageLeftOnStack)}"));

            Assert.AreEqual("OnRemovePage", tab.NavigationsFired[0]);
            Assert.AreEqual("OnPopAsync", tab.NavigationsFired[1]);
            Assert.AreEqual(2, tab.NavigationsFired.Count);
        }
        public async Task NavigationBetweenFlyoutItemWithPushedPageRetainsQueryString()
        {
            var testPage1 = new ShellTestPage();
            var testPage2 = new ShellTestPage();

            var flyoutItem1 = CreateShellItem <FlyoutItem>(testPage1, shellItemRoute: "flyoutItem1");
            var flyoutItem2 = CreateShellItem <FlyoutItem>(testPage2, shellItemRoute: "flyoutItem2");

            Routing.RegisterRoute("details", typeof(ShellTestPage));


            var shell = new TestShell(flyoutItem1, flyoutItem2);

            IShellController shellController = shell;
            await shell.GoToAsync(new ShellNavigationState($"//flyoutItem2/details?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));

            await shellController.OnFlyoutItemSelectedAsync(flyoutItem1);

            await shellController.OnFlyoutItemSelectedAsync(flyoutItem2);

            var testPage = (shell.CurrentItem.CurrentItem as IShellSectionController).PresentedPage as ShellTestPage;

            Assert.AreEqual("1234", testPage.SomeQueryParameter);
        }