Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: UWP Build #1263

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/Uno.Toolkit.RuntimeTests/Tests/AncestorBindingTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
// FindFirstDescendent is not available in UWP

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in toolkit, use GetFirstDescendent which is an any-plat impl
the Find... from uno.ui is uno-only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either case, this seems wrong way to fix the problem?

Copy link
Member

@Youssef1313 Youssef1313 Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small note here, FindFirstDescendent from Uno.UI is both Uno + WinAppSDK (when Uno.WinUI package is referenced) (but not available in Windows UWP)

https://github.com/unoplatform/uno/blob/9450602cda0194514512ba9572dfc7f745fdfae0/src/Uno.UI.Toolkit/Uno.UI.Toolkit.Windows.csproj#L31-L36

#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;
using Uno.Toolkit.RuntimeTests.Tests.TestPages;


#if IS_WINUI
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand All @@ -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
Expand All @@ -29,33 +32,34 @@ public async Task Ancestor_TopLevel_PageBinding()
{
var setup = new AncestorBindingTest();
await UnitTestUIContentHelperEx.SetContentAndWait(setup);

var sut = setup.FindFirstDescendant<TextBlock>("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<ListView>("TopLevelListView") ?? throw new Exception("Failed to find TopLevelListView");
var container = lv.ContainerFromIndex(0);
var sut = (container as FrameworkElement)?.FindFirstDescendant<TextBlock>("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<ListView>("TopLevelListView") ?? throw new Exception("Failed to find TopLevelListView");
var container = lv.ContainerFromIndex(0);
var sut = (container as FrameworkElement)?.FindFirstDescendant<TextBlock>("NestedLvTextBlock2") ?? throw new Exception("Failed to find NestedLvTextBlock2");
Assert.AreEqual(sut.Text, lv.Tag);
}
}
#endif
24 changes: 14 additions & 10 deletions src/Uno.Toolkit.RuntimeTests/Tests/DrawerTests.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
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;
#else
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;
#endif

namespace Uno.Toolkit.RuntimeTests.Tests;

[TestClass]
[RunsOnUIThread]
internal class DrawerTests
Expand All @@ -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<Border>(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
22 changes: 13 additions & 9 deletions src/Uno.Toolkit.RuntimeTests/Tests/ExtendedSplashScreenTests.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Image>() ?? 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
86 changes: 43 additions & 43 deletions src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public async Task ProvideValue_String_Value()
{
var sut = XamlHelper.LoadXaml<TextBlock>("""
<TextBlock Text="{utu:Responsive Narrow=asd, Wide=qwe}" />
<TextBlock Text="{utu:Responsive Narrow=asd, Wide=qwe}" />

Check failure on line 41 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.

Check failure on line 41 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.
""");
var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Text)) ?? throw new InvalidOperationException("Failed to resolve the markup extension.");
await UnitTestUIContentHelperEx.SetContentAndWait(sut);
Expand All @@ -51,7 +51,7 @@
public async Task ProvideValue_String_SizeChange()
{
var sut = XamlHelper.LoadXaml<TextBlock>("""
<TextBlock Text="{utu:Responsive Narrow=asd, Wide=qwe}" />
<TextBlock Text="{utu:Responsive Narrow=asd, Wide=qwe}" />

Check failure on line 54 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.

Check failure on line 54 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.
""");
var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Text)) ?? throw new InvalidOperationException("Failed to resolve the markup extension.");
await UnitTestUIContentHelperEx.SetContentAndWait(sut);
Expand All @@ -67,16 +67,16 @@
public async Task ProvideValue_Color_Value()
{
var sut = XamlHelper.LoadXaml<Border>("""
<Border Width="30"
<Border Width="30"

Check failure on line 70 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.

Check failure on line 70 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.
Height="30">
<Border.Resources>
<SolidColorBrush x:Key="BorderRed">Red</SolidColorBrush>
<SolidColorBrush x:Key="BorderBlue">Blue</SolidColorBrush>
</Border.Resources>
<Border.Background>
<utu:Responsive Narrow="{StaticResource BorderRed}" Wide="{StaticResource BorderBlue}" />
</Border.Background>
</Border>
<Border.Resources>
<SolidColorBrush x:Key="BorderRed">Red</SolidColorBrush>
<SolidColorBrush x:Key="BorderBlue">Blue</SolidColorBrush>
</Border.Resources>
<Border.Background>
<utu:Responsive Narrow="{StaticResource BorderRed}" Wide="{StaticResource BorderBlue}" />
</Border.Background>
</Border>
""");
var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Background)) ?? throw new InvalidOperationException("Failed to resolve the markup extension.");
await UnitTestUIContentHelperEx.SetContentAndWait(sut);
Expand All @@ -89,16 +89,16 @@
public async Task ProvideValue_Color_SizeChange()
{
var sut = XamlHelper.LoadXaml<Border>("""
<Border Width="30"
<Border Width="30"

Check failure on line 92 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.

Check failure on line 92 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.
Height="30">
<Border.Resources>
<SolidColorBrush x:Key="BorderRed">Red</SolidColorBrush>
<SolidColorBrush x:Key="BorderBlue">Blue</SolidColorBrush>
</Border.Resources>
<Border.Background>
<utu:Responsive Narrow="{StaticResource BorderRed}" Wide="{StaticResource BorderBlue}" />
</Border.Background>
</Border>
<Border.Resources>
<SolidColorBrush x:Key="BorderRed">Red</SolidColorBrush>
<SolidColorBrush x:Key="BorderBlue">Blue</SolidColorBrush>
</Border.Resources>
<Border.Background>
<utu:Responsive Narrow="{StaticResource BorderRed}" Wide="{StaticResource BorderBlue}" />
</Border.Background>
</Border>
""");
var ext = ResponsiveExtension.GetInstanceFor(sut, nameof(sut.Background)) ?? throw new InvalidOperationException("Failed to resolve the markup extension.");
await UnitTestUIContentHelperEx.SetContentAndWait(sut);
Expand All @@ -114,17 +114,17 @@
public async Task ProvideValue_Orientation_Value()
{
var container = XamlHelper.LoadXaml<Border>("""
<Border>
<Border.Resources>
<Orientation x:Key="NarrowOrientation">Vertical</Orientation>
<Orientation x:Key="WideOrientation">Horizontal</Orientation>
</Border.Resources>
<StackPanel Orientation="{utu:Responsive Narrow={StaticResource NarrowOrientation}, Wide={StaticResource WideOrientation}}">
<TextBlock Text="A" />
<TextBlock Text="B" />
<TextBlock Text="C" />
</StackPanel>
</Border>
<Border>

Check failure on line 117 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.
<Border.Resources>
<Orientation x:Key="NarrowOrientation">Vertical</Orientation>
<Orientation x:Key="WideOrientation">Horizontal</Orientation>
</Border.Resources>
<StackPanel Orientation="{utu:Responsive Narrow={StaticResource NarrowOrientation}, Wide={StaticResource WideOrientation}}">
<TextBlock Text="A" />
<TextBlock Text="B" />
<TextBlock Text="C" />
</StackPanel>
</Border>
""");
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.");
Expand All @@ -138,17 +138,17 @@
public async Task ProvideValue_Orientation_SizeChange()
{
var container = XamlHelper.LoadXaml<Border>("""
<Border>
<Border.Resources>
<Orientation x:Key="NarrowOrientation">Vertical</Orientation>
<Orientation x:Key="WideOrientation">Horizontal</Orientation>
</Border.Resources>
<StackPanel Orientation="{utu:Responsive Narrow={StaticResource NarrowOrientation}, Wide={StaticResource WideOrientation}}">
<TextBlock Text="A" />
<TextBlock Text="B" />
<TextBlock Text="C" />
</StackPanel>
</Border>
<Border>

Check failure on line 141 in src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Line does not start with the same whitespace as the closing line of the raw string literal.
<Border.Resources>
<Orientation x:Key="NarrowOrientation">Vertical</Orientation>
<Orientation x:Key="WideOrientation">Horizontal</Orientation>
</Border.Resources>
<StackPanel Orientation="{utu:Responsive Narrow={StaticResource NarrowOrientation}, Wide={StaticResource WideOrientation}}">
<TextBlock Text="A" />
<TextBlock Text="B" />
<TextBlock Text="C" />
</StackPanel>
</Border>
""");
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.");
Expand All @@ -161,7 +161,6 @@
Assert.AreEqual(Orientation.Horizontal, sut.Orientation);
}
}
#endif

[TestClass]
[RunsOnUIThread]
Expand Down Expand Up @@ -207,3 +206,4 @@
}
}
}
#endif
Loading