From a241159d73d5d7524450b0aa1493c659e382a2b9 Mon Sep 17 00:00:00 2001 From: Silviu Obreja Date: Mon, 27 Nov 2023 15:27:33 -0500 Subject: [PATCH] chore: Fix Runtime Tests --- .../Tests/ResponsiveExtensionsTests.cs | 100 +++++++++++++++--- .../Helpers/ResponsiveHelper.cs | 11 +- 2 files changed, 89 insertions(+), 22 deletions(-) diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs index 9c198b840..5a43898fb 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs @@ -39,26 +39,26 @@ public async Task ProvideValue_String_Initial() } #if !IS_UWP || HAS_UNO - [TestMethod] - public async Task ProvideValue_String_SizeChange() + [TestMethod] + public async Task ProvideValue_String_SizeChange() + { + using (ResponsiveHelper.UsingDebuggableInstance()) { - using (ResponsiveHelper.UsingDebuggableInstance()) - { - ResponsiveHelper.SetDebugSize(new Size(300, 400)); + ResponsiveHelper.SetDebugSize(new Size(300, 400)); - var host = XamlHelper.LoadXaml(""" - - """); + var host = XamlHelper.LoadXaml(""" + + """); - await UnitTestUIContentHelperEx.SetContentAndWait(host); + await UnitTestUIContentHelperEx.SetContentAndWait(host); - Assert.AreEqual("asd", host.Text); + Assert.AreEqual("asd", host.Text); - ResponsiveHelper.SetDebugSize(new Size(800, 400)); + ResponsiveHelper.SetDebugSize(new Size(800, 400)); - Assert.AreEqual("qwe", host.Text); - } + Assert.AreEqual("qwe", host.Text); } + } #endif [TestMethod] @@ -74,7 +74,7 @@ public async Task ProvideValue_Color_Initial() Red Blue - + """); @@ -86,20 +86,52 @@ public async Task ProvideValue_Color_Initial() } } +#if !IS_UWP || HAS_UNO [TestMethod] - public async Task ProvideValue_Orientation_Initial() + public async Task ProvideValue_Color_SizeChange() { using (ResponsiveHelper.UsingDebuggableInstance()) { + ResponsiveHelper.SetDebugSize(new Size(300, 400)); + + var host = XamlHelper.LoadXaml(""" + + + Red + Blue + + + + """); + + var border = (Border)host.FindName("MyBorder"); + + await UnitTestUIContentHelperEx.SetContentAndWait(host); + + Assert.AreEqual(Colors.Red, ((SolidColorBrush)border.Background).Color); + ResponsiveHelper.SetDebugSize(new Size(800, 400)); + Assert.AreEqual(Colors.Blue, ((SolidColorBrush)border.Background).Color); + + } + } +#endif + + [TestMethod] + public async Task ProvideValue_Orientation_Initial() + { + using (ResponsiveHelper.UsingDebuggableInstance()) + { + ResponsiveHelper.SetDebugSize(new Size(300, 400)); + var host = XamlHelper.LoadXaml(""" Vertical Horizontal - + @@ -111,7 +143,43 @@ public async Task ProvideValue_Orientation_Initial() await UnitTestUIContentHelperEx.SetContentAndWait(host); + Assert.AreEqual(Orientation.Vertical, stackPanel.Orientation); + } + } + +#if !IS_UWP || HAS_UNO + [TestMethod] + public async Task ProvideValue_Orientation_SizeChange() + { + using (ResponsiveHelper.UsingDebuggableInstance()) + { + ResponsiveHelper.SetDebugSize(new Size(300, 400)); + + var host = XamlHelper.LoadXaml(""" + + + Vertical + Horizontal + + + + + + + + """); + + var stackPanel = (StackPanel)host.FindName("MyStackPanel"); + + await UnitTestUIContentHelperEx.SetContentAndWait(host); + + Assert.AreEqual(Orientation.Vertical, stackPanel.Orientation); + + ResponsiveHelper.SetDebugSize(new Size(800, 400)); + Assert.AreEqual(Orientation.Horizontal, stackPanel.Orientation); } } +#endif + } diff --git a/src/Uno.Toolkit.UI/Helpers/ResponsiveHelper.cs b/src/Uno.Toolkit.UI/Helpers/ResponsiveHelper.cs index 024129315..c3f319d93 100644 --- a/src/Uno.Toolkit.UI/Helpers/ResponsiveHelper.cs +++ b/src/Uno.Toolkit.UI/Helpers/ResponsiveHelper.cs @@ -132,9 +132,11 @@ public void HookupEvent(Window window) window.SizeChanged += OnWindowSizeChanged; } - private void OnWindowSizeChanged(object sender, WindowSizeChangedEventArgs e) + private void OnWindowSizeChanged(object sender, WindowSizeChangedEventArgs e) => OnWindowSizeChanged(e.Size); + + private void OnWindowSizeChanged(Size size) { - WindowSize = e.Size; + WindowSize = size; // Clean up collected references _callbacks.RemoveAll(reference => !reference.IsAlive); @@ -185,8 +187,5 @@ internal static IDisposable UsingDebuggableInstance() return Disposable.Create(() => UseDebuggableInstance = false); } - internal static void SetDebugSize(Size size) - { - _debugInstance.WindowSize = size; - } + internal static void SetDebugSize(Size size) => _debugInstance.OnWindowSizeChanged(size); }