Skip to content

Commit

Permalink
Move PopLifeCycle to device tests (#23468)
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen authored Jul 6, 2024
1 parent e0ef424 commit 9b44c9a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public async Task PushLifeCycle(bool useMaui)

[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task PopLifeCycle(bool useMaui)
{
bool appearingShouldFireOnInitialPage = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,55 @@ await CreateHandlerAndAddToWindow<WindowHandlerStub>(new Window(navPage), async
Assert.False(pageFiredNavigated);
}

[Fact]
public async Task PopLifeCycle()
{
SetupBuilder();

bool appearingShouldFireOnInitialPage = false;
ContentPage initialPage = new ContentPage();
ContentPage pushedPage = new ContentPage();

ContentPage rootPageFiresAppearingAfterPop = null;
ContentPage pageDisappeared = null;

NavigationPage nav = new NavigationPage(initialPage);

// Because of queued change propagation on BPs
// sometimes the appearing will fire a bit later than we expect.
// This ensures the first one fires before we move on
TaskCompletionSource waitForFirstAppearing = new TaskCompletionSource();
initialPage.Appearing += OnInitialPageAppearing;
void OnInitialPageAppearing(object sender, EventArgs e)
{
waitForFirstAppearing.SetResult();
initialPage.Appearing -= OnInitialPageAppearing;
}

await CreateHandlerAndAddToWindow(nav, async () =>
{
await waitForFirstAppearing.Task.WaitAsync(TimeSpan.FromSeconds(2));
initialPage.Appearing += (sender, _) =>
{
Assert.True(appearingShouldFireOnInitialPage);
rootPageFiresAppearingAfterPop = (ContentPage)sender;
};
pushedPage.Disappearing += (sender, _)
=> pageDisappeared = (ContentPage)sender;
await nav.PushAsync(pushedPage).WaitAsync(TimeSpan.FromSeconds(2));
Assert.Null(rootPageFiresAppearingAfterPop);
appearingShouldFireOnInitialPage = true;
Assert.Null(pageDisappeared);
await nav.PopAsync().WaitAsync(TimeSpan.FromSeconds(2));
Assert.Equal(initialPage, rootPageFiresAppearingAfterPop);
Assert.Equal(pushedPage, pageDisappeared);
});
}

#if !IOS && !MACCATALYST

[Fact(DisplayName = "Swapping Navigation Toggles BackButton Correctly")]
Expand Down

0 comments on commit 9b44c9a

Please sign in to comment.