From 5d63323a2b2dea874db6bb3c4d1b1eaface264a2 Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Wed, 11 Dec 2024 13:19:11 +0000 Subject: [PATCH] test: Ensure duplicated navigation wont happen --- .../TestHarness.Core/TestSections.cs | 1 + .../Navigation/AddressBar/Given_AddressBar.cs | 16 ++++++++ .../AddressBar/AddressBarHomeModel.cs | 19 ++++++++++ .../AddressBar/AddressBarHomePage.xaml | 27 +++++++++++++ .../AddressBar/AddressBarHomePage.xaml.cs | 9 +++++ .../AddressBar/AddressBarHostInit.cs | 30 +++++++++++++++ .../AddressBar/AddressBarMainPage.xaml | 38 +++++++++++++++++++ .../AddressBar/AddressBarMainPage.xaml.cs | 15 ++++++++ .../Ext/Navigation/AddressBar/Constants.cs | 6 +++ .../Navigation/AddressBar/ShellViewModel.cs | 11 ++++++ .../AddressBar/appsettings.addressbar.json | 5 +++ .../TestHarness/TestHarness.csproj | 1 + 12 files changed, 178 insertions(+) create mode 100644 testing/TestHarness/TestHarness.UITest/Ext/Navigation/AddressBar/Given_AddressBar.cs create mode 100644 testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomeModel.cs create mode 100644 testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomePage.xaml create mode 100644 testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomePage.xaml.cs create mode 100644 testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHostInit.cs create mode 100644 testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarMainPage.xaml create mode 100644 testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarMainPage.xaml.cs create mode 100644 testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/Constants.cs create mode 100644 testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/ShellViewModel.cs create mode 100644 testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/appsettings.addressbar.json diff --git a/testing/TestHarness/TestHarness.Core/TestSections.cs b/testing/TestHarness/TestHarness.Core/TestSections.cs index f4edf27f92..da5984c564 100644 --- a/testing/TestHarness/TestHarness.Core/TestSections.cs +++ b/testing/TestHarness/TestHarness.Core/TestSections.cs @@ -13,6 +13,7 @@ public enum TestSections Navigation_NavigationView, Navigation_TabBar, Navigation_Reactive, + Navigation_AddressBar, Apps_Chefs, Apps_Commerce, Apps_Commerce_ShellControl, diff --git a/testing/TestHarness/TestHarness.UITest/Ext/Navigation/AddressBar/Given_AddressBar.cs b/testing/TestHarness/TestHarness.UITest/Ext/Navigation/AddressBar/Given_AddressBar.cs new file mode 100644 index 0000000000..6149a39681 --- /dev/null +++ b/testing/TestHarness/TestHarness.UITest/Ext/Navigation/AddressBar/Given_AddressBar.cs @@ -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); + } +} diff --git a/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomeModel.cs b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomeModel.cs new file mode 100644 index 0000000000..19d0b8de08 --- /dev/null +++ b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomeModel.cs @@ -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; + } +} diff --git a/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomePage.xaml b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomePage.xaml new file mode 100644 index 0000000000..8589613b36 --- /dev/null +++ b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomePage.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + diff --git a/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomePage.xaml.cs b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomePage.xaml.cs new file mode 100644 index 0000000000..ef931367cf --- /dev/null +++ b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHomePage.xaml.cs @@ -0,0 +1,9 @@ +namespace TestHarness.Ext.Navigation.AddressBar; + +public sealed partial class AddressBarHomePage : Page +{ + public AddressBarHomePage() + { + this.InitializeComponent(); + } +} diff --git a/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHostInit.cs b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHostInit.cs new file mode 100644 index 0000000000..0c59bb83b1 --- /dev/null +++ b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarHostInit.cs @@ -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(), + new ViewMap(ViewModel: typeof(ShellViewModel)) + ); + + routes.Register( + new RouteMap("", View: views.FindByViewModel(), + Nested: + [ + new RouteMap("AddressBarHome", View: views.FindByViewModel(), IsDefault: true) + ] + ) + ); + } +} diff --git a/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarMainPage.xaml b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarMainPage.xaml new file mode 100644 index 0000000000..b3f0955aca --- /dev/null +++ b/testing/TestHarness/TestHarness/Ext/Navigation/AddressBar/AddressBarMainPage.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + +