summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ScrollViewIsEnabled.cs
blob: 563a3319471ddb6bd7e829b2831a7a2c84106cd8 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
	[Category(UITestCategories.IsEnabled)]
#endif

	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.None, 0112358, "ScrollView set to disabled will still allow scrolling", PlatformAffected.All)]
	public class ScrollViewIsEnabled : TestNavigationPage
	{
		const string InitiallyEnabled = "Initially Enabled";
		const string InitiallyNotEnabled = "Initially Not Enabled";
		const string ToggleButton = "ToggleButton";
		const string ScrollView = "TheScrollView";
		const string FirstItem = "FirstItem";
		const string Success = "Success";

		protected override void Init()
		{
			var initiallyEnabled = new Button { Text = InitiallyEnabled };
			initiallyEnabled.Clicked += (sender, args) => { Navigation.PushAsync(ScrollViewTestPage(true)); };

			var initiallyNotEnabled = new Button { Text = InitiallyNotEnabled };
			initiallyNotEnabled.Clicked += (sender, args) => { Navigation.PushAsync(ScrollViewTestPage(false)); };

			var layout = new StackLayout { Children = { initiallyNotEnabled, initiallyEnabled } };

			var root = new ContentPage { Content = layout };

			PushAsync(root);
		}

		static ContentPage ScrollViewTestPage(bool initiallyEnabled)
		{
			var scrollViewContents = new StackLayout();
			scrollViewContents.Children.Add(new Label { Text = FirstItem });
			for (int n = 0; n < 100; n++)
			{
				scrollViewContents.Children.Add(new Label { Text = n.ToString() });
			}

			var sv = new ScrollView { Content = scrollViewContents, IsEnabled = initiallyEnabled, AutomationId = ScrollView };
			var layout = new StackLayout { Margin = new Thickness(5, 40, 5, 0) };

			var toggleButton = new Button { Text = $"Toggle IsEnabled (currently {sv.IsEnabled})", AutomationId = ToggleButton };

			toggleButton.Clicked += (sender, args) =>
			{
				sv.IsEnabled = !sv.IsEnabled;
				toggleButton.Text = $"Toggle IsEnabled (currently {sv.IsEnabled})";
			};

			var instructions = new Label
			{
				Text = @"Attempt to scroll the ScrollView below. 
If 'IsEnabled' is false and the ScrollView scrolls, this test has failed. 
If 'IsEnabled' is true and the ScrollView does not scroll, this test has failed. 
Use the toggle button to check both values of 'IsEnabled'."
			};

			var success = new Label();

			layout.Children.Add(instructions);
			layout.Children.Add(toggleButton);
			layout.Children.Add(success);
			layout.Children.Add(sv);

			sv.Scrolled += (sender, args) => success.Text = Success;

			return new ContentPage { Content = layout };
		}

#if UITEST
		[Test]
		public void ScrollViewInitiallyEnabled()
		{
			RunningApp.WaitForElement(InitiallyEnabled);
			RunningApp.Tap(InitiallyEnabled);
			RunningApp.WaitForElement(FirstItem);
			RunningApp.WaitForElement(ScrollView);
			RunningApp.ScrollDown(ScrollView, ScrollStrategy.Gesture);
			RunningApp.WaitForElement(Success); // If the ScrollView scrolled, the success label should be displayed
		}

		[Test]
		public void ScrollViewInitiallyEnabledThenDisabled()
		{
			RunningApp.WaitForElement(InitiallyEnabled);
			RunningApp.Tap(InitiallyEnabled);
			RunningApp.WaitForElement(ToggleButton);
			RunningApp.Tap(ToggleButton);
			
			// Scrolling should now be IsEnabled = false

			RunningApp.WaitForElement(FirstItem);
			RunningApp.WaitForElement(ScrollView);
			RunningApp.ScrollDown(ScrollView, ScrollStrategy.Gesture);
			RunningApp.WaitForNoElement(Success); // Shouldn't have scrolled, so no success label should be displayed
		}

		[Test]
		public void ScrollViewInitiallyNotEnabled()
		{
			RunningApp.WaitForElement(InitiallyNotEnabled);
			RunningApp.Tap(InitiallyNotEnabled);
			RunningApp.WaitForElement(FirstItem);
			RunningApp.WaitForElement(ScrollView);
			RunningApp.ScrollDown(ScrollView, ScrollStrategy.Gesture);
			RunningApp.WaitForNoElement(Success); // Shouldn't have scrolled, so no success label should be displayed
		}

		[Test]
		public void ScrollViewInitiallyNotEnabledThenEnabled()
		{
			RunningApp.WaitForElement(InitiallyNotEnabled);
			RunningApp.Tap(InitiallyNotEnabled);
			RunningApp.WaitForElement(ToggleButton);
			RunningApp.Tap(ToggleButton);

			// Scrolling should now be IsEnabled = true

			RunningApp.WaitForElement(FirstItem);
			RunningApp.WaitForElement(ScrollView);
			RunningApp.ScrollDown(ScrollView, ScrollStrategy.Gesture);
			RunningApp.WaitForElement(Success); // If the ScrollView scrolled, the success label should be displayed
		}
#endif
	}
}