Files
sbox-public/engine/Tests/Sandbox.Test.Engine/UI/Styles/AnimationRuntime.cs
Garry Newman d95169d8fa Unit Test Cleanup (#5064)
* Move all unit tests to Engine/Tests
* Fix Margin.EdgeSubtract
* Fix Capsule.Contains
* EnvironmentVariables.Remove if it's null
* Fixed ray trace never returning startedsolid
* Fix HistoryList.Navigate on empty list
* Fix GameObject.WorldPosition accepting NaNs
* Fix flex: initial expanding to the wrong grow/shrink
* Translation.TryConvert shouldn't throw on invalid enum strings
* Skip sound file tests on machines with no audio device
2026-06-12 13:23:50 +01:00

31 lines
1.0 KiB
C#

using Sandbox.UI;
namespace UITests;
[TestClass]
[DoNotParallelize] // Modifies UI System Global + the shared panel clock
public class AnimationRuntimeTest
{
/// <summary>
/// A finished finite animation should stop reporting changes, not re-run keyframes forever.
/// </summary>
[TestMethod]
public void FinishedAnimationSettles()
{
var r = new RootPanel();
r.StyleSheet.Parse( "@keyframes fade { 0% { opacity: 0; } 100% { opacity: 1; } }" );
var styles = new Styles();
Assert.IsTrue( styles.Set( "animation", "fade 1s 1 forwards" ) );
PanelRealTime.TimeNow = 0;
Assert.IsTrue( styles.ApplyAnimation( r ) ); // start the animation - mid-animation applies report a change
PanelRealTime.TimeNow = 1000; // far past the 1s duration
Assert.IsTrue( styles.ApplyAnimation( r ) ); // first apply after finishing holds the end frame (forwards) and reports one last change
// The animation is over - it must report no further change instead of animating forever
Assert.IsFalse( styles.ApplyAnimation( r ) );
}
}