From 75fd512ef5cc11c87018dc06c13dd0bcb3b79609 Mon Sep 17 00:00:00 2001 From: Alberto Aldegheri Date: Wed, 27 Mar 2024 14:16:11 +0100 Subject: [PATCH] Fixes a crash on complex navigation --- .../Internals/NavigationService.cs | 2 +- .../Navigation/NavigationServiceTests.cs | 36 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Source/Nalu.Maui.Navigation/Internals/NavigationService.cs b/Source/Nalu.Maui.Navigation/Internals/NavigationService.cs index 7d59fa6..5691a08 100644 --- a/Source/Nalu.Maui.Navigation/Internals/NavigationService.cs +++ b/Source/Nalu.Maui.Navigation/Internals/NavigationService.cs @@ -284,7 +284,7 @@ private async Task ExecuteAbsoluteNavigationAsync(INavigationInfo navigati .SelectMany(section => section.Contents) .Where(content => content.Page is not null) .OrderByDescending(content => content.Parent == currentSection) - .ThenBy(content => content.Parent) + .ThenBy(content => content.Parent.SegmentName) .ThenByDescending(content => content == currentContent)]; } else diff --git a/Tests/Nalu.Maui.Test/Navigation/NavigationServiceTests.cs b/Tests/Nalu.Maui.Test/Navigation/NavigationServiceTests.cs index 5bd42d3..ba49067 100644 --- a/Tests/Nalu.Maui.Test/Navigation/NavigationServiceTests.cs +++ b/Tests/Nalu.Maui.Test/Navigation/NavigationServiceTests.cs @@ -626,20 +626,30 @@ public async Task NavigationServiceWhenDoingAbsoluteNavigationOnSameItemButDiffe [Fact(DisplayName = "NavigationService, when doing absolute navigation on different item, should pop navigation stacks")] public async Task NavigationServiceWhenDoingAbsoluteNavigationOnDifferentItemShouldPopNavigationStacks() { - ConfigureTestAsync("c1,c5"); - await _navigationService.InitializeAsync(_shellProxy, nameof(Page1), null); + ConfigureTestAsync("i1[c1,c2,c3],c5"); + await _navigationService.InitializeAsync(_shellProxy, nameof(Page2), null); + await _navigationService.GoToAsync(Navigation.Absolute().ShellContent()); + await _navigationService.GoToAsync(Navigation.Absolute().ShellContent()); var shellContent1 = _shellProxy.GetContent(nameof(Page1)); - var shellSection = shellContent1.Parent; + var shellContent2 = _shellProxy.GetContent(nameof(Page2)); + var shellContent3 = _shellProxy.GetContent(nameof(Page3)); + var shellSection1 = shellContent1.Parent; var page1 = shellContent1.Page!; var model1 = (IPage1Model)page1.BindingContext; - - await _navigationService.GoToAsync(Navigation.Relative().Push()); - var navigationStackPages = shellSection.GetNavigationStack().ToList(); - var page2 = navigationStackPages[1].Page; + var page2 = shellContent2.Page!; var model2 = (IPage2Model)page2.BindingContext; + var page3 = shellContent3.Page!; + var model3 = (IPage3Model)page3.BindingContext; + + await _navigationService.GoToAsync(Navigation.Relative().Push()); + var navigationStackPages = shellSection1.GetNavigationStack().ToList(); + var page4 = navigationStackPages[1].Page; + var model4 = (IPage4Model)page4.BindingContext; model1.ClearReceivedCalls(); model2.ClearReceivedCalls(); + model3.ClearReceivedCalls(); + model4.ClearReceivedCalls(); _shellProxy.ClearReceivedCalls(); await _navigationService.GoToAsync(Navigation.Absolute().ShellContent()); @@ -649,15 +659,19 @@ public async Task NavigationServiceWhenDoingAbsoluteNavigationOnDifferentItemSho Received.InOrder(() => { - model2.OnDisappearingAsync(); - model2.OnLeavingAsync(); - _shellProxy.PopAsync(shellSection); + model4.OnDisappearingAsync(); + model4.OnLeavingAsync(); + _shellProxy.PopAsync(shellSection1); model1.OnLeavingAsync(); + model2.OnLeavingAsync(); + model3.OnLeavingAsync(); model5.OnEnteringAsync(); _shellProxy.SelectContentAsync(nameof(Page5)); model5.OnAppearingAsync(); - model2.Dispose(); + model4.Dispose(); model1.Dispose(); + model2.Dispose(); + model3.Dispose(); }); }