Skip to content

Commit

Permalink
chore: fix When_Binding_xLoad_Nested_With_ElementStub_LoadCount
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Nov 4, 2024
1 parent a05f4f4 commit b5c6f2a
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_xLoad.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#nullable enable
#if !WINAPPSDK
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -10,6 +12,7 @@
using Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Uno.UI.RuntimeTests.Helpers;
using SamplesApp.UITests;

Expand Down Expand Up @@ -290,6 +293,7 @@ public async Task When_Binding_xLoad_Nested()
Assert.IsNull(SUT.tb06);
}

#if HAS_UNO
#if __ANDROID__
[Ignore("https://github.com/unoplatform/uno/issues/7305")]
#endif
Expand Down Expand Up @@ -333,10 +337,11 @@ public async Task When_Binding_xLoad_Nested_With_ElementStub_LoadCount()
Assert.AreEqual(2, SUT.TopLevelVisiblity1GetCount);
Assert.AreEqual(0, SUT.TopLevelVisiblity1SetCount);

var tb01Stub = SUT.FindFirstChild<ElementStub>(e => e.Name == "tb01")!;
var tb02Stub = SUT.FindFirstChild<ElementStub>(e => e.Name == "tb02")!;
var panel01Stub = SUT.FindFirstChild<ElementStub>(e => e.Name == "panel01")!;
var panel03Stub = SUT.FindFirstChild<ElementStub>(e => e.Name == "panel03")!;
var stubs = GetAllChildren(SUT).OfType<ElementStub>().ToList();
var tb01Stub = stubs.First(e => e.Name == "tb01");
var tb02Stub = stubs.First(e => e.Name == "tb02")!;
var panel01Stub = stubs.First(e => e.Name == "panel01")!;
var panel03Stub = stubs.First(e => e.Name == "panel03");

var tb01StubChangedCount = 0;
tb01Stub.MaterializationChanged += _ => tb01StubChangedCount++;
Expand Down Expand Up @@ -380,7 +385,7 @@ public async Task When_Binding_xLoad_Nested_With_ElementStub_LoadCount()
Assert.AreEqual(1, tb02StubChangedCount);
Assert.AreEqual(1, panel01StubChangedCount);

var panel02Stub = SUT.FindFirstChild<ElementStub>(e => e.Name == "panel02")!;
var panel02Stub = GetAllChildren(SUT).OfType<ElementStub>().First(e => e.Name == "panel02");

var panel02StubChangedCount = 0;
panel02Stub.MaterializationChanged += _ => panel02StubChangedCount++;
Expand Down Expand Up @@ -457,7 +462,20 @@ public async Task When_Binding_xLoad_Nested_With_ElementStub_LoadCount()
Assert.AreEqual(2, tb02StubChangedCount);
Assert.AreEqual(2, panel01StubChangedCount);
Assert.AreEqual(2, panel02StubChangedCount);

IEnumerable<UIElement> GetAllChildren(UIElement element)
{
yield return element;
foreach (var child in VisualTreeHelper.GetChildren(element).OfType<UIElement>())
{
foreach (var childChild in GetAllChildren(child))
{
yield return childChild;
}
}
}
}
#endif

[TestMethod]
public async Task When_xLoad_Visibility_Set()
Expand Down

0 comments on commit b5c6f2a

Please sign in to comment.