-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
GroupListViewHeaderIndexOutOfRange.cs
131 lines (108 loc) · 3.37 KB
/
GroupListViewHeaderIndexOutOfRange.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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.None, 5955, "Group ListView Crashes when ItemSource is Cleared", PlatformAffected.iOS)]
#if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.Github5000)]
[Category(UITestCategories.ListView)]
#endif
public class GroupListViewHeaderIndexOutOfRange : TestContentPage
{
const string ButtonId = "button";
public static ObservableCollection<SamplePack> Samples { get; set; }
public static ObservableCollection<Grouping<string, SamplePack>> Testing { get; set; }
public static void ResetList()
{
Testing.Clear();
}
protected override void Init()
{
Samples = new ObservableCollection<SamplePack>
{
new SamplePack {Info = "1"},
new SamplePack {Info = "2"},
new SamplePack {Info = "3"}
};
var sorted = from sampleData in Samples
orderby sampleData.Info
group sampleData by sampleData.Info
into sampleGroup
select new Grouping<string, SamplePack>(sampleGroup.Key, sampleGroup);
Testing = new ObservableCollection<Grouping<string, SamplePack>>(sorted);
var groupLabel = new Label { FontSize = 18, TextColor = Color.FromHex("#1f1f1f"), HorizontalOptions = LayoutOptions.Start, HorizontalTextAlignment = TextAlignment.Start };
groupLabel.SetBinding(Label.TextProperty, new Binding("Key", stringFormat: "{0} Music"));
var itemLabel = new Label { TextColor = Color.Black };
itemLabel.SetBinding(Label.TextProperty, new Binding("Info"));
ListView TestingList = new ListView()
{
IsPullToRefreshEnabled = true,
IsGroupingEnabled = true,
GroupHeaderTemplate = new DataTemplate(() => new ViewCell
{
Height = 283,
View = new StackLayout
{
Spacing = 0,
Padding = 10,
BackgroundColor = Color.Blue,
Children = {
new StackLayout{ Padding=5, BackgroundColor=Color.White, HeightRequest=30, Children = { groupLabel } }
}
}
}),
ItemTemplate = new DataTemplate(() => new ViewCell
{
View = itemLabel
})
};
TestingList.ItemsSource = Testing;
TestingList.BindingContext = Testing;
TestingList.RefreshCommand = new Command(() =>
{
TestingList.IsRefreshing = true;
ResetList();
TestingList.IsRefreshing = false;
});
Button button = new Button { Text = "Click here to cause crash. Pass if no crash!", Command = new Command(() => ResetList()), AutomationId = ButtonId };
Content = new StackLayout { Children = { button, TestingList } };
}
[Preserve(AllMembers = true)]
public class Grouping<K, T> : ObservableCollection<T>
{
public Grouping(K key, IEnumerable<T> items)
{
Key = key;
foreach (var item in items)
{
Items.Add(item);
}
}
public K Key { get; }
}
[Preserve(AllMembers = true)]
public class SamplePack
{
public string Info { get; set; }
}
#if UITEST
[Test]
public void GroupListViewHeaderIndexOutOfRangeTest()
{
RunningApp.WaitForElement(q => q.Marked(ButtonId));
RunningApp.Tap(q => q.Marked(ButtonId));
RunningApp.WaitForElement(q => q.Marked(ButtonId));
}
#endif
}
}