Skip to content

Commit

Permalink
Navigate Directly To Test
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Apr 25, 2024
1 parent abada83 commit a51ab9a
Show file tree
Hide file tree
Showing 99 changed files with 494 additions and 530 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public override string ToString()
new GalleryPageFactory(() => new ImageButtonCoreGalleryPage(), "Image Button Gallery"),
new GalleryPageFactory(() => new ImageCoreGalleryPage(), "Image Gallery"),
new GalleryPageFactory(() => new KeyboardScrollingGridGallery(), "Keyboard Scrolling Gallery - Grid with Star Row"),
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageLargeTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Large Titles"),
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageSmallTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Small Titles"),
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageLargeTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Large Titles"),
new GalleryPageFactory(() => new KeyboardScrollingNonScrollingPageSmallTitlesGallery(), "Keyboard Scrolling Gallery - NonScrolling Page / Small Titles"),
new GalleryPageFactory(() => new KeyboardScrollingScrollingPageLargeTitlesGallery(), "Keyboard Scrolling Gallery - Scrolling Page / Large Titles"),
new GalleryPageFactory(() => new KeyboardScrollingScrollingPageSmallTitlesGallery(), "Keyboard Scrolling Gallery - Scrolling Page / Small Titles"),
new GalleryPageFactory(() => new LabelCoreGalleryPage(), "Label Gallery"),
new GalleryPageFactory(() => new LabelCoreGalleryPage(), "Label Gallery"),
new GalleryPageFactory(() => new ListViewCoreGalleryPage(), "ListView Gallery"),
new GalleryPageFactory(() => new PickerCoreGalleryPage(), "Picker Gallery"),
new GalleryPageFactory(() => new ProgressBarCoreGalleryPage(), "Progress Bar Gallery"),
Expand Down Expand Up @@ -152,19 +152,34 @@ async Task PushPage(Page contentPage)
}

readonly Dictionary<string, GalleryPageFactory> _titleToPage;
public async Task<bool> PushPage(string pageTitle)
public Task<bool> NavigateToGalleryPage(string pageTitle)
{
if (_titleToPage.TryGetValue(pageTitle.ToLowerInvariant(), out GalleryPageFactory pageFactory))
{
var page = pageFactory.Realize();
this.Window.Page = page;
return Task.FromResult(true);
}

return Task.FromResult(false);
}

await PushPage(page);
public async Task<bool> NavigateToTest(string pageTitle)
{
var testCaseScreen = new TestCases.TestCaseScreen();
if (testCaseScreen.TryToNavigateTo(pageTitle))
{
return true;
}
else if (await NavigateToGalleryPage(pageTitle))
{
return true;
}

return false;
}


