summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselAsync.cs
blob: 46065a3445116fe1e3df554c0835ecfe96bfe79f (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
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.None, 0, "Carousel Async Add Page Issue", PlatformAffected.All, NavigationBehavior.PushModalAsync)]
	public class CarouselAsync : TestCarouselPage
	{
		protected override void Init ()
		{
			Children.Add (new ContentPage {
				BackgroundColor = Color.Red,
				Content = new Label {
					Text = "Page One"
				}
			});
			Children.Add (new ContentPage {
				BackgroundColor = Color.Green,
				Content = new Label {
					Text = "Page Two"
				}
			});
			Update (this);
		}

		static void Update (CarouselPage page)
		{
			Device.StartTimer (TimeSpan.FromSeconds (1), () => {
				page.Children.Remove (page.Children.Skip (1).First () as ContentPage);
				Device.StartTimer (TimeSpan.FromSeconds (1), () => {
					page.Children.Add (new ContentPage { 
						BackgroundColor = Color.Blue,
						Content = new Label {
							Text = "Page Two - Added"
						}
					});
					page.Children.Add (new ContentPage { 
						BackgroundColor = Color.Gray,
						Content = new Label {
							Text = "Page Three - Added"
						}
					});
					return false;
				});
				return false;
			});
		}

#if UITEST
		[Test]
		[Description ("All elements renderered")]
		public void CarouselAsycTestsAllElementsPresent ()
		{
			RunningApp.WaitForElement (q => q.Marked ("Page One"));
			RunningApp.Screenshot ("All elements present");
		}

		[Test]
		[Description ("Async Pages inserted into a CarouselPage")]
		public void CarouselAsycTestsAllPagesExistAfterAsyncAdding ()
		{
			RunningApp.WaitForElement (q => q.Marked ("Page One"));

			var window = RunningApp.Query (q => q.Raw ("*").Index (0));
			var width = window [0].Rect.Width;
			var height = window [0].Rect.Height;

			System.Threading.Thread.Sleep (3000);

			// TODO Implement swipe left and swipe right
			//App.DragFromTo (width - 10.0f, height / 2.0f, 10.0f, height / 2.0f);
			//App.WaitForElement (q => q.Marked ("Page Two - Added"));
			//App.Screenshot ("At Page 2");

			//Thread.Sleep (3000);

			//App.DragFromTo (width - 10.0f, height / 2.0f, 10.0f, height / 2.0f);
			//App.WaitForElement (q => q.Marked ("Page Three - Added"));
			//App.Screenshot ("At Page 3");
		}

/*******************************************************/
/**************** Landscape tests **********************/
/*******************************************************/

		[Test]
		[Description ("All elements renderered - landscape")]
		public void CarouselAsycTestsAllElementsPresentLandscape ()
		{
			RunningApp.SetOrientationLandscape ();
			CarouselAsycTestsAllElementsPresent ();
			RunningApp.SetOrientationPortrait ();
		}

		[Test]
		[Description ("Async Pages inserted into a CarouselPage - landscape")]
		public void CarouselAsycTestsAllPagesExistAfterAsyncAddingLandscape ()
		{
			RunningApp.SetOrientationLandscape ();
			CarouselAsycTestsAllPagesExistAfterAsyncAdding ();
			RunningApp.SetOrientationPortrait ();
		}
#endif
	}
}