summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.iOS.UITests/Tests/ToolbarItemTests.cs
blob: 0231ca572c21f8764df0654b87386becd8184f62 (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
using NUnit.Framework;
using Xamarin.Forms.CustomAttributes;

using Xamarin.UITest.Queries;

namespace Xamarin.Forms.Core.UITests
{
	[TestFixture]
	[Category(UITestCategories.ToolbarItem)]
	internal class ToolbarItemTests : BaseTestFixture
	{
		string btn1Id = "tb1";
		string btn4Id = "tb4";
#if __ANDROID__
		static bool isSecondaryMenuOpen = false;
#endif
		static void ShouldShowMenu()
		{
#if __ANDROID__
			isSecondaryMenuOpen = true;
			//show secondary menu
			App.Tap(c => c.Class("android.support.v7.widget.ActionMenuPresenter$OverflowMenuButton"));
#endif
		}

		static void ShouldHideMenu()
		{
#if __ANDROID__
			if (isSecondaryMenuOpen)
			{
				isSecondaryMenuOpen = false;
				App.Back();
			}
#endif
		}

		protected override void NavigateToGallery()
		{
			App.NavigateToGallery(GalleryQueries.ToolbarItemGallery);
#if __IOS__
			btn1Id = "menuIcon";
			btn4Id = "tb4";
#endif
		}

		[Test]
		public void ToolbarButtonsClick()
		{
			ShouldHideMenu();
#if __MACOS__
			App.Tap(c => c.Button().Index(4));
#else
			App.Tap(c => c.Marked(btn1Id));
#endif
			var textLabel = App.Query((arg) => arg.Marked("label_id"))[0];
			Assert.False(textLabel.Text == "tb1");
			Assert.True(textLabel.Text == "Hello ContentPage");
		}

		[Test]
		public void ToolbarButtonsCommand()
		{
			ShouldShowMenu();
#if __ANDROID__
			//App.Query (c => c.Marked (btn4Id))[0];
#else
			App.Tap(c => c.Marked(btn4Id));
			var textLabel = App.Query((arg) => arg.Marked("label_id"))[0];
			Assert.False(textLabel.Text == "tb4");
#if __MACOS__
			App.Tap(c => c.Button().Index(6));
#else
			App.Tap(c => c.Marked("tb3"));
#endif
			App.Tap(c => c.Marked(btn4Id));
			textLabel = App.Query((arg) => arg.Marked("label_id"))[0];
			Assert.IsTrue(textLabel.Text == "tb4");
#if __MACOS__
			App.Tap(c => c.Button().Index(6));
#else
			App.Tap(c => c.Marked("tb3"));
#endif
#endif
		}

		[Test]
		public void ToolbarButtonsDisable()
		{
			ShouldHideMenu();
#if __MACOS__
			var result = App.Query(c => c.Button());
			var btn1 = result[4];
			var btn2 = App.Query(c => c.Marked(btn4Id))[0];
			Assert.False(btn2.Enabled, "Toolbar Item  should be disable");
#else
			var btn1 = App.Query(c => c.Marked(btn1Id))[0];
			ShouldShowMenu();
			//var btn2 = App.Query (c => c.Marked (btn4Id)) [0];		
			//TODO: how to check Enable for the textview
			//Assert.False (btn2.Enabled, "Toolbar Item  should be disable");
#endif
			Assert.False(btn1.Enabled, "Toolbar Item  should be disable");
		}

		[Test]
		public void ToolbarButtonsExist()
		{
			ShouldHideMenu();
#if __MACOS__
			var existsPrimary = App.Query(c => c.Button())[4];
			Assert.True(existsPrimary != null, "Toolbar Item 1 no name, not found");
#else
			var existsPrimary = App.Query(c => c.Marked(btn1Id)).Length;
			Assert.True(existsPrimary > 0, "Toolbar Item 1 no name, not found");
#endif
			var existsPrimary2 = App.Query(c => c.Marked("tb2")).Length;
			Assert.True(existsPrimary2 > 0, "Toolbar Item 2, not found");
			ShouldShowMenu();

#if __MACOS__
			var existsSecondary = App.Query(c => c.Button())[7];
			Assert.True(existsSecondary != null, "Toolbar Item 3 no name, not found");
#else
			var existsSecondary = App.Query(c => c.Marked("tb3")).Length;
			Assert.True(existsSecondary > 0, "Toolbar Item 1 no name, not found");
#endif
			var existsSecondary2 = App.Query(c => c.Marked(btn4Id)).Length;
			Assert.True(existsSecondary2 > 0, "Toolbar Item 4, not found");
		}

		[Test]
		public void ToolbarButtonsOrder()
		{
			ShouldHideMenu();
#if __MACOS__
			var btn1 = App.Query(c => c.Button())[4];
#else
			var btn1 = App.Query(c => c.Marked(btn1Id))[0];
#endif
			ShouldShowMenu();
			var btn2 = App.Query(c => c.Marked("tb4"))[0];
#if __IOS__
			Assert.True(btn1.Rect.CenterY < btn2.Rect.CenterY);
#elif __MACOS__
			Assert.True(btn1.Rect.CenterX < btn2.Rect.CenterX);
#endif
		}

	}
}