Skip to content

Commit

Permalink
tests: adding tests for WindowManagerExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Feb 11, 2024
1 parent 804d8db commit 5144958
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Maui/Prism.Maui/Navigation/IWindowManagerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class IWindowManagerExtensions
/// <returns>The <see cref="INavigationService"/> for the current <see cref="Page"/>.</returns>
public static INavigationService GetCurrentNavigationService(this IWindowManager windowManager)
{
var window = windowManager.Windows.OfType<PrismWindow>().First(x => x.IsActive);
var window = windowManager.Windows.OfType<PrismWindow>().First();

if (window.CurrentPage is null)
throw new InvalidOperationException("No current page has been set.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

using Prism.Navigation.Xaml;

namespace Prism.DryIoc.Maui.Tests.Fixtures.Navigation;

public class WindowManagerTests : TestBase
{
public WindowManagerTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}

[Theory]
[InlineData("NavigationPage/MockViewA/MockViewB/MockViewC")]
[InlineData("MockHome/NavigationPage/MockViewA")]
public void WindowManagerGetsNavigationServiceFromCurrentPage(string uri)
{
var mauiApp = CreateBuilder(prism => prism.CreateWindow(uri))
.Build();
var window = GetWindow(mauiApp);

var rootPage = window.Page;
var currentPage = rootPage;
if (rootPage is NavigationPage navigationPage)
{
currentPage = navigationPage.CurrentPage;
}
if (rootPage is FlyoutPage flyoutPage && flyoutPage.Detail is NavigationPage detailPage)
{
currentPage = detailPage.CurrentPage;
}

var currentNavigationService = Prism.Navigation.Xaml.Navigation.GetNavigationService(currentPage);
var windowManager = rootPage.GetContainerProvider().Resolve<IWindowManager>();
Assert.Same(currentNavigationService, windowManager.GetCurrentNavigationService());
}
}

0 comments on commit 5144958

Please sign in to comment.