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

[Testing] Written UI test for the issue resolved in PR 25453 #25573

Merged
merged 3 commits into from
Oct 30, 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
25 changes: 25 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25504.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue25504"
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues">

<ListView x:Name="listView"
AutomationId="listView"
HeightRequest="50"
ItemSelected="OnItemSelected">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Introduction to .NET MAUI</x:String>
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding .}"
AutomationId="Label"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
28 changes: 28 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25504.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 25504, "ListView crashes when changing the root page inside the ItemSelected event", PlatformAffected.UWP)]
public partial class Issue25504 : ContentPage
{
public Issue25504()
{
InitializeComponent();
this.BindingContext = this;
}

private void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
{
if (Application.Current?.Windows.Count > 0)
{
Application.Current.Windows[0].Page = new DetailsPage();
}
}

public class DetailsPage : ContentPage
{
public DetailsPage()
{
Content = new Label { Text = "Details Page", AutomationId = "DetailsPage" };
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue25504 : _IssuesUITest
{
public override string Issue => "ListView crashes when changing the root page inside the ItemSelected event";

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

[Test]
[Category(UITestCategories.ListView)]
public void ListViewShouldNotCrashWhenChangingRootPage()
{
App.WaitForElement("listView");
App.Tap("Label");
var testLabel = App.WaitForElement("DetailsPage");
Assert.That(testLabel.GetText(), Is.EqualTo("Details Page"));
}
}
}
Loading