Skip to content

Commit f770f95

Browse files
committed
Added a UI test (dotnet#20273)
1 parent 8ca7648 commit f770f95

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue20273">
5+
6+
<ContentPage.Resources>
7+
<x:Array x:Key="stringArray" Type="{x:Type x:String}">
8+
<x:String>First Item</x:String>
9+
<x:String>Second Item</x:String>
10+
<x:String>Third Item</x:String>
11+
</x:Array>
12+
</ContentPage.Resources>
13+
14+
<StackLayout>
15+
<CollectionView ItemsSource="{StaticResource stringArray}"
16+
SelectionMode="Single"
17+
SelectionChanged="CollectionView_SelectionChanged">
18+
<CollectionView.ItemTemplate>
19+
<DataTemplate>
20+
<HorizontalStackLayout>
21+
<Image HeightRequest="100"
22+
WidthRequest="100"
23+
Source="dotnet_bot.png"/>
24+
<Label AutomationId="{Binding .}"
25+
Text="{Binding .}"/>
26+
</HorizontalStackLayout>
27+
</DataTemplate>
28+
</CollectionView.ItemTemplate>
29+
</CollectionView>
30+
<Label AutomationId="numberOfNavigations"
31+
x:Name="numberOfNavigationsLabel"
32+
Text="0"/>
33+
</StackLayout>
34+
</ContentPage>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.Maui.Controls;
3+
using Microsoft.Maui.Controls.Xaml;
4+
namespace Maui.Controls.Sample.Issues;
5+
6+
[XamlCompilation(XamlCompilationOptions.Compile)]
7+
[Issue(IssueTracker.Github, 20273, "Previously selected item cannot be reselected", PlatformAffected.All)]
8+
9+
public partial class Issue20273 : ContentPage
10+
{
11+
int _numberOfNavigations;
12+
13+
public Issue20273()
14+
{
15+
InitializeComponent();
16+
}
17+
18+
void CollectionView_SelectionChanged(System.Object sender, Microsoft.Maui.Controls.SelectionChangedEventArgs e)
19+
{
20+
Navigation.PushAsync(new Issue20273DetailPage());
21+
numberOfNavigationsLabel.Text = (++_numberOfNavigations).ToString();
22+
}
23+
}
24+
25+
public class Issue20273DetailPage : ContentPage
26+
{
27+
protected override async void OnAppearing()
28+
{
29+
base.OnAppearing();
30+
await Task.Delay(100);
31+
await Navigation.PopAsync();
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.AppiumTests.Issues;
6+
7+
public class Issue20273 : _IssuesUITest
8+
{
9+
public override string Issue => "Previously selected item cannot be reselected";
10+
11+
public Issue20273(TestDevice device)
12+
: base(device)
13+
{ }
14+
15+
[Test]
16+
public void PreviouslySelectedItemShouldBeReselected()
17+
{
18+
var firstItem = App.WaitForElement("First Item");
19+
firstItem.Click();
20+
App.WaitForElement("First Item");
21+
firstItem.Click();
22+
var numberOfNavigations = App.WaitForElement("numberOfNavigations").GetText();
23+
24+
Assert.AreEqual(int.Parse(numberOfNavigations!), 2);
25+
}
26+
}

0 commit comments

Comments
 (0)