From ed11b75b815f07d5bc429059bd7ecc5207378b0a Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 20 Sep 2022 23:37:25 +0200 Subject: [PATCH] Added failing animation test. --- .../Styling/StyleTests.cs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs b/tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs index a8dbfc7142..fe444bbef4 100644 --- a/tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs +++ b/tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using Avalonia.Animation; +using Avalonia.Base.UnitTests.Animation; using Avalonia.Controls; using Avalonia.Controls.Templates; using Avalonia.Data; @@ -794,6 +796,56 @@ namespace Avalonia.Base.UnitTests.Styling Assert.Throws(() => parent.Children.Add(nested)); } + [Fact] + public void Animations_Should_Be_Activated_And_Deactivated() + { + Style style = new Style(x => x.OfType().Class("foo")) + { + Animations = + { + new Avalonia.Animation.Animation + { + Duration = TimeSpan.FromSeconds(1), + Children = + { + new KeyFrame + { + Setters = + { + new Setter { Property = Class1.DoubleProperty, Value = 5.0 } + }, + }, + new KeyFrame + { + Setters = + { + new Setter { Property = Class1.DoubleProperty, Value = 10.0 } + }, + Cue = new Cue(1d) + } + }, + } + } + }; + + var clock = new TestClock(); + var target = new Class1 { Clock = clock }; + + style.TryAttach(target, null); + + Assert.Equal(0.0, target.Double); + + target.Classes.Add("foo"); + clock.Step(TimeSpan.Zero); + Assert.Equal(5.0, target.Double); + + clock.Step(TimeSpan.FromSeconds(0.5)); + Assert.Equal(7.5, target.Double); + + target.Classes.Remove("foo"); + Assert.Equal(0.0, target.Double); + } + private class Class1 : Control { public static readonly StyledProperty FooProperty = @@ -802,6 +854,9 @@ namespace Avalonia.Base.UnitTests.Styling public static readonly StyledProperty ChildProperty = AvaloniaProperty.Register(nameof(Child)); + public static readonly StyledProperty DoubleProperty = + AvaloniaProperty.Register(nameof(Double)); + public string Foo { get { return GetValue(FooProperty); } @@ -814,6 +869,12 @@ namespace Avalonia.Base.UnitTests.Styling set => SetValue(ChildProperty, value); } + public double Double + { + get => GetValue(DoubleProperty); + set => SetValue(DoubleProperty, value); + } + protected override Size MeasureOverride(Size availableSize) { throw new NotImplementedException();