Files
Chronos/tests/Chronos.App.Tests/Editor/CameraTabTests.cs
T
Alby96andClaude Opus 5.5 eeaddc2d14 fix(phase4): close the owner review 1 phase 4 findings
Routing sizes render jobs from the resolved preset, and the node wait
applies the same routing as the claim, so a re-routed job neither keeps a
stale size nor waits for a node that will never take it. Settings an older
server cannot read stay on this side for the remote editor, archive sync
and workspace push, and the reason is shown where it applies. A turn on
one side and a framing on the other merge as one conflict.

Orientation and framing fixes: an out-of-range crop turns with the content
it shows, the aspect text transposes exactly, the Rotation row counts
turns as shown on screen, and Reset framing undoes the orientation press
by press, so keyframes and aspect stay on their content. The advisor
places the horizon in the view as shown. A look at zero strength is
cleared and no longer reaches the motion vectors.

Preview changes: the middle button pans, a press inside a box with no
slack pans while zoomed, the selected box shows a ring, and screen readers
hear when the crop value changes. Tooltips in en and it updated; stale
translations of changed tooltips removed so they fall back to English.

Test changes: the pinned hash is OS-independent, and the tautological
encoder and warning assertions became real checks. Added a non-screen
test of the Straighten slider binding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 21:40:07 +01:00

