-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue3019.cs
161 lines (135 loc) · 3.32 KB
/
Issue3019.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using Xamarin.Forms.CustomAttributes;
using System.Diagnostics;
using Xamarin.Forms.Internals;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 3019, "Grouped ListView Header empty for adding items", PlatformAffected.UWP)]
#if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.Github5000)]
[Category(UITestCategories.ListView)]
#endif
public class Issue3019 : TestContentPage
{
ListView _listViewIsGrouped;
[Preserve(AllMembers = true)]
class MyHeaderViewCell : ViewCell
{
public MyHeaderViewCell()
{
Height = 25;
var label = new Label { VerticalOptions = LayoutOptions.Center };
label.SetBinding(Label.TextProperty, nameof(GroupedItem.Name));
View = new StackLayout()
{
Children =
{
label
}
};
}
}
[Preserve(AllMembers = true)]
class Item
{
static int counter = 0;
public Item()
{
Text = $"Grouped Item: {counter++}";
}
public string Text { get; }
}
[Preserve(AllMembers = true)]
class GroupedItem : List<Item>
{
public GroupedItem()
{
AddRange(Enumerable.Range(0, 1).Select(i => new Item()));
}
public string Name { get; set; }
}
void LoadData()
{
_listViewIsGrouped.ItemsSource = new ObservableCollection<GroupedItem>(Enumerable.Range(0, 1).Select(x => new GroupedItem() { Name = $"Group {x}" }));
}
void AddData()
{
var list = _listViewIsGrouped.ItemsSource as IList<GroupedItem>;
list.Add(new GroupedItem() { Name = $"Group {list.Count}" });
}
void ReloadListViews()
{
StackLayout content = Content as StackLayout;
if (_listViewIsGrouped != null)
{
content.Children.Remove(_listViewIsGrouped);
}
_listViewIsGrouped = new ListView
{
IsGroupingEnabled = true,
GroupHeaderTemplate = new DataTemplate(typeof(MyHeaderViewCell)),
ItemTemplate = new DataTemplate(() =>
{
Label nameLabel = new Label();
nameLabel.SetBinding(Label.TextProperty, "Text");
var cell = new ViewCell
{
View = nameLabel,
};
return cell;
}),
ItemsSource = new ObservableCollection<GroupedItem>()
};
content.Children.Add(_listViewIsGrouped);
}
protected override void OnAppearing()
{
base.OnAppearing();
AddData();
}
protected override void Init()
{
Label label = new Label() { Text = "If you see two group headers and can click on each row without crashing test has passed" };
Content = new StackLayout
{
Children =
{
label,
new Button()
{
Text = "Click to add more rows",
Command = new Command(() =>
{
AddData();
})
}
},
};
ReloadListViews();
LoadData();
_listViewIsGrouped.ItemSelected += (sender, args) =>
{
label.Text = (args.SelectedItem as Item).Text + " Clicked";
};
}
#if UITEST
[Test]
public void MakeSureListGroupShowsUpAndItemsAreClickable()
{
RunningApp.WaitForElement("Group 1");
RunningApp.Tap(x => x.Marked("Grouped Item: 0"));
RunningApp.Tap(x => x.Marked("Grouped Item: 1"));
RunningApp.Tap(x => x.Marked("Grouped Item: 1 Clicked"));
}
#endif
}
}