summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.iOS.UITests/Tests/ButtonUITests.cs
blob: 89994a98e8e6c793738f934c0dc800936bfe8b16 (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Threading;
using System.Reflection;

using NUnit.Framework;

using Xamarin.Forms.CustomAttributes;
using Xamarin.UITest.Android;
using Xamarin.UITest.Queries;
using Xamarin.UITest.iOS;

namespace Xamarin.Forms.Core.UITests
{
	[TestFixture]
	[Category(UITestCategories.Button)]
	internal class ButtonUITests : _ViewUITests
	{
		public ButtonUITests ()
		{
			PlatformViewType = Views.Button;
		}

		protected override void NavigateToGallery ()
		{
			App.NavigateToGallery (GalleryQueries.ButtonGallery);
		}

		// View Tests
		[UiTestExempt (ExemptReason.CannotTest, "Invalid interaction")]
		public override void _Focus () {}

		[UiTestExempt (ExemptReason.CannotTest, "Invalid interaction")]
		public override void _GestureRecognizers () {}

		[UiTestExempt (ExemptReason.CannotTest, "Invalid interaction")]
		public override void _IsFocused () {}

		[UiTestExempt (ExemptReason.CannotTest, "Invalid interaction")]
		public override void _UnFocus () {}

		// Button Tests
		[Test]
		[UiTest (typeof(Button),"BorderColor")]
		[UiTestBroken (BrokenReason.CalabashAndroidUnsupported, "Figure out how to get Android Drawables")]
		[UiTestBroken (BrokenReason.CalabashiOSUnsupported, "iOS nil result")]
		public void BorderColor ()
		{
			//TODO iOS
			var remote = new ViewContainerRemote (App, Test.Button.BorderColor, PlatformViewType);
			remote.GoTo ();
			
		}

		[Test]
		[UiTest (typeof (Button), "BorderRadius")]
		[UiTestBroken (BrokenReason.CalabashAndroidUnsupported, "Figure out how to get Android Drawables")]
		public void BorderRadius ()
		{
			var remote = new ViewContainerRemote (App, Test.Button.BorderRadius, PlatformViewType);
			remote.GoTo ();

#if __IOS__
			var borderRadius = remote.GetProperty<float> (Button.BorderRadiusProperty);
			Assert.AreEqual (20.0f, borderRadius);
#endif

		}

		[Test]
		[UiTest (typeof (Button), "BorderWidth")]
		[UiTestBroken (BrokenReason.CalabashAndroidUnsupported, "Figure out how to get Android Drawables")]
		public void BorderWidth ()
		{
			var remote = new ViewContainerRemote (App, Test.Button.BorderWidth, PlatformViewType);
			remote.GoTo ();

#if __IOS__
			var borderWidth = remote.GetProperty<float> (Button.BorderWidthProperty);
				Assert.AreEqual (15.0f, borderWidth);
#endif

		}

		[Test]
		[UiTest (typeof (Button), "Clicked")]
		public void Clicked ()
		{
			var remote = new EventViewContainerRemote (App, Test.Button.Clicked, PlatformViewType);
			remote.GoTo ();

			var textBeforeClick = remote.GetEventLabel ().Text;
			Assert.AreEqual ("Event: Clicked (none)", textBeforeClick);
			
			// Click Button
			remote.TapView ();

			var textAfterClick = remote.GetEventLabel ().Text;
			Assert.AreEqual ("Event: Clicked (fired 1)", textAfterClick);
		}
		
		[Test]
		[UiTest (typeof (Button), "Command")]
		public void Command ()
		{
			var remote = new ViewContainerRemote (App, Test.Button.Command, PlatformViewType);
			remote.GoTo ();

			remote.TapView ();

			App.WaitForElement (q => q.Marked ("Hello Command"));
			App.Tap (q => q.Marked ("Destroy"));
		}

		[Test]
		[UiTest (typeof (Button), "Font")]
		public void Font ()
		{
			//TODO iOS
			var remote = new ViewContainerRemote (App, Test.Button.Font, PlatformViewType);
			remote.GoTo ();

#if __ANDROID__
			var isBold = remote.GetProperty<bool> (Button.FontProperty);
			Assert.True (isBold);
#elif __MACOS__
			Assert.Inconclusive("needs testing");
#else
			var font = remote.GetProperty<Font> (Button.FontProperty);
			Assert.True (font.FontAttributes.HasFlag (FontAttributes.Bold));
#endif
		}

		[Test]
		[UiTest (typeof (Button), "Image")]
		[UiTestExempt (ExemptReason.TimeConsuming, "Need way to check Android resources")]
		public void Image ()
		{
			//TODO iOS
			var remote = new ViewContainerRemote (App, Test.Button.Image, PlatformViewType);
			remote.GoTo ();
		}

		[Test]
		[UiTest (typeof (Button), "Text")]
		public void Text ()
		{
			var remote = new ViewContainerRemote (App, Test.Button.Text, PlatformViewType);
			remote.GoTo ();

			var buttonText = remote.GetProperty<string> (Button.TextProperty);
			Assert.AreEqual ("Text", buttonText);
		}

		//TODO iOS

#if __ANDROID__
		[Test]
		[UiTest (typeof (Button), "TextColor")]
		public void TextColor ()
		{
			var remote = new ViewContainerRemote (App, Test.Button.TextColor, PlatformViewType);
			remote.GoTo ();

			var buttonTextColor = remote.GetProperty<Color> (Button.TextColorProperty);
			Assert.AreEqual (Color.Pink, buttonTextColor);
		}
#endif

		protected override void FixtureTeardown ()
		{
			App.NavigateBack ();
			base.FixtureTeardown ();
		}
	}
}