Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move PopLifeCycle to device tests #23468

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading