Skip to content

Commit

Permalink
Fixing order of elements returned by "Find", so TapNth can use the co…
Browse files Browse the repository at this point in the history
…rrect index
  • Loading branch information
Rodja Trappe committed Mar 3, 2021
1 parent f9475a1 commit e93014e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions QuickTest/ElementSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public static List<ElementInfo> Find(this Element element, Predicate<Element> pr

if (containerPredicate != null && !containerPredicate.Invoke(element)) return result;

if (predicate.Invoke(element))
result.Add(ElementInfo.FromElement(element));

result.AddRange(FindInTitle(element, predicate, containerPredicate));
result.AddRange((element as ContentPage)?.Content?.Find(predicate, containerPredicate) ?? empty);
result.AddRange((element as ContentView)?.Content.Find(predicate, containerPredicate) ?? empty);
Expand All @@ -25,9 +28,6 @@ public static List<ElementInfo> Find(this Element element, Predicate<Element> pr
result.AddRange((element as ListView)?.Find(predicate, containerPredicate) ?? empty);
result.AddRange((element as ViewCell)?.View?.Find(predicate, containerPredicate) ?? empty);

if (predicate.Invoke(element))
result.Add(ElementInfo.FromElement(element));

AddTapGestureRecognizers(element, result);

return result;
Expand Down
17 changes: 17 additions & 0 deletions Tests/ToolingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ public void TestTapNth()
TapNth("Label", 0);
}

[Test]
public void TestTapElementWithIdenticalTitle()
{
OpenMenu("Elements");

// set itentical title for button and page title
(Find("Button").First() as DemoButton).Text = "Element demo";
ShouldSee("Element demo", 2);

var elements = Find("Element demo");
Assert.That(elements.First(), Is.TypeOf<ElementDemoPage>());
Assert.That(elements.Last(), Is.TypeOf<DemoButton>());

TapNth("Element demo", 1);
Tap("Ok");
}

[Test]
public void TestFind()
{
Expand Down

0 comments on commit e93014e

Please sign in to comment.