-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue3008.cs
217 lines (192 loc) · 5.29 KB
/
Issue3008.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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, 3008, "Setting ListView.ItemSource to null doesn't cause it clear out its contents", PlatformAffected.UWP)]
#if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.Github5000)]
[NUnit.Framework.Category(UITestCategories.ListView)]
#endif
public class Issue3008 : TestContentPage
{
ListView _listView;
ListView _listViewIsGrouped;
const string success1 = "InitialLoad: you should see a grouped and not grouped list view";
const string successEmpty1 = "Source is set to null: you should see nothing";
const string success2 = "Reload1: you should see a grouped and not grouped list view";
const string successEmpty2 = "If you see nothing now test has passed";
const string successEmpty3 = "List loaded and ItemSource not set: you should see nothing";
[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 = label;
}
}
[Preserve(AllMembers = true)]
class GroupedItem : List<Item>
{
public GroupedItem()
{
AddRange(Enumerable.Range(0, 3).Select(i => new Item()));
}
public string Name { get; set; }
}
[Preserve(AllMembers = true)]
class Item
{
}
void LoadData()
{
_listViewIsGrouped.ItemsSource = new ObservableCollection<GroupedItem>(Enumerable.Range(0, 3).Select(x => new GroupedItem() { Name = $"Group {x}" }));
_listView.ItemsSource = new ObservableCollection<Item>(Enumerable.Range(0, 13).Select(x => new Item()));
}
void ReloadListViews()
{
StackLayout content = Content as StackLayout;
if (_listView != null)
{
content.Children.Remove(_listView);
content.Children.Remove(_listViewIsGrouped);
}
_listView = new ListView
{
ItemTemplate = new DataTemplate(() =>
{
Label nameLabel = new Label() { Text = "Not Grouped Item" };
var cell = new ViewCell
{
View = nameLabel,
};
return cell;
}),
};
_listViewIsGrouped = new ListView
{
IsGroupingEnabled = true,
GroupHeaderTemplate = new DataTemplate(typeof(MyHeaderViewCell)),
ItemTemplate = new DataTemplate(() =>
{
Label nameLabel = new Label() { Text = "Grouped Item" };
var cell = new ViewCell
{
View = nameLabel,
};
return cell;
}),
};
content.Children.Add(_listView);
content.Children.Add(_listViewIsGrouped);
}
protected override void Init()
{
Label label = new Label();
int clickCount = 0;
Content = new StackLayout
{
Children =
{
label,
new Button()
{
Text = "Click Until Success",
Command = new Command(() =>
{
if(clickCount == 0)
{
LoadData();
label.Text = success1;
}
else if(clickCount == 1)
{
ReloadListViews();
LoadData();
label.Text = success1;
}
else if(clickCount <= 3)
{
if(_listViewIsGrouped.ItemsSource != null)
{
_listViewIsGrouped.ItemsSource = null;
_listView.ItemsSource = null;
label.Text = successEmpty1;
}
else
{
LoadData();
label.Text = success2;
}
}
else if(clickCount <= 5)
{
if(_listViewIsGrouped.ItemsSource != null)
{
ReloadListViews();
label.Text = successEmpty3;
}
else
{
LoadData();
label.Text = success2;
}
}
else
{
if(_listViewIsGrouped.ItemsSource != null)
{
_listViewIsGrouped.ItemsSource = new List<GroupedItem>();
_listView.ItemsSource = new List<Item>();
label.Text = successEmpty2;
}
}
clickCount++;
})
}
},
};
ReloadListViews();
}
#if UITEST && !__ANDROID__
[Test]
public void EnsureListViewEmptiesOut()
{
RunningApp.Tap("Click Until Success");
RunningApp.WaitForElement("Not Grouped Item");
RunningApp.WaitForElement("Grouped Item");
RunningApp.Tap("Click Until Success");
RunningApp.WaitForElement("Not Grouped Item");
RunningApp.WaitForElement("Grouped Item");
RunningApp.Tap("Click Until Success");
RunningApp.WaitForNoElement("Not Grouped Item");
RunningApp.WaitForNoElement("Grouped Item");
RunningApp.Tap("Click Until Success");
RunningApp.WaitForElement("Not Grouped Item");
RunningApp.WaitForElement("Grouped Item");
RunningApp.Tap("Click Until Success");
RunningApp.WaitForNoElement("Not Grouped Item");
RunningApp.WaitForNoElement("Grouped Item");
RunningApp.Tap("Click Until Success");
RunningApp.WaitForElement("Not Grouped Item");
RunningApp.WaitForElement("Grouped Item");
RunningApp.Tap("Click Until Success");
RunningApp.WaitForNoElement("Not Grouped Item");
RunningApp.WaitForNoElement("Grouped Item");
}
#endif
}
}