-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Bugzilla44461.cs
91 lines (80 loc) · 2.28 KB
/
Bugzilla44461.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Linq;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using Xamarin.UITest.Queries;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.Bugzilla)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 44461, "ScrollToPosition.Center works differently on Android and iOS", PlatformAffected.iOS)]
public class Bugzilla44461 : TestContentPage
{
const string BtnPrefix = "Button";
protected override void Init()
{
var grid = new Grid
{
RowSpacing = 0,
};
var instructions = new Label
{
Text = @"Tap the first button (Button0). The button should be aligned with the left side of the screen "
+ "and should not move. If it's not, the test failed."
};
grid.Children.Add(instructions);
var scrollView = new ScrollView
{
Orientation = ScrollOrientation.Horizontal,
VerticalOptions = LayoutOptions.Center,
BackgroundColor = Color.Yellow,
HeightRequest = 50
};
grid.Children.Add(scrollView);
var stackLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal,
Spacing = 20
};
for (var i = 0; i < 10; i++)
{
var button = new Button
{
Text = $"{BtnPrefix}{i}"
};
button.Clicked += (sender, args) =>
{
scrollView.ScrollToAsync(sender as Button, ScrollToPosition.Center, true);
};
stackLayout.Children.Add(button);
}
scrollView.Content = stackLayout;
Content = grid;
}
#if UITEST && __IOS__
[Test]
public void Bugzilla44461Test()
{
var positions = TapButton(0);
Assert.AreEqual(positions.initialPosition.X, positions.finalPosition.X);
Assert.LessOrEqual(positions.finalPosition.X, 1);
RunningApp.Screenshot("Button0 is aligned with the left side of the screen");
}
(AppRect initialPosition, AppRect finalPosition) TapButton(int position)
{
var buttonText = $"{BtnPrefix}{position}";
RunningApp.WaitForElement(q => q.Button(buttonText));
var initialPosition = RunningApp.Query(buttonText)[0].Rect;
RunningApp.Tap(q => q.Button(buttonText));
var finalPosition = RunningApp.Query(buttonText)[0].Rect;
return (initialPosition, finalPosition);
}
#endif
}
}