summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2470.xaml.cs
blob: de0602ed9dc708a37d46204504cad1711f6a90c1 (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
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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using NUnit.Framework;
using Xamarin.UITest;
#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	public class Issue2470ViewModelBase : INotifyPropertyChanged
	{
		public event PropertyChangedEventHandler PropertyChanged;

		protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
		}
	}

	[Preserve (AllMembers = true)]
	public class EntryViewModel : ViewModelBase
	{
		string _name;
		public string Name
		{
			get { return _name; }
			set { _name = value; OnPropertyChanged (); }
		}

		bool _selected;
		public bool Selected
		{
			get { return _selected; }
			set { _selected = value; OnPropertyChanged (); }
		}
	}

	[Preserve (AllMembers = true)]
	public class Issue2470MainViewModel : Issue2470ViewModelBase
	{
		public ObservableCollection<EntryViewModel> Entries { get; private set; }

		double _desiredCount;
		public double DesiredCount
		{
			get { return _desiredCount; }
			set
			{
				_desiredCount = value;
				OnPropertyChanged ();
				GenerateEntries ();
			}
		}

		bool _twoOrFive;
		public bool TwoOrFive
		{
			get { return _twoOrFive; }
			set
			{
				_twoOrFive = value;
				OnPropertyChanged ();
				DesiredCount = _twoOrFive ? 5 : 2;
			}
		}

		public Issue2470MainViewModel ()
		{
			Entries = new ObservableCollection<EntryViewModel> ();
			TwoOrFive = false; // prime
		}

		void GenerateEntries ()
		{
			Entries.Clear ();
			for (var i = 0; i < DesiredCount; i++) {
				Entries.Add (new EntryViewModel { Name = "Entry " + i + " of " + DesiredCount });
			}
		}
	}

	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Github, 2470, "ObservableCollection changes do not update ListView", PlatformAffected.Android)]
	public partial class Issue2470 : TestTabbedPage
	{
		protected override void Init ()
		{
			var mainViewModel = new Issue2470MainViewModel ();
			BindingContext = mainViewModel;
		}

#if APP
		[Preserve (AllMembers = true)]
		public Issue2470 ()
		{
			InitializeComponent ();
		}
#endif

#if UITEST
		[Test]
		public void OnservableCollectionChangeListView ()
		{
			// Tab 1
			RunningApp.Tap (q => q.Marked ("Switch"));
			RunningApp.Screenshot ("Switch On");
			RunningApp.Tap (q => q.Marked ("Results"));

			// Tab 2
			RunningApp.WaitForElement (q => q.Marked ("Entry 0 of 5"));
			RunningApp.WaitForElement (q => q.Marked ("Entry 1 of 5"));
			RunningApp.WaitForElement (q => q.Marked ("Entry 2 of 5"));
			RunningApp.WaitForElement (q => q.Marked ("Entry 3 of 5"));
			RunningApp.WaitForElement (q => q.Marked ("Entry 4 of 5"));
			RunningApp.Screenshot ("Should be 5 elements");
			RunningApp.Tap (q => q.Marked ("Generate"));
			
			// Tab 1
			RunningApp.Tap (q => q.Marked ("Switch"));	
			RunningApp.Screenshot ("Switch Off");
			RunningApp.Tap (q => q.Marked ("Results"));

			// Tab 2
			RunningApp.WaitForElement (q => q.Marked ("Entry 0 of 2"));
			RunningApp.WaitForElement (q => q.Marked ("Entry 1 of 2"));
			RunningApp.Screenshot ("Should be 2 elements");
			
			// Tab 1
			RunningApp.Tap (q => q.Marked ("Generate"));
			RunningApp.Tap (q => q.Marked ("Switch"));
			RunningApp.Screenshot ("Switch On");
			RunningApp.Tap (q => q.Marked ("Results"));

			// Tab 2
			RunningApp.WaitForElement (q => q.Marked ("Entry 0 of 5"));
			RunningApp.WaitForElement (q => q.Marked ("Entry 1 of 5"));
			RunningApp.WaitForElement (q => q.Marked ("Entry 2 of 5"));
			RunningApp.WaitForElement (q => q.Marked ("Entry 3 of 5"));
			RunningApp.WaitForElement (q => q.Marked ("Entry 4 of 5"));
			RunningApp.Screenshot ("Should be 5 elements");
		}
#endif
	}
}