Skip to content

Commit a51ab9a

Browse files
committed
Navigate Directly To Test
1 parent abada83 commit a51ab9a

99 files changed

Lines changed: 494 additions & 530 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Controls/samples/Controls.Sample.UITests/CoreViews/CorePageView.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public override string ToString()
6464
new GalleryPageFactory(() => new ImageButtonCoreGalleryPage(), "Image Button Gallery"),
6565
new GalleryPageFactory(() => new ImageCoreGalleryPage(), "Image Gallery"),
6666
new GalleryPageFactory(() => new KeyboardScrollingGridGallery(), "Keyboard Scrolling Gallery - Grid with Star Row"),
67-
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageLargeTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Large Titles"),
68-
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageSmallTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Small Titles"),
67+
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageLargeTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Large Titles"),
68+
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageSmallTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Small Titles"),
6969
new GalleryPageFactory(() => new KeyboardScrollingScrollingPageLargeTitlesGallery(), "Keyboard Scrolling Gallery - Scrolling Page / Large Titles"),
7070
new GalleryPageFactory(() => new KeyboardScrollingScrollingPageSmallTitlesGallery(), "Keyboard Scrolling Gallery - Scrolling Page / Small Titles"),
71-
new GalleryPageFactory(() => new LabelCoreGalleryPage(), "Label Gallery"),
71+
new GalleryPageFactory(() => new LabelCoreGalleryPage(), "Label Gallery"),
7272
new GalleryPageFactory(() => new ListViewCoreGalleryPage(), "ListView Gallery"),
7373
new GalleryPageFactory(() => new PickerCoreGalleryPage(), "Picker Gallery"),
7474
new GalleryPageFactory(() => new ProgressBarCoreGalleryPage(), "Progress Bar Gallery"),
@@ -152,19 +152,34 @@ async Task PushPage(Page contentPage)
152152
}
153153

154154
readonly Dictionary<string, GalleryPageFactory> _titleToPage;
155-
public async Task<bool> PushPage(string pageTitle)
155+
public Task<bool> NavigateToGalleryPage(string pageTitle)
156156
{
157157
if (_titleToPage.TryGetValue(pageTitle.ToLowerInvariant(), out GalleryPageFactory pageFactory))
158158
{
159159
var page = pageFactory.Realize();
160+
this.Window.Page = page;
161+
return Task.FromResult(true);
162+
}
163+
164+
return Task.FromResult(false);
165+
}
160166

161-
await PushPage(page);
167+
public async Task<bool> NavigateToTest(string pageTitle)
168+
{
169+
var testCaseScreen = new TestCases.TestCaseScreen();
170+
if (testCaseScreen.TryToNavigateTo(pageTitle))
171+
{
172+
return true;
173+
}
174+
else if (await NavigateToGalleryPage(pageTitle))
175+
{
162176
return true;
163177
}
164178

165179
return false;
166180
}
167181

