summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41153.cs
blob: 76174183e3ff20734fb1a64871bba1eb6b191e9d (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
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;

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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 41153, "jobject must not be IntPtr.Zero with TabbedPage and ToolbarItems")]
	public class Bugzilla41153 : TestTabbedPage
	{
		MyViewModel _Vm = new MyViewModel();
		const string Tab1 = "Tab 1";
		const string Tab1Content = "On Tab 1";
		const string Tab2 = "Tab 2";
		const string Tab3 = "Tab 3";
		const string Tab3Content = "On Tab 3";
		const string ToolbarItemText = "Toolbar Item";
		const string Success = "Success";

		[Preserve(AllMembers = true)]
		class MyViewModel : INotifyPropertyChanged
		{
			string _toolBarItemText;
			public string ToolbarItemText
			{
				get
				{
					return _toolBarItemText;
				}
				set
				{
					_toolBarItemText = value;
					OnPropertyChanged();
				}
			}

			ICommand _toolBarItemCommand;
			public ICommand ToolbarItemCommand
			{
				get
				{
					if (_toolBarItemCommand == null)
					{
						_toolBarItemCommand = new Command(() =>
						{
							ToolbarItemText = Success;
						});
					}

					return _toolBarItemCommand;
				}
			}

			public event PropertyChangedEventHandler PropertyChanged;

			protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
			{
				PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
			}
		}

		protected override void Init()
		{
			var page1 = new ContentPage { Content = new Label { Text = Tab1Content }, BindingContext = _Vm };
			var toolBarItem = new ToolbarItem();
			toolBarItem.SetBinding(ToolbarItem.CommandProperty, nameof(MyViewModel.ToolbarItemCommand));
			toolBarItem.SetBinding(ToolbarItem.TextProperty, nameof(MyViewModel.ToolbarItemText));
			page1.ToolbarItems.Add(toolBarItem);
			var page2 = new ContentPage();
			var page3 = new ContentPage { Content = new Label { Text = Tab3Content } };
			Children.Add(new NavigationPage(page1) { Title = Tab1 });
			Children.Add(new NavigationPage(page2) { Title = Tab2 });
			Children.Add(new NavigationPage(page3) { Title = Tab3 });
			_Vm.ToolbarItemText = ToolbarItemText;
		}

#if UITEST
		[Test]
		public void Bugzilla41153Test()
		{
			RunningApp.WaitForElement(q => q.Marked(Tab1Content));
			RunningApp.Tap(q => q.Marked(Tab2));
			RunningApp.Tap(q => q.Marked(Tab3));
			RunningApp.WaitForElement(q => q.Marked(Tab3Content));
			RunningApp.Tap(q => q.Marked(Tab1));
			RunningApp.WaitForElement(q => q.Marked(Tab1Content));
			RunningApp.Tap(q => q.Marked(ToolbarItemText));
			RunningApp.WaitForElement(q => q.Marked(Success));
		}
#endif
	}
}