Skip to content

Commit

Permalink
[iOS] Add UITest for #21806 (#21951)
Browse files Browse the repository at this point in the history
* Add UITest and use IsDescendant of ContainverVC

* Add button to focus entry in the navbar

* UITests working separately

* Use the modal stack
  • Loading branch information
tj-devel709 committed Apr 24, 2024
1 parent c1912df commit a0abfd0
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue21630"
Title="Issue21630">

<VerticalStackLayout>
<Button Text="Swap Main Page for NavigationPage" AutomationId="SwapNavigationPage" Clicked="SwapMainPageNav"/>
<Button Text="Swap Main Page for Shell Page" AutomationId="SwapShellPage" Clicked="SwapMainPageShell"/>
</VerticalStackLayout>

</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 21630, "Entries in NavBar don't trigger keyboard scroll", PlatformAffected.iOS)]
public partial class Issue21630 : ContentPage
{
Page _page;
List<Page> _modalStack;

public Issue21630()
{
InitializeComponent();
Loaded += OnLoaded;
}

private void OnLoaded(object sender, EventArgs e)
{
_page = Application.Current.MainPage;
_modalStack = Navigation.ModalStack.ToList();
}

void SwapMainPageNav (object sender, EventArgs e)
{
Application.Current.MainPage = new NavigationPage(new Issue21630_navPage(_page, _modalStack));
}

void SwapMainPageShell (object sender, EventArgs e)
{
Application.Current.MainPage = new Issue21630_shellPage(_page, _modalStack);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue21630_navPage"
Title="Issue21630_navPage"
Shell.BackgroundColor="Green">

<NavigationPage.TitleView>
<HorizontalStackLayout Spacing="40">
<Entry BackgroundColor="Yellow" Text="Input Entry" AutomationId="NavBarEntryNavigationPage" x:Name="NavBarEntryNav"/>
</HorizontalStackLayout>
</NavigationPage.TitleView>

<Shell.TitleView>
<HorizontalStackLayout Spacing="40">
<Entry BackgroundColor="Yellow" Text="Input Entry" AutomationId="NavBarEntryShellPage" x:Name="NavBarEntryShell"/>
</HorizontalStackLayout>
</Shell.TitleView>

<CollectionView
SelectionMode="None"
BackgroundColor="white"
Margin="10.0">

<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
</x:Array>
</CollectionView.ItemsSource>

<CollectionView.ItemsLayout>
<LinearItemsLayout
Orientation="Vertical"
ItemSpacing="15"/>
</CollectionView.ItemsLayout>

<CollectionView.Header>
<VerticalStackLayout Spacing="20" Padding="10,20">
<Entry BackgroundColor="Yellow" Text="Input Entry" AutomationId="HeaderEntry"/>
<Button Text="Focus NavBarEntryNav" Clicked="FocusNavBarEntryNav" AutomationId="FocusButtonNavigationPage"/>
<Button Text="Focus NavBarEntryShell" Clicked="FocusNavBarEntryShell" AutomationId="FocusButtonShellPage"/>
<Button Text="Restore MainPage" Clicked="RestoreMainPage" AutomationId="RestoreMainPageButton"/>
</VerticalStackLayout>
</CollectionView.Header>

<CollectionView.Footer>
<ContentView HeightRequest="100"></ContentView>
</CollectionView.Footer>

<CollectionView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<Border
StrokeThickness="0.6">
<Label
Text="{Binding}"
FontSize="20"/>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>

</CollectionView>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Issues;

public partial class Issue21630_navPage : ContentPage
{
Page _page;
List<Page> _modalStack;

public Issue21630_navPage()
{
InitializeComponent();
var bc = (ValueTuple<Page, List<Page>>)Shell.Current.BindingContext;
_page = bc.Item1;
_modalStack = bc.Item2;
}

public Issue21630_navPage(Page page, List<Page> modalStack)
{
InitializeComponent();
_page = page;
_modalStack = modalStack;
}

void FocusNavBarEntryNav (object sender, EventArgs e)
{
NavBarEntryNav.Focus();
}

void FocusNavBarEntryShell (object sender, EventArgs e)
{
NavBarEntryShell.Focus();
}

async void RestoreMainPage (object sender, EventArgs e)
{
Application.Current.MainPage = _page;
await Task.Yield();

foreach(var page in _modalStack)
{
await _page.Navigation.PushModalAsync(page);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Shell
x:Class="Maui.Controls.Sample.Issues.Issue21630_shellPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
Shell.FlyoutBehavior="Disabled">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:Issue21630_navPage}"
Route="Issue21630_navPage" />
</Shell>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Maui.Controls;
using System.Collections.Generic;

namespace Maui.Controls.Sample.Issues
{
public partial class Issue21630_shellPage : Shell
{
public Issue21630_shellPage(Page page, List<Page> modalStack)
{
InitializeComponent();
BindingContext = (page, modalStack);
}
}
}
58 changes: 58 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue21630.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues;

public class Issue21630 : _IssuesUITest
{
public override string Issue => "Entries in NavBar don't trigger keyboard scroll";

public Issue21630(TestDevice device)
: base(device)
{ }

string NavBarEntry => "NavBarEntry";
string HeaderEntry => "HeaderEntry";
string FocusButton => "FocusButton";
string RestoreButton => "RestoreMainPageButton";

[TestCase("SwapNavigationPage")]
[TestCase("SwapShellPage")]
public void NavBarEntryDoesNotTriggerKeyboardScroll(string scenario)
{
try
{
var scenarioSuffix = scenario == "SwapNavigationPage" ? "NavigationPage" : "ShellPage";

App.WaitForElement(scenario);
App.Click(scenario);

var navBarEntry = App.WaitForElement(NavBarEntry + scenarioSuffix);
var navBarLocation = navBarEntry.GetRect();
var headerEntry = App.WaitForElement(HeaderEntry);
var headerLocation = headerEntry.GetRect();

App.Click(FocusButton + scenarioSuffix);

var newNavBarEntry = App.WaitForElement(NavBarEntry + scenarioSuffix);
var newNavBarEntryLocation = newNavBarEntry.GetRect();
Assert.AreEqual(navBarLocation, newNavBarEntryLocation);

var newHeaderEntry = App.WaitForElement(HeaderEntry);
var newHeaderLocation = newHeaderEntry.GetRect();

Assert.AreEqual(headerLocation, newHeaderLocation);

App.WaitForElement(RestoreButton);
App.Click(RestoreButton);
}
catch
{
// Just in case these tests leave the app in an unreliable state
App.ResetApp();
FixtureSetup();
throw;
}
}
}

0 comments on commit a0abfd0

Please sign in to comment.