From 13923312d1b00a329e0d33d229681b21b6322c49 Mon Sep 17 00:00:00 2001 From: xiaoy312 Date: Thu, 9 Nov 2023 16:45:02 -0500 Subject: [PATCH] chore: fix drawer flyout tests --- .../Tests/DrawerFlyoutTests.cs | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/DrawerFlyoutTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/DrawerFlyoutTests.cs index 3d41562e1..67d906ea6 100644 --- a/src/Uno.Toolkit.RuntimeTests/Tests/DrawerFlyoutTests.cs +++ b/src/Uno.Toolkit.RuntimeTests/Tests/DrawerFlyoutTests.cs @@ -28,14 +28,12 @@ namespace Uno.Toolkit.RuntimeTests.Tests; [RunsOnUIThread] internal class DrawerFlyoutTests { -#if !DEBUG [TestCleanup] // note that this is only run, after each [TestMethod], **not** between [DataRow]. public void CloseOpenPopup() { // killing the host, will close the associated popup. UnitTestsUIContentHelper.Content = null; } -#endif [TestMethod] public async Task Can_Open() @@ -58,7 +56,7 @@ public async Task Can_Open() GetOpenPopup(); } -#if false // uno#14372: can't use "xmlns'd attached property style setter" with XamlReader +#if !HAS_UNO // uno#14372: can't use "xmlns'd attached property style setter" with XamlReader [TestMethod] #endif public async Task AttachedProperty_Inheritance() @@ -68,7 +66,7 @@ public async Task AttachedProperty_Inheritance() @@ -82,13 +80,18 @@ public async Task AttachedProperty_Inheritance() await UnitTestUIContentHelperEx.SetContentAndWait(SUT); SUT.Flyout.ShowAt(SUT); +#if !HAS_UNO + await UnitTestUIContentHelperEx.WaitFor(() => GetOpenPopupsCompat().Any(), message: "Timeout waiting on flyout open"); +#endif + var popup = GetOpenPopup(); - var presenter = popup.Child.GetFirstDescendant() ?? throw new InvalidOperationException("DrawerFlyoutPresenter not found"); + var child = popup.Child as FlyoutPresenter ?? throw new InvalidOperationException("FlyoutPresenter not found"); + await UnitTestsUIContentHelper.WaitForLoaded(child); - // note: don't need to wait for DrawerFlyoutPresenter to be loaded here, since we don't care about its measurements... + var presenter = popup.Child.GetFirstDescendant() ?? throw new InvalidOperationException("DrawerFlyoutPresenter not found"); Assert.AreEqual(presenter.OpenDirection, DrawerOpenDirection.Left); - Assert.AreEqual(presenter.DrawerDepth, new GridLength(3.12, GridUnitType.Star)); + Assert.AreEqual(presenter.DrawerDepth, new GridLength(312, GridUnitType.Star)); Assert.AreEqual(presenter.IsGestureEnabled, true); Assert.AreEqual((presenter.LightDismissOverlayBackground as SolidColorBrush)?.Color, Colors.Pink); } @@ -100,22 +103,22 @@ public async Task AttachedProperty_Inheritance() [DataRow(DrawerOpenDirection.Down)] public async Task OpenDirection_Layout(DrawerOpenDirection openDirection) { -#if false // uno#14372: can't use "xmlns'd attached property style setter" with XamlReader - //var SUT = BuildButtonFlyout($$""" - // - // - // - // - // - // - // - // - //"""); +#if !HAS_UNO // uno#14372: can't use "xmlns'd attached property style setter" with XamlReader + var SUT = BuildButtonFlyout($$""" + + + + + + + + + """); #else var SUT = new Button { @@ -141,7 +144,10 @@ void Setup(DrawerFlyoutPresenter presenter) await UnitTestUIContentHelperEx.SetContentAndWait(SUT); SUT.Flyout.ShowAt(SUT); - // Flyout.ShowAt guarantees its presence in visual tree, but it is not loaded, and we wont be able to read any measurements. +#if !HAS_UNO + await UnitTestUIContentHelperEx.WaitFor(() => GetOpenPopupsCompat().Any(), message: "Timeout waiting on flyout open"); +#endif + var popup = GetOpenPopup(); var child = popup.Child as FlyoutPresenter ?? throw new InvalidOperationException("FlyoutPresenter not found"); await UnitTestsUIContentHelper.WaitForLoaded(child); @@ -165,6 +171,10 @@ void Setup(DrawerFlyoutPresenter presenter) ? (AvailableLength: presenter.ActualWidth, ContentLength: content.ActualWidth, PrimaryAxis: nameof(presenter.Width)) : (AvailableLength: presenter.ActualHeight, ContentLength: content.ActualHeight, PrimaryAxis: nameof(presenter.Height)); Assert.AreEqual(ctx.AvailableLength * 0.5, ctx.ContentLength, ctx.AvailableLength * 0.05, $"Invalid content size, expecting it to be half of given: {presenter.ActualWidth}x{presenter.ActualHeight} vs {content.ActualWidth}x{content.ActualHeight}, axis={ctx.PrimaryAxis}, direction={openDirection}"); + +#if !HAS_UNO + UnitTestsUIContentHelper.Content = null; +#endif } private static Button BuildButtonFlyout(string flyoutXaml, string? header = null) @@ -184,7 +194,7 @@ private static IReadOnlyList GetOpenPopupsCompat() { return VisualTreeHelper #if IS_WINUI - .GetOpenPopupsForXamlRoot(Window.Current.Content.XamlRoot); + .GetOpenPopupsForXamlRoot(UnitTestsUIContentHelper.RootElement?.XamlRoot); #else .GetOpenPopups(UnitTestsUIContentHelper.CurrentTestWindow); #endif