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:
1 parent
4ea44bb917
commit
5aeb6aa787
214 files changed
+6547
-826
No files matched your search
@@ -0,0 +1,390 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Titano.App.Editor;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Sections;
|
||||
using Titano.App.Shell;
|
||||
using Titano.App.Tests.Windows;
|
||||
using Titano.Core.Export;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Editor;
|
||||
|
||||
/// <summary>
|
||||
/// The Edit path in the real main window at the 1200 × 788 capture size (owner review 1, R7): the step bar for screen
|
||||
/// readers and the keyboard, Previous and Next, the findings' way to their step, the step memory and right to left.
|
||||
/// </summary>
|
||||
[WindowsOnly]
|
||||
[Serial]
|
||||
[Timeout(300_000)]
|
||||
public sealed class EditPathSmokeTests
|
||||
{
|
||||
[Test]
|
||||
public Task TheStepBarNamesEachStepItsStateAndItsShortcut() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var (editor, view) = await OpenAsync(app);
|
||||
await using (editor)
|
||||
{
|
||||
var steps = StepItems(view);
|
||||
Assert.Count(8, steps);
|
||||
for (var i = 0; i < steps.Count; i++)
|
||||
{
|
||||
var tab = (EditorTab)steps[i].DataContext;
|
||||
Assert.Equal(i + 1, tab.Number);
|
||||
Assert.Equal(tab.Header, AutomationProperties.GetName(steps[i]));
|
||||
Assert.Equal(tab.StateText, AutomationProperties.GetItemStatus(steps[i]));
|
||||
Assert.Equal($"Alt+{i + 1}", AutomationProperties.GetAcceleratorKey(steps[i]));
|
||||
Assert.True(((string)steps[i].ToolTip).EndsWith($"Alt+{i + 1}", StringComparison.Ordinal), $"{tab.Key}: the tooltip names the shortcut");
|
||||
Assert.False(string.IsNullOrEmpty(tab.StateText), $"{tab.Key}: a state");
|
||||
}
|
||||
Assert.Equal(EditPath.Frames, editor.SelectedTab.Key, "an analysed sequence opens on Frames");
|
||||
Assert.True(editor.Frames.IsVisited);
|
||||
Assert.False(editor.Exposure.IsVisited);
|
||||
|
||||
// Previous waits on the first step; Next names where it goes.
|
||||
editor.SelectedTab = editor.Analysis;
|
||||
Assert.False(editor.PreviousStepCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Tooltips.Editor.Step.First"), editor.PreviousToolTip);
|
||||
Assert.Equal(Loc.L("Tooltips.Editor.Step.Next", editor.Frames.Header), editor.NextToolTip);
|
||||
Assert.Equal("1 / 8", editor.StepCounter);
|
||||
editor.NextStepCommand.Execute(null);
|
||||
Assert.Same(editor.Frames, editor.SelectedTab);
|
||||
Assert.Equal(Loc.L("Editor.Step.Announce", 2, 8, editor.Frames.Header, editor.Frames.StateText), editor.StepAnnouncement);
|
||||
|
||||
// Alt+3 opens the third step; Ctrl+PgDn and Ctrl+PgUp move one step and stop at the ends.
|
||||
var root = Find<Grid>(view).Single(g => g.Name == "EditorRoot");
|
||||
var alt3 = root.InputBindings.OfType<KeyBinding>().Single(b => b.Key == Key.D3 && b.Modifiers == ModifierKeys.Alt);
|
||||
alt3.Command.Execute(alt3.CommandParameter);
|
||||
Assert.Same(editor.Exposure, editor.SelectedTab);
|
||||
Assert.Equal(1, SequenceView.StepDelta(Key.PageDown, ModifierKeys.Control));
|
||||
Assert.Equal(-1, SequenceView.StepDelta(Key.PageUp, ModifierKeys.Control));
|
||||
Assert.Null(SequenceView.StepDelta(Key.PageDown, ModifierKeys.None), "Page Down alone stays the filmstrip's");
|
||||
editor.MoveStep(-10);
|
||||
Assert.Same(editor.Exposure, editor.SelectedTab, "a move past the first step does nothing");
|
||||
Assert.False(root.InputBindings.OfType<KeyBinding>().Any(b => b.Modifiers == ModifierKeys.Alt && b.Key is >= Key.NumPad0 and <= Key.NumPad9),
|
||||
"no Alt+NumPad binding: those type characters into text fields");
|
||||
|
||||
// On the last step, Next chooses the next sequence: the picker covers the editor, which stays open.
|
||||
editor.SelectedTab = editor.Tabs[^1];
|
||||
Assert.Equal(Loc.L("Editor.Step.NextSequence"), editor.NextText);
|
||||
editor.NextStepCommand.Execute(null);
|
||||
Assert.True(app.Shell.Sequence.IsPicking);
|
||||
Assert.Same(editor, app.Shell.Sequence.Editor);
|
||||
app.Shell.Sequence.CancelPickCommand.Execute(null);
|
||||
Assert.False(app.Shell.Sequence.IsPicking);
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task AFindingOpensTheStepThatDealsWithIt() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var (editor, view) = await OpenAsync(app);
|
||||
await using (editor)
|
||||
{
|
||||
editor.SelectedTab = editor.Analysis;
|
||||
await SettleAsync(app.Window);
|
||||
var finding = Assert.Contains(editor.Analysis.Findings, f => f.Step is not null && !ReferenceEquals(f.Step, editor.Analysis));
|
||||
var row = Find<ListBoxItem>(view).Single(i => ReferenceEquals(i.DataContext, finding));
|
||||
var goTo = Find<Button>(row).Single(b => b.IsVisible);
|
||||
Assert.Equal(finding.Step!.Header, AutomationProperties.GetName(goTo));
|
||||
Assert.Equal(Loc.L("Tooltips.Editor.Analysis.GoTo", finding.Step.Header, finding.Step.Number), goTo.ToolTip);
|
||||
goTo.Command.Execute(goTo.CommandParameter);
|
||||
Assert.Same(finding.Step, editor.SelectedTab);
|
||||
|
||||
// The panel lists the other steps with where each stands; the measurements of the deep analysis show.
|
||||
editor.SelectedTab = editor.Analysis;
|
||||
await SettleAsync(app.Window);
|
||||
Assert.Count(7, editor.Analysis.PathSteps);
|
||||
Assert.True(editor.Analysis.Rows.OfType<InfoRow>().All(r => r.IsApplicable), "the sequence is analysed: every measurement shows");
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task TheSectionRemembersTheStepOfEachSequence() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var (editor, _) = await OpenAsync(app);
|
||||
editor.SelectedTab = editor.Tabs.OfType<CameraTab>().Single();
|
||||
editor.SelectedTab = editor.Exposure;
|
||||
await app.Shell.Sequence.CloseAsync();
|
||||
|
||||
var again = new EditorViewModel(app.Shell, new EditorSession(new FakeSequenceSource(EditorFixture.Sunset, editor.Session.Content), editor.Session.Content, []),
|
||||
[], EncoderHost.Client);
|
||||
app.Shell.Sequence.Attach(again);
|
||||
await using (again)
|
||||
{
|
||||
Assert.Same(again.Exposure, again.SelectedTab, "the step shown last");
|
||||
Assert.True(again.Tabs.OfType<CameraTab>().Single().IsVisited, "and the steps visited");
|
||||
Assert.False(again.Tabs.OfType<StackTab>().Single().IsVisited);
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// At 1200 px every step's tooltip starts with its name (a name cut by an ellipsis reads whole), and every English and
|
||||
/// Italian name fits its cell, also in semibold as the step shown (owner review 1, R7 review).
|
||||
/// </summary>
|
||||
[Test]
|
||||
public Task StepNamesFitInEnglishAndItalianAndEveryTooltipStartsWithTheName() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var (editor, view) = await OpenAsync(app);
|
||||
await using (editor)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var language in Languages.Shipped)
|
||||
{
|
||||
UiLanguage.Apply(language);
|
||||
await SettleAsync(app.Window);
|
||||
foreach (var item in StepItems(view))
|
||||
{
|
||||
var tab = (EditorTab)item.DataContext;
|
||||
Assert.True(((string)item.ToolTip).StartsWith(tab.Header, StringComparison.Ordinal), $"{language}: the {tab.Key} tooltip starts with its name");
|
||||
if (language is not ("en" or "it")) continue;
|
||||
var label = Find<TextBlock>(item).Single(t => t.Name == "Label");
|
||||
var dock = (FrameworkElement)VisualTreeHelper.GetParent(label);
|
||||
// The badge takes 22 px; the rest of the cell, without the label's margins, is the name's.
|
||||
var room = dock.ActualWidth - 22 - label.Margin.Left - label.Margin.Right;
|
||||
Assert.True(Width(label, FontWeights.Normal) <= room + 0.5 && Width(label, FontWeights.SemiBold) <= room + 0.5,
|
||||
$"{language}: '{tab.Header}' needs {Width(label, FontWeights.SemiBold):0} px in semibold, the cell gives {room:0}");
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>On the last step, Previous and "Next sequence" are whole in every language: the counter gives way first.</summary>
|
||||
[Test]
|
||||
public Task PreviousAndNextSequenceAreWholeInEveryLanguage() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var (editor, view) = await OpenAsync(app);
|
||||
await using (editor)
|
||||
{
|
||||
editor.SelectedTab = editor.Tabs[^1];
|
||||
try
|
||||
{
|
||||
foreach (var language in Languages.Shipped)
|
||||
{
|
||||
UiLanguage.Apply(language);
|
||||
await SettleAsync(app.Window);
|
||||
var previous = Find<Button>(view).Single(b => b.Name == "PreviousStep");
|
||||
var next = Find<Button>(view).Single(b => b.Name == "NextStep");
|
||||
var row = (FrameworkElement)VisualTreeHelper.GetParent(next);
|
||||
foreach (var button in new[] { previous, next })
|
||||
{
|
||||
var shown = button.ActualWidth;
|
||||
button.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
var wanted = button.DesiredSize.Width;
|
||||
button.InvalidateMeasure();
|
||||
Assert.True(wanted <= shown + 0.5, $"{language}: '{AutomationProperties.GetName(button)}{button.Content}' needs {wanted:0} px, has {shown:0}");
|
||||
var left = button.TranslatePoint(new Point(0, 0), row).X;
|
||||
var right = button.TranslatePoint(new Point(button.ActualWidth, 0), row).X;
|
||||
Assert.True(double.Min(left, right) >= -0.5 && double.Max(left, right) <= row.ActualWidth + 0.5, $"{language}: inside the column");
|
||||
}
|
||||
app.Window.UpdateLayout();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// A step's own button (a finding's) and Previous turning itself off on the first step leave the keyboard on the new
|
||||
/// step's cell, so the editor's shortcuts keep working (it used to fall to the window).
|
||||
/// </summary>
|
||||
[Test]
|
||||
public Task TheKeyboardFollowsTheStep() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var (editor, view) = await OpenAsync(app);
|
||||
await using (editor)
|
||||
{
|
||||
editor.SelectedTab = editor.Analysis;
|
||||
await SettleAsync(app.Window);
|
||||
var finding = Assert.Contains(editor.Analysis.Findings, f => f.Step is not null);
|
||||
var row = Find<ListBoxItem>(view).Single(i => ReferenceEquals(i.DataContext, finding));
|
||||
var goTo = Find<Button>(row).Single(b => b.IsVisible);
|
||||
FocusManager.SetFocusedElement(app.Window, goTo);
|
||||
goTo.Command.Execute(goTo.CommandParameter);
|
||||
await SettleAsync(app.Window);
|
||||
Assert.Same(StepItems(view)[finding.Step!.Number - 1], FocusManager.GetFocusedElement(app.Window), "the new step's cell has the keyboard");
|
||||
|
||||
editor.SelectedTab = editor.Frames;
|
||||
await SettleAsync(app.Window);
|
||||
var previous = Find<Button>(view).Single(b => b.Name == "PreviousStep");
|
||||
FocusManager.SetFocusedElement(app.Window, previous);
|
||||
previous.Command.Execute(null);
|
||||
await SettleAsync(app.Window);
|
||||
Assert.False(previous.IsEnabled, "Previous waits on the first step");
|
||||
Assert.Same(StepItems(view)[0], FocusManager.GetFocusedElement(app.Window));
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>Space on the step shown plays, as everywhere in the editor (the step bar used to swallow it).</summary>
|
||||
[Test]
|
||||
public Task SpaceOnTheStepShownPlays() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var (editor, view) = await OpenAsync(app);
|
||||
await using (editor)
|
||||
{
|
||||
var cell = StepItems(view)[editor.SelectedTab.Number - 1];
|
||||
Assert.False(editor.IsPlaying);
|
||||
cell.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(cell)!, 0, Key.Space) { RoutedEvent = Keyboard.PreviewKeyDownEvent });
|
||||
Assert.True(editor.IsPlaying);
|
||||
editor.PlayCommand.Execute(null);
|
||||
Assert.True(cell.IsSelected, "the step stays the current one");
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// The title button names the sequence first (accessible name and tooltip); Export gives its preset cards more of the
|
||||
/// height than the preview (Export.html); the findings read as their sentences, and only those with a frame offer a seek.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public Task TheTitleTheExportLayoutAndTheFindingRows() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var (editor, view) = await OpenAsync(app);
|
||||
await using (editor)
|
||||
{
|
||||
var title = Find<Button>(view).Single(b => b.Name == "ChangeSequence");
|
||||
Assert.True(AutomationProperties.GetName(title).StartsWith(editor.Title, StringComparison.Ordinal), "its name starts with its visible text");
|
||||
Assert.True(((string)title.ToolTip).StartsWith(editor.Title, StringComparison.Ordinal), "a cut title reads whole on hover");
|
||||
|
||||
editor.SelectedTab = editor.Tabs[^1];
|
||||
await SettleAsync(app.Window);
|
||||
Assert.True(editor.IsTallMeasure);
|
||||
var measure = Find<ContentControl>(view).Single(c => c.Name == "StepMeasure");
|
||||
var preview = Find<Titano.Ui.Visuals.PreviewViewport>(view).Single(v => v.IsVisible);
|
||||
Assert.Greater(measure.ActualHeight, preview.ActualHeight, "the preset cards take more room than the preview");
|
||||
|
||||
editor.SelectedTab = editor.Analysis;
|
||||
await SettleAsync(app.Window);
|
||||
Assert.True(editor.Analysis.Findings.Any(f => f.Frame is null) && editor.Analysis.Findings.Any(f => f.Frame is not null), "the fixture has both kinds");
|
||||
foreach (var finding in editor.Analysis.Findings)
|
||||
{
|
||||
var row = Find<ListBoxItem>(view).Single(i => ReferenceEquals(i.DataContext, finding));
|
||||
Assert.Equal(finding.Text, System.Windows.Automation.Peers.UIElementAutomationPeer.CreatePeerForElement(row).GetName());
|
||||
Assert.Equal(finding.Frame is null, row.ToolTip is null, $"'{finding.Text}': a seek is offered only with a frame");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>A deep analysis that ended while the sequence was closed leaves only the step shown visited when it opens again.</summary>
|
||||
[Test]
|
||||
public Task AnAnalysisThatEndedWhileClosedResetsTheVisitedSteps() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var bare = EditorFixture.Content(EditorFixture.Sunset, deep: false);
|
||||
var editor = new EditorViewModel(app.Shell, new EditorSession(new FakeSequenceSource(EditorFixture.Sunset, bare), bare, []), [], EncoderHost.Client);
|
||||
app.Shell.Sequence.Attach(editor);
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await SettleAsync(app.Window);
|
||||
editor.SelectedTab = editor.Frames;
|
||||
editor.SelectedTab = editor.Exposure;
|
||||
await app.Shell.Sequence.CloseAsync();
|
||||
|
||||
var analysed = bare with { Deep = EditorFixture.Content(EditorFixture.Sunset).Deep };
|
||||
var again = new EditorViewModel(app.Shell, new EditorSession(new FakeSequenceSource(EditorFixture.Sunset, analysed), analysed, []), [], EncoderHost.Client);
|
||||
app.Shell.Sequence.Attach(again);
|
||||
await using (again)
|
||||
{
|
||||
Assert.Same(again.Exposure, again.SelectedTab, "the step shown last");
|
||||
Assert.True(again.Exposure.IsVisited);
|
||||
Assert.False(again.Frames.IsVisited, "the analysis changed the steps: they are to be looked at again");
|
||||
Assert.False(again.Analysis.IsVisited);
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task TheStepsRunFromTheRightInArabic() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync("ar");
|
||||
var (editor, view) = await OpenAsync(app);
|
||||
await using (editor)
|
||||
{
|
||||
var steps = StepItems(view);
|
||||
var first = steps[0].PointToScreen(new Point(steps[0].ActualWidth / 2, 0)).X;
|
||||
var second = steps[1].PointToScreen(new Point(steps[1].ActualWidth / 2, 0)).X;
|
||||
Assert.Greater(first, second, "step 1 sits to the right of step 2");
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>The synthetic sunset, analysed, open in Edit at 1200 × 788.</summary>
|
||||
private static async Task<(EditorViewModel Editor, SequenceView View)> OpenAsync(ScreenSmokeTests.SampleApp app)
|
||||
{
|
||||
app.Window.Width = 1200;
|
||||
app.Window.Height = 788;
|
||||
var content = EditorFixture.Content(EditorFixture.Sunset);
|
||||
var editor = new EditorViewModel(app.Shell, new EditorSession(new FakeSequenceSource(EditorFixture.Sunset, content), content, []), [], EncoderHost.Client);
|
||||
app.Shell.Sequence.Attach(editor);
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await SettleAsync(app.Window);
|
||||
Assert.True(await editor.WhenIdleAsync(TimeSpan.FromSeconds(60)), "the editor settled");
|
||||
await SettleAsync(app.Window);
|
||||
return (editor, Find<SequenceView>(app.Window).Single(v => v.IsVisible));
|
||||
}
|
||||
|
||||
private static List<ListBoxItem> StepItems(SequenceView view)
|
||||
{
|
||||
var bar = Find<ListBox>(view).Single(l => l.Name == "Steps");
|
||||
return [.. bar.Items.Cast<object>().Select(item => (ListBoxItem)bar.ItemContainerGenerator.ContainerFromItem(item))];
|
||||
}
|
||||
|
||||
/// <summary>The width <paramref name="text"/>'s text needs in <paramref name="weight"/>, measured by the same layout engine.</summary>
|
||||
private static double Width(TextBlock text, FontWeight weight)
|
||||
{
|
||||
var probe = new TextBlock
|
||||
{
|
||||
Text = text.Text,
|
||||
FontFamily = text.FontFamily,
|
||||
FontSize = text.FontSize,
|
||||
FontStyle = text.FontStyle,
|
||||
FontWeight = weight,
|
||||
FontStretch = text.FontStretch,
|
||||
FlowDirection = text.FlowDirection,
|
||||
Language = text.Language,
|
||||
};
|
||||
TextOptions.SetTextFormattingMode(probe, TextOptions.GetTextFormattingMode(text));
|
||||
probe.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
return probe.DesiredSize.Width;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
using System.Reflection;
|
||||
using Titano.App.Editor;
|
||||
using Titano.Core.Advice;
|
||||
using Titano.Core.Analysis;
|
||||
using Titano.Core.Analysis.Deep;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Editor;
|
||||
|
||||
/// <summary>The Edit path (owner review 1, R7): where each step stands, the step of each finding, the opening step and the render comparison.</summary>
|
||||
public sealed class EditPathTests
|
||||
{
|
||||
private static readonly string[] Steps =
|
||||
[EditPath.Analysis, EditPath.Frames, EditPath.Exposure, EditPath.Motion, EditPath.Camera, EditPath.Time, EditPath.Stack, EditPath.Export];
|
||||
|
||||
[Test]
|
||||
public void TheAnalysisStepIsToDoRunningDoneOrStale()
|
||||
{
|
||||
var bare = EditorFixture.Content(EditorFixture.Sunset, deep: false);
|
||||
Assert.Equal(StepStatus.Todo, State(EditPath.Analysis, bare).Status);
|
||||
Assert.Equal(Loc.L("Editor.Chart.NotAnalysed"), State(EditPath.Analysis, bare).Text);
|
||||
|
||||
var running = State(EditPath.Analysis, bare, analysis: Job(JobKind.DeepAnalyse, JobState.Running));
|
||||
Assert.Equal(StepStatus.Running, running.Status);
|
||||
Assert.Equal("Deep analysis · running", running.Text);
|
||||
|
||||
var stale = bare with { Sequence = bare.Sequence with { Status = SequenceStatus.AnalyzedDeep }, DeepOfOtherFrames = true };
|
||||
Assert.Equal(StepStatus.Attention, State(EditPath.Analysis, stale).Status, "the saved analysis is of other frames");
|
||||
Assert.Equal(Loc.L("Editor.Step.FramesChanged"), State(EditPath.Analysis, stale).Text);
|
||||
// Analysed, but the saved analysis cannot be read now (archive offline, file moved): not "frames changed".
|
||||
var unreadable = stale with { DeepOfOtherFrames = false };
|
||||
Assert.Equal(StepStatus.Attention, State(EditPath.Analysis, unreadable).Status);
|
||||
Assert.Equal(Loc.L("Editor.Step.AnalysisUnavailable"), State(EditPath.Analysis, unreadable).Text);
|
||||
Assert.Equal(Loc.L("Tooltips.Editor.Step.AnalysisUnavailable"), State(EditPath.Analysis, unreadable).Detail);
|
||||
|
||||
var analysed = EditorFixture.Content(EditorFixture.Sunset);
|
||||
var done = State(EditPath.Analysis, analysed);
|
||||
Assert.Equal(StepStatus.Done, done.Status);
|
||||
var warnings = Advice(analysed).Findings.Count(f => f.Severity >= FindingSeverity.Warning);
|
||||
Assert.Equal(warnings == 0 ? "Analysed" : "Analysed · " + Loc.Plural("Editor.Summary.Warnings", warnings), done.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FramesWaitForTheAnalysisAndAskUntilTheFlaggedFramesAreExcluded()
|
||||
{
|
||||
Assert.Equal(StepStatus.Waiting, State(EditPath.Frames, EditorFixture.Content(EditorFixture.Sunset, deep: false)).Status);
|
||||
|
||||
var analysed = EditorFixture.Content(EditorFixture.Sunset);
|
||||
var flagged = analysed with { Deep = analysed.Deep! with { Issues = new FrameIssues([], [5], [9], [], [3]) } };
|
||||
var attention = State(EditPath.Frames, flagged);
|
||||
Assert.Equal(StepStatus.Attention, attention.Status);
|
||||
Assert.Equal("2 flagged frames", attention.Text, "a scene change is not a frame to exclude");
|
||||
|
||||
var one = State(EditPath.Frames, flagged, project: new ProjectSettings { ExcludedFrames = [5] });
|
||||
Assert.Equal("1 flagged frame", one.Text);
|
||||
|
||||
var done = State(EditPath.Frames, flagged, project: new ProjectSettings { ExcludedFrames = [5, 9, 20] });
|
||||
Assert.Equal(StepStatus.Done, done.Status);
|
||||
Assert.Equal("Excluded: 3", done.Text);
|
||||
|
||||
// A frame the render skips anyway (unreadable in the archive) needs nothing from the user.
|
||||
var frames = flagged.Frames.ToList();
|
||||
frames[9] = frames[9] with { Flags = FrameFlags.Undecodable };
|
||||
var skipped = flagged with { Frames = frames };
|
||||
Assert.Equal("1 flagged frame", State(EditPath.Frames, skipped).Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingsStepsWaitForTheDeepAnalysisOnlyWhileAnAutoSettingNeedsIt()
|
||||
{
|
||||
var bare = EditorFixture.Content(EditorFixture.Sunset, deep: false);
|
||||
Assert.Equal(StepStatus.Waiting, State(EditPath.Exposure, bare).Status);
|
||||
Assert.Equal(Loc.L("Editor.Step.Waiting"), State(EditPath.Exposure, bare).Text);
|
||||
Assert.Equal(StepStatus.Waiting, State(EditPath.Motion, bare).Status);
|
||||
|
||||
// Every setting of the section taken over by hand: nothing waits for the analysis any more.
|
||||
var manual = Advice(bare).In(AdvisorSection.Exposure).Aggregate(new ProjectSettings(), (p, r) =>
|
||||
EditorSettings.All.FirstOrDefault(s => s.Id == r.Parameter) is { } setting ? Manual(setting, p) : p);
|
||||
var edited = State(EditPath.Exposure, bare, project: manual);
|
||||
Assert.Equal(StepStatus.Done, edited.Status);
|
||||
Assert.Equal(Loc.L("Editor.Step.Edited"), edited.Text);
|
||||
|
||||
var analysed = EditorFixture.Content(EditorFixture.Sunset);
|
||||
var auto = State(EditPath.Exposure, analysed);
|
||||
Assert.Equal(StepStatus.Done, auto.Status);
|
||||
Assert.Equal(Loc.L("Common.Auto"), auto.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MissingTimestampsNeedAttentionUntilTheTimingIsSetByHand()
|
||||
{
|
||||
var analysed = EditorFixture.Content(EditorFixture.Sunset);
|
||||
var frames = analysed.Frames.Select(f => f with { CapturedAt = null }).ToList();
|
||||
var untimed = analysed with { Frames = frames, Light = LightAnalyzer.Analyze(frames) };
|
||||
var time = State(EditPath.Time, untimed);
|
||||
Assert.Equal(StepStatus.Attention, time.Status);
|
||||
Assert.Equal(Loc.L("Editor.Step.MissingData"), time.Text);
|
||||
var reason = Advice(untimed).Find(AdvisorParameters.TimingMode)!;
|
||||
Assert.Equal(Advisor.Explain(reason), time.Detail, "the tooltip says what is missing");
|
||||
|
||||
var manual = Manual(EditorSettings.TimingMode, new ProjectSettings());
|
||||
Assert.Equal(StepStatus.Done, State(EditPath.Time, untimed, project: manual).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StackingIsOptional()
|
||||
{
|
||||
var content = EditorFixture.Content(EditorFixture.Sunset);
|
||||
var none = State(EditPath.Stack, content);
|
||||
Assert.Equal(StepStatus.Todo, none.Status);
|
||||
Assert.Equal(Loc.L("Editor.Step.Optional"), none.Text);
|
||||
var trails = State(EditPath.Stack, content, project: new ProjectSettings { Stack = new StackSettings { Mode = StackSetting.StarTrails } });
|
||||
Assert.Equal(StepStatus.Done, trails.Status);
|
||||
Assert.Equal(Loc.L("Editor.Stack.StarTrails"), trails.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExportFollowsTheRenderItsBlockerAndWhetherTheVideoIsCurrent()
|
||||
{
|
||||
var content = EditorFixture.Content(EditorFixture.Sunset);
|
||||
Assert.Equal(StepStatus.Todo, State(EditPath.Export, content).Status);
|
||||
Assert.Equal(Loc.L("Editor.Step.NotRendered"), State(EditPath.Export, content).Text);
|
||||
|
||||
var blocked = State(EditPath.Export, content, renderBlocked: "No encoder");
|
||||
Assert.Equal(StepStatus.Attention, blocked.Status);
|
||||
Assert.Equal("No encoder", blocked.Detail);
|
||||
|
||||
Assert.Equal(StepStatus.Running, State(EditPath.Export, content, render: Job(JobKind.Render, JobState.Queued)).Status);
|
||||
|
||||
var rendered = content with { Renders = [Render(new ProjectSettings().ToJson())] };
|
||||
Assert.Equal(StepStatus.Done, State(EditPath.Export, rendered, renderMatches: true).Status);
|
||||
var outdated = State(EditPath.Export, rendered, renderMatches: false);
|
||||
Assert.Equal(StepStatus.Attention, outdated.Status);
|
||||
Assert.Equal(Loc.L("Editor.Step.Outdated"), outdated.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheSignatureIgnoresWhatDoesNotChangeTheVideo()
|
||||
{
|
||||
var project = new ProjectSettings();
|
||||
var same = project with
|
||||
{
|
||||
HeroFrame = 12,
|
||||
PendingFrames = [new PendingFrame { Sha256 = "ab", Size = 10, Excluded = true }],
|
||||
Export = project.Export with { Batch = ["4k-hevc"], Folder = @"D:\Videos", NameTemplate = "{title}", SyncToServer = true },
|
||||
};
|
||||
Assert.Equal(EditPath.Signature(project), EditPath.Signature(same));
|
||||
Assert.NotEqual(EditPath.Signature(project), EditPath.Signature(project with { ExcludedFrames = [3] }));
|
||||
Assert.NotEqual(EditPath.Signature(project), EditPath.Signature(EditorSettings.Deflicker.WithManual(project, true)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ARenderCountsAsCurrentWhenAnyRenderHasTheSettingsOrTheNewestKeepsNone()
|
||||
{
|
||||
var a = new ProjectSettings();
|
||||
var b = EditorSettings.Deflicker.WithManual(a, true);
|
||||
Assert.False(new RenderedSettings([]).Matches(a), "no render");
|
||||
var rendered = new RenderedSettings([Render(b.ToJson()), Render(a.ToJson())]);
|
||||
Assert.True(rendered.Matches(a), "an older render has these settings");
|
||||
Assert.True(rendered.Matches(b));
|
||||
Assert.False(rendered.Matches(a with { ExcludedFrames = [1] }));
|
||||
Assert.True(new RenderedSettings([Render(null), Render(a.ToJson())]).Matches(b), "the newest (a server's) says nothing about its settings");
|
||||
Assert.True(new RenderedSettings([Render("{ not json")]).Matches(b), "unreadable settings say nothing either");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheEditorOpensOnTheRememberedStepElseAnalysisUntilTheSequenceIsAnalysed()
|
||||
{
|
||||
var bare = EditorFixture.Content(EditorFixture.Sunset, deep: false);
|
||||
var analysed = EditorFixture.Content(EditorFixture.Sunset);
|
||||
Assert.Equal(EditPath.Analysis, EditPath.Start(null, bare));
|
||||
Assert.Equal(EditPath.Frames, EditPath.Start(null, analysed));
|
||||
Assert.Equal(EditPath.Export, EditPath.Start(EditPath.Export, bare));
|
||||
// A deep analysis that waits, runs or is paused shows first, also for an analysed sequence; the memory still wins.
|
||||
Assert.Equal(EditPath.Analysis, EditPath.Start(null, analysed, Job(JobKind.DeepAnalyse, JobState.Queued)));
|
||||
Assert.Equal(EditPath.Camera, EditPath.Start(EditPath.Camera, analysed, Job(JobKind.DeepAnalyse, JobState.Running)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FramesOfAnotherSizeOrOrientationAreForTheFramesStep()
|
||||
{
|
||||
Assert.Equal(EditPath.Frames, EditPath.StepOf(FindingKeys.MixedResolution), "Frames excludes them; no Camera setting acts on single frames");
|
||||
Assert.Equal(EditPath.Frames, EditPath.StepOf(FindingKeys.MixedOrientation));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValuesSetByHandReadEditedEvenWhenEveryAutoSettingIsAuto()
|
||||
{
|
||||
var content = EditorFixture.Content(EditorFixture.Sunset);
|
||||
Assert.Equal(Loc.L("Common.Auto"), State(EditPath.Camera, content).Text);
|
||||
Assert.Equal(Loc.L("Common.Auto"), State(EditPath.Time, content).Text);
|
||||
Assert.Equal(Loc.L("Common.Auto"), State(EditPath.Exposure, content).Text);
|
||||
|
||||
var project = new ProjectSettings();
|
||||
Assert.Equal(Loc.L("Editor.Step.Edited"), State(EditPath.Camera, content, project: project with { Camera = new CameraSettings { Crop = [0, 0.1, 1, 0.9] } }).Text, "a crop");
|
||||
Assert.Equal(Loc.L("Editor.Step.Edited"),
|
||||
State(EditPath.Camera, content, project: project with { Camera = new CameraSettings { Keyframes = [new CameraKey(10, 0.5, 0.5, 1, 0)] } }).Text, "a camera move");
|
||||
Assert.Equal(Loc.L("Editor.Step.Edited"), State(EditPath.Camera, content, project: project with { Camera = new CameraSettings { OffsetX = 0.05 } }).Text, "an offset");
|
||||
Assert.Equal(Loc.L("Editor.Step.Edited"), State(EditPath.Time, content, project: project with { Timing = project.Timing with { FitToSeconds = 30 } }).Text, "fit to 30 s");
|
||||
Assert.Equal(Loc.L("Editor.Step.Edited"),
|
||||
State(EditPath.Exposure, content, project: project with { Exposure = project.Exposure with { ExposureOffsetEv = 0.5 } }).Text, "an exposure offset");
|
||||
Assert.Equal(Loc.L("Common.Auto"), State(EditPath.Camera, content, project: project with { Camera = new CameraSettings { Crop = [0, 0, 1, 1] } }).Text,
|
||||
"a crop of the whole frame is no crop");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AMissingValueOfASettingThatDoesNotApplyAsksNothing()
|
||||
{
|
||||
// No aperture in the metadata (a manual lens): holy grail and its transition length cannot be decided.
|
||||
var analysed = EditorFixture.Content(EditorFixture.Sunset);
|
||||
var frames = analysed.Frames.Select(f => f with { FNumber = null }).ToList();
|
||||
var blind = analysed with { Frames = frames, Light = LightAnalyzer.Analyze(frames) };
|
||||
Assert.True(Advice(blind).Find(AdvisorParameters.TransitionLength) is { IsMissingData: true }, "the transition length lacks data");
|
||||
Assert.Equal(StepStatus.Attention, State(EditPath.Exposure, blind).Status, "holy grail is to be decided");
|
||||
// Holy grail switched off by hand: the transition length shows n/a and cannot be set, so it is not asked for.
|
||||
var off = EditorSettings.HolyGrail.WithManual(new ProjectSettings(), false);
|
||||
var decided = State(EditPath.Exposure, blind, project: off);
|
||||
Assert.Equal(StepStatus.Done, decided.Status);
|
||||
Assert.Equal(Loc.L("Editor.Step.Edited"), decided.Text);
|
||||
Assert.False(EditorSettings.Applies(EditorSettings.TransitionLength, off, blind.Deep));
|
||||
Assert.True(EditorSettings.Applies(EditorSettings.TransitionLength, EditorSettings.HolyGrail.WithManual(off, true), blind.Deep));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnAnalysisThatFoundNoRegionsDoesNotKeepExposureWaiting()
|
||||
{
|
||||
var analysed = EditorFixture.Content(EditorFixture.Sunset);
|
||||
var noRegions = analysed with { Deep = analysed.Deep! with { Regions = null } };
|
||||
Assert.True(Advice(noRegions).Find(AdvisorParameters.Regions) is { IsMissingData: true }, "the advisor has no region value");
|
||||
Assert.NotEqual(StepStatus.Waiting, State(EditPath.Exposure, noRegions).Status, "the analysis has run: regions stay at the engine's fallback");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheAnalysisStampTellsOneAnalysisFromAnother()
|
||||
{
|
||||
var bare = EditorFixture.Content(EditorFixture.Sunset, deep: false);
|
||||
var analysed = EditorFixture.Content(EditorFixture.Sunset);
|
||||
Assert.Null(EditPath.AnalysisStamp(bare));
|
||||
Assert.NotNull(EditPath.AnalysisStamp(analysed));
|
||||
Assert.Equal(EditPath.AnalysisStamp(analysed), EditPath.AnalysisStamp(EditorFixture.Content(EditorFixture.Sunset)), "the same analysis read again");
|
||||
var again = analysed with { Deep = analysed.Deep! with { Shake = analysed.Deep.Shake with { RmsPx = analysed.Deep.Shake.RmsPx + 1 } } };
|
||||
Assert.NotEqual(EditPath.AnalysisStamp(analysed), EditPath.AnalysisStamp(again));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EveryFindingHasTheStepThatDealsWithIt()
|
||||
{
|
||||
var keys = typeof(FindingKeys).GetFields(BindingFlags.Public | BindingFlags.Static)
|
||||
.Concat(typeof(DeepFindingKeys).GetFields(BindingFlags.Public | BindingFlags.Static))
|
||||
.Where(f => f.IsLiteral && f.FieldType == typeof(string))
|
||||
.Select(f => (string)f.GetRawConstantValue()!)
|
||||
.ToList();
|
||||
Assert.Count(29, keys);
|
||||
foreach (var key in keys)
|
||||
{
|
||||
var step = EditPath.StepOf(key);
|
||||
Assert.NotNull(step, key);
|
||||
Assert.Contains(step!, Steps, key);
|
||||
Assert.NotEqual(EditPath.Analysis, step, $"{key}: the Analysis step lists every finding, it deals with none");
|
||||
}
|
||||
}
|
||||
|
||||
private static StepState State(string step, SequenceContent content, ProjectSettings? project = null, Job? analysis = null, Job? render = null,
|
||||
string? renderBlocked = null, bool renderMatches = false) =>
|
||||
EditPath.Of(step, new PathFacts(content, Advice(content), project ?? content.Project, analysis, render, renderBlocked, renderMatches));
|
||||
|
||||
private static AdvisorResult Advice(SequenceContent content) => Advisor.Recommend(content.Light, content.Deep, SequenceContext.FromFrames(content.Frames, []));
|
||||
|
||||
/// <summary><paramref name="setting"/> taken over by hand at its current value.</summary>
|
||||
private static ProjectSettings Manual(IAutoSetting setting, ProjectSettings project) => setting switch
|
||||
{
|
||||
AutoSetting<bool> b => b.WithManual(project, b.Effective(project, null)),
|
||||
AutoSetting<int> i => i.WithManual(project, i.Effective(project, null)),
|
||||
AutoSetting<double> d => d.WithManual(project, d.Effective(project, null)),
|
||||
AutoSetting<string> s => s.WithManual(project, s.Effective(project, null)),
|
||||
AutoSetting<TimingMode> t => t.WithManual(project, t.Effective(project, null)),
|
||||
AutoSetting<RegionMode> r => r.WithManual(project, r.Effective(project, null)),
|
||||
AutoSetting<FlowQualitySetting> f => f.WithManual(project, f.Effective(project, null)),
|
||||
_ => throw new InvalidOperationException(setting.Id),
|
||||
};
|
||||
|
||||
private static Job Job(JobKind kind, JobState state) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Kind = kind,
|
||||
State = state,
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
private static Render Render(string? settings) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
SequenceId = Guid.CreateVersion7(),
|
||||
PresetName = "4K",
|
||||
OutputPath = "exports/a.mp4",
|
||||
SettingsJson = settings,
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
};
|
||||
}
|
||||
@@ -111,6 +111,9 @@ internal sealed class FakeSequenceSource(SyntheticSequence sequence, SequenceCon
|
||||
/// <summary>Thrown by the next save.</summary>
|
||||
public Exception? FailNextSave { get; set; }
|
||||
|
||||
/// <summary>Thrown by every save while set (an archive that stays offline).</summary>
|
||||
public Exception? FailSaves { get; set; }
|
||||
|
||||
/// <summary>Awaited by every decode (tests of cancellation).</summary>
|
||||
public Task DecodeGate { get; set; } = Task.CompletedTask;
|
||||
|
||||
@@ -158,6 +161,7 @@ internal sealed class FakeSequenceSource(SyntheticSequence sequence, SequenceCon
|
||||
|
||||
public Task<ProjectSettings> SaveProjectAsync(ProjectSettings project, ProjectSettings basis, CancellationToken cancellationToken)
|
||||
{
|
||||
if (FailSaves is { } lasting) return Task.FromException<ProjectSettings>(lasting);
|
||||
if (FailNextSave is { } failure)
|
||||
{
|
||||
FailNextSave = null;
|
||||
|
||||
@@ -494,6 +494,11 @@ public sealed class EditorSmokeTests
|
||||
{
|
||||
switch (tab)
|
||||
{
|
||||
case AnalysisTab analysis:
|
||||
// The findings, each with the step that deals with it, or the sentence that there are none.
|
||||
Assert.True(Find<ListBoxItem>(view).Any(i => i.DataContext is AnalysisFinding && i.IsVisible)
|
||||
|| Find<EmptyState>(view).Any(e => e.IsVisible && e.Message == analysis.EmptyText), "Analysis: findings or why there are none");
|
||||
break;
|
||||
case FramesTab frames:
|
||||
Assert.Equal(96, frames.Frames.Count);
|
||||
Assert.NotEmpty(Find<ListBoxItem>(view).Where(i => i.DataContext is FrameRow && i.IsVisible));
|
||||
|
||||
@@ -194,6 +194,75 @@ public sealed class SchedulingTests
|
||||
Assert.Equal(attempts, saved);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AHeldChangeIsNotRetriedUntilReleased()
|
||||
{
|
||||
var fail = true;
|
||||
var attempts = 0;
|
||||
var stored = new List<int?>();
|
||||
var saver = new ProjectSaver(p =>
|
||||
{
|
||||
attempts++;
|
||||
if (fail) throw new System.IO.IOException("offline");
|
||||
stored.Add(p.HeroFrame);
|
||||
return Task.CompletedTask;
|
||||
}, TimeSpan.Zero);
|
||||
saver.Schedule(new ProjectSettings { HeroFrame = 1 });
|
||||
Assert.False(await saver.FlushAsync());
|
||||
Assert.True(await saver.HoldAsync(), "the failed change still waits");
|
||||
fail = false;
|
||||
var tried = attempts;
|
||||
// Neither the retry (2 s after the failure) nor a flush writes while the user is asked.
|
||||
var flush = saver.FlushAsync();
|
||||
await Task.Delay(2500);
|
||||
Assert.Equal(tried, attempts, "no write while held");
|
||||
Assert.False(flush.IsCompleted);
|
||||
saver.Release();
|
||||
Assert.True(await flush.WaitAsync(TimeSpan.FromSeconds(10)), "kept: stored once released");
|
||||
Assert.SequenceEqual([(int?)1], stored);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ADiscardedChangeIsNeverWrittenEvenWhenTheArchiveComesBack()
|
||||
{
|
||||
var fail = true;
|
||||
var stored = new List<int?>();
|
||||
var saver = new ProjectSaver(p =>
|
||||
{
|
||||
if (fail) throw new System.IO.IOException("offline");
|
||||
stored.Add(p.HeroFrame);
|
||||
return Task.CompletedTask;
|
||||
}, TimeSpan.Zero);
|
||||
saver.Schedule(new ProjectSettings { HeroFrame = 3 });
|
||||
Assert.False(await saver.FlushAsync());
|
||||
Assert.True(await saver.HoldAsync());
|
||||
// The archive answers again while the question is open; the user then discards the change.
|
||||
fail = false;
|
||||
await Task.Delay(2500);
|
||||
saver.Stop();
|
||||
Assert.True(await saver.FlushAsync().WaitAsync(TimeSpan.FromSeconds(10)));
|
||||
Assert.Count(0, stored, "the discarded change was never written");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AHoldWaitsForTheWriteUnderWay()
|
||||
{
|
||||
var gate = new TaskCompletionSource();
|
||||
var started = new TaskCompletionSource();
|
||||
var saver = new ProjectSaver(async _ =>
|
||||
{
|
||||
started.TrySetResult();
|
||||
await gate.Task;
|
||||
}, TimeSpan.Zero);
|
||||
saver.Schedule(new ProjectSettings { HeroFrame = 1 });
|
||||
await started.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
var hold = saver.HoldAsync();
|
||||
Assert.False(hold.IsCompleted, "the write under way may still fail");
|
||||
gate.SetResult();
|
||||
Assert.False(await hold.WaitAsync(TimeSpan.FromSeconds(10)), "it stored the change: nothing to ask");
|
||||
saver.Release();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FlushWithNothingPendingIsStored()
|
||||
{
|
||||
|
||||
@@ -70,6 +70,27 @@ public sealed class SequenceJobsTests
|
||||
Assert.Equal(paused.Id, jobs.Shown!.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EachStepFollowsTheRunningJobOfItsKindThenThePausedThenTheOldestWaiting()
|
||||
{
|
||||
var jobs = new SequenceJobs(Sunset);
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var waiting = Job(JobKind.DeepAnalyse, JobState.Queued) with { Created = now.AddMinutes(-9) };
|
||||
var paused = Job(JobKind.DeepAnalyse, JobState.Paused) with { Created = now.AddMinutes(-1), Started = now.AddMinutes(-1) };
|
||||
var render = Job(JobKind.Render, JobState.Running) with { Started = now };
|
||||
Assert.Null(jobs.Active(JobKind.DeepAnalyse));
|
||||
jobs.Track(waiting);
|
||||
Assert.Equal(waiting.Id, jobs.Active(JobKind.DeepAnalyse)!.Id);
|
||||
jobs.Track(paused);
|
||||
Assert.Equal(paused.Id, jobs.Active(JobKind.DeepAnalyse)!.Id, "a paused one before a waiting one");
|
||||
jobs.Track(render);
|
||||
Assert.Equal(paused.Id, jobs.Active(JobKind.DeepAnalyse)!.Id, "the running render is of another kind");
|
||||
Assert.Equal(render.Id, jobs.Active(JobKind.Render)!.Id);
|
||||
jobs.Track(waiting with { State = JobState.Running, Started = now });
|
||||
Assert.Equal(waiting.Id, jobs.Active(JobKind.DeepAnalyse)!.Id, "a running one first");
|
||||
Assert.Null(jobs.Active(JobKind.LightAnalyse));
|
||||
}
|
||||
|
||||
private static Job Job(JobKind kind, JobState state, Guid? target = null) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
|
||||
Reference in new issue
Block a user