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

Port all remaining Xamarin.UITest tests to Appium #24153

Merged
merged 13 commits into from
Oct 10, 2024
  •  
  •  
  •  
1 change: 1 addition & 0 deletions src/Controls/src/Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
[assembly: InternalsVisibleTo("CommunityToolkit.Maui.UnitTests")]
[assembly: InternalsVisibleTo("CommunityToolkit.Maui.Markup")]
[assembly: InternalsVisibleTo("CommunityToolkit.Maui.Markup.UnitTests")]
[assembly: InternalsVisibleTo("Controls.TestCases.HostApp")]

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

Expand Down
97 changes: 97 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Elements/ContactsPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Maui.Controls.CustomAttributes;
using Microsoft.Maui.Controls.Internals;

namespace Maui.Controls.Sample.Issues;

[Preserve(AllMembers = true)]
public class ContactsPage : ContentPage
{
public ContactsPage()
{
var listView = new ListView
{
ItemTemplate = new DataTemplate(() =>
{
var cell = new TextCell();
cell.SetBinding(TextCell.TextProperty, new Binding("Name"));
cell.SetBinding(TextCell.DetailProperty, new Binding("Number"));
return cell;
}),
IsGroupingEnabled = true,
GroupDisplayBinding = new Binding("Name")
};

var groupedContacts = new ObservableCollection<Group<ContactViewModel>> {
new Group<ContactViewModel> ("E", new[] {
new ContactViewModel { Name = "Egor1", Number = "'Tap' on this item won't fire the event" },
new ContactViewModel { Name = "Egor2", Number = "123" },
new ContactViewModel { Name = "Egor3", Number = "123" },
})
};

listView.ItemsSource = groupedContacts;
listView.ItemTapped += ListViewOnItemTapped;

Content = listView;
}

void ListViewOnItemTapped(object sender, ItemTappedEventArgs itemTappedEventArgs)
{
DisplayActionSheet("Tapped a List item", "Cancel", "Destruction");
}
}

[Preserve(AllMembers = true)]
public class ContactViewModel : ViewModelBase2
{
string _name;
string _number;

public string Name
{
get { return _name; }
set { SetProperty(ref _name, value); }
}

public string Number
{
get { return _number; }
set { SetProperty(ref _number, value); }
}
}

[Preserve(AllMembers = true)]
public class Group<TItem> : ObservableCollection<TItem>
{
public Group(string name, IEnumerable<TItem> items)
{
Name = name;
foreach (var item in items)
Add(item);
}

public string Name { get; set; }
}

[Preserve(AllMembers = true)]
public class ViewModelBase2 : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

protected virtual ViewModelBase2 SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
field = value;
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Microsoft.Maui.Controls.Internals;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.None, 0, "Adding Multiple Items to a ListView", PlatformAffected.All)]

