| … | … | @@ -0,0 +1,76 @@ |
| 1 | using System; |
| 2 | using System.Linq; |
| 3 | |
| 4 | using Avalonia; |
| 5 | using Avalonia.Controls; |
| 6 | using Avalonia.Headless.XUnit; |
| 7 | using Avalonia.LogicalTree; |
| 8 | |
| 9 | using IFSEngine.Animation; |
| 10 | |
| 11 | using IFSRenderer.AvaloniaShell.Tests.Fakes; |
| 12 | |
| 13 | using Xunit; |
| 14 | |
| 15 | namespace IFSRenderer.AvaloniaShell.Tests; |
| 16 | |
| 17 | /// <summary> |
| 18 | /// Editing a keyframe has to reach the viewport. |
| 19 | /// </summary> |
| 20 | /// <remarks> |
| 21 | /// <para> |
| 22 | /// "if you edit a keyframe there it won't update the viewport until you change the frame." |
| 23 | /// </para> |
| 24 | /// <para> |
| 25 | /// The same ORDERING bug this harness was built for, in a third place. <c>TimeChanged</c> |
| 26 | /// re-evaluated the dopesheet onto the fractal and invalidated the params buffer; |
| 27 | /// <c>Changed</c> - which every keyframe edit raises - pushed the panel state and stopped. The |
| 28 | /// fractal kept the values the last <c>EvaluateAt</c> had written, so the edit became visible |
| 29 | /// only when the playhead next moved and re-evaluated for its own reasons. |
| 30 | /// </para> |
| 31 | /// <para> |
| 32 | /// Asserted through the queue rather than by reading the fractal: the point is that the engine |
| 33 | /// was asked to re-render, and <see cref="FakeRenderQueue"/> defers exactly as the real service |
| 34 | /// does, so a fix that merely mutated the model on the UI thread would not pass. |
| 35 | /// </para> |
| 36 | /// </remarks> |
| 37 | public class AnimationViewportRefreshTests |
| 38 | { |
| 39 | [AvaloniaFact] |
| 40 | public void Editing_a_keyframe_re_evaluates_without_moving_the_playhead() |
| 41 | { |
| 42 | (MainWindow window, FakeRenderQueue queue) = MainWindowHarness.Start(); |
| 43 | |
| 44 | // By name, and through the LOGICAL tree: the animation panel lives in a tab that the |
| 45 | // headless run never realizes, so it has no visual tree to walk. |
| 46 | AnimationPanel panel = window.FindControl<AnimationPanel>("AnimationView"); |
| 47 | Assert.NotNull(panel); |
| 48 | Dopesheet sheet = queue.Current.Dopesheet; |
| 49 | |
| 50 | // Two keys on one channel, made the way the ◇ diamond makes them. |
| 51 | foreach ((double t, double v) in new[] { (0.0, 1.0), (4.0, 5.0) }) |
| 52 | sheet.AddOrUpdateChannel("Brightness", "Brightness", |
| 53 | TimeOnly.FromTimeSpan(TimeSpan.FromSeconds(t)), v); |
| 54 | panel.SetFractal(queue.Current); |
| 55 | panel.ReloadChannels(); |
| 56 | MainWindowHarness.Settle(queue); |
| 57 | |
| 58 | CurveCanvas curve = panel.GetLogicalDescendants().OfType<CurveCanvas>().Single(); |
| 59 | Keyframe key = sheet.Channels["Brightness"].Keyframes[0]; |
| 60 | curve.BeginDrag(key, new Point(0, 0)); |
| 61 | |
| 62 | queue.Renderer.Calls.Clear(); |
| 63 | int postsBefore = queue.PostCount; |
| 64 | |
| 65 | // The edit, with the playhead left exactly where it was. |
| 66 | key.Value = 42; |
| 67 | curve.EndDrag(); |
| 68 | MainWindowHarness.Settle(queue); |
| 69 | |
| 70 | Assert.True(queue.PostCount > postsBefore, |
| 71 | "editing a keyframe queued no engine work at all"); |
| 72 | Assert.Contains(nameof(FakeRenderer.InvalidateParamsBuffer), queue.Renderer.Calls); |
| 73 | // The evaluation ran, so the fractal now carries the edited value. |
| 74 | Assert.Equal(42, queue.Current.Brightness, 6); |
| 75 | } |
| 76 | } |