Skip to content

Commit e33f6dd

Browse files
committed
Added unit tests for ExpressionFunctions.ColorLerpRgb and ColorLerpHsl
1 parent 0637901 commit e33f6dd

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

components/Animations/tests/Animations.Tests.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
</PropertyGroup>
1111
<ItemGroup>
1212
<Compile Include="$(MSBuildThisFileDirectory)Test_AnimationBuilderStart.cs" />
13+
<Compile Include="$(MSBuildThisFileDirectory)Test_ExpressionFunctions.cs" />
1314
</ItemGroup>
1415
</Project>

components/Animations/tests/Test_AnimationBuilderStart.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace AnimationsExperiment.Tests;
1010

1111
[TestClass]
12-
[TestCategory("Test_AnimationBuilderStart")]
12+
[TestCategory(nameof(Test_AnimationBuilderStart))]
1313
public class Test_AnimationBuilderStart : VisualUITestBase
1414
{
1515
[TestMethod]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if WINUI2
6+
using Windows.UI.Composition;
7+
using Windows.UI.Xaml.Hosting;
8+
#elif WINUI3
9+
using Microsoft.UI.Composition;
10+
using Microsoft.UI.Xaml.Hosting;
11+
#endif
12+
13+
using System.Numerics;
14+
using CommunityToolkit.Tests;
15+
using CommunityToolkit.Tooling.TestGen;
16+
using CommunityToolkit.WinUI.Animations.Expressions;
17+
18+
namespace AnimationsExperiment.Tests;
19+
20+
[TestClass]
21+
[TestCategory(nameof(Test_ExpressionFunctions))]
22+
public partial class Test_ExpressionFunctions : VisualUITestBase
23+
{
24+
[UIThreadTestMethod]
25+
public void ColorLerpRgb(Grid rootGrid)
26+
{
27+
// See https://github.com/CommunityToolkit/Windows/issues/303
28+
var compositor = ElementCompositionPreview.GetElementVisual(rootGrid).Compositor;
29+
var brush = compositor.CreateColorBrush();
30+
var temp = ExpressionFunctions.ColorRgb(255f, 255f, 0f, 0f);
31+
var color = ExpressionFunctions.ColorLerpRgb(temp, temp, 0.5f);
32+
33+
brush.StartAnimation("Color", color);
34+
35+
var visual = compositor.CreateSpriteVisual();
36+
visual.Brush = brush;
37+
visual.RelativeSizeAdjustment = Vector2.One;
38+
39+
ElementCompositionPreview.SetElementChildVisual(rootGrid, visual);
40+
}
41+
42+
[UIThreadTestMethod]
43+
public void ColorLerpHsl(Grid rootGrid)
44+
{
45+
// See https://github.com/CommunityToolkit/Windows/issues/303
46+
var compositor = ElementCompositionPreview.GetElementVisual(rootGrid).Compositor;
47+
var brush = compositor.CreateColorBrush();
48+
var temp = ExpressionFunctions.ColorHsl(255f, 255f, 0f);
49+
var color = ExpressionFunctions.ColorLerpHsl(temp, temp, 0.5f);
50+
51+
brush.StartAnimation("Color", color);
52+
53+
var visual = compositor.CreateSpriteVisual();
54+
visual.Brush = brush;
55+
visual.RelativeSizeAdjustment = Vector2.One;
56+
57+
ElementCompositionPreview.SetElementChildVisual(rootGrid, visual);
58+
}
59+
}

0 commit comments

Comments
 (0)