Skip to content

Commit

Permalink
separate tests
Browse files Browse the repository at this point in the history
clean up test naming
ensuring bug is attached to each test
  • Loading branch information
RLittlesII committed May 24, 2024
1 parent a9d344e commit f757300
Showing 1 changed file with 72 additions and 26 deletions.
98 changes: 72 additions & 26 deletions tests/Maui/Prism.Maui.Tests/Fixtures/Common/MvvmHelperFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections;
using Prism.Common;
using Prism.Maui.Tests.Mocks.Views;

namespace Prism.Maui.Tests.Fixtures.Common;

Expand All @@ -10,40 +8,88 @@ public class MvvmHelperFixture
/// This test was introduced to verify GH3143
/// </summary>
/// <a href="https://github.com/PrismLibrary/Prism/issues/3143">Git Hub Issue 3143</a>
/// <param name="window">The window representing the root of the navigation.</param>
/// <param name="page">The actual page we expect to return.</param>
/// <param name="modal">The model page we are pushing on the stack that causes the problem.</param>
[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<object[]>
/// <summary>
/// This test was introduced to verify GH3143
/// </summary>
/// <a href="https://github.com/PrismLibrary/Prism/issues/3143">Git Hub Issue 3143</a>
[Fact]
public async Task GetCurrentPageFromComplexFlyoutPageWithModalReturnsCorrectPage()
{
public IEnumerator<object[]> 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);
}

/// <summary>
/// This test was introduced to verify GH3143
/// </summary>
/// <a href="https://github.com/PrismLibrary/Prism/issues/3143">Git Hub Issue 3143</a>
[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);
}

/// <summary>
/// This test was introduced to verify GH3143
/// </summary>
/// <a href="https://github.com/PrismLibrary/Prism/issues/3143">Git Hub Issue 3143</a>
[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);
}
}

0 comments on commit f757300

Please sign in to comment.