public void FilterPages(string filter)
{
ItemsSource = string.IsNullOrWhiteSpace(filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CoreRootPage(Microsoft.Maui.Controls.Page rootPage)
{
if (!string.IsNullOrEmpty(searchBar.Text))
{
await corePageView.PushPage(searchBar.Text);
await corePageView.NavigateToTest(searchBar.Text);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.None, 12003, "Hide Soft Input On Tapped Page",
PlatformAffected.iOS | PlatformAffected.Android)]
public class HideSoftInputOnTappedPage : TestContentPage
public class HideSoftInputOnTappedPage : NavigationPage
{
public HideSoftInputOnTappedPage()
public HideSoftInputOnTappedPage() : base(new StartingPage())
{

}

protected override void Init()
public class StartingPage : TestContentPage
{
Content = new VerticalStackLayout()

protected override void Init()
{
Content = new VerticalStackLayout()
{
new Button()
{
Expand All @@ -36,48 +40,48 @@ protected override void Init()
}
};

(Content as VerticalStackLayout).Spacing = 6;
}
(Content as VerticalStackLayout).Spacing = 6;
}

public class TestPage : ContentPage
{
Label _isKeyboardOpen = new Label();
public TestPage(bool hideSoftInputOnTapped)
public class TestPage : ContentPage
{
this.HideSoftInputOnTapped = hideSoftInputOnTapped;
Title = "Hide Soft Input On Tapped Page";
_isKeyboardOpen.Text = "Tap Page and Keyboard Should Close";
_isKeyboardOpen.AutomationId = "EmptySpace";
Label _isKeyboardOpen = new Label();
public TestPage(bool hideSoftInputOnTapped)
{
this.HideSoftInputOnTapped = hideSoftInputOnTapped;
Title = "Hide Soft Input On Tapped Page";
_isKeyboardOpen.Text = "Tap Page and Keyboard Should Close";
_isKeyboardOpen.AutomationId = "EmptySpace";

Entry entry = new Entry() { AutomationId = "Entry" };
Entry entry = new Entry() { AutomationId = "Entry" };

var checkbox = new CheckBox();
checkbox.BindingContext = this;
checkbox.SetBinding(
CheckBox.IsCheckedProperty,
nameof(HideSoftInputOnTapped));
var checkbox = new CheckBox();
checkbox.BindingContext = this;
checkbox.SetBinding(
CheckBox.IsCheckedProperty,
nameof(HideSoftInputOnTapped));

checkbox.AutomationId = "ToggleHideSoftInputOnTapped";
checkbox.AutomationId = "ToggleHideSoftInputOnTapped";

Entry dontHideKeyboardWhenTappingPage = new Entry()
{
Placeholder = "When this entry is focused tapping the page won't close the keyboard",
AutomationId = "DontHideKeyboardWhenTappingPage"
};
Entry dontHideKeyboardWhenTappingPage = new Entry()
{
Placeholder = "When this entry is focused tapping the page won't close the keyboard",
AutomationId = "DontHideKeyboardWhenTappingPage"
};

dontHideKeyboardWhenTappingPage
.Focused += (_, _) => checkbox.IsChecked = false;
dontHideKeyboardWhenTappingPage
.Focused += (_, _) => checkbox.IsChecked = false;

Entry hideKeyboardWhenTappingPage = new Entry()
{
Placeholder = "When this entry is focused tapping the page will close the keyboard",
AutomationId = "HideKeyboardWhenTappingPage"
};
Entry hideKeyboardWhenTappingPage = new Entry()
{
Placeholder = "When this entry is focused tapping the page will close the keyboard",
AutomationId = "HideKeyboardWhenTappingPage"
};

hideKeyboardWhenTappingPage
.Focused += (_, _) => checkbox.IsChecked = true;
hideKeyboardWhenTappingPage
.Focused += (_, _) => checkbox.IsChecked = true;

Content = new VerticalStackLayout()
Content = new VerticalStackLayout()
{
new HorizontalStackLayout()
{
Expand All @@ -90,6 +94,7 @@ public TestPage(bool hideSoftInputOnTapped)
dontHideKeyboardWhenTappingPage,
hideKeyboardWhenTappingPage
};
}
}
}
}
Expand Down
89 changes: 49 additions & 40 deletions src/Controls/samples/Controls.Sample.UITests/Issues/Issue11501.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,57 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 11501, "Making Fragment Changes While App is Backgrounded Fails", PlatformAffected.Android)]
public class Issue11501 : TestContentPage

public class Issue11501 : NavigationPage
{
Func<Task> _currentTest;
Page _mainPage;
List<Page> _modalStack;
Window _window;
public Issue11501()
public Issue11501() : base(new TestPage())
{
Loaded += OnLoaded;
}

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

private async void OnWindowActivated(object sender, EventArgs e)
public class TestPage : TestContentPage
{
DisconnectFromWindow();
if (_currentTest is not null)
Func<Task> _currentTest;
Page _mainPage;
List<Page> _modalStack;
Window _window;
public TestPage()
{
await Task.Yield();
await _currentTest();
_currentTest = null;
Loaded += OnLoaded;
}
}

void ConnectToWindow()
{
_window.Stopped -= OnWindowActivated;
_window.Stopped += OnWindowActivated;
}
private void OnLoaded(object sender, EventArgs e)
{
_window = Window;
_mainPage = Application.Current.MainPage;
_modalStack = Navigation.ModalStack.ToList();
}

void DisconnectFromWindow()
{
_window.Stopped -= OnWindowActivated;
}
private async void OnWindowActivated(object sender, EventArgs e)
{
DisconnectFromWindow();
if (_currentTest is not null)
{
await Task.Yield();
await _currentTest();
_currentTest = null;
}
}

protected override void Init()
{
Content = new VerticalStackLayout()
void ConnectToWindow()
{
_window.Stopped -= OnWindowActivated;
_window.Stopped += OnWindowActivated;
}

void DisconnectFromWindow()
{
_window.Stopped -= OnWindowActivated;
}

protected override void Init()
{
Content = new VerticalStackLayout()
{
new Button()
{
Expand Down Expand Up @@ -151,14 +159,14 @@ protected override void Init()
})
},
};
}
}

ContentPage CreateDestinationPage()
{
return new ContentPage()
ContentPage CreateDestinationPage()
{
Title = "Test",
Content = new VerticalStackLayout()
return new ContentPage()
{
Title = "Test",
Content = new VerticalStackLayout()
{
new Button()
{
Expand All @@ -177,7 +185,8 @@ ContentPage CreateDestinationPage()
})
}
}
};
};
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Maui.Controls;
using System;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

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

async void Issue14829_NavigatedTo(object sender, NavigatedToEventArgs e)
async void OnLoaded(object sender, EventArgs e)
{
NavigatedTo -= Issue14829_NavigatedTo;

Loaded -= OnLoaded;
await Navigation.PushModalAsync(navPage);
}
}
Expand Down
45 changes: 26 additions & 19 deletions src/Controls/samples/Controls.Sample.UITests/Issues/Issue16499.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,39 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 16499, "Crash when using NavigationPage.TitleView and Restarting App", PlatformAffected.Android)]
public class Issue16499 : TestContentPage
public class Issue16499 : NavigationPage
{
protected override void Init()
public Issue16499() : base(new MainPage())
{
var contentPage = new ContentPage();
var navPage = new NavigationPage(contentPage);
}

NavigationPage.SetTitleView(contentPage, new Label());
public class MainPage : ContentPage
{
public MainPage() : base()
{
var contentPage = new ContentPage();
var navPage = new NavigationPage(contentPage);

NavigatedTo += Issue16499_NavigatedTo;
NavigationPage.SetTitleView(contentPage, new Label());

async void Issue16499_NavigatedTo(object sender, NavigatedToEventArgs e)
{
NavigatedTo -= Issue16499_NavigatedTo;
await Navigation.PushModalAsync(navPage);
await Navigation.PopModalAsync();
await Navigation.PushModalAsync(navPage);
await Navigation.PopModalAsync();
this.Content = new VerticalStackLayout()
NavigatedTo += Issue16499_NavigatedTo;

async void Issue16499_NavigatedTo(object sender, NavigatedToEventArgs e)
{
new Label()
NavigatedTo -= Issue16499_NavigatedTo;
await Navigation.PushModalAsync(navPage);
await Navigation.PopModalAsync();
await Navigation.PushModalAsync(navPage);
await Navigation.PopModalAsync();
Content = new VerticalStackLayout()
{
Text = "If the app didn't crash this test was a success",
AutomationId = "SuccessLabel"
}
};
new Label()
{
Text = "If the app didn't crash this test was a success",
AutomationId = "SuccessLabel"
}
};
}
}
}
}
Expand Down
Loading

0 comments on commit a51ab9a

Please sign in to comment.