summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla58875.cs
blob: 20eb1ed049c9108d4e6f159fd66f6c1cbee32e21 (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
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Collections.ObjectModel;

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

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

	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 58875, "Back navigation disables Context Action in whole app, if Context Action left open", PlatformAffected.iOS)]
	public class Bugzilla58875 : TestNavigationPage
	{
		const string Button1Id = "Button1Id";
		const string ContextAction = "More";
		const string Target = "Swipe me";

		protected override void Init()
		{
			var page1 = new Page1();
			Navigation.PushAsync(page1);
		}

		[Preserve(AllMembers = true)]
		class ListViewPage : ContentPage
		{
			public ListViewPage()
			{
				BindingContext = this;

				var listView = new ListView(ListViewCachingStrategy.RecycleElement)
				{
					ItemTemplate = new DataTemplate(() =>
					{
						var label = new Label { };
						label.SetBinding(Label.TextProperty, ".");
						var viewcell = new ViewCell
						{
							View = new StackLayout { Children = { label } }
						};
						viewcell.ContextActions.Add(new MenuItem { Text = ContextAction });
						viewcell.ContextActions.Add(new MenuItem { Text = "Delete", IsDestructive = true });
						return viewcell;
					})
				};

				listView.SetBinding(ListView.ItemsSourceProperty, nameof(Items));

				Items = new ObservableCollection<string> {
						"Item 1",
						Target,
						"Item 3",
						"Swipe me too, leave me open",
						"Swipe left -> right (trigger back navigation)"
				};

				Content = listView;
			}

			public ObservableCollection<string> Items { get; set; }
		}

		[Preserve(AllMembers = true)]
		class Page1 : ContentPage
		{
			public Page1()
			{
				var button = new Button { Text = "Tap me", AutomationId = Button1Id };
				button.Clicked += Button_Clicked;
				Content = button;
			}

			void Button_Clicked(object sender, System.EventArgs e)
			{
				var listPage = new ListViewPage();
				Navigation.PushAsync(listPage);
			}
		}

#if UITEST
		[Test]
		public void Bugzilla58875Test()
		{
			RunningApp.WaitForElement(q => q.Marked(Button1Id));
			RunningApp.Tap(q => q.Marked(Button1Id));
			RunningApp.WaitForElement(q => q.Marked(Target));
			RunningApp.ActivateContextMenu(Target);
			RunningApp.WaitForElement(q => q.Marked(ContextAction));
			RunningApp.Back();

#if __ANDROID__
			RunningApp.Back(); // back button dismisses the ContextAction first, so we need to hit back one more time to get to previous page
#endif

			RunningApp.WaitForElement(q => q.Marked(Button1Id));
			RunningApp.Tap(q => q.Marked(Button1Id));
			RunningApp.WaitForElement(q => q.Marked(Target));
			RunningApp.ActivateContextMenu(Target);
			RunningApp.WaitForElement(q => q.Marked(ContextAction));
		}
#endif
	}
}