diff options
author | kingces95 <kingces95@users.noreply.github.com> | 2016-04-07 14:55:19 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-04-07 22:55:19 +0100 |
commit | 870f9c98ffccce86d80c6ff7a05de7238fc1b0e8 (patch) | |
tree | 5d754265da426d5afef51ce2001257ae07acfa56 /Xamarin.Forms.Controls.Issues | |
parent | e9eaacff4a1ee16729ae434d44fe0f9846712ef3 (diff) | |
download | xamarin-forms-870f9c98ffccce86d80c6ff7a05de7238fc1b0e8.tar.gz xamarin-forms-870f9c98ffccce86d80c6ff7a05de7238fc1b0e8.tar.bz2 xamarin-forms-870f9c98ffccce86d80c6ff7a05de7238fc1b0e8.zip |
[A, iOS] CarouselView Bug Fixes (#49)
* CarouselView programatic scrolling fixes; swipe back fixes
* Make iOS CarouselView events consistant with Android
* bump swipe distance; add Screenshot on Exception
* Formatting. No logical change.
* Comment out [Test] on UITest and fix TestCloud failures later.
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
3 files changed, 287 insertions, 4 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselViewGallery.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselViewGallery.cs new file mode 100644 index 00000000..9c7d9cd5 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselViewGallery.cs @@ -0,0 +1,280 @@ +using System; + +using Xamarin.Forms.CustomAttributes; +using System.Threading; +using System.Linq; +using System.Collections.Generic; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls +{ + [Preserve (AllMembers = true)] + [Issue (IssueTracker.Github, 900000, "CarouselView General Tests")] + public class CarouselViewGalleryTests + { +#if UITEST + + public interface IUIProxy + { + void Load(IApp app); + } + public interface IGalleryPage : IUIProxy + { + string Name { get; } + } + + public class Gallery + { + static class Id + { + internal const string SearchBar = nameof(SearchBar); + internal const string GoToTestButton = nameof(GoToTestButton); + } + + public static Gallery Launch() + { + var app = AppSetup.Setup(); + app.WaitForElement(Id.SearchBar); + return new Gallery(app); + } + + IApp _app; + + Gallery(IApp app) + { + _app = app; + } + + public TGalleryPage NaviateToGallery<TGalleryPage>() where TGalleryPage : IGalleryPage, new() + { + var galleryPage = new TGalleryPage(); + _app.EnterText(Id.SearchBar, galleryPage.Name); + _app.Tap(Id.GoToTestButton); + galleryPage.Load(_app); + return galleryPage; + } + public void Screenshot(string message) => _app.Screenshot(message); + } + + public class CarouselViewGallery : IGalleryPage + { + internal const int InitialItems = 4; + internal const int InitialItemId = 1; + internal const string OnItemSelectedAbbr = "i"; + internal const string OnPositionSelectedAbbr = "p"; + internal const int EventQueueDepth = 7; + + private const double SwipePercentage = 0.50; + private const int SwipeSpeed = 2000; + + static class Id + { + internal const string Name = "CarouselView Gallery"; + internal static string ItemId = nameof(ItemId); + internal static string EventLog = nameof(EventLog); + internal static string SelectedItem = nameof(SelectedItem); + internal static string Position = nameof(Position); + internal static string SelectedPosition = nameof(SelectedPosition); + internal static string Next = nameof(Next); + internal static string Previous = nameof(Previous); + internal static string First = nameof(First); + internal static string Last = nameof(Last); + } + enum Event + { + OnItemSelected, + OnPositionSelected + } + + IApp _app; + List<int> _itemIds; + int _currentPosition; + int _currentItem; + Queue<string> _expectedEvents; + int _eventId; + + public CarouselViewGallery() { + _itemIds = Enumerable.Range(0, InitialItems).ToList(); + _currentPosition = InitialItemId; + _currentItem = _itemIds[_currentPosition]; + _expectedEvents = new Queue<string>(); + _eventId = 0; + } + + void IUIProxy.Load(IApp app) + { + _app = app; + WaitForValue(Id.ItemId, _currentItem); + WaitForValue(Id.Position, _currentPosition); + } + + private void WaitForValue(string marked, object value) + { + var query = $"* marked:'{marked}' text:'{value}'"; + _app.WaitForElement(o => o.Raw(query)); + + } + private void WaitForPosition(int expectedPosition) + { + var expectedItem = _itemIds[expectedPosition]; + + // expect no movement + if (_currentItem == expectedItem) + Thread.Sleep(TimeSpan.FromMilliseconds(500)); + + // wait for for expected item and corresponding event + WaitForValue(Id.ItemId, expectedItem); + WaitForValue(Id.SelectedItem, expectedItem); + _currentItem = expectedItem; + + // wait for for expected position and corresponding event + WaitForValue(Id.Position, expectedPosition); + WaitForValue(Id.SelectedPosition, expectedPosition); + _currentPosition = expectedPosition; + + // check expected events + var expectedEvents = string.Join(", ", _expectedEvents.ToArray().Reverse()); + WaitForValue(Id.EventLog, expectedEvents); + } + private void ExpectMovementEvents(int expectedPosition) + { + if (expectedPosition == _currentPosition) + return; + + ExpectEvent(Event.OnPositionSelected); + ExpectEvent(Event.OnItemSelected); + } + private void ExpectEvent(Event e) + { + if (e == Event.OnItemSelected) + _expectedEvents.Enqueue($"{OnItemSelectedAbbr}/{_eventId++}"); + + if (e == Event.OnPositionSelected) + _expectedEvents.Enqueue($"{OnPositionSelectedAbbr}/{_eventId++}"); + + if (_expectedEvents.Count == EventQueueDepth) + _expectedEvents.Dequeue(); + } + private void Tap(string buttonText, int expectedPosition) + { + // tap + _app.Tap(buttonText); + + // anticipate events + ExpectMovementEvents(expectedPosition); + + // wait + WaitForPosition(expectedPosition); + } + private void Swipe(bool next, int expectedPosition) + { + // swipe + if (next) + _app.SwipeRightToLeft(swipePercentage: SwipePercentage/*, swipeSpeed: SwipeSpeed*/); + else + _app.SwipeLeftToRight(swipePercentage: SwipePercentage/*, swipeSpeed: SwipeSpeed*/); + + // handle swipe past first + if (expectedPosition == -1 && _currentPosition == 0) + expectedPosition = 0; + + // handle swipe past last + else if (expectedPosition == Count && _currentPosition == Count -1) + expectedPosition = Count -1; + + // anticipate events + ExpectMovementEvents(expectedPosition); + + // wait + WaitForPosition(expectedPosition); + } + private void Move(int steps, bool swipe) + { + Action next = swipe ? (Action)SwipeNext : StepNext; + Action previous = swipe ? (Action)SwipePrevious : StepPrevious; + + var action = next; + if (steps < 0) + { + action = previous; + steps = -steps; + } + + for (int i = 0; i < steps; i++) + action(); + } + private void MoveToPosition(int position, bool swipe) + { + Assert.True(position >= 0 && position < Count); + Move(position - _currentPosition, swipe); + } + private void MoveToItem(int targetPage, bool swipe) + { + MoveToPosition(_itemIds.IndexOf(targetPage), swipe); + } + public void MoveToFirst(bool swipe) => MoveToPosition(0, swipe); + public void MoveToLast(bool swipe) => MoveToPosition(Count - 1, swipe); + + public int ItemId => int.Parse(_app.Query(Id.ItemId)[0].Text); + + public string Name => Id.Name; + public int Count => _itemIds.Count; + + public void First() => Tap(Id.First, 0); + public void Last() => Tap(Id.Last, _itemIds.Count - 1); + + public void StepNext() => Tap(Id.Next, _currentPosition + 1); + public void StepPrevious() => Tap(Id.Previous, _currentPosition - 1); + public void Step(int steps) => Move(steps, swipe: false); + public void StepToPosition(int position) => MoveToPosition(position, swipe: false); + public void StepToItem(int item) => MoveToItem(item, swipe: false); + public void StepToFirst() => MoveToFirst(swipe: false); + public void StepToLast() => MoveToLast(swipe: false); + + public void SwipeNext() => Swipe(next: true, expectedPosition: _currentPosition + 1); + public void SwipePrevious() => Swipe(next: false, expectedPosition: _currentPosition - 1); + public void Swipe(int swipes) => Move(swipes, swipe: true); + public void SwipeToPosition(int position) => MoveToPosition(position, swipe: true); + public void SwipeToItem(int item) => MoveToItem(item, swipe: true); + public void SwipeToFirst() => MoveToFirst(swipe: true); + public void SwipeToLast() => MoveToLast(swipe: true); + } + + //[Test] + public void SwipeStepJump() + { + var gallery = Gallery.Launch(); + + try { + var carousel = gallery.NaviateToGallery<CarouselViewGallery>(); + + // start at something other than 0 + Assert.AreNotEqual(0, CarouselViewGallery.InitialItemId); + Assert.AreEqual(CarouselViewGallery.InitialItemId, carousel.ItemId); + + // programatic jump to first/last + carousel.Last(); + carousel.First(); + + // programatic step to page + carousel.StepToLast(); + carousel.StepToFirst(); + + // swiping + carousel.SwipeToLast(); + carousel.SwipeNext(); // test swipe past end + carousel.SwipeToFirst(); + carousel.SwipePrevious(); // test swipe past start + + } catch (Exception e) { + gallery.Screenshot(e.ToString()); + throw e; + } + } +#endif + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs index 15e658ce..e63e8d4a 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs @@ -64,16 +64,18 @@ namespace Xamarin.Forms.Controls app.Tap (q => q.Raw ("* marked:'SearchButton'")); } - public static IApp Setup (Type pageType) + public static IApp Setup (Type pageType = null) { IApp runningApp = null; try { runningApp = InitializeApp (); - } catch { - Assert.Inconclusive ("App did not start for some reason"); + } catch (Exception e) { + Assert.Inconclusive ($"App did not start for some reason: {e}"); } - NavigateToIssue (pageType, runningApp); + if (pageType != null) + NavigateToIssue (pageType, runningApp); + return runningApp; } } diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 3d745c38..e13847bf 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -142,6 +142,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39829.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39458.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39853.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)CarouselViewGallery.cs" /> <Compile Include="$(MSBuildThisFileDirectory)_Template.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1075.cs" /> |