Add comprehensive tests for EditSection functionality in the Windows application

- Implement tests for picker behavior, including loading sequences, searching, and handling empty libraries.
- Validate sequence opening via Enter key and double-click actions.
- Ensure proper handling of unsaved edits and sequence deletion scenarios.
- Verify accessibility features for picker rows across different languages.
- Introduce a dialog counting mechanism to manage unsaved edit confirmations.
This commit is contained in:
Alby96 committed 2026-10-19 12:10:42 +02:00
1 parent 4ea44bb917
commit 5aeb6aa787
214 files changed
+6547 -826

No files matched your search

+174 -17
View File
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
@@ -23,11 +24,12 @@ using Titano.Ui.Visuals;
namespace Titano.App.Editor;
/// <summary>
/// The sequence editor of one open sequence (BRIEF §12.3, Editor.html): header actions, the preview with its tools
/// (wipe compare, zoom, overlays) rendered through the pipeline at preview size (at the source's own size for 1:1 and
/// wheel zoom), the filmstrip with markers, the section tabs and the keyboard (space, arrows, Ctrl+Z/Y, Ctrl+0/1,
/// Ctrl+R, Ctrl+Shift+A). Preview frames, corrections, the export plan and the card estimates are computed off the UI
/// thread; each request cancels the previous one. While an analysis or render of this sequence runs, settings are
/// The editor of one open sequence (BRIEF §12.3, Editor.html): header actions, the preview with its tools (wipe
/// compare, zoom, overlays) rendered through the pipeline at preview size (at the source's own size for 1:1 and wheel
/// zoom), the filmstrip with markers, the steps of the Edit path from the analysis to the export (owner review 1, R7:
/// each with where it stands, Previous and Next, Alt+1…8, Ctrl+PgUp/PgDn) and the keyboard (space, arrows, Ctrl+Z/Y,
/// Ctrl+0/1, Ctrl+R, Ctrl+Shift+A). Preview frames, corrections, the export plan and the card estimates are computed off
/// the UI thread; each request cancels the previous one. While an analysis or render of this sequence runs, settings are
/// disabled and viewing tools stay live.
/// </summary>
public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
@@ -79,6 +81,14 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private int _playLimit;
private double? _analysisSecondsPerFrame;
private ExportSyncGate _syncGate;
private RenderedSettings _rendered;
/// <summary>The step shown came from the section's memory of this sequence (<see cref="RestoreSteps"/>).</summary>
private bool _stepRestored;
/// <summary>The user chose a step since the editor opened.</summary>
private bool _stepChosen;
private bool _disposed;
public EditorViewModel(ShellViewModel shell, EditorSession session, IReadOnlyList<IVideoEncoderProvider> encoders, EncoderHost host)
@@ -108,11 +118,25 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
StepForwardCommand = new RelayCommand(() => CurrentIndex++);
FitCommand = new RelayCommand(() => ZoomMode = PreviewZoomMode.Fit);
ActualSizeCommand = new RelayCommand(() => ZoomMode = PreviewZoomMode.Actual, () => !IsExportTab);
PreviousStepCommand = new RelayCommand(() => MoveStep(-1), () => StepIndex > 0);
NextStepCommand = new RelayCommand(NextStep, () => !SelectedTab.IsLast || Shell.Sequence.ChangeSequenceCommand.CanExecute(null));
GoToStepCommand = new RelayCommand(p =>
{
if (StepFor(p) is { } step) SelectedTab = step;
});
Analysis = new AnalysisTab(this);
Frames = new FramesTab(this);
Exposure = new ExposureTab(this);
Tabs = [Frames, Exposure, new MotionTab(this), new CameraTab(this), new TimeTab(this), new StackTab(this), new ExportTab(this)];
_selectedTab = Exposure;
Tabs = [Analysis, Frames, Exposure, new MotionTab(this), new CameraTab(this), new TimeTab(this), new StackTab(this), new ExportTab(this)];
for (var i = 0; i < Tabs.Count; i++)
{
Tabs[i].Number = i + 1;
Tabs[i].IsLast = i == Tabs.Count - 1;
}
_selectedTab = Step(EditPath.Start(null, session.Content));
_selectedTab.IsVisited = true;
_rendered = new RenderedSettings(session.Content.Renders);
_currentIndex = session.Project.HeroFrame is { } hero && (uint)hero < (uint)FrameCount ? hero : 0;
_currentFrameId = FrameId(_currentIndex);
// Until the link is read (AttachJobsAsync), a sequence of this PC cannot send its renders.
@@ -127,6 +151,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
session.Source.ReadOnlyChanged += OnReadOnlyChanged;
shell.Services.Sync.Changed += OnSyncChanged;
UpdateMarkers();
RefreshSteps();
RequestCorrections();
RequestPlan();
RequestPreview(immediate: true);
@@ -140,6 +165,12 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
public string Title => Session.Content.Sequence.DisplayTitle;
/// <summary>The title button's accessible name: its visible text (the title), then what it does ("Harbour sunset · Change sequence").</summary>
public string ChangeName => Title + Loc.Separator + Loc.L("Editor.Change");
/// <summary>The title button's tooltip: the whole title (it may be cut), then what the button does.</summary>
public string ChangeToolTip => Title + Loc.Separator + Loc.L("Tooltips.Editor.Change");
/// <summary>A server sequence edited with proxies (the header says where it lives).</summary>
public bool IsRemote => Session.IsRemote;
@@ -200,32 +231,57 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
? EditorText.OutputSummary(Session.Content, plan)
: EditorText.Summary(Session.Content, Session.Advice.Findings.Count(f => f.Severity >= FindingSeverity.Warning));
/// <summary>The first step: what the analyses found and where every other step stands.</summary>
public AnalysisTab Analysis { get; }
public FramesTab Frames { get; }
public ExposureTab Exposure { get; }
/// <summary>The steps of the Edit path, in order (owner review 1, R7).</summary>
public IReadOnlyList<EditorTab> Tabs { get; }
/// <summary>The step on screen; any step can be chosen at any time, and choosing one marks it visited.</summary>
public EditorTab SelectedTab
{
get => _selectedTab;
set
{
if (value is null || !Set(ref _selectedTab, value)) return;
OnPropertyChanged(nameof(IsExportTab));
OnPropertyChanged(nameof(Summary));
OnToolsChanged();
// 1:1 is not a tool of the Export tab (Export.html): its picture fits the view.
if (IsExportTab) ZoomMode = PreviewZoomMode.Fit;
UpdateInfo();
RequestPreview(immediate: true);
CommandManager.InvalidateRequerySuggested();
if (value is null || !Tabs.Contains(value)) return;
_stepChosen = true;
Select(value);
}
}
/// <summary>The Export tab swaps the preview tools for compare, crop mask and a 10-second preview (Export.html).</summary>
/// <summary>The Export step swaps the preview tools for compare, crop mask and a 10-second preview (Export.html).</summary>
public bool IsExportTab => SelectedTab is ExportTab;
/// <summary>The measuring area takes more of the height than the preview (the Analysis findings, the Export preset cards).</summary>
public bool IsTallMeasure => SelectedTab.PrefersTallMeasure;
/// <summary>"3 / 8".</summary>
public string StepCounter => Loc.L("Editor.Step.Counter", SelectedTab.Number, Tabs.Count);
/// <summary>What screen readers hear when the step or its state changes: "Step 3 of 8: Exposure, Auto".</summary>
public string StepAnnouncement => Loc.L("Editor.Step.Announce", SelectedTab.Number, Tabs.Count, SelectedTab.Header, SelectedTab.StateText);
/// <summary>"Next", "Next sequence" on the last step.</summary>
public string NextText => Loc.L(SelectedTab.IsLast ? "Editor.Step.NextSequence" : "Editor.Step.Next");
public string NextToolTip => SelectedTab.IsLast ? Loc.L("Tooltips.Editor.Step.NextSequence") : Loc.L("Tooltips.Editor.Step.Next", Tabs[StepIndex + 1].Header);
public string PreviousToolTip => StepIndex == 0 ? Loc.L("Tooltips.Editor.Step.First") : Loc.L("Tooltips.Editor.Step.Previous", Tabs[StepIndex - 1].Header);
public ICommand PreviousStepCommand { get; }
/// <summary>The next step; on the last one, the choice of the next sequence.</summary>
public ICommand NextStepCommand { get; }
/// <summary>Opens a step, given as the step itself, its number (Alt+n) or its key.</summary>
public ICommand GoToStepCommand { get; }
private int StepIndex => SelectedTab.Number - 1;
// ---- Frames ----
public int FrameCount => Session.Content.Count;
@@ -518,6 +574,30 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
/// <summary>"Optimise section": the advisor's heavier decisions, reported in a toast (what changed, from what to what).</summary>
public void Optimise(AdvisorSection section) => Report(Session.Optimise(section));
/// <summary>The step <paramref name="delta"/> steps away, stopping at the first and the last (Ctrl+PgUp, Ctrl+PgDn).</summary>
public void MoveStep(int delta)
{
var index = StepIndex + delta;
if ((uint)index < (uint)Tabs.Count) SelectedTab = Tabs[index];
}
/// <summary>The step on screen and the steps visited, which the section gives back when the sequence opens again in this run.</summary>
public StepMemory StepMemory() => new(SelectedTab.Key, [.. Tabs.Where(t => t.IsVisited).Select(t => t.Key)], EditPath.AnalysisStamp(Session.Content));
/// <summary>
/// Shows the step <paramref name="memory"/> kept, with its visited marks (before the editor is on screen); a deep
/// analysis that ended while the sequence was closed leaves only that step visited, as it would have with the editor open.
/// </summary>
public void RestoreSteps(StepMemory memory)
{
ArgumentNullException.ThrowIfNull(memory);
var sameAnalysis = memory.Analysis == EditPath.AnalysisStamp(Session.Content);
foreach (var tab in Tabs) tab.IsVisited = sameAnalysis && memory.Visited.Contains(tab.Key);
if (Tabs.FirstOrDefault(t => t.Key == memory.Step) is not { } step) return;
_stepRestored = true;
Select(step);
}
/// <summary>
/// Queues a render of the project's export (with its batch presets when <paramref name="batch"/>): on this PC's
/// engine, or one server job per preset for a server sequence.
@@ -590,6 +670,14 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
var jobs = await Session.Source.ListJobsAsync(CancellationToken.None);
foreach (var job in jobs) _jobs.Track(job);
foreach (var job in jobs.OrderBy(j => j.Finished)) LearnAnalysisSpeed(job);
// A sequence opened while its analysis waits, runs or is paused shows that first (EditPath.Start), unless the user or
// the section's memory chose a step meanwhile; the step shown only until then is not counted as visited.
if (!_stepRestored && !_stepChosen && Step(EditPath.Start(null, Session.Content, _jobs.Active(JobKind.DeepAnalyse))) is var start
&& !ReferenceEquals(start, _selectedTab))
{
_selectedTab.IsVisited = false;
Select(start);
}
OnBusyChanged();
}
@@ -749,6 +837,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
OnPropertyChanged(nameof(Summary));
foreach (var tab in Tabs) tab.OnPlanChanged();
UpdateInfo();
RefreshSteps();
RefreshCommands();
}
@@ -793,6 +882,68 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
return int.Max(1, (int)(plan.Setup.Plan.IncludedFrames.Count * double.Min(1, 10 / plan.Setup.Plan.DurationSeconds)));
}
// ---- Steps ----
private void Select(EditorTab step)
{
step.IsVisited = true;
if (!Set(ref _selectedTab, step, nameof(SelectedTab))) return;
OnPropertyChanged(nameof(IsExportTab));
OnPropertyChanged(nameof(IsTallMeasure));
OnPropertyChanged(nameof(Summary));
OnStepNavigationChanged();
OnToolsChanged();
// 1:1 is not a tool of the Export step (Export.html): its picture fits the view.
if (IsExportTab) ZoomMode = PreviewZoomMode.Fit;
UpdateInfo();
RequestPreview(immediate: true);
CommandManager.InvalidateRequerySuggested();
}
private void OnStepNavigationChanged()
{
OnPropertyChanged(nameof(StepCounter));
OnPropertyChanged(nameof(StepAnnouncement));
OnPropertyChanged(nameof(NextText));
OnPropertyChanged(nameof(NextToolTip));
OnPropertyChanged(nameof(PreviousToolTip));
}
private EditorTab Step(string key) => Tabs.First(t => t.Key == key);
private EditorTab? StepFor(object? parameter) => parameter switch
{
EditorTab tab when Tabs.Contains(tab) => tab,
int number => (uint)(number - 1) < (uint)Tabs.Count ? Tabs[number - 1] : null,
string text when int.TryParse(text, NumberStyles.None, CultureInfo.InvariantCulture, out var number) =>
(uint)(number - 1) < (uint)Tabs.Count ? Tabs[number - 1] : null,
string key => Tabs.FirstOrDefault(t => t.Key == key),
_ => null,
};
private void NextStep()
{
if (!SelectedTab.IsLast) MoveStep(1);
else if (Shell.Sequence.ChangeSequenceCommand.CanExecute(null)) Shell.Sequence.ChangeSequenceCommand.Execute(null);
}
/// <summary>Works out where every step stands: after any change of the project, the sequence, its jobs or the plan.</summary>
private void RefreshSteps()
{
if (_disposed) return;
var facts = new PathFacts(Session.Content, Session.Advice, Session.Project, _jobs.Active(JobKind.DeepAnalyse), _jobs.Active(JobKind.Render),
_planned ? RenderBlockedReason : null, _rendered.Matches(Session.Project));
foreach (var tab in Tabs) tab.SetStep(EditPath.Of(tab.Key, facts));
Analysis.OnStepChanged();
OnPropertyChanged(nameof(StepAnnouncement));
}
/// <summary>A deep analysis the editor followed ended: the steps it changed are to be looked at again.</summary>
private void ClearVisited()
{
foreach (var tab in Tabs) tab.IsVisited = ReferenceEquals(tab, SelectedTab);
}
// ---- Changes ----
private void OnToolsChanged()
@@ -807,6 +958,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
foreach (var tab in Tabs) tab.Refresh();
UpdateMarkers();
RefreshSteps();
RequestCorrections();
RequestPlan();
RequestPreview();
@@ -822,11 +974,13 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
Planner = new ExportPlanner(Session.Content, _encoders, _host);
if (Thumbnails.Count != FrameCount) Thumbnails = new EditorThumbnails(Session.Source, FrameCount);
Corrections = null;
_rendered = new RenderedSettings(Session.Content.Renders);
foreach (var tab in Tabs) tab.OnContentChanged();
OnPropertyChanged(nameof(Summary));
OnPropertyChanged(nameof(FrameCount));
CurrentIndex = shown;
UpdateMarkers();
RefreshSteps();
RequestCorrections();
RequestPlan();
RequestPreview(immediate: true);
@@ -857,6 +1011,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
foreach (var tab in Tabs) tab.OnContentChanged();
UpdateMarkers();
UpdateInfo();
RefreshSteps();
}
base.OnLanguageChanged();
}
@@ -974,6 +1129,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
else OnServerJobChanged();
LearnAnalysisSpeed(job);
if (!wasActive) return;
if (job is { Kind: JobKind.DeepAnalyse, State: JobState.Done }) ClearVisited();
// A render this editor followed to its end is said here, with its output, unless the Jobs screen said it first.
if (job.State == JobState.Done) _ = ReloadAsync(job.Kind == JobKind.Render && Shell.Jobs.ClaimRenderToast(job.Id) ? job : null);
else if (IsRemote && job.State is JobState.Failed or JobState.Cancelled) ReportServerJobEnded(job);
@@ -1108,6 +1264,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
OnPropertyChanged(nameof(OptimiseAllToolTip));
OnServerJobChanged();
foreach (var tab in Tabs) tab.OnBusyChanged();
RefreshSteps();
RefreshCommands();
}