summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla46363.cs
blob: 9beb0ef51d1e71f5660d1b04c80cb6f1a5644b05 (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
using System.Collections.Generic;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
	[Category(UITestCategories.Gestures)]
	[Category(UITestCategories.ListView)]
	[Category(UITestCategories.Cells)]
	[Category(UITestCategories.ContextActions)]
#endif

	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 46363, "TapGestureRecognizer blocks List View Context Actions", PlatformAffected.Android)]
	public class Bugzilla46363 : TestContentPage
	{
		const string Target = "Two";
		const string ContextAction = "Context Action";
		const string TapSuccess = "Tap Success";
		const string TapFailure = "Tap command executed more than once";
		const string ContextSuccess = "Context Menu Success";
		const string Testing = "Testing";

		static Command s_tapCommand;
		static Command s_contextCommand;

		protected override void Init()
		{
			var list = new List<string> { "One", Target, "Three", "Four" };

			var lv = new ListView
			{
				ItemsSource = list,
				ItemTemplate = new DataTemplate(typeof(_46363Template))
			};

			var instructions = new Label();
			var result = new Label { Text = Testing };

			s_tapCommand = new Command(() =>
			{
				if (result.Text == TapSuccess || result.Text == TapFailure)
				{
					// We want this test to fail if the tap command is executed more than once
					result.Text = TapFailure;
				}
				else
				{
					result.Text = TapSuccess;
				}
			});

			s_contextCommand = new Command(() =>
			{
				result.Text = ContextSuccess;
			});

			var layout = new StackLayout { VerticalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill };

			layout.Children.Add(instructions);
			layout.Children.Add(result);
			layout.Children.Add(lv);

			Content = layout;
		}

		[Preserve(AllMembers = true)]
		class _46363Template : ViewCell
		{
			public _46363Template()
			{
				var label = new Label();
				label.SetBinding(Label.TextProperty, ".");
				View = new StackLayout { Children = { label } };

				ContextActions.Add(new MenuItem
				{
					Text = ContextAction,
					Command = s_contextCommand
				});

				View.GestureRecognizers.Add(new TapGestureRecognizer
				{
					Command = s_tapCommand
				});
			}
		}

#if UITEST
		[Test]
		public void _46363_Tap_Succeeds()
		{
			RunningApp.WaitForElement(Testing);
			RunningApp.Tap(Target);
			RunningApp.WaitForElement(TapSuccess);

			// First run at fixing this caused the context menu to open on a regular tap
			// So this check is to ensure that doesn't happen again
			RunningApp.WaitForNoElement(ContextAction);
		}

		[Test]
		public void _46363_ContextAction_Succeeds()
		{
			RunningApp.WaitForElement(Testing);
			RunningApp.ActivateContextMenu(Target);
			RunningApp.WaitForElement(ContextAction);
			RunningApp.Tap(ContextAction);
			RunningApp.WaitForElement(ContextSuccess);
		}
#endif
	}
}