summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla38112.cs
blob: 194c07bfcbf2f3df459994c33a5fa2638751397a (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
using System;

using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 38112, "Switch becomes reenabled when previous ViewCell is removed from TableView", PlatformAffected.Android)]
	public class Bugzilla38112 : TestContentPage
	{
		bool _removed;
		protected override void Init ()
		{
			var layout = new StackLayout ();
			var button = new Button { Text = "Click" };
			var tablesection = new TableSection { Title = "Switches" };
			var tableview = new TableView { Intent = TableIntent.Form, Root = new TableRoot { tablesection } };
			var viewcell1 = new ViewCell {
				View = new StackLayout {
					HorizontalOptions = LayoutOptions.FillAndExpand,
					Orientation = StackOrientation.Horizontal,
					Children = {
						new Label { Text = "Switch 1", HorizontalOptions = LayoutOptions.StartAndExpand },
						new Switch { AutomationId = "switch1", HorizontalOptions = LayoutOptions.End, IsToggled = true }
					}
				}
			};
			var viewcell2 = new ViewCell {
				View = new StackLayout {
					HorizontalOptions = LayoutOptions.FillAndExpand,
					Orientation = StackOrientation.Horizontal,
					Children = {
						new Label { Text = "Switch 2", HorizontalOptions = LayoutOptions.StartAndExpand },
						new Switch { AutomationId = "switch2", HorizontalOptions = LayoutOptions.End, IsToggled = true }
					}
				}
			};
			Label label = new Label { Text = "Switch 3", HorizontalOptions = LayoutOptions.StartAndExpand };
			Switch switchie = new Switch { AutomationId = "switch3", HorizontalOptions = LayoutOptions.End, IsToggled = true, IsEnabled = false };
			switchie.Toggled += (sender, e) => {
				label.Text = "FAIL";
			};
			var viewcell3 = new ViewCell {
				View = new StackLayout {
					HorizontalOptions = LayoutOptions.FillAndExpand,
					Orientation = StackOrientation.Horizontal,
					Children = {
						label,
						switchie,
					}
				}
			};

			tablesection.Add (viewcell1);
			tablesection.Add (viewcell2);
			tablesection.Add (viewcell3);

			button.Clicked += (sender, e) => {
				if (_removed)
					tablesection.Insert (1, viewcell2);
				else
					tablesection.Remove (viewcell2);

				_removed = !_removed;
			};

			layout.Children.Add (button);
			layout.Children.Add (tableview);

			Content = layout;
		}

#if UITEST
		[Test]
		public void Bugzilla38112_SwitchIsStillOnScreen ()
		{
			RunningApp.WaitForElement (q => q.Marked ("Click"));
			RunningApp.Tap (q => q.Marked ("Click"));
			RunningApp.WaitForElement (q => q.Marked ("switch3"));
		}

		[Test]
		public void Bugzilla38112_SwitchIsStillDisabled ()
		{
			RunningApp.WaitForElement (q => q.Marked ("Click"));
			RunningApp.Tap (q => q.Marked ("Click"));
			RunningApp.WaitForElement (q => q.Marked ("switch3"));
			RunningApp.Tap (q => q.Marked ("switch3"));
			RunningApp.WaitForNoElement (q => q.Marked ("FAIL"));
		}
#endif
	}
}