Skip to content

Commit a0abfd0

Browse files
authored
[iOS] Add UITest for #21806 (#21951)
* Add UITest and use IsDescendant of ContainverVC * Add button to focus entry in the navbar * UITests working separately * Use the modal stack
1 parent c1912df commit a0abfd0

File tree

7 files changed

+271
-0
lines changed

7 files changed

+271
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue21630"
5+
Title="Issue21630">
6+
7+
<VerticalStackLayout>
8+
<Button Text="Swap Main Page for NavigationPage" AutomationId="SwapNavigationPage" Clicked="SwapMainPageNav"/>
9+
<Button Text="Swap Main Page for Shell Page" AutomationId="SwapShellPage" Clicked="SwapMainPageShell"/>
10+
</VerticalStackLayout>
11+
12+
</ContentPage>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Microsoft.Maui.Controls;
5+
using Microsoft.Maui.Controls.Xaml;
6+
7+
namespace Maui.Controls.Sample.Issues;
8+
9+
[XamlCompilation(XamlCompilationOptions.Compile)]
10+
[Issue(IssueTracker.Github, 21630, "Entries in NavBar don't trigger keyboard scroll", PlatformAffected.iOS)]
11+
public partial class Issue21630 : ContentPage
12+
{
13+
Page _page;
14+
List<Page> _modalStack;
15+
16+
public Issue21630()
17+
{
18+
InitializeComponent();
19+
Loaded += OnLoaded;
20+
}
21+
22+
private void OnLoaded(object sender, EventArgs e)
23+
{
24+
_page = Application.Current.MainPage;
25+
_modalStack = Navigation.ModalStack.ToList();
26+
}
27+
28+
void SwapMainPageNav (object sender, EventArgs e)
29+
{
30+
Application.Current.MainPage = new NavigationPage(new Issue21630_navPage(_page, _modalStack));
31+
}
32+
33+
void SwapMainPageShell (object sender, EventArgs e)
34+
{
35+
Application.Current.MainPage = new Issue21630_shellPage(_page, _modalStack);
36+
}
37+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue21630_navPage"
5+
Title="Issue21630_navPage"
6+
Shell.BackgroundColor="Green">
7+
8+
<NavigationPage.TitleView>
9+
<HorizontalStackLayout Spacing="40">
10+
<Entry BackgroundColor="Yellow" Text="Input Entry" AutomationId="NavBarEntryNavigationPage" x:Name="NavBarEntryNav"/>
11+
</HorizontalStackLayout>
12+
</NavigationPage.TitleView>
13+
14+
<Shell.TitleView>
15+
<HorizontalStackLayout Spacing="40">
16+
<Entry BackgroundColor="Yellow" Text="Input Entry" AutomationId="NavBarEntryShellPage" x:Name="NavBarEntryShell"/>
17+
</HorizontalStackLayout>
18+
</Shell.TitleView>
19+
20+
<CollectionView
21+
SelectionMode="None"
22+
BackgroundColor="white"
23+
Margin="10.0">
24+
25+
<CollectionView.ItemsSource>
26+
<x:Array Type="{x:Type x:String}">
27+
<x:String>asdf</x:String>
28+
<x:String>asdf</x:String>
29+
<x:String>asdf</x:String>
30+
<x:String>asdf</x:String>
31+
<x:String>asdf</x:String>
32+
<x:String>asdf</x:String>
33+
<x:String>asdf</x:String>
34+
<x:String>asdf</x:String>
35+
<x:String>asdf</x:String>
36+
<x:String>asdf</x:String>
37+
<x:String>asdf</x:String>
38+
<x:String>asdf</x:String>
39+
<x:String>asdf</x:String>
40+
<x:String>asdf</x:String>
41+
<x:String>asdf</x:String>
42+
<x:String>asdf</x:String>
43+
<x:String>asdf</x:String>
44+
<x:String>asdf</x:String>
45+
<x:String>asdf</x:String>
46+
<x:String>asdf</x:String>
47+
<x:String>asdf</x:String>
48+
<x:String>asdf</x:String>
49+
<x:String>asdf</x:String>
50+
<x:String>asdf</x:String>
51+
<x:String>asdf</x:String>
52+
<x:String>asdf</x:String>
53+
<x:String>asdf</x:String>
54+
<x:String>asdf</x:String>
55+
<x:String>asdf</x:String>
56+
</x:Array>
57+
</CollectionView.ItemsSource>
58+
59+
<CollectionView.ItemsLayout>
60+
<LinearItemsLayout
61+
Orientation="Vertical"
62+
ItemSpacing="15"/>
63+
</CollectionView.ItemsLayout>
64+
65+
<CollectionView.Header>
66+
<VerticalStackLayout Spacing="20" Padding="10,20">
67+
<Entry BackgroundColor="Yellow" Text="Input Entry" AutomationId="HeaderEntry"/>
68+
<Button Text="Focus NavBarEntryNav" Clicked="FocusNavBarEntryNav" AutomationId="FocusButtonNavigationPage"/>
69+
<Button Text="Focus NavBarEntryShell" Clicked="FocusNavBarEntryShell" AutomationId="FocusButtonShellPage"/>
70+
<Button Text="Restore MainPage" Clicked="RestoreMainPage" AutomationId="RestoreMainPageButton"/>
71+
</VerticalStackLayout>
72+
</CollectionView.Header>
73+
74+
<CollectionView.Footer>
75+
<ContentView HeightRequest="100"></ContentView>
76+
</CollectionView.Footer>
77+
78+
<CollectionView.ItemTemplate>
79+
<DataTemplate x:DataType="x:String">
80+
<Border
81+
StrokeThickness="0.6">
82+
<Label
83+
Text="{Binding}"
84+
FontSize="20"/>
85+
</Border>
86+
</DataTemplate>
87+
</CollectionView.ItemTemplate>
88+
89+
</CollectionView>
90+
</ContentPage>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using Microsoft.Maui.Controls;
5+
6+
namespace Maui.Controls.Sample.Issues;
7+
8+
public partial class Issue21630_navPage : ContentPage
9+
{
10+
Page _page;
11+
List<Page> _modalStack;
12+
13+
public Issue21630_navPage()
14+
{
15+
InitializeComponent();
16+
var bc = (ValueTuple<Page, List<Page>>)Shell.Current.BindingContext;
17+
_page = bc.Item1;
18+
_modalStack = bc.Item2;
19+
}
20+
21+
public Issue21630_navPage(Page page, List<Page> modalStack)
22+
{
23+
InitializeComponent();
24+
_page = page;
25+
_modalStack = modalStack;
26+
}
27+
28+
void FocusNavBarEntryNav (object sender, EventArgs e)
29+
{
30+
NavBarEntryNav.Focus();
31+
}
32+
33+
void FocusNavBarEntryShell (object sender, EventArgs e)
34+
{
35+
NavBarEntryShell.Focus();
36+
}
37+
38+
async void RestoreMainPage (object sender, EventArgs e)
39+
{
40+
Application.Current.MainPage = _page;
41+
await Task.Yield();
42+
43+
foreach(var page in _modalStack)
44+
{
45+
await _page.Navigation.PushModalAsync(page);
46+
}
47+
}
48+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Shell
2+
x:Class="Maui.Controls.Sample.Issues.Issue21630_shellPage"
3+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
6+
Shell.FlyoutBehavior="Disabled">
7+
8+
<ShellContent
9+
Title="Home"
10+
ContentTemplate="{DataTemplate local:Issue21630_navPage}"
11+
Route="Issue21630_navPage" />
12+
</Shell>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.Maui.Controls;
2+
using System.Collections.Generic;
3+
4+
namespace Maui.Controls.Sample.Issues
5+
{
6+
public partial class Issue21630_shellPage : Shell
7+
{
8+
public Issue21630_shellPage(Page page, List<Page> modalStack)
9+
{
10+
InitializeComponent();
11+
BindingContext = (page, modalStack);
12+
}
13+
}
14+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.AppiumTests.Issues;
6+
7+
public class Issue21630 : _IssuesUITest
8+
{
9+
public override string Issue => "Entries in NavBar don't trigger keyboard scroll";
10+
11+
public Issue21630(TestDevice device)
12+
: base(device)
13+
{ }
14+
15+
string NavBarEntry => "NavBarEntry";
16+
string HeaderEntry => "HeaderEntry";
17+
string FocusButton => "FocusButton";
18+
string RestoreButton => "RestoreMainPageButton";
19+
20+
[TestCase("SwapNavigationPage")]
21+
[TestCase("SwapShellPage")]
22+
public void NavBarEntryDoesNotTriggerKeyboardScroll(string scenario)
23+
{
24+
try
25+
{
26+
var scenarioSuffix = scenario == "SwapNavigationPage" ? "NavigationPage" : "ShellPage";
27+
28+
App.WaitForElement(scenario);
29+
App.Click(scenario);
30+
31+
var navBarEntry = App.WaitForElement(NavBarEntry + scenarioSuffix);
32+
var navBarLocation = navBarEntry.GetRect();
33+
var headerEntry = App.WaitForElement(HeaderEntry);
34+
var headerLocation = headerEntry.GetRect();
35+
36+
App.Click(FocusButton + scenarioSuffix);
37+
38+
var newNavBarEntry = App.WaitForElement(NavBarEntry + scenarioSuffix);
39+
var newNavBarEntryLocation = newNavBarEntry.GetRect();
40+
Assert.AreEqual(navBarLocation, newNavBarEntryLocation);
41+
42+
var newHeaderEntry = App.WaitForElement(HeaderEntry);
43+
var newHeaderLocation = newHeaderEntry.GetRect();
44+
45+
Assert.AreEqual(headerLocation, newHeaderLocation);
46+
47+
App.WaitForElement(RestoreButton);
48+
App.Click(RestoreButton);
49+
}
50+
catch
51+
{
52+
// Just in case these tests leave the app in an unreliable state
53+
App.ResetApp();
54+
FixtureSetup();
55+
throw;
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)