312 lines
15 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Globalization;
using Chronos.App.Editor;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
/// <summary>
/// The Camera step's rows (owner review 1, R5/R6) and the Exposure step's Look group on an open session of the 96 × 64
/// synthetic sunset: the crop box locked to the aspect through Crop size, X and Y, the orientation controls, Straighten,
/// the look written only when it is not the identity, and every row's label and tooltip in English and Italian.
/// </summary>
[Serial]
public sealed class CameraTabTests
{
private static (EditorSession Session, FakeSequenceSource Source) Open(ProjectSettings? project = null)
{
var content = EditorFixture.Content(EditorFixture.Sunset, project);
var source = new FakeSequenceSource(EditorFixture.Sunset, content);
return (new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20)), source);
}
private static ProjectSettings WithAspect(string aspect, string? preset = null)
{
var project = new ProjectSettings();
project = project with { Camera = project.Camera with { Aspect = project.Camera.Aspect.WithManual(aspect) } };
return preset is null ? project : project with { Export = project.Export with { Preset = project.Export.Preset.WithManual(preset) } };
}
private static T Row<T>(IReadOnlyList<SettingRow> rows, string headerKey)
where T : SettingRow => (T)rows.Single(r => r.Header == Loc.L(headerKey));
private static void Refresh(IReadOnlyList<SettingRow> rows)
{
foreach (var row in rows) row.Refresh();
}
[Test]
public void TheRotationRowCountsTheTurnsAsShown()
{
var camera = new CameraSettings();
foreach (var op in new[] { OrientationOp.Mirror, OrientationOp.RotateRight, OrientationOp.RotateRight, OrientationOp.Flip, OrientationOp.RotateRight })
{
var before = CameraTab.ShownTurns(camera);
camera = OrientationEdit.Apply(camera, op);
var expected = op == OrientationOp.RotateRight ? (before + 1) % 4 : (4 - before) % 4;
Assert.Equal(expected, CameraTab.ShownTurns(camera), $"after {op}");
}
Assert.Equal(3, CameraTab.ShownTurns(new CameraSettings { Rotate = 90, Mirror = true }));
Assert.Equal(1, CameraTab.ShownTurns(new CameraSettings { Rotate = 90, Mirror = true, Flip = true }));
}
[Test]
public async Task CropSizeAndPlaceMoveTheBoxLockedToTheAspect()
{
var (session, _) = Open(WithAspect("9:16"));
await using (session)
{
var rows = CameraTab.FramingRows(session);
var size = Row<NumberRow>(rows, "Editor.Camera.CropSize");
var x = Row<NumberRow>(rows, "Editor.Camera.CropX");
var y = Row<NumberRow>(rows, "Editor.Camera.CropY");
Assert.Equal(1.0, size.Value, "no crop: the largest box");
Assert.Equal(0.0, x.Value);
Assert.True(x.IsApplicable, "a 9:16 box can move across a 3:2 frame");
Assert.False(y.IsApplicable, "but not up or down");
Assert.Equal(Loc.L("Tooltips.Editor.NotApplicable.NoSlack"), y.NotApplicableReason);
var ratio = session.CropLockRatio(session.Project);
x.Value = 1;
var box = CropFrame.Of(session.Project.Camera.Crop);
Assert.Approximately(1, box.Right, 1e-9, "Crop X +1 puts the box at the right edge");
Assert.Approximately(ratio, box.Width / box.Height, 1e-9, "locked to the aspect");
Refresh(rows);
size.Value = 0.5;
box = CropFrame.Of(session.Project.Camera.Crop);
Assert.Approximately(0.5, box.Height, 1e-9, "half the largest box");
Assert.Approximately(1, box.Right, 1e-9, "still at the right edge");
Assert.Approximately(ratio, box.Width / box.Height, 1e-9);
Refresh(rows);
Assert.True(y.IsApplicable, "a smaller box can move up and down");
Assert.Equal(1.0, x.Value);
Assert.Equal("+1.00", x.DisplayValue);
Assert.Equal("50 %", size.DisplayValue);
y.Value = -1;
Assert.Approximately(0, CropFrame.Of(session.Project.Camera.Crop).Y, 1e-9, "Crop Y −1 is the top");
Refresh(rows);
size.Value = 0.02;
Assert.Approximately(CropFrame.MinimumShare, CropFrame.Of(session.Project.Camera.Crop).Height, 1e-9, "never below a tenth of the largest box");
Assert.True(session.Project.Camera is { OffsetX: 0, OffsetY: 0 });
}
}
[Test]
public async Task TheWholeFrameAtItsOwnProportionsIsNoCrop()
{
var (session, _) = Open(WithAspect("source", "png-sequence"));
await using (session)
{
var rows = CameraTab.FramingRows(session);
var size = Row<NumberRow>(rows, "Editor.Camera.CropSize");
size.Value = 0.6;
Assert.NotNull(session.Project.Camera.Crop);
Refresh(rows);
size.Value = 1;
Assert.Null(session.Project.Camera.Crop, "the largest box is the whole view: nothing is stored");
Assert.Equal(ProjectSettings.BaseVersion, session.Project.RequiredFormat);
}
}
[Test]
public async Task ALegacyCropPlacedByOffsetsIsBakedInAtItsFirstEdit()
{
var legacy = WithAspect("1:1");
legacy = legacy with { Camera = legacy.Camera with { OffsetX = 1 } };
var (session, _) = Open(legacy);
await using (session)
{
var rows = CameraTab.FramingRows(session);
var before = CameraTab.LockedBox(session, session.Project);
Assert.Approximately(1, before.Right, 1e-9, "the render puts the square at the right");
Assert.Equal(1.0, Row<NumberRow>(rows, "Editor.Camera.CropX").Value, "the rows show it where it renders");
Row<NumberRow>(rows, "Editor.Camera.CropSize").Value = 0.8;
var after = CropFrame.Of(session.Project.Camera.Crop);
Assert.True(session.Project.Camera is { OffsetX: 0, OffsetY: 0 }, "the offsets are baked into the box");
Assert.Approximately(1, after.Right, 1e-9);
Assert.Approximately(0.8 * before.Height, after.Height, 1e-9);
}
}
[Test]
public async Task TheRotationButtonsTurnAndTheRowShowsTheStoredAngle()
{
var (session, _) = Open(WithAspect("16:9"));
await using (session)
{
var rows = CameraTab.FramingRows(session);
var rotation = Row<IconActionsRow>(rows, "Editor.Camera.Rotation");
Assert.Equal("0°", rotation.Value);
Assert.SequenceEqual([Loc.L("Editor.Camera.RotateLeft"), Loc.L("Editor.Camera.RotateRight")], rotation.Actions.Select(a => a.Name));
Assert.SequenceEqual(["Icon.RotateLeft", "Icon.RotateRight"], rotation.Actions.Select(a => a.GlyphKey));
rotation.Actions[1].Command.Execute(null);
Refresh(rows);
Assert.Equal("90°", rotation.Value);
rotation.Actions[0].Command.Execute(null);
rotation.Actions[0].Command.Execute(null);
Refresh(rows);
Assert.Equal("270°", rotation.Value);
Assert.Equal("9:16", session.Project.Camera.Aspect.Manual, "three quarter turns: portrait");
}
}
[Test]
public async Task MirrorAndFlipAreSwitchesThatMoveTheCropWithThePicture()
{
var project = WithAspect("16:9");
project = project with { Camera = project.Camera with { Crop = [0.1, 0.2, 0.3, 0.4] } };
var (session, _) = Open(project);
await using (session)
{
var rows = CameraTab.FramingRows(session);
var mirror = Row<SwitchRow>(rows, "Editor.Camera.Mirror");
var flip = Row<SwitchRow>(rows, "Editor.Camera.Flip");
Assert.False(mirror.IsOn);
mirror.IsOn = true;
Assert.True(session.Project.Camera.Mirror);
Assert.SequenceEqual([0.6, 0.2, 0.3, 0.4], session.Project.Camera.Crop!, "x becomes 1 − x − w");
flip.IsOn = true;
Assert.True(session.Project.Camera.Flip);
Assert.SequenceEqual([0.6, 0.4, 0.3, 0.4], session.Project.Camera.Crop!, "y becomes 1 − y − h");
Assert.True(session.Undo());
Refresh(rows);
Assert.False(flip.IsOn, "the switch follows undo");
Assert.True(mirror.IsOn);
}
}
[Test]
public async Task ASwitchTheProjectDoesNotTakeSpringsBack()
{
var (session, source) = Open();
await using (session)
{
var mirror = Row<SwitchRow>(CameraTab.FramingRows(session), "Editor.Camera.Mirror");
source.IsReadOnly = true;
mirror.IsOn = true;
Assert.False(mirror.IsOn);
Assert.False(session.Project.Camera.Mirror);
}
}
[Test]
public async Task StraightenStoresTenthsOfADegreeAndShowsTheGrid()
{
var (session, _) = Open();
await using (session)
{
var straighten = Row<NumberRow>(CameraTab.FramingRows(session), "Editor.Camera.Straighten");
Assert.True(straighten.ShowsGrid, "using it shows the preview's grid");
Assert.Equal((-15.0, 15.0), (straighten.Minimum, straighten.Maximum));
straighten.Value = -1.23;
Assert.Equal(-1.2, session.Project.Camera.Straighten);
Assert.Equal("−1.2°", straighten.DisplayValue);
Assert.Equal(ProjectSettings.CurrentVersion, session.Project.RequiredFormat, "a straighten needs format 2");
straighten.Value = 0.02;
Assert.Equal(0.0, session.Project.Camera.Straighten);
Assert.False(double.IsNegative(session.Project.Camera.Straighten), "never −0");
Assert.Equal(ProjectSettings.BaseVersion, session.Project.RequiredFormat, "level again: format 1");
Assert.True(CameraTab.FramingRows(session).OfType<NumberRow>().Count(r => r.ShowsGrid) == 1, "only Straighten");
}
}
[Test]
public async Task TheLookIsWrittenOnlyWhenAFilterIsChosen()
{
var (session, _) = Open();
await using (session)
{
var before = session.Project.ToJson();
var rows = ExposureTab.LookRows(session);
Assert.True(rows[0] is GroupRow, "the group starts with its name");
var filter = Row<ChoiceRow>(rows, "Editor.Look.Filter");
var strength = Row<NumberRow>(rows, "Editor.Look.Strength");
Assert.Equal("none", filter.Selected?.Value);
Assert.False(strength.IsApplicable, "no filter: Strength is n/a");
Assert.Equal(Loc.L("Tooltips.Editor.NotApplicable.NoLook"), strength.NotApplicableReason);
Assert.SequenceEqual(["None", "Mono", "Sepia", "Warm", "Cool", "Vivid", "Muted", "Fade"], filter.Options.Select(o => o.Label));
filter.Selected = filter.Options.Single(o => Equals(o.Value, "sepia"));
Assert.Equal(new LookSettings { Filter = "sepia" }.Filter, session.Project.Look?.Filter);
Assert.Null(session.Project.Look!.Strength, "100 % is the default");
Assert.Equal(ProjectSettings.CurrentVersion, session.Project.RequiredFormat);
Refresh(rows);
Assert.True(strength.IsApplicable);
Assert.Equal(1.0, strength.Value);
strength.Value = 0.6;
Assert.Equal(0.6, session.Project.Look!.Strength);
Assert.Equal("60 %", strength.DisplayValue);
strength.Value = 1;
Assert.Null(session.Project.Look!.Strength);
// 0 % would be a look that changes nothing yet changes the text: None is the one way there.
Assert.Equal(ExposureTab.MinimumStrength, strength.Minimum);
Assert.Null(ExposureTab.WithLook(session.Project, "sepia", 0).Look, "the identity is written as no look");
Refresh(rows);
filter.Selected = filter.Options.Single(o => Equals(o.Value, "none"));
Assert.Null(session.Project.Look, "the identity is no look");
Assert.Equal(ProjectSettings.BaseVersion, session.Project.RequiredFormat);
Assert.Equal(before, session.Project.ToJson(), "and the text is the one before the look");
}
}
[Test]
public void ALookOfANewerChronosKeepsWhatItDoesNotKnow()
{
var extra = ProjectSettings.FromJson("""{"look":{"filter":"warm","strength":0.4,"grain":0.2}}""");
var changed = ExposureTab.WithLook(extra, "cool", 0.4);
Assert.Equal("cool", changed.Look?.Filter);
Assert.Contains("\"grain\":0.2", changed.ToJson().Replace(" ", string.Empty, StringComparison.Ordinal));
}
[Test]
public async Task EveryRowHasATooltipAndALabelOfAtMostThreeWordsInEnglishAndItalian()
{
var (session, _) = Open(WithAspect("9:16"));
await using (session)
{
var missing = new List<string>();
void OnMissing(string key) => missing.Add(key);
Loc.MissingKey += OnMissing;
try
{
foreach (var culture in new[] { "en", "it" })
{
Loc.SetCulture(CultureInfo.GetCultureInfo(culture));
var rows = CameraTab.FramingRows(session).Concat(ExposureTab.LookRows(session)).ToList();
var labels = new List<string>();
foreach (var row in rows)
{
labels.Add(row.Header);
Assert.False(string.IsNullOrWhiteSpace(row.ToolTip), $"{culture}: {row.Header} has a tooltip");
Assert.NotEqual(row.Header, row.ToolTip, $"{culture}: the tooltip explains, it does not repeat the label");
if (row is IconActionsRow icons)
{
foreach (var action in icons.Actions)
{
labels.Add(action.Name);
Assert.False(string.IsNullOrWhiteSpace(action.ToolTip), $"{culture}: {action.Name} has a tooltip");
}
}
if (row is ChoiceRow choices) labels.AddRange(choices.Options.Select(o => o.Label));
}
labels.AddRange(new[] { "Editor.Camera.ResetFraming", "Editor.Export.OutputSize" }.Select(k => Loc.L(k)));
foreach (var key in new[] { "Tooltips.Editor.Camera.ResetFraming", "Tooltips.Editor.Camera.ResetFramingNone", "Tooltips.Editor.Export.OutputSize" })
Assert.False(string.IsNullOrWhiteSpace(Loc.L(key)), key);
foreach (var label in labels)
Assert.LessOrEqual(label.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length, 3, $"{culture}: \"{label}\" is at most three words");
}
}
finally
{
Loc.MissingKey -= OnMissing;
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
Assert.Empty(missing);
}
}
}