Skip to content

Commit

Permalink
test: Ensure duplicated navigation wont happen
Browse files Browse the repository at this point in the history
  • Loading branch information
eriklimakc committed Dec 11, 2024
1 parent ae9c07f commit 5d63323
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 0 deletions.
1 change: 1 addition & 0 deletions testing/TestHarness/TestHarness.Core/TestSections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum TestSections
Navigation_NavigationView,
Navigation_TabBar,
Navigation_Reactive,
Navigation_AddressBar,
Apps_Chefs,
Apps_Commerce,
Apps_Commerce_ShellControl,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TestHarness.UITest;

public class Given_AddressBar : NavigationTestBase
{
[Test]
public async Task When_AddressBar_HomePage_Wont_Navigate_Twice()
{
InitTestSection(TestSections.Navigation_AddressBar);

App.WaitElement("TbInstanceCountProperty");

var intanceCount = App.GetText("TbInstanceCountProperty");

Assert.AreEqual("1", intanceCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace TestHarness.Ext.Navigation.AddressBar;

public partial class AddressBarHomeModel
{
public static int InstanceCount
{
get => ApplicationData.Current.LocalSettings.Values.TryGetValue(Constants.HomeInstanceCountKey, out var value)
? (int)value
: 0;
private set => ApplicationData.Current.LocalSettings.Values[Constants.HomeInstanceCountKey] = value;
}

public int InstanceCountProperty { get; private set; }

public AddressBarHomeModel()
{
InstanceCountProperty = ++InstanceCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Page x:Class="TestHarness.Ext.Navigation.AddressBar.AddressBarHomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestHarness.Ext.Navigation.RoutesNavigation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid>
<StackPanel Grid.Row="1"
HorizontalAlignment="Center"
Spacing="16">
<TextBlock Text="AddressBar HomePage" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="This page was created: " />
<TextBlock AutomationProperties.AutomationId="TbInstanceCountProperty"
Text="{Binding InstanceCountProperty, Mode=TwoWay}" />
<TextBlock Text=" times" />
</StackPanel>

</StackPanel>

</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TestHarness.Ext.Navigation.AddressBar;

public sealed partial class AddressBarHomePage : Page
{
public AddressBarHomePage()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace TestHarness.Ext.Navigation.AddressBar;

public class AddressBarHostInit : BaseHostInitialization
{
protected override string[] ConfigurationFiles => new string[] { "TestHarness.Ext.Navigation.AddressBar.appsettings.addressbar.json" };

public AddressBarHostInit()
{
if (ApplicationData.Current.LocalSettings.Values.TryGetValue(Constants.HomeInstanceCountKey, out var value))
{
ApplicationData.Current.LocalSettings.Values[Constants.HomeInstanceCountKey] = 0;
}
}
protected override void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap<AddressBarHomePage, AddressBarHomeModel>(),
new ViewMap(ViewModel: typeof(ShellViewModel))
);

routes.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested:
[
new RouteMap("AddressBarHome", View: views.FindByViewModel<AddressBarHomeModel>(), IsDefault: true)
]
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<testharness:BaseTestSectionPage xmlns:testharness="using:TestHarness"
x:Class="TestHarness.Ext.Navigation.AddressBar.AddressBarMainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestHarness.Ext.Navigation.RoutesNavigation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="AddressBar Navigation Tests"
Margin="20"
FontSize="30" />

<ContentControl AutomationProperties.AutomationId="NavigationRoot"
x:Name="NavigationRoot"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Grid.Row="1" />

<StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Center">
<Button AutomationProperties.AutomationId="ShowAppButton"
Content="AddressBar App"
Click="ShowAppClick" />
</StackPanel>
</Grid>

</testharness:BaseTestSectionPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace TestHarness.Ext.Navigation.AddressBar;

[TestSectionRoot("AddressBar Navigation", TestSections.Navigation_AddressBar, typeof(AddressBarHostInit))]
public sealed partial class AddressBarMainPage : BaseTestSectionPage
{
public AddressBarMainPage()
{
this.InitializeComponent();
}

public async void ShowAppClick(object sender, RoutedEventArgs e)
{
await Navigator.NavigateRouteAsync(this, "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TestHarness.Ext.Navigation.AddressBar;

internal class Constants
{
public const string HomeInstanceCountKey = "HomeInstanceCount";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TestHarness.Ext.Navigation.AddressBar;

public record ShellViewModel
{
public INavigator? Navigator { get; init; }

public ShellViewModel(INavigator navigator)
{
Navigator = navigator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"HostConfiguration": {
"LaunchUrl": "http://localhost:5000/AddressBarHome"
}
}
1 change: 1 addition & 0 deletions testing/TestHarness/TestHarness/TestHarness.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<EmbeddedResource Include="Ext\Http\Endpoints\appsettings.httpendpoints.json" />
<EmbeddedResource Include="Ext\Http\Refit\appsettings.httprefit.json" />
<EmbeddedResource Include="Ext\Localization\appsettings.locale.json" />
<EmbeddedResource Include="Ext\Navigation\AddressBar\appsettings.addressbar.json" />
<EmbeddedResource Include="Ext\Navigation\Apps\Commerce\appsettings.logging.json" />
</ItemGroup>

Expand Down

0 comments on commit 5d63323

Please sign in to comment.