Files
Chronos/tests/Chronos.App.Tests/Editor/RenderHeaderTests.cs
T
Alby96andClaude Opus 5.5 7701fcac3e feat(P5): Render menu with grouped presets, Save frame and a fixed-width header
The editor header's button now reads "Render" whatever the preset, so its
width stays the same in every language, and the tooltip carries the preset,
size, codec, fps and estimates (owner review 1, R3, decisions 1, 2 and 12).
Its menu is rebuilt every time it opens. Top to bottom it lists:
- Recommended, the batch and up to three recent presets (taken from the
  render history);
- Other presets, grouped by Video, Social, Intermediate, Sequence and Web,
  each entry with a details line;
- Render batch, Add to queue, Save frame (PNG, JPEG or TIFF 16-bit) and
  Videos.
SplitButton learns hierarchical, two-line menu entries.

Still jobs come from EditorSession.StillRequests and carry the frame index
and the photo hash. Save frame stays disabled, with the reason in its
tooltip, in these cases:
- the sequence is read-only;
- there is no renderable frame;
- the server is older than settings format 3;
- the project is a workspace one, which has no still route yet (the
  IProjectStills hook is left for it).
A playback render is now gated on the format of the job's own export.
The project menu gains "Save project file".

Refs #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 02:18:24 +01:00

