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 52bbc83
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ public async Task When_Chefs_FavoriteRecipes_RecipeDetails()
App.WaitThenTap("FavoriteRecipesButton");
App.WaitThenTap("RecipeDetailsButton");
}

[Test]
public async Task When_Chefs_WelcomePage_Wont_Navigate_Twice()
{
InitTestSection(TestSections.Apps_Chefs);

App.WaitElement("TbInstanceCountProperty");

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

Assert.AreEqual("1", intanceCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ namespace TestHarness.Ext.Navigation.Apps.Chefs;

public partial class ChefsHostInit : BaseHostInitialization
{
protected override string[] ConfigurationFiles => new string[] { "TestHarness.Ext.Navigation.Apps.Chefs.appsettings.chefs.json" };

public ChefsHostInit()
{
if (ApplicationData.Current.LocalSettings.Values.TryGetValue(Constants.ChefsWelcomeInstanceCountKey, out var value))
{
ApplicationData.Current.LocalSettings.Values[Constants.ChefsWelcomeInstanceCountKey] = 0;
}
}

protected override IHostBuilder Navigation(IHostBuilder builder)
{
return builder.UseNavigation(ReactiveViewModelMappings.ViewModelMappings, RegisterRoutes).UseToolkitNavigation();
Expand Down Expand Up @@ -37,7 +47,7 @@ protected override void RegisterRoutes(IViewRegistry views, IRouteRegistry route
new RouteMap("", View: views.FindByViewModel<ChefsShellModel>(),
Nested: new RouteMap[]
{
new RouteMap("ChefsWelcome", View: views.FindByViewModel<ChefsWelcomeModel>()),
new RouteMap("ChefsWelcome", View: views.FindByViewModel<ChefsWelcomeModel>(), IsDefault: true),
new RouteMap("ChefsLogin", View: views.FindByViewModel<ChefsLoginModel>()),
new RouteMap("ChefsRoot", View: views.FindByViewModel<ChefsRootModel>(), Nested: new RouteMap[]
{
Expand Down Expand Up @@ -96,5 +106,3 @@ protected override void RegisterRoutes(IViewRegistry views, IRouteRegistry route
);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,5 @@ internal record ChefsShellModel
public ChefsShellModel(INavigator navigator)
{
Navigator = navigator;

_ = Start();
}


public async Task Start() => await Navigator.NavigateViewModelAsync<ChefsWelcomeModel>(this);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@

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

public int InstanceCountProperty { get; private set; }

public ChefsWelcomeModel()
{
InstanceCountProperty = ++InstanceCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<StackPanel>
<TextBlock Text="ChefsWelcome" />
<TextBlock AutomationProperties.AutomationId="TbInstanceCountProperty"
Text="{Binding InstanceCountProperty, Mode=TwoWay}" />
<Button AutomationProperties.AutomationId="NextButton"
Content="Next"
uen:Navigation.Request="ChefsLogin" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TestHarness.Ext.Navigation.Apps.Chefs;

internal class Constants
{
public const string ChefsWelcomeInstanceCountKey = "ChefsWelcomeInstanceCount";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"HostConfiguration": {
"LaunchUrl": "http://localhost:5000/ChefsWelcome"
}
}
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\Apps\Chefs\appsettings.chefs.json" />
<EmbeddedResource Include="Ext\Navigation\Apps\Commerce\appsettings.logging.json" />
</ItemGroup>

Expand Down

0 comments on commit 52bbc83

Please sign in to comment.