182+
168183
public void FilterPages(string filter)
169184
{
170185
ItemsSource = string.IsNullOrWhiteSpace(filter)

src/Controls/samples/Controls.Sample.UITests/CoreViews/CoreRootPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public CoreRootPage(Microsoft.Maui.Controls.Page rootPage)
3030
{
3131
if (!string.IsNullOrEmpty(searchBar.Text))
3232
{
33-
await corePageView.PushPage(searchBar.Text);
33+
await corePageView.NavigateToTest(searchBar.Text);
3434
}
3535
else
3636
{

src/Controls/samples/Controls.Sample.UITests/Issues/HideSoftInputOnTappedPage.cs

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ namespace Maui.Controls.Sample.Issues
66
{
77
[Issue(IssueTracker.None, 12003, "Hide Soft Input On Tapped Page",
88
PlatformAffected.iOS | PlatformAffected.Android)]
9-
public class HideSoftInputOnTappedPage : TestContentPage
9+
public class HideSoftInputOnTappedPage : NavigationPage
1010
{
11-
public HideSoftInputOnTappedPage()
11+
public HideSoftInputOnTappedPage() : base(new StartingPage())
1212
{
13+
1314
}
1415

15-
protected override void Init()
16+
public class StartingPage : TestContentPage
1617
{
17-
Content = new VerticalStackLayout()
18+
19+
protected override void Init()
20+
{
21+
Content = new VerticalStackLayout()
1822
{
1923
new Button()
2024
{
@@ -36,48 +40,48 @@ protected override void Init()
3640
}
3741
};
3842

39-
(Content as VerticalStackLayout).Spacing = 6;
40-
}
43+
(Content as VerticalStackLayout).Spacing = 6;
44+
}
4145

42-
public class TestPage : ContentPage
43-
{
44-
Label _isKeyboardOpen = new Label();
45-
public TestPage(bool hideSoftInputOnTapped)
46+
public class TestPage : ContentPage
4647
{
47-
this.HideSoftInputOnTapped = hideSoftInputOnTapped;
48-
Title = "Hide Soft Input On Tapped Page";
49-
_isKeyboardOpen.Text = "Tap Page and Keyboard Should Close";
50-
_isKeyboardOpen.AutomationId = "EmptySpace";
48+
Label _isKeyboardOpen = new Label();
49+
public TestPage(bool hideSoftInputOnTapped)
50+
{
51+
this.HideSoftInputOnTapped = hideSoftInputOnTapped;
52+
Title = "Hide Soft Input On Tapped Page";
53+
_isKeyboardOpen.Text = "Tap Page and Keyboard Should Close";
54+
_isKeyboardOpen.AutomationId = "EmptySpace";
5155

52-
Entry entry = new Entry() { AutomationId = "Entry" };
56+
Entry entry = new Entry() { AutomationId = "Entry" };
5357

54-
var checkbox = new CheckBox();
55-
checkbox.BindingContext = this;
56-
checkbox.SetBinding(
57-
CheckBox.IsCheckedProperty,
58-
nameof(HideSoftInputOnTapped));
58+
var checkbox = new CheckBox();
59+
checkbox.BindingContext = this;
60+
checkbox.SetBinding(
61+
CheckBox.IsCheckedProperty,
62+
nameof(HideSoftInputOnTapped));
5963

60-
checkbox.AutomationId = "ToggleHideSoftInputOnTapped";
64+
checkbox.AutomationId = "ToggleHideSoftInputOnTapped";
6165

62-
Entry dontHideKeyboardWhenTappingPage = new Entry()
63-
{
64-
Placeholder = "When this entry is focused tapping the page won't close the keyboard",
65-
AutomationId = "DontHideKeyboardWhenTappingPage"
66-
};
66+
Entry dontHideKeyboardWhenTappingPage = new Entry()
67+
{
68+
Placeholder = "When this entry is focused tapping the page won't close the keyboard",
69+
AutomationId = "DontHideKeyboardWhenTappingPage"
70+
};
6771

68-
dontHideKeyboardWhenTappingPage
69-
.Focused += (_, _) => checkbox.IsChecked = false;
72+
dontHideKeyboardWhenTappingPage
73+
.Focused += (_, _) => checkbox.IsChecked = false;
7074

71-
Entry hideKeyboardWhenTappingPage = new Entry()
72-
{
73-
Placeholder = "When this entry is focused tapping the page will close the keyboard",
74-
AutomationId = "HideKeyboardWhenTappingPage"
75-
};
75+
Entry hideKeyboardWhenTappingPage = new Entry()
76+
{
77+
Placeholder = "When this entry is focused tapping the page will close the keyboard",
78+
AutomationId = "HideKeyboardWhenTappingPage"
79+
};
7680

77-
hideKeyboardWhenTappingPage
78-
.Focused += (_, _) => checkbox.IsChecked = true;
81+
hideKeyboardWhenTappingPage
82+
.Focused += (_, _) => checkbox.IsChecked = true;
7983

80-
Content = new VerticalStackLayout()
84+
Content = new VerticalStackLayout()
8185
{
8286
new HorizontalStackLayout()
8387
{
@@ -90,6 +94,7 @@ public TestPage(bool hideSoftInputOnTapped)
9094
dontHideKeyboardWhenTappingPage,
9195
hideKeyboardWhenTappingPage
9296
};
97+
}
9398
}
9499
}
95100
}

src/Controls/samples/Controls.Sample.UITests/Issues/Issue11501.cs

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,57 @@
88
namespace Maui.Controls.Sample.Issues
99
{
1010
[Issue(IssueTracker.Github, 11501, "Making Fragment Changes While App is Backgrounded Fails", PlatformAffected.Android)]
11-
public class Issue11501 : TestContentPage
11+
12+
public class Issue11501 : NavigationPage
1213
{
13-
Func<Task> _currentTest;
14-
Page _mainPage;
15-
List<Page> _modalStack;
16-
Window _window;
17-
public Issue11501()
14+
public Issue11501() : base(new TestPage())
1815
{
19-
Loaded += OnLoaded;
2016
}
2117

22-
private void OnLoaded(object sender, EventArgs e)
23-
{
24-
_window = Window;
25-
_mainPage = Application.Current.MainPage;
26-
_modalStack = Navigation.ModalStack.ToList();
27-
}
2818

29-
private async void OnWindowActivated(object sender, EventArgs e)
19+
public class TestPage : TestContentPage
3020
{
31-
DisconnectFromWindow();
32-
if (_currentTest is not null)
21+
Func<Task> _currentTest;
22+
Page _mainPage;
23+
List<Page> _modalStack;
24+
Window _window;
25+
public TestPage()
3326
{
34-
await Task.Yield();
35-
await _currentTest();
36-
_currentTest = null;
27+
Loaded += OnLoaded;
3728
}
38-
}
3929

40-
void ConnectToWindow()
41-
{
42-
_window.Stopped -= OnWindowActivated;
43-
_window.Stopped += OnWindowActivated;
44-
}
30+
private void OnLoaded(object sender, EventArgs e)
31+
{
32+
_window = Window;
33+
_mainPage = Application.Current.MainPage;
34+
_modalStack = Navigation.ModalStack.ToList();
35+
}
4536

46-
void DisconnectFromWindow()
47-
{
48-
_window.Stopped -= OnWindowActivated;
49-
}
37+
private async void OnWindowActivated(object sender, EventArgs e)
38+
{
39+
DisconnectFromWindow();
40+
if (_currentTest is not null)
41+
{
42+
await Task.Yield();
43+
await _currentTest();
44+
_currentTest = null;
45+
}
46+
}
5047

51-
protected override void Init()
52-
{
53-
Content = new VerticalStackLayout()
48+
void ConnectToWindow()
49+
{
50+
_window.Stopped -= OnWindowActivated;
51+
_window.Stopped += OnWindowActivated;
52+
}
53+
54+
void DisconnectFromWindow()
55+
{
56+
_window.Stopped -= OnWindowActivated;
57+
}
58+
59+
protected override void Init()
60+
{
61+
Content = new VerticalStackLayout()
5462
{
5563
new Button()
5664
{
@@ -151,14 +159,14 @@ protected override void Init()
151159
})
152160
},
153161
};
154-
}
162+
}
155163

156-
ContentPage CreateDestinationPage()
157-
{
158-
return new ContentPage()
164+
ContentPage CreateDestinationPage()
159165
{
160-
Title = "Test",
161-
Content = new VerticalStackLayout()
166+
return new ContentPage()
167+
{
168+
Title = "Test",
169+
Content = new VerticalStackLayout()
162170
{
163171
new Button()
164172
{
@@ -177,7 +185,8 @@ ContentPage CreateDestinationPage()
177185
})
178186
}
179187
}
180-
};
188+
};
189+
}
181190
}
182191
}
183-
}
192+
}

src/Controls/samples/Controls.Sample.UITests/Issues/Issue14829.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Maui.Controls;
1+
using System;
2+
using Microsoft.Maui.Controls;
23
using Microsoft.Maui.Graphics;
34

45
namespace Maui.Controls.Sample.Issues
@@ -9,12 +10,11 @@ public class Issue14829 : TestContentPage
910
protected override void Init()
1011
{
1112
var navPage = new NavigationPage(new MainPage());
12-
NavigatedTo += Issue14829_NavigatedTo;
13+
Loaded += OnLoaded;
1314

14-
async void Issue14829_NavigatedTo(object sender, NavigatedToEventArgs e)
15+
async void OnLoaded(object sender, EventArgs e)
1516
{
16-
NavigatedTo -= Issue14829_NavigatedTo;
17-
17+
Loaded -= OnLoaded;
1818
await Navigation.PushModalAsync(navPage);
1919
}
2020
}

src/Controls/samples/Controls.Sample.UITests/Issues/Issue16499.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,39 @@
33
namespace Maui.Controls.Sample.Issues
44
{
55
[Issue(IssueTracker.Github, 16499, "Crash when using NavigationPage.TitleView and Restarting App", PlatformAffected.Android)]
6-
public class Issue16499 : TestContentPage
6+
public class Issue16499 : NavigationPage
77
{
8-
protected override void Init()
8+
public Issue16499() : base(new MainPage())
99
{
10-
var contentPage = new ContentPage();
11-
var navPage = new NavigationPage(contentPage);
10+
}
1211

13-
NavigationPage.SetTitleView(contentPage, new Label());
12+
public class MainPage : ContentPage
13+
{
14+
public MainPage() : base()
15+
{
16+
var contentPage = new ContentPage();
17+
var navPage = new NavigationPage(contentPage);
1418

15-
NavigatedTo += Issue16499_NavigatedTo;
19+
NavigationPage.SetTitleView(contentPage, new Label());
1620

17-
async void Issue16499_NavigatedTo(object sender, NavigatedToEventArgs e)
18-
{
19-
NavigatedTo -= Issue16499_NavigatedTo;
20-
await Navigation.PushModalAsync(navPage);
21-
await Navigation.PopModalAsync();
22-
await Navigation.PushModalAsync(navPage);
23-
await Navigation.PopModalAsync();
24-
this.Content = new VerticalStackLayout()
21+
NavigatedTo += Issue16499_NavigatedTo;
22+
23+
async void Issue16499_NavigatedTo(object sender, NavigatedToEventArgs e)
2524
{
26-
new Label()
25+
NavigatedTo -= Issue16499_NavigatedTo;
26+
await Navigation.PushModalAsync(navPage);
27+
await Navigation.PopModalAsync();
28+
await Navigation.PushModalAsync(navPage);
29+
await Navigation.PopModalAsync();
30+
Content = new VerticalStackLayout()
2731
{
28-
Text = "If the app didn't crash this test was a success",
29-
AutomationId = "SuccessLabel"
30-
}
31-
};
32+
new Label()
33+
{
34+
Text = "If the app didn't crash this test was a success",
35+
AutomationId = "SuccessLabel"
36+
}
37+
};
38+
}
3239
}
3340
}
3441
}

0 commit comments

Comments
 (0)