diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-04-26 15:35:52 -0400 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-04-26 15:35:52 -0400 |
commit | 409e10528495238a680c1bf3867a71f758b0d452 (patch) | |
tree | 0cb19f682b0b192ebad3dc0c77cfe32974abe09c /Xamarin.Forms.Controls.Issues | |
parent | 9ae4ea3c82444561353eb77bf746f96cdbfb4583 (diff) | |
download | xamarin-forms-409e10528495238a680c1bf3867a71f758b0d452.tar.gz xamarin-forms-409e10528495238a680c1bf3867a71f758b0d452.tar.bz2 xamarin-forms-409e10528495238a680c1bf3867a71f758b0d452.zip |
Carousel clean (#135)
CarouselView moving to preview repo
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
3 files changed, 0 insertions, 483 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39499.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39499.cs deleted file mode 100644 index 0d63868a..00000000 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39499.cs +++ /dev/null @@ -1,184 +0,0 @@ -using System; - -using Xamarin.Forms.CustomAttributes; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Collections.ObjectModel; -using Xamarin.Forms.Internals; -#if UITEST -using Xamarin.UITest; -using NUnit.Framework; -#endif - -namespace Xamarin.Forms.Controls -{ - [Preserve(AllMembers = true)] - [Issue(IssueTracker.Bugzilla, 39499, "CarouselViewTest")] - public sealed class CarouselViewContentPage : TestContentPage // or TestMasterDetailPage, etc ... - { - [Preserve(AllMembers = true)] - public sealed class Item - { - static int s_id = 0; - - int id; - - internal Item() - { - id = s_id++; - } - - public int Id => id; - - public string Text => $"Item {Id}"; - } - - [Preserve(AllMembers = true)] - public sealed class ItemView : ContentView - { - public ItemView() - { - var idLabel = new Label() { StyleId = "id", TextColor = Color.White }; - idLabel.SetBinding(Label.TextProperty, nameof(Item.Text)); - - var stackLayout = new StackLayout - { - Children = { - new Label { Text = "Target" }, - new Label { Text = "Stack" } - }, - BackgroundColor = Color.Red - }; - - var button = CreateButton("Hide Target Stack", () => - { - stackLayout.IsVisible = false; - }); - - var buttonImage = CreateButton("AddImage", () => - { - stackLayout.IsVisible = true; - stackLayout.Children.Add(new Image { Source = "menuIcon.png" }); - }); - Content = new StackLayout - { - Children = { - idLabel, - button, - buttonImage, - stackLayout, - } - }; - } - - Button CreateButton(string text, Action clicked) - { - var button = new Button(); - button.Text = text; - button.Clicked += (s, e) => - { - clicked(); - }; - return button; - } - } - - static readonly IList<Item> Items = new ObservableCollection<Item>() { - new Item(), - new Item(), - }; - - Button CreateButton(string text, Action onClicked = null) - { - var button = new Button - { - Text = text - }; - - if (onClicked != null) - button.Clicked += (s, e) => onClicked(); - - return button; - } - - protected override void Init() - { - BackgroundColor = Color.Blue; - - var carouselView = new CarouselView - { - BackgroundColor = Color.Purple, - ItemsSource = Items, - ItemTemplate = new DataTemplate(typeof(ItemView)), - Position = 0 - }; - - var moveBar = new StackLayout - { - Orientation = StackOrientation.Horizontal, - HorizontalOptions = LayoutOptions.FillAndExpand, - Children = - { - CreateButton("+", () => Items.Add(new Item())), - CreateButton("<<", () => carouselView.Position = 0), - CreateButton("<", () => - { - try - { - carouselView.Position--; - } - catch - { - } - }), - CreateButton(">", () => - { - try - { - carouselView.Position++; - } - catch - { - } - }), - CreateButton(">>", () => carouselView.Position = Items.Count - 1) - } - }; - - Content = new StackLayout - { - Children = - { - carouselView, - moveBar - } - }; - } - -#if UITEST - //[Test] - public void CarouselViewTest() - { - var app = RunningApp; - app.WaitForElement(q => q.Marked("Item 0")); - app.SwipeRightToLeft(); - app.WaitForElement(q => q.Marked("Item 1")); - app.Tap(c => c.Marked("<")); - app.WaitForElement(q => q.Marked("Item 0")); - } - - [Test] - public void CarouselViewTestAddItem() - { - var app = RunningApp; - app.WaitForElement(q => q.Marked("Hide Target Stack")); - app.Tap(c => c.Marked("+")); - app.SwipeRightToLeft(); - app.SwipeRightToLeft(); - app.WaitForElement(q => q.Marked("Item 2")); - app.Screenshot("I see the Item 2"); - } -#endif - } -} 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 deleted file mode 100644 index 60817b2b..00000000 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselViewGallery.cs +++ /dev/null @@ -1,297 +0,0 @@ -using System; - -using Xamarin.Forms.CustomAttributes; -using System.Threading; -using System.Linq; -using System.Collections.Generic; -using Xamarin.Forms.Internals; - -#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 IApp App => _app; - } - - 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); - - gallery.App.SetOrientationPortrait(); - - for (var i = 0; i < 2; i++) - { - // 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 - - gallery.App.SetOrientationLandscape(); - } - - gallery.Screenshot("End"); - } - catch (Exception e) - { - gallery.Screenshot("End"); - throw e; - } - } -#endif - } -} 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 913a3e69..7a1892b0 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,13 +142,11 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla36788.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla38978.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla38112.cs" /> - <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39499.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39668.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla21177.cs" /> <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" /> |