Skip to content

Commit 9ef021c

Browse files
committed
fix: Re-resolve page references after XAML HR in TabBar tests
XAML HR replaces the page instance when changes affect anonymous children (TabBarItems without x:Name). After replacement, the old page's controls are stale — navigators and content grids must be re-queried from the active page in the visual tree. Tests 8 (Region.Name rename) and 9 (add TabBarItem) now correctly re-resolve via ResolveCurrentPage after HR, matching the framework's actual behavior. All 10 TabBar HR tests now pass.
1 parent 6e5b3b0 commit 9ef021c

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

src/Uno.Extensions.Navigation.UI.Tests/Given_TabBarHotReload.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ public async Task When_RegionAttachedRemovedFromTabBarViaXamlHR_Then_ContentNotB
338338
/// XAML HR renames <c>Region.Name="TabTwo"</c> to <c>"TabTwoRenamed"</c>
339339
/// on the second TabBarItem. Route "TabTwoRenamed" is pre-registered so the
340340
/// SelectorNavigator can resolve it.
341+
/// XAML HR replaces the page instance — references must be re-resolved after HR.
341342
/// </summary>
342343
[TestMethod]
343344
[RunsOnUIThread]
@@ -368,13 +369,25 @@ public async Task When_RegionNameChangedOnTabBarItemViaXamlHR_Then_NavigationRes
368369
"""<utu:TabBarItem Content="Tab Two" uen:Region.Name="TabTwoRenamed" IsSelectable="True" />""",
369370
ct);
370371

371-
await Task.Delay(500, ct);
372+
await Task.Delay(1000, ct);
373+
374+
// XAML HR replaces the page instance — re-resolve to get the new one.
375+
var activePage = ResolveCurrentPage<HotReloadTabBarXamlPage>(app.NavigationRoot)!;
376+
377+
// Verify the Region.Name DP was updated on the new page's TabBarItems.
378+
var regionNames = activePage.TabBar.Items.OfType<FrameworkElement>()
379+
.Select(i => Uno.Extensions.Navigation.UI.Region.GetName(i))
380+
.ToList();
381+
regionNames.Should().Contain("TabTwoRenamed",
382+
"XAML HR should produce TabBarItems with the renamed Region.Name");
372383

373-
// Navigate to the renamed route.
374-
await tabBarNavigator.NavigateRouteAsync(hostPage, "TabTwoRenamed");
384+
// Navigate to the renamed route using the new page's navigator.
385+
var activeNavigator = await WaitForTabBarNavigatorAsync(
386+
activePage.TabBar, TimeSpan.FromSeconds(30), ct);
387+
await activeNavigator.NavigateRouteAsync(activePage, "TabTwoRenamed");
375388
await Task.Delay(500, ct);
376389

377-
var renamedVm = FindTabContentVm(hostPage.ContentGrid, "TabTwoRenamed");
390+
var renamedVm = FindTabContentVm(activePage.ContentGrid, "TabTwoRenamed");
378391
renamedVm.Should().NotBeNull(
379392
"Navigation should resolve the renamed Region.Name after XAML HR");
380393
}
@@ -386,6 +399,7 @@ public async Task When_RegionNameChangedOnTabBarItemViaXamlHR_Then_NavigationRes
386399
/// <summary>
387400
/// XAML HR adds a third <c>TabBarItem</c> with Region.Name="TabThree".
388401
/// The route is pre-registered so the SelectorNavigator can navigate to it.
402+
/// XAML HR replaces the page instance — references must be re-resolved after HR.
389403
/// </summary>
390404
[TestMethod]
391405
[RunsOnUIThread]
@@ -419,17 +433,20 @@ public async Task When_TabBarItemAddedViaXamlHR_Then_NewTabNavigable(Cancellatio
419433

420434
await Task.Delay(1000, ct);
421435

422-
// TabBar should now have 3 items.
423-
hostPage.TabBar.Items.Count.Should().Be(3,
424-
"XAML HR should have added a third TabBarItem");
436+
// XAML HR replaces the page instance — re-resolve to get the new one.
437+
var activePage = ResolveCurrentPage<HotReloadTabBarXamlPage>(app.NavigationRoot)!;
425438

426-
// Navigate to the new tab.
439+
// TabBar should now have 3 items on the replaced page.
440+
activePage.TabBar.Items.Count.Should().Be(3,
441+
"XAML HR should have added a third TabBarItem on the replaced page");
442+
443+
// Navigate to the new tab using the new page's navigator.
427444
var tabBarNavigator = await WaitForTabBarNavigatorAsync(
428-
hostPage.TabBar, TimeSpan.FromSeconds(30), ct);
429-
await tabBarNavigator.NavigateRouteAsync(hostPage, "TabThree");
445+
activePage.TabBar, TimeSpan.FromSeconds(30), ct);
446+
await tabBarNavigator.NavigateRouteAsync(activePage, "TabThree");
430447

431448
var tabThreeVm = await WaitForTabContentVmAsync(
432-
hostPage.ContentGrid, "TabThree", TimeSpan.FromSeconds(30), ct);
449+
activePage.ContentGrid, "TabThree", TimeSpan.FromSeconds(30), ct);
433450
tabThreeVm.Should().NotBeNull(
434451
"Newly added TabThree should be navigable after XAML HR");
435452
}

0 commit comments

Comments
 (0)