Skip to content
Merged
63 changes: 63 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25371.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using Microsoft.Maui;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 25371, "OnNavigatedTo not called when navigating back to a specific page", PlatformAffected.iOS | PlatformAffected.macOS)]
public class Issue25371 : NavigationPage
{
public Issue25371() : base(new FirstPage25371())
{
}
}
public class FirstPage25371 : ContentPage
{
Label label;
public FirstPage25371()
{
var stackLayout = new StackLayout();
label = new Label()
{
Text = "Welcome to Main page",
AutomationId = "FirstPageLabel"
};

var button = new Button() { Text = "MoveToNextPage", AutomationId = "MoveToNextPage" };
button.Clicked += Button_Clicked;
stackLayout.Children.Add(label);
stackLayout.Children.Add(button);
Content = stackLayout;

}

protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
label.Text = "OnNavigationTo method is called";
base.OnNavigatedTo(args);
}

private void Button_Clicked(object sender, EventArgs e)
{
label.Text = "Welcome to Main page"; // label text should be reset to original text
Navigation.PushAsync(new SecondPage25371());
}
}

public class SecondPage25371 : ContentPage
{
public SecondPage25371()
{
var label = new Label()
{
AutomationId = "SecondPageLabel",
Text = "Welcome to Second Page",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center
};

Content = label;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if IOS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue25371 : _IssuesUITest
{
public override string Issue => "OnNavigatedTo not called when navigating back to a specific page";

public Issue25371(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Navigation)]
public void ValidateOnNavigationToMethod()
{
App.WaitForElement("MoveToNextPage");
App.Tap("MoveToNextPage");
App.WaitForElement("SecondPageLabel");

App.LongPress("Back");

var navigationToLabel = App.FindElement("FirstPageLabel").GetText();
Assert.That(navigationToLabel, Is.EqualTo("OnNavigationTo method is called"));
}
}
}
#endif