145 lines
7.3 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.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using Chronos.App.Infrastructure;
using Chronos.App.Tests.Windows;
using Chronos.Core.Localization;
using Chronos.Core.Render;
using Chronos.Testing;
using Chronos.Ui.Visuals;
namespace Chronos.App.Tests.Editor;
/// <summary>
/// The editor's header in the real main window at the 1200 px minimum (owner review 1, R3, decision 1): "Render ▾" keeps one
/// width whatever the preset in every language, and its menu shows the presets as two-line entries with the current one checked.
/// </summary>
[WindowsOnly]
[Serial]
[Timeout(300_000)]
public sealed class RenderHeaderTests
{
private static readonly string[] Presets = ["1080p-h264", "8k-hevc10-archive", "gif-preview", "tiff16-sequence", "vertical-1080x1920"];
[Test]
public Task TheHeaderKeepsItsWidthWhateverThePresetInEveryLanguage() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
app.Window.Width = 1200;
app.Window.Height = 788;
var id = await app.Sample.FillEditorAsync();
app.Shell.OpenSequence(id);
await app.Shell.Sequence.OpenAsync(id);
var editor = Assert.NotNull(app.Shell.Sequence.Editor);
try
{
foreach (var language in Languages.Shipped)
{
UiLanguage.Apply(language);
var widths = new List<double>();
foreach (var preset in Presets)
{
editor.SelectPresetCommand.Execute(preset);
await CheckedAsync(editor, preset, app.Window);
var button = RenderButton(app.Window);
Assert.Equal(Loc.L("Editor.RenderButton"), button.Content, $"{language}: no preset name on the button");
var right = button.TranslatePoint(new Point(button.ActualWidth, 0), app.Window).X;
var left = button.TranslatePoint(new Point(0, 0), app.Window).X;
Assert.True(Math.Min(left, right) >= 0 && Math.Max(left, right) <= app.Window.ActualWidth,
$"{language}, {preset}: Render spans {Math.Min(left, right):0}–{Math.Max(left, right):0} px in a {app.Window.ActualWidth:0} px window");
widths.Add(Math.Round(button.ActualWidth, 1));
}
Assert.True(widths.Max() - widths.Min() < 0.5, $"{language}: Render is {string.Join(", ", widths)} px wide across the presets");
}
}
finally
{
UiLanguage.Apply("en");
await app.Shell.Sequence.CloseAsync();
}
});
[Test]
public Task TheRenderMenuShowsTwoLinePresetsWithTheCurrentOneChecked() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
app.Window.Width = 1200;
app.Window.Height = 788;
var id = await app.Sample.FillEditorAsync();
app.Shell.OpenSequence(id);
await app.Shell.Sequence.OpenAsync(id);
var editor = Assert.NotNull(app.Shell.Sequence.Editor);
try
{
editor.SelectPresetCommand.Execute("1080p-h264");
await CheckedAsync(editor, "1080p-h264", app.Window);
var button = RenderButton(app.Window);
button.IsDropDownOpen = true;
await SettleAsync(app.Window);
var menu = Assert.NotNull(button.Menu);
Assert.True(menu.IsOpen);
var items = menu.Items.OfType<Control>().ToList();
var current = items.OfType<MenuItem>().Single(m => m.IsChecked);
Assert.Equal("preset:1080p-h264", ((RenderMenuItem)current.Header).Id);
Assert.Equal(Loc.L("Export.Preset.1080pShare"), System.Windows.Automation.AutomationProperties.GetName(current));
Assert.True(current.ActualHeight >= 32, $"a preset entry has a details line ({current.ActualHeight:0} px)");
var lines = Find<TextBlock>(current).Where(t => t.IsVisible).Select(t => t.Text).ToList();
Assert.Contains(Loc.L("Export.Preset.1080pShare"), lines);
Assert.Contains(lines, l => l.Contains("1920×1080", StringComparison.Ordinal));
Assert.True(items.OfType<Separator>().Any(), "the commands sit under a separator");
var frame = items.OfType<MenuItem>().Single(m => m.Header is RenderMenuItem { Id: "frame" });
Assert.Equal(RenderRules.StillCodecs.Count, frame.Items.Count);
var untipped = items.OfType<MenuItem>().Where(m => m.Header is RenderMenuItem { Kind: not RenderMenuItemKind.Header } && m.ToolTip is not string { Length: > 0 });
Assert.False(untipped.Any(), "every entry but a title has a tooltip: " + string.Join(", ", untipped.Select(m => ((RenderMenuItem)m.Header).Id)));
Assert.True(items.OfType<MenuItem>().Where(m => m.Header is RenderMenuItem { Kind: RenderMenuItemKind.Header }).All(m => !m.Focusable && !m.IsHitTestVisible),
"a title is not an entry");
// Another preset chosen: the menu, made again when it opens, checks that one.
((MenuItem)items.Single(i => i is MenuItem { Header: RenderMenuItem { Id: "preset:1080p-h264" } })).Command.Execute("8k-hevc10-archive");
button.IsDropDownOpen = false;
await CheckedAsync(editor, "8k-hevc10-archive", app.Window);
button.IsDropDownOpen = true;
await SettleAsync(app.Window);
Assert.Equal("preset:8k-hevc10-archive", ((RenderMenuItem)menu.Items.OfType<MenuItem>().Single(m => m.IsChecked).Header).Id);
button.IsDropDownOpen = false;
}
finally
{
await app.Shell.Sequence.CloseAsync();
}
});
private static SplitButton RenderButton(Window window) => Find<SplitButton>(window).Single(b => b.Name == "RenderButton" && b.IsVisible);
/// <summary>Waits until the editor's plan has the preset (it is made off the UI thread), then lets the layout settle.</summary>
private static async Task CheckedAsync(Chronos.App.Editor.EditorViewModel editor, string preset, Window window)
{
for (var i = 0; i < 400 && !editor.RenderMenuItems.SelectMany(m => m.Flatten()).Any(m => m.IsChecked && m.Id == "preset:" + preset); i++) await Task.Delay(10);
Assert.True(editor.RenderMenuItems.SelectMany(m => m.Flatten()).Any(m => m.IsChecked && m.Id == "preset:" + preset), $"{preset} is the current preset");
await SettleAsync(window);
}
private static async Task SettleAsync(Window window)
{
window.UpdateLayout();
await window.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle);
await Task.Delay(30);
await window.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle);
window.UpdateLayout();
}
private static List<T> Find<T>(DependencyObject root)
where T : DependencyObject
{
var found = new List<T>();
var stack = new Stack<DependencyObject>([root]);
while (stack.TryPop(out var node))
{
if (node is T match) found.Add(match);
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(node); i++) stack.Push(VisualTreeHelper.GetChild(node, i));
}
return found;
}
}