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

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

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

	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 34912, "ListView.IsEnabled has no effect on iOS")]
	public class Bugzilla34912 : TestContentPage // or TestMasterDetailPage, etc ...
	{
		protected override void Init ()
		{
			Padding = new Thickness (0, 20, 0, 0);

			var source = SetupList ();

			var list = new ListView
			{
				ItemTemplate = new DataTemplate(typeof(TextCell))
				{
					Bindings = {
						{ TextCell.TextProperty, new Binding ("Name") }
					}
				},

				GroupDisplayBinding = new Binding("LongTitle"),
				GroupShortNameBinding = new Binding("Title"),
				Header = "HEADER",
				Footer = "FOOTER",
				IsGroupingEnabled = true,
				ItemsSource = SetupList(),
			};

			list.ItemTapped += (sender, e) =>
			{
				var listItem = (Issue2777.ListItemValue)e.Item;
				DisplayAlert(listItem.Name, "You tapped " + listItem.Name, "OK", "Cancel");
			};

			var btnDisable = new Button () {
				Text = "Disable ListView",
				AutomationId = "btnDisable"
			};
			btnDisable.Clicked += (object sender, EventArgs e) => {
				if (list.IsEnabled == true){
					list.IsEnabled = false;
					btnDisable.Text = "Enable ListView";
				}
				else {
					list.IsEnabled = true;
					btnDisable.Text = "Disable ListView";
				}
			};

			Content = new StackLayout
			{
				VerticalOptions = LayoutOptions.FillAndExpand,
				Children = { btnDisable, list }
			};
		}

		ObservableCollection<Issue2777.ListItemCollection> SetupList()
		{
			var allListItemGroups = new ObservableCollection<Issue2777.ListItemCollection>();

			foreach (var item in Issue2777.ListItemCollection.GetSortedData())
			{
				// Attempt to find any existing groups where theg group title matches the first char of our ListItem's name.
				var listItemGroup = allListItemGroups.FirstOrDefault(g => g.Title == item.Label);

				// If the list group does not exist, we create it.
				if (listItemGroup == null)
				{
					listItemGroup = new Issue2777.ListItemCollection(item.Label);
					listItemGroup.Add(item);
					allListItemGroups.Add(listItemGroup);
				}
				else
				{ // If the group does exist, we simply add the demo to the existing group.
					listItemGroup.Add(item);
				}
			}
			return allListItemGroups;
		}

#if UITEST
		[Test]
		public void Bugzilla34912Test ()
		{
			RunningApp.Tap (q => q.Marked ("Allen"));
			RunningApp.WaitForElement (q => q.Marked ("You tapped Allen"));
			RunningApp.Tap (q => q.Marked ("OK"));
			RunningApp.Tap (q => q.Marked ("btnDisable"));
			RunningApp.Tap (q => q.Marked ("Allen"));
			RunningApp.WaitForNoElement (q => q.Marked ("You tapped Allen"));
		}
#endif
	}
}