public class AddingMultipleItemsListView : TestContentPage
{
protected override void Init()
{
Title = "Hours";
var exampleViewModel = new ExampleViewModel();
BindingContext = exampleViewModel;

var listView = new ListView
{
ItemTemplate = new DataTemplate(typeof(CustomViewCell)),
HeightRequest = 400,
VerticalOptions = LayoutOptions.Start
};

listView.SetBinding(ListView.ItemsSourceProperty, new Binding("Jobs", BindingMode.TwoWay));

var addOneJobButton = new Button
{
Text = "Add One",
AutomationId = "Add One"
};
addOneJobButton.SetBinding(Button.CommandProperty, new Binding("AddOneCommand"));

var addTwoJobsButton = new Button
{
Text = "Add Two",
AutomationId = "Add Two"
};
addTwoJobsButton.SetBinding(Button.CommandProperty, new Binding("AddTwoCommand"));

var layout = new StackLayout
{
Orientation = StackOrientation.Vertical,
#pragma warning disable CS0618 // Type or member is obsolete
VerticalOptions = LayoutOptions.StartAndExpand,
#pragma warning restore CS0618 // Type or member is obsolete
Spacing = 15,
Children = {
listView,
addOneJobButton,
addTwoJobsButton
}
};
Content = layout;
}

[Preserve(AllMembers = true)]
public class CustomViewCell : ViewCell
{
public CustomViewCell()
{
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
var jobId = new Label
{
FontSize = 20,
WidthRequest = 105,
VerticalOptions = LayoutOptions.Center,

HorizontalOptions = LayoutOptions.StartAndExpand
};
jobId.SetBinding(Label.TextProperty, "JobId");
jobId.SetBinding(Label.AutomationIdProperty, "JobId");

var jobName = new Label
{
VerticalOptions = LayoutOptions.Center,
WidthRequest = 175,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
jobName.SetBinding(Label.TextProperty, "JobName");
jobName.SetBinding(Label.AutomationIdProperty, "JobName");

var hours = new Label
{
WidthRequest = 45,
VerticalOptions = LayoutOptions.Center,
HorizontalTextAlignment = TextAlignment.End,
HorizontalOptions = LayoutOptions.EndAndExpand,

};
#pragma warning restore CS0612
#pragma warning restore CS0618
hours.SetBinding(Label.TextProperty, new Binding("Hours", BindingMode.OneWay, new DoubleStringConverter()));

var hlayout = new StackLayout
{
Children = {
jobId,
jobName,
hours
},
Orientation = StackOrientation.Horizontal,
};

View = hlayout;
}
}
}
80 changes: 80 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Bugzilla38978.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Linq;
using Microsoft.Maui.Controls.CustomAttributes;
using Microsoft.Maui.Controls.Internals;


namespace Maui.Controls.Sample.Issues;

[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 38978, "Cell.ForceUpdateSize issues with row selection/deselection (ViewCell)", PlatformAffected.Android)]
public class Bugzilla38978 : TestContentPage
{
[Preserve(AllMembers = true)]
public class MyViewCell : ViewCell
{
Image _image;
public MyViewCell()
{
_image = new Image
{
Source = ImageSource.FromFile("oasis.jpg"),
HeightRequest = 50
};

Label label = new Label { Text = "Click the image to resize", VerticalOptions = LayoutOptions.Center };

var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (sender, e) =>
{
if (_image.HeightRequest < 250)
{
_image.HeightRequest = _image.Height + 100;
ForceUpdateSize();
label.Text = "If the tapped image is not larger, this test has failed.";
}
};
_image.GestureRecognizers.Add(tapGestureRecognizer);

var stackLayout = new StackLayout
{
Padding = new Thickness(20, 5, 5, 5),
Orientation = StackOrientation.Horizontal,
Children = {
_image,
label
}
};

View = stackLayout;
}

protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
var item = BindingContext?.ToString();
if (string.IsNullOrWhiteSpace(item))
return;

_image.AutomationId = item;
}
}

protected override void Init()
{
var listView = new ListView
{
HasUnevenRows = true,
ItemTemplate = new DataTemplate(typeof(MyViewCell)),
ItemsSource = Enumerable.Range(0, 10)
};

Content = new StackLayout
{
Padding = new Thickness(0, 20, 0, 0),
Children = {
listView
}
};
}
}
75 changes: 75 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Bugzilla39331.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using Microsoft.Maui.Controls.CustomAttributes;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
using Microsoft.Maui.Graphics;
using AbsoluteLayoutFlags = Microsoft.Maui.Layouts.AbsoluteLayoutFlags;
using Button = Microsoft.Maui.Controls.Button;

namespace Maui.Controls.Sample.Issues;

[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 39331, "[Android] BoxView Is InputTransparent Even When Set to False")]
public class Bugzilla39331 : TestContentPage
{
View _busyBackground;
Button _btnLogin;

protected override void Init()
{
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
AbsoluteLayout layout = new AbsoluteLayout
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
};
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete

BackgroundColor = Color.FromUint(0xFFDBDBDB);

#pragma warning disable CS0618 // Type or member is obsolete
_btnLogin = new Button
{
HorizontalOptions = LayoutOptions.FillAndExpand,
AutomationId = "btnLogin",
Text = "Press me",
BackgroundColor = Color.FromUint(0xFF6E932D),
TextColor = Colors.White,
};
#pragma warning restore CS0618 // Type or member is obsolete
_btnLogin.Clicked += BtnLogin_Clicked;
layout.Children.Add(_btnLogin);

_busyBackground = new BoxView
{
BackgroundColor = new Color(0, 0, 0, 0.5f),
IsVisible = false,
InputTransparent = false
};

// Bump up elevation on Android to cover FastRenderer Button
((BoxView)_busyBackground).On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetElevation(10f);

layout.Children.Add(_busyBackground);

Content = layout;
}

void BtnLogin_Clicked(object sender, EventArgs e)
{

if (!_busyBackground.IsVisible)
{
_btnLogin.Text = "Blocked?";
_busyBackground.IsVisible = true;
}
else
{
_btnLogin.Text = "Guess Not";
_busyBackground.IsVisible = false;
}
}
}
Loading
Loading