Skip to content

Commit

Permalink
Added a Ui test (dotnet#19786)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo committed Apr 28, 2024
1 parent 9a84ec4 commit aad3c85
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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.Issue19786">
<StackLayout>
<CarouselView Position="{Binding Position}" HeightRequest="200" ItemsSource="{Binding Items}">
<CarouselView.ItemTemplate>
<DataTemplate>
<Frame Margin="10" WidthRequest="200" BackgroundColor="Red">
<Label Text="{Binding .}"/>
</Frame>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>

<Grid ColumnDefinitions="*,*,*">
<Button AutomationId="addItemButton" Grid.Column="0" Text="Add item" Command="{Binding AddItemCommand}"/>
<Button AutomationId="goToNextItemButton" Grid.Column="1" Text="Go to next item" Command="{Binding GoToNextItemCommand}"/>
<Button AutomationId="removeLastItemButton" Grid.Column="2" Text="Remove last item" Command="{Binding RemoveItemCommand}"/>
</Grid>
</StackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.ObjectModel;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 19786, "[Android] Crash removing item from CarouselView", PlatformAffected.All)]
public partial class Issue19786 : ContentPage
{
public Command AddItemCommand { get; set; }
public Command RemoveItemCommand { get; set; }
public Command GoToNextItemCommand { get; set; }

private int _position;
public int Position
{
get => _position;
set
{
_position = value;
OnPropertyChanged();
}
}

private ObservableCollection<string> _items = new();
public ObservableCollection<string> Items
{
get => _items;
set
{
_items = value;
OnPropertyChanged();
}
}

public Issue19786()
{
InitializeComponent();

AddItemCommand = new Command(() =>
{
Items.Add(Items.Count.ToString());
});

RemoveItemCommand = new Command(() =>
{
if (Items.Count > 0)
Items.RemoveAt(Items.Count - 1);
});

GoToNextItemCommand = new Command(() =>
{
if (Position < Items.Count - 1)
Position++;
});

BindingContext = this;
}
}
}
31 changes: 31 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue19786.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue19786 : _IssuesUITest
{
public Issue19786(TestDevice device) : base(device)
{
}

public override string Issue => "[Android] Crash removing item from CarouselView";

[Test]
[Category(UITestCategories.CarouselView)]
public void RemovingItemsShouldNotCauseCrash()
{
_ = App.WaitForElement("addItemButton");
App.Click("addItemButton");
App.Click("addItemButton");
App.Click("addItemButton");
App.Click("goToNextItemButton");
App.Click("goToNextItemButton");
App.Click("removeLastItemButton");
App.Click("removeLastItemButton");
App.Click("removeLastItemButton");
}

}
}

0 comments on commit aad3c85

Please sign in to comment.