From a69c076364d4cd4097ea410e2aa205b4b639df3e Mon Sep 17 00:00:00 2001 From: vatsashah45 Date: Thu, 10 Oct 2024 11:47:57 -0400 Subject: [PATCH 1/2] fix: UWP Build --- .../Tests/AncestorBindingTests.cs | 26 +++--- .../Tests/DrawerTests.cs | 24 +++--- .../Tests/ExtendedSplashScreenTests.cs | 22 +++-- .../Tests/ResponsiveExtensionsTests.cs | 86 +++++++++---------- 4 files changed, 85 insertions(+), 73 deletions(-) diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/AncestorBindingTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/AncestorBindingTests.cs index 5d1c97027..240a4bc43 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/AncestorBindingTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/AncestorBindingTests.cs @@ -1,4 +1,7 @@ -using System; +// FindFirstDescendent is not available in UWP + +#if !IS_UWP +using System; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Uno.UI.RuntimeTests; @@ -6,8 +9,8 @@ using Uno.Toolkit.UI; using Uno.UI.Extensions; using Uno.Toolkit.RuntimeTests.Tests.TestPages; - - + + #if IS_WINUI using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; @@ -17,9 +20,9 @@ using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; #endif - + namespace Uno.Toolkit.RuntimeTests.Tests; - + [TestClass] [RunsOnUIThread] internal class AncestorBindingTests @@ -29,33 +32,34 @@ public async Task Ancestor_TopLevel_PageBinding() { var setup = new AncestorBindingTest(); await UnitTestUIContentHelperEx.SetContentAndWait(setup); - + var sut = setup.FindFirstDescendant("TopLevelTextBlock") ?? throw new Exception("Failed to find TopLevelTextBlock"); Assert.AreEqual(sut.Text, setup.Tag); } - + [TestMethod] public async Task Ancestor_Nested_PageBinding() { var setup = new AncestorBindingTest(); await UnitTestUIContentHelperEx.SetContentAndWait(setup); - + var lv = setup.FindFirstDescendant("TopLevelListView") ?? throw new Exception("Failed to find TopLevelListView"); var container = lv.ContainerFromIndex(0); var sut = (container as FrameworkElement)?.FindFirstDescendant("NestedLvTextBlock1") ?? throw new Exception("Failed to find NestedLvTextBlock1"); - + Assert.AreEqual(sut.Text, setup.Tag); } - + [TestMethod] public async Task Ancestor_Nested_LvBinding() { var setup = new AncestorBindingTest(); await UnitTestUIContentHelperEx.SetContentAndWait(setup); - + var lv = setup.FindFirstDescendant("TopLevelListView") ?? throw new Exception("Failed to find TopLevelListView"); var container = lv.ContainerFromIndex(0); var sut = (container as FrameworkElement)?.FindFirstDescendant("NestedLvTextBlock2") ?? throw new Exception("Failed to find NestedLvTextBlock2"); Assert.AreEqual(sut.Text, lv.Tag); } } +#endif diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/DrawerTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/DrawerTests.cs index 72f38f373..9510c49bf 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/DrawerTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/DrawerTests.cs @@ -1,11 +1,14 @@ -using System; +// FindFirstDescendent is not available in UWP + +#if !IS_UWP +using System; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Uno.UI.RuntimeTests; using Uno.Toolkit.RuntimeTests.Helpers; using Uno.Toolkit.UI; using Uno.UI.Extensions; - + #if IS_WINUI using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; @@ -13,9 +16,9 @@ using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; #endif - + namespace Uno.Toolkit.RuntimeTests.Tests; - + [TestClass] [RunsOnUIThread] internal class DrawerTests @@ -30,29 +33,30 @@ public async Task IsOpen_FromNonUIThread() { Content = new Grid() }; - + // don't wait for loaded, start the task immediately UIHelper.Content = drawer; await Task.Run(async () => { drawer.IsOpen = true; - + await UIHelper.WaitForLoaded(drawer); await UIHelper.WaitForIdle(); await UnitTestUIContentHelperEx.WaitFor(() => drawer.AnimationStoryboard?.GetCurrentState() == ClockState.Stopped); - + drawer.IsOpen = false; }); - + // leave time for IsOpen=false (animation or not) to finish (if it doesn't throw) await UIHelper.WaitForIdle(); await UnitTestUIContentHelperEx.WaitFor(() => drawer.AnimationStoryboard?.GetCurrentState() == ClockState.Stopped); - + var lightDismissOverlay = drawer.FindFirstDescendant(x => x.Name == DrawerControl.TemplateParts.LightDismissOverlayName) ?? throw new Exception($"Failed to find {DrawerControl.TemplateParts.LightDismissOverlayName}"); - + await UnitTestUIContentHelperEx.WaitFor( () => lightDismissOverlay.Opacity == 0, message: $"Expected lightDismissOverlay.Opacity to be 0, got {lightDismissOverlay.Opacity}"); } } +#endif diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/ExtendedSplashScreenTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/ExtendedSplashScreenTests.cs index 6db342134..20dbd8be9 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/ExtendedSplashScreenTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/ExtendedSplashScreenTests.cs @@ -1,19 +1,22 @@ -using System; +// FindFirstDescendent is not available in UWP + +#if !IS_UWP +using System; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Uno.Toolkit.RuntimeTests.Helpers; using Uno.Toolkit.UI; using Uno.UI.Extensions; using Uno.UI.RuntimeTests; - + #if IS_WINUI using Microsoft.UI.Xaml.Controls; #else using Windows.UI.Xaml.Controls; #endif - + namespace Uno.Toolkit.RuntimeTests.Tests; - + [TestClass] [RunsOnUIThread] public class ExtendedSplashScreenTests @@ -25,23 +28,24 @@ public class ExtendedSplashScreenTests public async Task Smoke_Test() { var host = await ExtendedSplashScreen.GetNativeSplashScreen().ConfigureAwait(false) ?? throw new Exception("Failed to load native splash screen"); - + #if !__MOBILE__ // ignore native platforms impl: ios,droid,macos var sut = host.FindFirstDescendant() ?? throw new Exception("Failed to find splash image control"); var tcs = new TaskCompletionSource<(bool Success, string? Message)>(); - + sut.ImageOpened += (s, e) => tcs.SetResult((Success: true, null)); sut.ImageFailed += (s, e) => tcs.SetResult((Success: false, e.ErrorMessage)); #endif - + await UnitTestUIContentHelperEx.SetContentAndWait(host); - + #if !__MOBILE__ if (await Task.WhenAny(tcs.Task, Task.Delay(2000)) != tcs.Task) throw new TimeoutException("Timed out waiting on image to load"); - + if ((await tcs.Task) is { Success: false, Message: var message }) throw new Exception($"Failed to load image: {message}"); #endif } } +#endif diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs index 1119cb89c..c9a0689dd 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs @@ -38,7 +38,7 @@ internal class ResponsiveExtensionsTests public async Task ProvideValue_String_Value() { var sut = XamlHelper.LoadXaml(""" - + """); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Text)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); await UnitTestUIContentHelperEx.SetContentAndWait(sut); @@ -51,7 +51,7 @@ public async Task ProvideValue_String_Value() public async Task ProvideValue_String_SizeChange() { var sut = XamlHelper.LoadXaml(""" - + """); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Text)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); await UnitTestUIContentHelperEx.SetContentAndWait(sut); @@ -67,16 +67,16 @@ public async Task ProvideValue_String_SizeChange() public async Task ProvideValue_Color_Value() { var sut = XamlHelper.LoadXaml(""" - - - Red - Blue - - - - - + +Red +Blue + + + + + """); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Background)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); await UnitTestUIContentHelperEx.SetContentAndWait(sut); @@ -89,16 +89,16 @@ public async Task ProvideValue_Color_Value() public async Task ProvideValue_Color_SizeChange() { var sut = XamlHelper.LoadXaml(""" - - - Red - Blue - - - - - + +Red +Blue + + + + + """); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Background)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); await UnitTestUIContentHelperEx.SetContentAndWait(sut); @@ -114,17 +114,17 @@ public async Task ProvideValue_Color_SizeChange() public async Task ProvideValue_Orientation_Value() { var container = XamlHelper.LoadXaml(""" - - - Vertical - Horizontal - - - - - - - + + +Vertical +Horizontal + + + + + + + """); var sut = container.Child as StackPanel ?? throw new InvalidOperationException("Failed to resolve the SUT"); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Orientation)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); @@ -138,17 +138,17 @@ public async Task ProvideValue_Orientation_Value() public async Task ProvideValue_Orientation_SizeChange() { var container = XamlHelper.LoadXaml(""" - - - Vertical - Horizontal - - - - - - - + + +Vertical +Horizontal + + + + + + + """); var sut = container.Child as StackPanel ?? throw new InvalidOperationException("Failed to resolve the SUT"); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Orientation)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); @@ -161,7 +161,6 @@ public async Task ProvideValue_Orientation_SizeChange() Assert.AreEqual(Orientation.Horizontal, sut.Orientation); } } -#endif [TestClass] [RunsOnUIThread] @@ -207,3 +206,4 @@ public async Task Setup_And_Teardown() } } } +#endif From 1c08cf1abd829431c19407c4ffa35125d88e2b1b Mon Sep 17 00:00:00 2001 From: vatsashah45 Date: Thu, 10 Oct 2024 12:03:37 -0400 Subject: [PATCH 2/2] fix: identation --- .../Tests/AncestorBindingTests.cs | 18 ++-- .../Tests/DrawerTests.cs | 18 ++-- .../Tests/ExtendedSplashScreenTests.cs | 14 ++-- .../Tests/ResponsiveExtensionsTests.cs | 84 +++++++++---------- 4 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/AncestorBindingTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/AncestorBindingTests.cs index 240a4bc43..93f54ea2a 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/AncestorBindingTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/AncestorBindingTests.cs @@ -9,8 +9,8 @@ using Uno.Toolkit.UI; using Uno.UI.Extensions; using Uno.Toolkit.RuntimeTests.Tests.TestPages; - - + + #if IS_WINUI using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; @@ -20,9 +20,9 @@ using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; #endif - + namespace Uno.Toolkit.RuntimeTests.Tests; - + [TestClass] [RunsOnUIThread] internal class AncestorBindingTests @@ -32,24 +32,24 @@ public async Task Ancestor_TopLevel_PageBinding() { var setup = new AncestorBindingTest(); await UnitTestUIContentHelperEx.SetContentAndWait(setup); - + var sut = setup.FindFirstDescendant("TopLevelTextBlock") ?? throw new Exception("Failed to find TopLevelTextBlock"); Assert.AreEqual(sut.Text, setup.Tag); } - + [TestMethod] public async Task Ancestor_Nested_PageBinding() { var setup = new AncestorBindingTest(); await UnitTestUIContentHelperEx.SetContentAndWait(setup); - + var lv = setup.FindFirstDescendant("TopLevelListView") ?? throw new Exception("Failed to find TopLevelListView"); var container = lv.ContainerFromIndex(0); var sut = (container as FrameworkElement)?.FindFirstDescendant("NestedLvTextBlock1") ?? throw new Exception("Failed to find NestedLvTextBlock1"); - + Assert.AreEqual(sut.Text, setup.Tag); } - + [TestMethod] public async Task Ancestor_Nested_LvBinding() { diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/DrawerTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/DrawerTests.cs index 9510c49bf..cb8008654 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/DrawerTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/DrawerTests.cs @@ -8,7 +8,7 @@ using Uno.Toolkit.RuntimeTests.Helpers; using Uno.Toolkit.UI; using Uno.UI.Extensions; - + #if IS_WINUI using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; @@ -16,9 +16,9 @@ using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; #endif - + namespace Uno.Toolkit.RuntimeTests.Tests; - + [TestClass] [RunsOnUIThread] internal class DrawerTests @@ -33,27 +33,27 @@ public async Task IsOpen_FromNonUIThread() { Content = new Grid() }; - + // don't wait for loaded, start the task immediately UIHelper.Content = drawer; await Task.Run(async () => { drawer.IsOpen = true; - + await UIHelper.WaitForLoaded(drawer); await UIHelper.WaitForIdle(); await UnitTestUIContentHelperEx.WaitFor(() => drawer.AnimationStoryboard?.GetCurrentState() == ClockState.Stopped); - + drawer.IsOpen = false; }); - + // leave time for IsOpen=false (animation or not) to finish (if it doesn't throw) await UIHelper.WaitForIdle(); await UnitTestUIContentHelperEx.WaitFor(() => drawer.AnimationStoryboard?.GetCurrentState() == ClockState.Stopped); - + var lightDismissOverlay = drawer.FindFirstDescendant(x => x.Name == DrawerControl.TemplateParts.LightDismissOverlayName) ?? throw new Exception($"Failed to find {DrawerControl.TemplateParts.LightDismissOverlayName}"); - + await UnitTestUIContentHelperEx.WaitFor( () => lightDismissOverlay.Opacity == 0, message: $"Expected lightDismissOverlay.Opacity to be 0, got {lightDismissOverlay.Opacity}"); diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/ExtendedSplashScreenTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/ExtendedSplashScreenTests.cs index 20dbd8be9..28c1e0d75 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/ExtendedSplashScreenTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/ExtendedSplashScreenTests.cs @@ -8,15 +8,15 @@ using Uno.Toolkit.UI; using Uno.UI.Extensions; using Uno.UI.RuntimeTests; - + #if IS_WINUI using Microsoft.UI.Xaml.Controls; #else using Windows.UI.Xaml.Controls; #endif - + namespace Uno.Toolkit.RuntimeTests.Tests; - + [TestClass] [RunsOnUIThread] public class ExtendedSplashScreenTests @@ -28,7 +28,7 @@ public class ExtendedSplashScreenTests public async Task Smoke_Test() { var host = await ExtendedSplashScreen.GetNativeSplashScreen().ConfigureAwait(false) ?? throw new Exception("Failed to load native splash screen"); - + #if !__MOBILE__ // ignore native platforms impl: ios,droid,macos var sut = host.FindFirstDescendant() ?? throw new Exception("Failed to find splash image control"); var tcs = new TaskCompletionSource<(bool Success, string? Message)>(); @@ -36,13 +36,13 @@ public async Task Smoke_Test() sut.ImageOpened += (s, e) => tcs.SetResult((Success: true, null)); sut.ImageFailed += (s, e) => tcs.SetResult((Success: false, e.ErrorMessage)); #endif - + await UnitTestUIContentHelperEx.SetContentAndWait(host); - + #if !__MOBILE__ if (await Task.WhenAny(tcs.Task, Task.Delay(2000)) != tcs.Task) throw new TimeoutException("Timed out waiting on image to load"); - + if ((await tcs.Task) is { Success: false, Message: var message }) throw new Exception($"Failed to load image: {message}"); #endif diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs index c9a0689dd..8d79200f0 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs @@ -38,7 +38,7 @@ internal class ResponsiveExtensionsTests public async Task ProvideValue_String_Value() { var sut = XamlHelper.LoadXaml(""" - + """); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Text)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); await UnitTestUIContentHelperEx.SetContentAndWait(sut); @@ -51,7 +51,7 @@ public async Task ProvideValue_String_Value() public async Task ProvideValue_String_SizeChange() { var sut = XamlHelper.LoadXaml(""" - + """); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Text)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); await UnitTestUIContentHelperEx.SetContentAndWait(sut); @@ -67,16 +67,16 @@ public async Task ProvideValue_String_SizeChange() public async Task ProvideValue_Color_Value() { var sut = XamlHelper.LoadXaml(""" - - -Red -Blue - - - - - + + Red + Blue + + + + + """); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Background)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); await UnitTestUIContentHelperEx.SetContentAndWait(sut); @@ -89,16 +89,16 @@ public async Task ProvideValue_Color_Value() public async Task ProvideValue_Color_SizeChange() { var sut = XamlHelper.LoadXaml(""" - - -Red -Blue - - - - - + + Red + Blue + + + + + """); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Background)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); await UnitTestUIContentHelperEx.SetContentAndWait(sut); @@ -114,17 +114,17 @@ public async Task ProvideValue_Color_SizeChange() public async Task ProvideValue_Orientation_Value() { var container = XamlHelper.LoadXaml(""" - - -Vertical -Horizontal - - - - - - - + + + Vertical + Horizontal + + + + + + + """); var sut = container.Child as StackPanel ?? throw new InvalidOperationException("Failed to resolve the SUT"); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Orientation)) ?? throw new InvalidOperationException("Failed to resolve the markup extension."); @@ -138,17 +138,17 @@ public async Task ProvideValue_Orientation_Value() public async Task ProvideValue_Orientation_SizeChange() { var container = XamlHelper.LoadXaml(""" - - -Vertical -Horizontal - - - - - - - + + + Vertical + Horizontal + + + + + + + """); var sut = container.Child as StackPanel ?? throw new InvalidOperationException("Failed to resolve the SUT"); var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Orientation)) ?? throw new InvalidOperationException("Failed to resolve the markup extension.");