From f757300b68b127069dfafead8edb1a449f23717b Mon Sep 17 00:00:00 2001 From: rlittlesii <6969701+RLittlesII@users.noreply.github.com> Date: Fri, 24 May 2024 17:05:26 -0500 Subject: [PATCH] separate tests clean up test naming ensuring bug is attached to each test --- .../Fixtures/Common/MvvmHelperFixture.cs | 98 ++++++++++++++----- 1 file changed, 72 insertions(+), 26 deletions(-) diff --git a/tests/Maui/Prism.Maui.Tests/Fixtures/Common/MvvmHelperFixture.cs b/tests/Maui/Prism.Maui.Tests/Fixtures/Common/MvvmHelperFixture.cs index 90c3da0c4..63846b6c7 100644 --- a/tests/Maui/Prism.Maui.Tests/Fixtures/Common/MvvmHelperFixture.cs +++ b/tests/Maui/Prism.Maui.Tests/Fixtures/Common/MvvmHelperFixture.cs @@ -1,6 +1,4 @@ -using System.Collections; using Prism.Common; -using Prism.Maui.Tests.Mocks.Views; namespace Prism.Maui.Tests.Fixtures.Common; @@ -10,40 +8,88 @@ public class MvvmHelperFixture /// This test was introduced to verify GH3143 /// /// Git Hub Issue 3143 - /// The window representing the root of the navigation. - /// The actual page we expect to return. - /// The model page we are pushing on the stack that causes the problem. - [Theory] - [ClassData(typeof(GetCurrentPageTestData))] - public async Task GetCurrentPageWithModalReturnsPrismWindowPage(Window window, Page page, Page modal) + [Fact] + public async Task GetCurrentPageFromFlyoutPageWithModalReturnsDetailPage() { // Given - await window.Navigation.PushModalAsync(modal); + FlyoutPage flyout = new FlyoutPage + { Flyout = new ContentPage { Title = "Title" }, Detail = new NavigationPage(), }; + PrismWindow window = new PrismWindow { Page = flyout }; + await window.Navigation.PushModalAsync(new DialogContainerPage()); // When var result = MvvmHelpers.GetCurrentPage(window.Page); // Then - Assert.Equal(result, page); + Assert.Equal(result, flyout.Detail); } - private class GetCurrentPageTestData : IEnumerable + /// + /// This test was introduced to verify GH3143 + /// + /// Git Hub Issue 3143 + [Fact] + public async Task GetCurrentPageFromComplexFlyoutPageWithModalReturnsCorrectPage() { - public IEnumerator GetEnumerator() + // Given + ContentPage current = new ContentPage { Title = "D" }; + var navigationPage = new NavigationPage(); + await navigationPage.PushAsync(new ContentPage { Title = "A" }); + await navigationPage.PushAsync(new ContentPage { Title = "B" }); + await navigationPage.PushAsync(new ContentPage { Title = "C" }); + await navigationPage.PushAsync(current); + + PrismWindow window = new PrismWindow { - ContentPage contentPage = new ContentPage { Title = "Title" }; - NavigationPage navigationPage = new NavigationPage(); - // TabbedPage tabbedPage = new TabbedPage { CurrentPage = contentPage }; - FlyoutPage flyout = new FlyoutPage { Flyout = contentPage, Detail = new NavigationPage(), }; - DialogContainerPage dialogContainerPage = new DialogContainerPage(); - yield return new object[] { PrismWindow(contentPage), contentPage, dialogContainerPage }; - yield return new object[] { PrismWindow(navigationPage), navigationPage, dialogContainerPage }; - // yield return new object[] { PrismWindow(tabbedPage), tabbedPage, dialogContainerPage }; - yield return new object[] { PrismWindow(flyout), flyout.Detail, dialogContainerPage }; - } - - private static PrismWindow PrismWindow(Page page) => new() { Page = page }; - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + Page = new FlyoutPage + { Flyout = new ContentPage { Title = "Title" }, Detail = navigationPage, } + }; + + await window.Navigation.PushModalAsync(new DialogContainerPage()); + + // When + var result = MvvmHelpers.GetCurrentPage(window.Page); + + // Then + Assert.Equal(result, current); + } + + /// + /// This test was introduced to verify GH3143 + /// + /// Git Hub Issue 3143 + [Fact] + public async Task GetCurrentPageFromNavigationPageWithModalReturnsContentPage() + { + // Given + var contentPage = new ContentPage(); + NavigationPage navigationPage = new NavigationPage(contentPage); + PrismWindow window = new PrismWindow { Page = navigationPage }; + await window.Navigation.PushModalAsync(new DialogContainerPage()); + + // When + var result = MvvmHelpers.GetCurrentPage(window.Page); + + // Then + Assert.Equal(result, contentPage); + } + + /// + /// This test was introduced to verify GH3143 + /// + /// Git Hub Issue 3143 + [Fact] + public async Task GetCurrentPageFromContentPageWithModalReturnsContentPage() + { + // Given + ContentPage contentPage = new ContentPage { Title = "Title" }; + PrismWindow window = new PrismWindow { Page = contentPage }; + await window.Navigation.PushModalAsync(new DialogContainerPage()); + + // When + var result = MvvmHelpers.GetCurrentPage(window.Page); + + // Then + Assert.Equal(result, contentPage); } }