Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed Feb 2, 2023
1 parent 9d9dbe0 commit d6da301
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/workflow/scripts/ios-uitest-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ echo Response file:
cat $UNO_TESTS_RESPONSE_FILE

## Show the tests list
mono $BUILD_SOURCESDIRECTORY/build/NUnit.ConsoleRunner.$NUNIT_VERSION/tools/nunit3-console.exe \
mono $BUILD_SOURCESDIRECTORY/build/NUnit.ConsoleRunner.$UNO_UITEST_NUNIT_VERSION/tools/nunit3-console.exe \
@$UNO_TESTS_RESPONSE_FILE --explore || true

## Run NUnit tests
Expand Down
1 change: 1 addition & 0 deletions build/workflow/stage-uitests-android.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
jobs:
- job: Android_UITests
displayName: 'Android UI Tests'
timeoutInMinutes: 90
variables:
CI_Build: true
SourceLinkEnabled: false
Expand Down
1 change: 1 addition & 0 deletions build/workflow/stage-uitests-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- job: Wasm_UITests
displayName: 'WebAssembly UI Tests'
container: unoplatform/wasm-build:3.0
timeoutInMinutes: 90

strategy:
maxParallel: 2
Expand Down
150 changes: 146 additions & 4 deletions src/Uno.Toolkit.RuntimeTests/Tests/NavigationBarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,37 @@
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 class NavigationBarTests
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 shouldClosePopup = mainCommandMode == MainCommandMode.Back;
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 } };
Expand All @@ -46,11 +51,148 @@ public async Task MainCommand_In_Popup_Without_Page(MainCommandMode mainCommandM
await UnitTestsUIContentHelper.WaitForIdle();
await UnitTestsUIContentHelper.WaitForLoaded(popup);

Assert.IsTrue(navigationBar.TryPerformMainCommand() == shouldClosePopup, "Unexpected result from TryPerformMainCommand");
Assert.IsTrue(navigationBar.TryPerformMainCommand() == shouldGoBack, "Unexpected result from TryPerformMainCommand");

await UnitTestsUIContentHelper.WaitForIdle();

Assert.IsTrue(popup.IsOpen == !shouldClosePopup, "Popup is in an incorrect state");
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
{
Expand Down
14 changes: 14 additions & 0 deletions src/Uno.Toolkit.RuntimeTests/Tests/TestPages/NavBarFirstPage.xaml
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>
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 src/Uno.Toolkit.RuntimeTests/Tests/TestPages/NavBarSecondPage.xaml
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>
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();
}
}
}

0 comments on commit d6da301

Please sign in to comment.