From 5828832821741fcf32ffb33885b115a138b763bd Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Mon, 18 Feb 2019 11:18:50 +0000 Subject: [PATCH] Collectionview uitest (#5231) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * [UITests] Add basic CollectionView tests * [UITests] Enable uitests ObservableCollectionGallery * [UITests] Update itemssource * Update Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/CollectionViewGallery.cs Co-Authored-By: rmarinho --- .../CollectionViewGalleries/CollectionModifier.cs | 4 +- .../CollectionViewGallery.cs | 3 +- .../ItemsSourceGenerator.cs | 10 +- .../ObservableCodeCollectionViewGallery.cs | 2 +- .../ObservableCollectionGallery.cs | 6 +- .../ObservableMultiItemCollectionViewGallery.cs | 2 +- .../TemplateCodeCollectionViewGallery.cs | 3 +- .../TemplateCodeCollectionViewGridGallery.cs | 2 +- .../TextCodeCollectionViewGallery.cs | 3 +- .../TextCodeCollectionViewGridGallery.cs | 4 +- .../GalleryPages/GalleryBuilder.cs | 3 +- Xamarin.Forms.Core.UITests.Shared/Queries.cs | 1 + .../Tests/CollectionViewUITests.cs | 283 +++++++++++++++++++++ .../Xamarin.Forms.Core.UITests.projitems | 1 + 14 files changed, 308 insertions(+), 19 deletions(-) create mode 100644 Xamarin.Forms.Core.UITests.Shared/Tests/CollectionViewUITests.cs diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/CollectionModifier.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/CollectionModifier.cs index 9b212e1..fa81807 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/CollectionModifier.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/CollectionModifier.cs @@ -17,10 +17,10 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries HorizontalOptions = LayoutOptions.Fill }; - var button = new Button { Text = buttonText }; + var button = new Button { Text = buttonText, AutomationId = $"btn{buttonText}" }; var label = new Label { Text = LabelText, VerticalTextAlignment = TextAlignment.Center }; - Entry = new Entry { Keyboard = Keyboard.Numeric, Text = InitialEntryText, WidthRequest = 100 }; + Entry = new Entry { Keyboard = Keyboard.Numeric, Text = InitialEntryText, WidthRequest = 100, AutomationId = $"entry{buttonText}" }; layout.Children.Add(label); layout.Children.Add(Entry); diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/CollectionViewGallery.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/CollectionViewGallery.cs index 66b51e4..10ff236 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/CollectionViewGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/CollectionViewGallery.cs @@ -10,7 +10,8 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries Content = new StackLayout { Children = - { + { + new Button { Text ="Enable CollectionView", AutomationId = "EnableCollectionView", Command = new Command(() => Device.SetFlags(new[] { ExperimentalFlags.CollectionViewExperimental })) }, GalleryBuilder.NavButton("Default Text Galleries", () => new DefaultTextGallery(), Navigation), GalleryBuilder.NavButton("DataTemplate Galleries", () => new DataTemplateGallery(), Navigation), GalleryBuilder.NavButton("Observable Collection Galleries", () => new ObservableCollectionGallery(), Navigation), diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ItemsSourceGenerator.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ItemsSourceGenerator.cs index a79e8c6..9a5cec9 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ItemsSourceGenerator.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ItemsSourceGenerator.cs @@ -23,7 +23,7 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries public override string ToString() { - return $"{Date:D}"; + return $"Item: {Index}"; } } @@ -51,9 +51,9 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries HorizontalOptions = LayoutOptions.Fill }; - var button = new Button { Text = "Update" }; + var button = new Button { Text = "Update", AutomationId = "btnUpdate" }; var label = new Label { Text = "Item count:", VerticalTextAlignment = TextAlignment.Center }; - _entry = new Entry { Keyboard = Keyboard.Numeric, Text = initialItems.ToString(), WidthRequest = 200 }; + _entry = new Entry { Keyboard = Keyboard.Numeric, Text = initialItems.ToString(), WidthRequest = 200, AutomationId = "entryUpdate" }; layout.Children.Add(label); layout.Children.Add(_entry); @@ -100,7 +100,7 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries for (int n = 0; n < count; n++) { items.Add(new CollectionViewGalleryTestItem(DateTime.Now.AddDays(n), - $"{_images[n % _images.Length]}, {n}", _images[n % _images.Length], n)); + $"Item: {n}", _images[n % _images.Length], n)); } _cv.ItemsSource = items; @@ -116,7 +116,7 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries for (int n = 0; n < count; n++) { items.Add(new CollectionViewGalleryTestItem(DateTime.Now.AddDays(n), - $"{_images[n % _images.Length]}, {n}", _images[n % _images.Length], n)); + $"Item: {n}", _images[n % _images.Length], n)); } _cv.ItemsSource = new ObservableCollection(items); diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableCodeCollectionViewGallery.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableCodeCollectionViewGallery.cs index 15324f6..a3e2530 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableCodeCollectionViewGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableCodeCollectionViewGallery.cs @@ -24,7 +24,7 @@ var itemTemplate = ExampleTemplates.PhotoTemplate(); - var collectionView = new CollectionView {ItemsLayout = itemsLayout, ItemTemplate = itemTemplate}; + var collectionView = new CollectionView {ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView, initialItems, ItemsSourceType.ObservableCollection); diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableCollectionGallery.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableCollectionGallery.cs index 5595142..fd45f4f 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableCollectionGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableCollectionGallery.cs @@ -20,13 +20,13 @@ GalleryBuilder.NavButton("Filter Items", () => new FilterCollectionView(), Navigation), - GalleryBuilder.NavButton("Add/Remove Items (list)", () => + GalleryBuilder.NavButton("Add/Remove Items (List)", () => new ObservableCodeCollectionViewGallery(grid: false), Navigation), - GalleryBuilder.NavButton("Add/Remove Items (grid)", () => + GalleryBuilder.NavButton("Add/Remove Items (Grid)", () => new ObservableCodeCollectionViewGallery(), Navigation), - GalleryBuilder.NavButton("Add/Remove Items (grid, initially empty)", () => + GalleryBuilder.NavButton("Add/Remove Items (Grid, initially empty)", () => new ObservableCodeCollectionViewGallery(initialItems: 0), Navigation), GalleryBuilder.NavButton("Multi-item add/remove, no index", diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableMultiItemCollectionViewGallery.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableMultiItemCollectionViewGallery.cs index 2b60a31..7562ecd 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableMultiItemCollectionViewGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/ObservableMultiItemCollectionViewGallery.cs @@ -24,7 +24,7 @@ var itemTemplate = ExampleTemplates.PhotoTemplate(); - var collectionView = new CollectionView {ItemsLayout = itemsLayout, ItemTemplate = itemTemplate}; + var collectionView = new CollectionView {ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView, initialItems, ItemsSourceType.MultiTestObservableCollection); diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TemplateCodeCollectionViewGallery.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TemplateCodeCollectionViewGallery.cs index cb01f08..44f0f44 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TemplateCodeCollectionViewGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TemplateCodeCollectionViewGallery.cs @@ -18,7 +18,8 @@ var collectionView = new CollectionView { ItemsLayout = itemsLayout, - ItemTemplate = itemTemplate + ItemTemplate = itemTemplate, + AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView, initialItems: 20); diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TemplateCodeCollectionViewGridGallery.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TemplateCodeCollectionViewGridGallery.cs index 9367cd3..b0f7a93 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TemplateCodeCollectionViewGridGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TemplateCodeCollectionViewGridGallery.cs @@ -18,7 +18,7 @@ var itemTemplate = ExampleTemplates.PhotoTemplate(); - var collectionView = new CollectionView {ItemsLayout = itemsLayout, ItemTemplate = itemTemplate}; + var collectionView = new CollectionView {ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView, 100); var spanSetter = new SpanSetter(collectionView); diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TextCodeCollectionViewGallery.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TextCodeCollectionViewGallery.cs index 969043f..ceea620 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TextCodeCollectionViewGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TextCodeCollectionViewGallery.cs @@ -16,7 +16,8 @@ var collectionView = new CollectionView { ItemsLayout = itemsLayout, - SelectionMode = SelectionMode.Single + SelectionMode = SelectionMode.Single, + AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView); diff --git a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TextCodeCollectionViewGridGallery.cs b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TextCodeCollectionViewGridGallery.cs index 4249080..29a7450 100644 --- a/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TextCodeCollectionViewGridGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/CollectionViewGalleries/TextCodeCollectionViewGridGallery.cs @@ -5,7 +5,7 @@ public TextCodeCollectionViewGridGallery(ItemsLayoutOrientation orientation = ItemsLayoutOrientation.Vertical) { var layout = new Grid - { + { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, @@ -16,7 +16,7 @@ var itemsLayout = new GridItemsLayout(2, orientation); - var collectionView = new CollectionView {ItemsLayout = itemsLayout}; + var collectionView = new CollectionView { ItemsLayout = itemsLayout, AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView); var spanSetter = new SpanSetter(collectionView); diff --git a/Xamarin.Forms.Controls/GalleryPages/GalleryBuilder.cs b/Xamarin.Forms.Controls/GalleryPages/GalleryBuilder.cs index 57719da..8554e4a 100644 --- a/Xamarin.Forms.Controls/GalleryPages/GalleryBuilder.cs +++ b/Xamarin.Forms.Controls/GalleryPages/GalleryBuilder.cs @@ -6,7 +6,8 @@ namespace Xamarin.Forms.Controls.GalleryPages { public static Button NavButton(string galleryName, Func gallery, INavigation nav) { - var button = new Button { Text = $"{galleryName}" }; + var automationId = System.Text.RegularExpressions.Regex.Replace(galleryName, " |\\(|\\)", string.Empty); + var button = new Button { Text = $"{galleryName}", AutomationId = automationId }; button.Clicked += (sender, args) => { nav.PushAsync(gallery()); }; return button; } diff --git a/Xamarin.Forms.Core.UITests.Shared/Queries.cs b/Xamarin.Forms.Core.UITests.Shared/Queries.cs index d20596c..88d1940 100644 --- a/Xamarin.Forms.Core.UITests.Shared/Queries.cs +++ b/Xamarin.Forms.Core.UITests.Shared/Queries.cs @@ -17,6 +17,7 @@ namespace Xamarin.Forms.Core.UITests public const string ActivityIndicatorGallery = "* marked:'ActivityIndicator Gallery'"; public const string BoxViewGallery = "* marked:'BoxView Gallery'"; public const string ButtonGallery = "* marked:'Button Gallery'"; + public const string CollectionViewGallery = "* marked:'CollectionView Gallery'"; public const string ContextActionsListGallery = "* marked:'ContextActions List Gallery'"; public const string ContextActionsTableGallery = "* marked:'ContextActions Table Gallery'"; public const string DatePickerGallery = "* marked:'DatePicker Gallery'"; diff --git a/Xamarin.Forms.Core.UITests.Shared/Tests/CollectionViewUITests.cs b/Xamarin.Forms.Core.UITests.Shared/Tests/CollectionViewUITests.cs new file mode 100644 index 0000000..31df17e --- /dev/null +++ b/Xamarin.Forms.Core.UITests.Shared/Tests/CollectionViewUITests.cs @@ -0,0 +1,283 @@ +using NUnit.Framework; + +namespace Xamarin.Forms.Core.UITests +{ + [Category(UITestCategories.CollectionView)] + internal class CollectionViewUITests : BaseTestFixture + { + string _collectionViewId = "collectionview"; + string _enableCollectionView = "Enable CollectionView"; + string _btnUpdate = "Update"; + string _entryUpdate = "entryUpdate"; + string _entryInsert = "entryInsert"; + string _entryRemove = "entryRemove"; + string _entryReplace = "entryReplace"; + string _entryScrollTo = "entryScrollTo"; + string _btnInsert = "btnInsert"; + string _btnRemove = "btnRemove"; + string _btnReplace = "btnReplace"; + string _btnGo = "btnGo"; + string _inserted = "Inserted"; + string _replaced = "Replacement"; + string _picker = "pickerSelectItem"; +#if __ANDROID__ + string _dialogAndroidFrame = "select_dialog_listview"; +#else + string _pickeriOSFrame = "UIPickerTableView"; +#endif + + public CollectionViewUITests() + { + } + + protected override void NavigateToGallery() + { + App.NavigateToGallery(GalleryQueries.CollectionViewGallery); + } + + protected override void TestTearDown() + { + base.TestTearDown(); + ResetApp(); + NavigateToGallery(); + } + //#if __ANDROID__ + // [TestCase("CarouselView", new string[] { "CarouselViewCode,Horizontal", "CarouselViewCode,Vertical" }, 19, 6)] + //#endif + //[TestCase("ScrollTo", new string[] { + // "ScrollToIndexCode,HorizontalList", "ScrollToIndexCode,VerticalList", "ScrollToIndexCode,HorizontalGrid", "ScrollToIndexCode,VerticalGrid", + // "ScrollToItemCode,HorizontalList", "ScrollToItemCode,VerticalList", "ScrollToItemCode,HorizontalGrid", "ScrollToItemCode,VerticalGrid", + // }, 19, 3)] + //[TestCase("Snap Points", new string[] { "SnapPointsCode,HorizontalList", "SnapPointsCode,VerticalList", "SnapPointsCode,HorizontalGrid", "SnapPointsCode,VerticalGrid" }, 19, 2)] + [TestCase("Observable Collection", new string[] { "Add/RemoveItemsList", "Add/RemoveItemsGrid" }, 19, 6)] + [TestCase("Default Text", new string[] { "VerticalListCode", "HorizontalListCode", "VerticalGridCode", "HorizontalGridCode" }, 101, 11)] + [TestCase("DataTemplate", new string[] { "VerticalListCode", "HorizontalListCode", "VerticalGridCode", "HorizontalGridCode" }, 19, 6)] + public void VisitAndUpdateItemsSource(string collectionTestName, string[] subGalleries, int firstItem, int lastItem) + { + VisitInitialGallery(collectionTestName); + + foreach (var gallery in subGalleries) + { + if (gallery == "FilterItems") + continue; + + VisitSubGallery(gallery, !gallery.Contains("Horizontal"), $"Item: {firstItem}", $"Item: {lastItem}", lastItem - 1, true, false); + App.NavigateBack(); + } + } + + //[TestCase("ScrollTo", new string[] { + // "ScrollToIndexCode,HorizontalList", "ScrollToIndexCode,VerticalList", "ScrollToIndexCode,HorizontalGrid", "ScrollToIndexCode,VerticalGrid", + // "ScrollToItemCode,HorizontalList", "ScrollToItemCode,VerticalList", "ScrollToItemCode,HorizontalGrid", "ScrollToItemCode,VerticalGrid", + // }, 1, 20)] + //public void ScrollTo(string collectionTestName, string[] subGalleries, int firstItem, int goToItem) + //{ + // VisitInitialGallery(collectionTestName); + + // foreach (var galleryName in subGalleries) + // { + // if (galleryName == "FilterItems") + // continue; + + // var isVertical = !galleryName.Contains("Horizontal"); + // var isList = !galleryName.Contains("Grid"); + // var isItem = !galleryName.Contains("Index"); + // if (isItem) + // { + // TestScrollToItem(firstItem, goToItem, galleryName, isList); + // } + // else + // { + // TestScrollToIndex(firstItem, goToItem, galleryName, isList); + // } + // App.Back(); + // } + //} + + void TestScrollToItem(int firstItem, int goToItem, string galleryName, bool isList) + { + App.WaitForElement(t => t.Marked(galleryName)); + App.Tap(t => t.Marked(galleryName)); + App.WaitForElement(t => t.Marked(_picker)); + App.Tap(t => t.Marked(_picker)); + + var firstItemMarked = $"Item: {firstItem}"; + var goToItemMarked = isList ? $"Item: {goToItem}" : $"Item: {goToItem - 1}"; + App.WaitForElement(firstItemMarked); +#if __ANDROID__ + var pickerDialogFrame = App.Query(q => q.Marked(_dialogAndroidFrame))[0].Rect; +#else + var pickerDialogFrame = App.Query(q => q.Class(_pickeriOSFrame))[0].Rect; +#endif + App.ScrollForElement($"* marked:'{goToItemMarked}'", new Drag(pickerDialogFrame, Drag.Direction.BottomToTop, Drag.DragLength.Short)); + App.Tap(goToItemMarked); + App.DismissKeyboard(); + App.Tap(_btnGo); + App.WaitForNoElement(c => c.Marked(firstItemMarked)); + App.WaitForElement(c => c.Marked(goToItemMarked)); + } + + void TestScrollToIndex(int firstItem, int goToItem, string galleryName, bool isList) + { + App.WaitForElement(t => t.Marked(galleryName)); + App.Tap(t => t.Marked(galleryName)); + App.WaitForElement(t => t.Marked(_entryScrollTo)); + App.ClearText(_entryScrollTo); + App.EnterText(_entryScrollTo, goToItem.ToString()); + App.DismissKeyboard(); + App.Tap(_btnGo); + App.WaitForNoElement(c => c.Marked($"Item: {firstItem}")); + var itemToCheck = isList ? $"Item: {goToItem}" : $"Item: {goToItem - 1}"; + App.WaitForElement(c => c.Marked(itemToCheck)); + } + + [TestCase("Observable Collection", new string[] { "Add/RemoveItemsList", "Add/RemoveItemsGrid" }, 1, 6)] + public void AddRemoveItems(string collectionTestName, string[] subGalleries, int firstItem, int lastItem) + { + VisitInitialGallery(collectionTestName); + + foreach (var gallery in subGalleries) + { + if (gallery == "FilterItems") + continue; + + VisitSubGallery(gallery, !gallery.Contains("Horizontal"), $"Item: {firstItem}", $"Item: {lastItem}", lastItem - 1, false, true); + App.NavigateBack(); + } + } + + [TestCase("Observable Collection", new string[] { "Add/RemoveItemsList", "Add/RemoveItemsGrid" }, 19, 6)] + [TestCase("Default Text", new string[] { "VerticalListCode", "HorizontalListCode", "VerticalGridCode" }, 101, 11)] //HorizontalGridCode + [TestCase("DataTemplate", new string[] { "VerticalListCode", "HorizontalListCode", "VerticalGridCode", "HorizontalGridCode" }, 19, 6)] + public void VisitAndTestItemsPosition(string collectionTestName, string[] subGalleries, int firstItem, int lastItem) + { + VisitInitialGallery(collectionTestName); + + foreach (var gallery in subGalleries) + { + if (gallery == "FilterItems") + continue; + App.WaitForElement(t => t.Marked(gallery)); + App.Tap(t => t.Marked(gallery)); + TesItemsPosition(gallery); + App.NavigateBack(); + } + } + + void VisitInitialGallery(string collectionTestName) + { + var galeryName = $"{collectionTestName} Galleries"; + App.WaitForElement(t => t.Marked(_enableCollectionView)); + App.Tap(t => t.Marked(_enableCollectionView)); + + App.WaitForElement(t => t.Marked(galeryName)); + App.Tap(t => t.Marked(galeryName)); + } + + void VisitSubGallery(string galleryName, bool scrollDown, string lastItem, string firstPageItem, int updateItemsCount, bool testItemSource, bool testAddRemove) + { + App.WaitForElement(t => t.Marked(galleryName)); + App.Tap(t => t.Marked(galleryName)); + + //let's test the update + if (testItemSource) + { + UITest.Queries.AppRect collectionViewFrame = TestItemsExist(scrollDown, lastItem); + TestUpdateItemsWorks(scrollDown, firstPageItem, updateItemsCount.ToString(), collectionViewFrame); + } + + if (testAddRemove) + { + TestAddRemoveReplaceWorks(lastItem); + } + } + + void TestAddRemoveReplaceWorks(string lastItem) + { + App.WaitForElement(t => t.Marked(_entryRemove)); + App.ClearText(_entryRemove); + App.EnterText(_entryRemove, "1"); + App.DismissKeyboard(); + App.Tap(_btnRemove); + App.WaitForNoElement(lastItem); + App.ClearText(_entryInsert); + App.EnterText(_entryInsert, "1"); + App.DismissKeyboard(); + App.Tap(_btnInsert); + App.WaitForElement(_inserted); + //TODO: enable replace + App.ClearText(_entryReplace); + App.EnterText(_entryReplace, "1"); + App.DismissKeyboard(); + App.Tap(_btnReplace); + App.WaitForElement(_replaced); + } + + void TestUpdateItemsWorks(bool scrollDown, string itemMarked, string updateItemsCount, UITest.Queries.AppRect collectionViewFrame) + { + App.WaitForElement(t => t.Marked(_entryUpdate)); + App.ScrollForElement($"* marked:'{itemMarked}'", new Drag(collectionViewFrame, scrollDown ? Drag.Direction.TopToBottom : Drag.Direction.LeftToRight, Drag.DragLength.Long), 50); + + App.ClearText(_entryUpdate); + App.EnterText(_entryUpdate, updateItemsCount); + App.DismissKeyboard(); + App.Tap(_btnUpdate); + App.WaitForNoElement(t => t.Marked(itemMarked)); + } + + UITest.Queries.AppRect TestItemsExist(bool scrollDown, string itemMarked) + { + App.WaitForElement(t => t.Marked(_btnUpdate)); + + var collectionViewFrame = App.Query(q => q.Marked(_collectionViewId))[0].Rect; + App.ScrollForElement($"* marked:'{itemMarked}'", new Drag(collectionViewFrame, scrollDown ? Drag.Direction.BottomToTop : Drag.Direction.RightToLeft, Drag.DragLength.Long)); + return collectionViewFrame; + } + + void TesItemsPosition(string gallery) + { + var isVertical = !gallery.Contains("Horizontal"); + var isList = !gallery.Contains("Grid"); + App.WaitForNoElement(t => t.Marked(gallery)); + + var element1 = App.Query(c => c.Marked("Item: 0"))[0]; + if (App.Query(c => c.Marked("Item: 2")).Length == 0) + { + var collectionViewFrame = App.Query(q => q.Marked(_collectionViewId))[0].Rect; + App.ScrollForElement($"* marked:'Item: 2'", new Drag(collectionViewFrame, isVertical ? Drag.Direction.BottomToTop : Drag.Direction.RightToLeft, Drag.DragLength.Long), 50); + } + var element2 = App.Query(c => c.Marked("Item: 2"))[0]; + + if (isVertical) + { + if (isList) + { + Assert.AreEqual(element1.Rect.X, element2.Rect.X); + Assert.Greater(element2.Rect.Y, element1.Rect.Y); + } + else + { + var element3 = App.Query(c => c.Marked("Item: 3"))[0]; + Assert.AreEqual(element2.Rect.Y, element1.Rect.Y); + Assert.Greater(element3.Rect.Y, element1.Rect.Y); + Assert.AreEqual(element3.Rect.X, element1.Rect.X); + } + } + else + { + if (isList) + { + Assert.AreEqual(element1.Rect.Y, element2.Rect.Y); + Assert.Greater(element2.Rect.X, element1.Rect.X); + } + else + { + var element3 = App.Query(c => c.Marked("Item: 3"))[0]; + Assert.AreEqual(element2.Rect.X, element1.Rect.X); + Assert.Greater(element3.Rect.X, element1.Rect.X); + Assert.AreEqual(element3.Rect.Y, element1.Rect.Y); + } + } + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Core.UITests.Shared/Xamarin.Forms.Core.UITests.projitems b/Xamarin.Forms.Core.UITests.Shared/Xamarin.Forms.Core.UITests.projitems index 39ce124..6dce2c4 100644 --- a/Xamarin.Forms.Core.UITests.Shared/Xamarin.Forms.Core.UITests.projitems +++ b/Xamarin.Forms.Core.UITests.Shared/Xamarin.Forms.Core.UITests.projitems @@ -56,5 +56,6 @@ + \ No newline at end of file -- 2.7.4