generated from unoplatform/template
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ensure NavBar closes Popup regardless of being within a Page (#466)
* fix: Ensure NavBar closes Popup regardless of being within a Packages
- Loading branch information
Showing
6 changed files
with
339 additions
and
13 deletions.
There are no files selected for viewing
204 changes: 204 additions & 0 deletions
204
src/Uno.Toolkit.RuntimeTests/Tests/NavigationBarTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Uno.Disposables; | ||
using Uno.Toolkit.RuntimeTests.Extensions; | ||
using Uno.Toolkit.RuntimeTests.Helpers; | ||
using Uno.Toolkit.RuntimeTests.Tests.TestPages; | ||
using Uno.Toolkit.UI; | ||
using Uno.UI.RuntimeTests; | ||
using Windows.System; | ||
|
||
#if IS_WINUI | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
#else | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Markup; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
#endif | ||
|
||
|
||
namespace Uno.Toolkit.RuntimeTests.Tests | ||
{ | ||
[TestClass] | ||
[RunsOnUIThread] | ||
internal partial class NavigationBarTests | ||
{ | ||
[TestMethod] | ||
[DataRow(MainCommandMode.Back, DisplayName = nameof(MainCommandMode.Back))] | ||
[DataRow(MainCommandMode.Action, DisplayName = nameof(MainCommandMode.Action))] | ||
public async Task MainCommand_In_Popup_Without_Page(MainCommandMode mainCommandMode) | ||
{ | ||
var shouldGoBack = mainCommandMode == MainCommandMode.Back; | ||
var navigationBar = new NavigationBar { Content = "Title", MainCommandMode = mainCommandMode }; | ||
var popup = new Popup { Width = 100, Height = 100, HorizontalOffset = 100, VerticalOffset = 100, Child = new StackPanel { Children = { navigationBar } } }; | ||
var content = new StackPanel { Children = { popup } }; | ||
|
||
try | ||
{ | ||
await UnitTestUIContentHelperEx.SetContentAndWait(content); | ||
|
||
popup.IsOpen = true; | ||
|
||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
await UnitTestsUIContentHelper.WaitForLoaded(popup); | ||
|
||
Assert.IsTrue(navigationBar.TryPerformMainCommand() == shouldGoBack, "Unexpected result from TryPerformMainCommand"); | ||
|
||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
|
||
Assert.IsTrue(popup.IsOpen == !shouldGoBack, "Popup is in an incorrect state"); | ||
} | ||
finally | ||
{ | ||
popup.IsOpen = false; | ||
} | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(MainCommandMode.Back, DisplayName = nameof(MainCommandMode.Back))] | ||
[DataRow(MainCommandMode.Action, DisplayName = nameof(MainCommandMode.Action))] | ||
public async Task MainCommand_In_Popup_With_Page(MainCommandMode mainCommandMode) | ||
{ | ||
NavigationBar? firstPageNavBar = null; | ||
var shouldGoBack = mainCommandMode == MainCommandMode.Back; | ||
var popup = new Popup { Width = 100, Height = 100, HorizontalOffset = 100, VerticalOffset = 100 }; | ||
var content = new Border { Width = 100, Height = 100, Child = popup }; | ||
var frame = new Frame() { Width = 400, Height = 400 }; | ||
|
||
popup.Child = frame; | ||
try | ||
{ | ||
await UnitTestUIContentHelperEx.SetContentAndWait(content); | ||
|
||
popup.IsOpen = true; | ||
|
||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
|
||
frame.Navigate(typeof(NavBarFirstPage)); | ||
|
||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
|
||
var firstPage = frame.Content as NavBarFirstPage; | ||
if (firstPage?.FindChild<NavigationBar>() is { } firstNavBar) | ||
{ | ||
firstPageNavBar = firstNavBar; | ||
firstNavBar.MainCommandMode = mainCommandMode; | ||
} | ||
|
||
await UnitTestsUIContentHelper.WaitForLoaded(firstPageNavBar!); | ||
|
||
Assert.IsTrue(firstPageNavBar!.TryPerformMainCommand() == shouldGoBack, "Unexpected result from TryPerformMainCommand"); | ||
|
||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
|
||
Assert.IsTrue(popup.IsOpen == !shouldGoBack, "Popup is in an incorrect state"); | ||
} | ||
finally | ||
{ | ||
popup.IsOpen = false; | ||
} | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(MainCommandMode.Back, DisplayName = nameof(MainCommandMode.Back))] | ||
[DataRow(MainCommandMode.Action, DisplayName = nameof(MainCommandMode.Action))] | ||
public async Task MainCommand_In_Popup_With_Page_With_BackStack(MainCommandMode mainCommandMode) | ||
{ | ||
NavigationBar? firstPageNavBar = null; | ||
NavigationBar? secondPageNavBar = null; | ||
|
||
var shouldGoBack = mainCommandMode == MainCommandMode.Back; | ||
var popup = new Popup { Width = 100, Height = 100, HorizontalOffset = 100, VerticalOffset = 100 }; | ||
|
||
var content = new Border { Width = 100, Height = 100, Child = popup }; | ||
var frame = new Frame() { Width = 400, Height = 400 }; | ||
|
||
popup.Child = frame; | ||
|
||
try | ||
{ | ||
await UnitTestUIContentHelperEx.SetContentAndWait(content); | ||
|
||
popup.IsOpen = true; | ||
|
||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
|
||
frame.Navigate(typeof(NavBarFirstPage)); | ||
|
||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
|
||
var firstPage = frame.Content as NavBarFirstPage; | ||
if (firstPage?.FindChild<NavigationBar>() is { } firstNavBar) | ||
{ | ||
firstPageNavBar = firstNavBar; | ||
firstNavBar.MainCommandMode = mainCommandMode; | ||
} | ||
|
||
frame.Navigate(typeof(NavBarSecondPage)); | ||
|
||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
|
||
var secondPage = frame.Content as NavBarSecondPage; | ||
if (secondPage?.FindChild<NavigationBar>() is { } secondNavBar) | ||
{ | ||
secondPageNavBar = secondNavBar; | ||
secondNavBar.MainCommandMode = mainCommandMode; | ||
} | ||
|
||
await UnitTestsUIContentHelper.WaitForLoaded(secondPageNavBar!); | ||
|
||
//Assert that the back was handled by the NavBar | ||
Assert.IsTrue(secondPageNavBar!.TryPerformMainCommand() == shouldGoBack, "Unexpected result from TryPerformMainCommand"); | ||
|
||
if (mainCommandMode == MainCommandMode.Back) | ||
{ | ||
await UnitTestsUIContentHelper.WaitForLoaded(firstPageNavBar!); | ||
Assert.IsTrue(frame.CurrentSourcePageType == typeof(NavBarFirstPage), "Expected to navigate back to NavBarFirstPage"); | ||
} | ||
else | ||
{ | ||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
Assert.IsTrue(frame.CurrentSourcePageType == typeof(NavBarSecondPage), "Expected to stay on NavBarSecondPage"); | ||
} | ||
|
||
Assert.IsTrue(popup.IsOpen, "Expected Popup to remain open"); | ||
|
||
// Now we try to GoBack again | ||
if (mainCommandMode == MainCommandMode.Back) | ||
{ | ||
Assert.IsTrue(firstPageNavBar!.TryPerformMainCommand(), "Expected Back to be handled by NavigationBar"); | ||
} | ||
else | ||
{ | ||
Assert.IsFalse(secondPageNavBar!.TryPerformMainCommand(), "Expected Back to not be handled by NavigationBar"); | ||
} | ||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
|
||
|
||
if (mainCommandMode == MainCommandMode.Back) | ||
{ | ||
Assert.IsFalse(popup.IsOpen, "Expected Popup to be closed"); | ||
} | ||
else | ||
{ | ||
Assert.IsTrue(frame.CurrentSourcePageType == typeof(NavBarSecondPage), "Expected to stay on NavBarSecondPage"); | ||
} | ||
|
||
} | ||
finally | ||
{ | ||
popup.IsOpen = false; | ||
} | ||
} | ||
} | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
src/Uno.Toolkit.RuntimeTests/Tests/TestPages/NavBarFirstPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:utu="using:Uno.Toolkit.UI" | ||
x:Class="Uno.Toolkit.RuntimeTests.Tests.TestPages.NavBarFirstPage"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="100" /> | ||
</Grid.RowDefinitions> | ||
<utu:NavigationBar Content="NavBarFirstPage" Width="100"/> | ||
<TextBlock Grid.Row="1" | ||
Text="Hello from NavBarFirstPage" /> | ||
</Grid> | ||
</Page> |
44 changes: 44 additions & 0 deletions
44
src/Uno.Toolkit.RuntimeTests/Tests/TestPages/NavBarFirstPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Uno.Toolkit.UI; | ||
|
||
#if IS_WINUI | ||
using Microsoft.UI; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
#else | ||
using Windows.UI; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
#endif | ||
|
||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace Uno.Toolkit.RuntimeTests.Tests.TestPages | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class NavBarFirstPage : Page | ||
{ | ||
public NavBarFirstPage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Uno.Toolkit.RuntimeTests/Tests/TestPages/NavBarSecondPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:utu="using:Uno.Toolkit.UI" | ||
x:Class="Uno.Toolkit.RuntimeTests.Tests.TestPages.NavBarSecondPage"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="100" /> | ||
</Grid.RowDefinitions> | ||
<utu:NavigationBar Content="NavBarSecondPage" /> | ||
<TextBlock Grid.Row="1" | ||
Text="Hello from NavBarSecondPage" /> | ||
</Grid> | ||
</Page> |
43 changes: 43 additions & 0 deletions
43
src/Uno.Toolkit.RuntimeTests/Tests/TestPages/NavBarSecondPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Uno.Toolkit.UI; | ||
|
||
#if IS_WINUI | ||
using Microsoft.UI; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
#else | ||
using Windows.UI; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
#endif | ||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace Uno.Toolkit.RuntimeTests.Tests.TestPages | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class NavBarSecondPage : Page | ||
{ | ||
public NavBarSecondPage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters