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(),
|
||||
|
||||
@@ -0,0 +1,482 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Automation.Peers;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Titano.App.Archiving;
|
||||
using Titano.App.Editor;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Library;
|
||||
using Titano.App.Sections;
|
||||
using Titano.App.Shell;
|
||||
using Titano.App.Tests.Editor;
|
||||
using Titano.Core.Export;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Testing;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Ui.Mvvm;
|
||||
|
||||
namespace Titano.App.Tests.Windows;
|
||||
|
||||
/// <summary>
|
||||
/// The Edit section's picker (owner review 1, R7) on the capture sample: one list of this PC's and the server's
|
||||
/// sequences, the search, the empty states, opening with Enter or a double-click, Change sequence and Esc, a sequence
|
||||
/// that cannot open, the open sequence deleted, and the open sequence's unsaved edit, kept or discarded, asked about once.
|
||||
/// </summary>
|
||||
[WindowsOnly]
|
||||
[Serial]
|
||||
[Timeout(300_000)]
|
||||
public sealed class EditSectionTests
|
||||
{
|
||||
[Test]
|
||||
public Task ThePickerListsThisPcAndTheServerNewestFirstAndSearches() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
await app.Sample.FillAsync();
|
||||
await app.Shell.Services.Server.RestoreAsync();
|
||||
await app.Shell.Services.Sync.RefreshAsync();
|
||||
await app.Shell.Library.RefreshAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
await app.ExpectAsync<SequenceView>("edit-picker");
|
||||
Assert.True(section.ShowsPicker, "no sequence open: the picker shows");
|
||||
Assert.Equal(Text("Shell.Nav.Edit"), section.Title);
|
||||
|
||||
var items = section.Picker.Items.ToList();
|
||||
Assert.True(items.Count > 10, "the sample's sequences");
|
||||
var captures = items.Select(i => i.Sequence.FirstCapture).ToList();
|
||||
for (var i = 1; i < captures.Count; i++)
|
||||
Assert.True(captures[i] is not { } after || (captures[i - 1] is { } before && before >= after), $"newest first at row {i}");
|
||||
Assert.Contains(items, i => i.IsRemote && i.Title == "Sunrise over Superga");
|
||||
Assert.Same(items[0], section.Picker.Selected, "nothing edited yet: the first row is selected");
|
||||
|
||||
// The search narrows the list a moment after the last key; no match offers Clear search.
|
||||
await SearchAsync(section, "harbour");
|
||||
Assert.True(section.Picker.Items.Count is > 0 and < 5, "only the harbour sequence");
|
||||
Assert.True(section.Picker.Items.All(i => i.Title.Contains("Harbour", StringComparison.OrdinalIgnoreCase)));
|
||||
await SearchAsync(section, "no such sequence");
|
||||
Assert.True(section.Picker.IsNoMatch);
|
||||
Assert.False(section.Picker.IsEmptyLibrary);
|
||||
var shown = section.Picker.Loading;
|
||||
section.Picker.ClearCommand.Execute(null);
|
||||
await DebouncedAsync(section, shown);
|
||||
Assert.Equal(items.Count, section.Picker.Items.Count);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task AnEmptyLibraryOffersImport() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
Assert.True(section.Picker.IsEmptyLibrary);
|
||||
Assert.False(section.Picker.OpenCommand.CanExecute(null));
|
||||
section.OpenImportCommand.Execute(null);
|
||||
Assert.Equal(SectionKey.Import, app.Shell.Current.Key);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task EnterOpensTheSequenceAndChangeSequenceComesBackToTheSameEditor() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
var saves = 0;
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync(saveSettings: () => saves++);
|
||||
await app.Sample.FillAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
await SettleAsync(app.Window);
|
||||
|
||||
// The search box has the keyboard; Enter there opens the selected row (the first).
|
||||
var first = section.Picker.Items[0];
|
||||
var search = Find<TextBox>(app.Window).Single(t => t.Name == "Search");
|
||||
Assert.Same(search, FocusManager.GetFocusedElement(app.Window), "the search box has the keyboard when the picker shows");
|
||||
Press(search, Key.Enter);
|
||||
var editor = await OpenedAsync(section);
|
||||
Assert.Equal(first.Id, editor.Session.Content.Sequence.Id);
|
||||
Assert.False(section.ShowsPicker);
|
||||
Assert.Equal(first.Id, app.Shell.Services.Settings.LastEditedSequence);
|
||||
Assert.True(saves > 0, "the sequence edited last is written");
|
||||
await SettleAsync(app.Window);
|
||||
|
||||
// Change sequence: the picker covers the editor, which stays open and laid out; the open sequence is selected.
|
||||
Assert.True(section.ChangeSequenceCommand.CanExecute(null), "the open has ended");
|
||||
section.ChangeSequenceCommand.Execute(null);
|
||||
await section.Picker.Loading;
|
||||
await SettleAsync(app.Window);
|
||||
Assert.True(section.ShowsPicker && section.IsPicking);
|
||||
Assert.Same(search, FocusManager.GetFocusedElement(app.Window), "the search box has the keyboard again");
|
||||
Assert.Equal(first.Id, section.Picker.Selected?.Id);
|
||||
Assert.Equal(Text("Shell.Nav.Edit"), section.Title, "the window title names the section while choosing");
|
||||
var root = Find<Grid>(app.Window).Single(g => g.Name == "EditorRoot");
|
||||
Assert.Greater(root.ActualWidth, 0, "the editor stays laid out behind the picker");
|
||||
|
||||
// Esc with an empty search goes back to the same editor.
|
||||
Press(search, Key.Escape);
|
||||
Assert.False(section.IsPicking);
|
||||
Assert.Same(editor, section.Editor);
|
||||
|
||||
// Coming back to Edit leaves a choice on screen; asking for the open sequence (the Library's Open) ends it.
|
||||
Assert.True(section.ChangeSequenceCommand.CanExecute(null));
|
||||
section.ChangeSequenceCommand.Execute(null);
|
||||
app.Shell.Navigate(SectionKey.Library);
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
Assert.True(section.IsPicking, "coming back to Edit leaves the choice on screen");
|
||||
app.Shell.Navigate(SectionKey.Library);
|
||||
app.Shell.OpenSequence(first.Id);
|
||||
Assert.Equal(SectionKey.Edit, app.Shell.Current.Key);
|
||||
Assert.False(section.IsPicking, "opening the open sequence shows it");
|
||||
Assert.Same(editor, section.Editor);
|
||||
// Also while Edit is on screen (a toast's Open, a project file of the open sequence).
|
||||
section.ChangeSequenceCommand.Execute(null);
|
||||
app.Shell.OpenSequence(first.Id);
|
||||
Assert.False(section.IsPicking);
|
||||
Assert.Same(editor, section.Editor);
|
||||
});
|
||||
|
||||
/// <summary>Enter typed within the search's 250 ms opens a match of what was typed, not the row selected before.</summary>
|
||||
[Test]
|
||||
public Task EnterRightAfterTypingOpensAMatch() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
await app.Sample.FillAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
await SettleAsync(app.Window);
|
||||
Assert.False(section.Picker.Selected!.Title.Contains("Langhe", StringComparison.OrdinalIgnoreCase), "another sequence is selected first");
|
||||
var search = Find<TextBox>(app.Window).Single(t => t.Name == "Search");
|
||||
section.Picker.SearchText = "langhe";
|
||||
Press(search, Key.Enter);
|
||||
var editor = await OpenedAsync(section);
|
||||
Assert.True(editor.Title.Contains("Langhe", StringComparison.OrdinalIgnoreCase), $"opened '{editor.Title}'");
|
||||
});
|
||||
|
||||
/// <summary>A double-click on a row opens it, in the picker and in the Library's list and grid (the row takes the mouse-down).</summary>
|
||||
[Test]
|
||||
public Task ADoubleClickOnARowOpensIt() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
await app.Sample.FillAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
await SettleAsync(app.Window);
|
||||
var list = Find<ListBox>(app.Window).Single(l => l.Name == "List" && l.IsVisible);
|
||||
var item = section.Picker.Items.Skip(1).First(i => !i.IsRemote);
|
||||
DoubleClick(Cell(list, item));
|
||||
var editor = await OpenedAsync(section);
|
||||
Assert.Equal(item.Id, editor.Session.Content.Sequence.Id, "the row double-clicked opened, not the one selected");
|
||||
|
||||
// The Library's list and grid: a double-click opens the sequence in Edit.
|
||||
foreach (var grid in new[] { false, true })
|
||||
{
|
||||
app.Shell.Navigate(SectionKey.Library);
|
||||
await app.Shell.Library.RefreshAsync();
|
||||
app.Shell.Library.LayoutIndex = grid ? 0 : 1;
|
||||
await SettleAsync(app.Window);
|
||||
var name = grid ? "CardGrid" : "RowList";
|
||||
var library = Find<ListBox>(app.Window).Single(l => l.Name == name && l.IsVisible);
|
||||
var target = app.Shell.Library.Items.First(i => !i.IsRemote && i.Id != app.Shell.CurrentSequenceId);
|
||||
DoubleClick(Cell(library, target));
|
||||
Assert.Equal(SectionKey.Edit, app.Shell.Current.Key, grid ? "a card" : "a row");
|
||||
Assert.Equal(target.Id, app.Shell.CurrentSequenceId);
|
||||
await OpenedAsync(section, target.Id);
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// A sequence that cannot open (gone from the index, no server to ask) leaves the open one open behind the picker, with
|
||||
/// Cancel still there, and the open one again the sequence asked for (owner review 1, R7 review).
|
||||
/// </summary>
|
||||
[Test]
|
||||
public Task ASequenceThatCannotOpenLeavesTheOpenOneOpen() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
await app.Sample.FillAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
var first = section.Picker.Items.First(i => !i.IsRemote);
|
||||
await section.PickAsync(first);
|
||||
var editor = await OpenedAsync(section);
|
||||
section.ChangeSequenceCommand.Execute(null);
|
||||
await section.Picker.Loading;
|
||||
|
||||
// The window shows and clears the toasts: they are counted as they come.
|
||||
var errors = 0;
|
||||
app.Shell.PendingToasts.CollectionChanged += (_, e) => errors += e.NewItems?.OfType<Toast>().Count(t => t.IsError) ?? 0;
|
||||
var gone = new SequenceItem(first.Sequence with { Id = Guid.CreateVersion7() }, null);
|
||||
await section.PickAsync(gone);
|
||||
Assert.Same(editor, section.Editor, "the open sequence stayed open");
|
||||
Assert.True(section.IsPicking && section.CanCancelPick, "the choice goes on, and Cancel goes back");
|
||||
Assert.Equal(first.Id, app.Shell.CurrentSequenceId, "the open sequence is again the one asked for");
|
||||
Assert.Equal(1, errors, "the failure is reported once");
|
||||
section.CancelPickCommand.Execute(null);
|
||||
app.Shell.Navigate(SectionKey.Library);
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await SettleAsync(app.Window);
|
||||
Assert.Same(editor, section.Editor);
|
||||
Assert.Equal(1, errors, "coming back neither tries again nor reports it again");
|
||||
});
|
||||
|
||||
/// <summary>The open sequence deleted from the Library: the editor closes, and coming back to Edit shows the picker, not a failed open.</summary>
|
||||
[Test]
|
||||
public Task DeletingTheOpenSequenceLeavesThePicker() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
await app.Sample.FillAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
var first = section.Picker.Items.First(i => !i.IsRemote);
|
||||
await section.PickAsync(first);
|
||||
await OpenedAsync(section);
|
||||
var row = Assert.NotNull(await app.Shell.Services.Database!.Sequences.GetAsync(first.Id));
|
||||
|
||||
app.Shell.Navigate(SectionKey.Library);
|
||||
Assert.True(await SequenceDeletion.CloseEditorAsync(app.Shell, new DeletePlan([new DeleteStep(row, null, 0, 0)], [])));
|
||||
Assert.Null(section.Editor, "the editor closed");
|
||||
Assert.Null(app.Shell.CurrentSequenceId, "the deleted sequence is no longer asked for");
|
||||
var errors = 0;
|
||||
app.Shell.PendingToasts.CollectionChanged += (_, e) => errors += e.NewItems?.OfType<Toast>().Count(t => t.IsError) ?? 0;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
await SettleAsync(app.Window);
|
||||
Assert.True(section.ShowsPicker);
|
||||
Assert.False(section.IsLoading);
|
||||
Assert.Equal(0, errors, "no failed open");
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// The sequence edited last is selected and in view even when it is older than the first page (read on until it comes),
|
||||
/// and with a sequence open the open one is (owner review 1, R7 review).
|
||||
/// </summary>
|
||||
[Test]
|
||||
public Task TheSequenceEditedLastIsSelectedAndShownBeyondTheFirstPage() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
app.Window.Width = 1200;
|
||||
app.Window.Height = 788;
|
||||
await app.Sample.FillAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
var oldest = section.Picker.Items.Last(i => !i.IsRemote);
|
||||
Assert.True(section.Picker.Items.IndexOf(oldest) > 20, "an old sequence, far down the list");
|
||||
app.Shell.Services.Settings.LastEditedSequence = oldest.Id;
|
||||
section.Picker.PageSize = 5;
|
||||
await section.Picker.ReloadAsync();
|
||||
await SettleAsync(app.Window);
|
||||
Assert.Equal(oldest.Id, section.Picker.Selected?.Id, "read on until the sequence edited last is listed");
|
||||
var list = Find<ListBox>(app.Window).Single(l => l.Name == "List" && l.IsVisible);
|
||||
var row = Assert.NotNull(list.ItemContainerGenerator.ContainerFromItem(section.Picker.Selected!) as ListBoxItem, "its row is realised");
|
||||
var top = row.TranslatePoint(new Point(0, 0), list).Y;
|
||||
Assert.True(top >= -0.5 && top + row.ActualHeight <= list.ActualHeight + 0.5, "and scrolled into view");
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// At 1200 px in every language each picker row reads as its title to screen readers, and its states (Analysed,
|
||||
/// Proxies, Remote) are whole inside the row.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public Task PickerRowsReadAsTheirTitleAndKeepTheirStatesWholeInEveryLanguage() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
app.Window.Width = 1200;
|
||||
app.Window.Height = 788;
|
||||
await app.Sample.FillAsync();
|
||||
await app.Shell.Services.Server.RestoreAsync();
|
||||
await app.Shell.Services.Sync.RefreshAsync();
|
||||
await app.Shell.Library.RefreshAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await section.Picker.Loading;
|
||||
try
|
||||
{
|
||||
foreach (var language in Languages.Shipped)
|
||||
{
|
||||
UiLanguage.Apply(language);
|
||||
await section.Picker.ReloadAsync();
|
||||
await SettleAsync(app.Window);
|
||||
var rows = Find<ListBoxItem>(app.Window).Where(r => r.IsVisible && r.DataContext is SequenceItem).ToList();
|
||||
Assert.True(rows.Count > 5, $"{language}: rows show");
|
||||
Assert.True(rows.Any(r => ((SequenceItem)r.DataContext).IsRemote), $"{language}: a server row shows");
|
||||
foreach (var row in rows)
|
||||
{
|
||||
var item = (SequenceItem)row.DataContext;
|
||||
Assert.Equal(item.Title, UIElementAutomationPeer.CreatePeerForElement(row).GetName(), $"{language}: the row reads as its title");
|
||||
var states = Find<ItemsControl>(row).Single(c => c.ItemsSource is not null && !ReferenceEquals(c, row));
|
||||
var a = states.TranslatePoint(new Point(0, 0), row).X;
|
||||
var b = states.TranslatePoint(new Point(states.ActualWidth, 0), row).X;
|
||||
Assert.True(double.Min(a, b) >= row.Padding.Left - 0.5 && double.Max(a, b) <= row.ActualWidth - row.Padding.Right + 0.5,
|
||||
$"{language}: the states of '{item.Title}' span {double.Min(a, b):0}–{double.Max(a, b):0} px in a {row.ActualWidth:0} px row");
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task AnUnsavedEditIsAskedAboutOnceAndKeptOrDiscarded() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
var dialogs = new CountingDialogs { Discard = false };
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync(dialogs: dialogs);
|
||||
await app.Sample.FillAsync();
|
||||
var section = app.Shell.Sequence;
|
||||
var content = EditorFixture.Content(EditorFixture.Sunset);
|
||||
var source = new FakeSequenceSource(EditorFixture.Sunset, content);
|
||||
var editor = new EditorViewModel(app.Shell, new EditorSession(source, content, []), [], EncoderHost.Client);
|
||||
section.Attach(editor);
|
||||
app.Shell.KeepSequence(content.Sequence.Id);
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await SettleAsync(app.Window);
|
||||
section.ChangeSequenceCommand.Execute(null);
|
||||
await section.Picker.Loading;
|
||||
var other = section.Picker.Items.First(i => !i.IsRemote);
|
||||
|
||||
// The archive stays offline: Keep editing keeps the open sequence, which stays the one asked for.
|
||||
editor.Session.Edit(p => p with { HeroFrame = 2 });
|
||||
source.FailSaves = new IOException("The archive drive is gone");
|
||||
await section.PickAsync(other);
|
||||
Assert.Equal(1, dialogs.Asked);
|
||||
Assert.Same(editor, section.Editor);
|
||||
Assert.False(section.IsPicking);
|
||||
Assert.Equal(content.Sequence.Id, app.Shell.CurrentSequenceId);
|
||||
app.Shell.Navigate(SectionKey.Library);
|
||||
app.Shell.Navigate(SectionKey.Edit);
|
||||
await SettleAsync(app.Window);
|
||||
Assert.Equal(1, dialogs.Asked, "coming back to Edit does not ask again");
|
||||
Assert.Same(editor, section.Editor, "nor opens the other sequence");
|
||||
Assert.Equal(content.Sequence.Id, app.Shell.CurrentSequenceId);
|
||||
|
||||
// Discard: the archive answers again while the question is open (retries would write the edit then), yet the edit is
|
||||
// dropped unwritten and the other sequence opens.
|
||||
dialogs.Discard = true;
|
||||
dialogs.WhileAsked = () =>
|
||||
{
|
||||
source.FailSaves = null;
|
||||
PumpFor(TimeSpan.FromSeconds(2.5));
|
||||
};
|
||||
editor.Session.Edit(p => p with { HeroFrame = 3 });
|
||||
var saves = source.Saves;
|
||||
await section.PickAsync(other);
|
||||
Assert.Equal(2, dialogs.Asked);
|
||||
Assert.Equal(other.Id, section.Editor?.Session.Content.Sequence.Id);
|
||||
Assert.Equal(saves, source.Saves, "nothing was written once the user chose to discard");
|
||||
Assert.NotEqual(3, source.Stored.HeroFrame);
|
||||
});
|
||||
|
||||
/// <summary>Types <paramref name="text"/> in the search and waits for the list it reads.</summary>
|
||||
private static async Task SearchAsync(SequenceViewModel section, string text)
|
||||
{
|
||||
var before = section.Picker.Loading;
|
||||
section.Picker.SearchText = text;
|
||||
await DebouncedAsync(section, before);
|
||||
}
|
||||
|
||||
/// <summary>Waits for the search's own read (its 250 ms timer fires), then for the list it reads, whatever the machine's speed.</summary>
|
||||
private static async Task DebouncedAsync(SequenceViewModel section, Task before)
|
||||
{
|
||||
for (var i = 0; i < 250 && ReferenceEquals(section.Picker.Loading, before); i++) await Task.Delay(20);
|
||||
Assert.False(ReferenceEquals(section.Picker.Loading, before), "the search read the list again");
|
||||
await section.Picker.Loading;
|
||||
}
|
||||
|
||||
/// <summary>Waits until a sequence (<paramref name="id"/>, else any) is open and the whole open, Enter included, has ended.</summary>
|
||||
private static async Task<EditorViewModel> OpenedAsync(SequenceViewModel section, Guid? id = null)
|
||||
{
|
||||
bool Busy() => section.Editor is not { } editor || (id is { } wanted && editor.Session.Content.Sequence.Id != wanted) || section.IsLoading
|
||||
|| ((AsyncRelayCommand)section.Picker.SearchOpenCommand).IsRunning || ((AsyncRelayCommand)section.Picker.OpenItemCommand).IsRunning;
|
||||
for (var i = 0; i < 400 && Busy(); i++) await Task.Delay(50);
|
||||
Assert.False(Busy(), "the sequence opened");
|
||||
await section.Editor!.WhenIdleAsync(TimeSpan.FromSeconds(30));
|
||||
return section.Editor;
|
||||
}
|
||||
|
||||
private static void Press(UIElement target, Key key) =>
|
||||
target.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target)!, 0, key) { RoutedEvent = Keyboard.PreviewKeyDownEvent });
|
||||
|
||||
/// <summary>A left double-click as the mouse raises it: a mouse-down with a click count of 2 on a text of the row (else on the row).</summary>
|
||||
private static void DoubleClick(ListBoxItem row)
|
||||
{
|
||||
UIElement target = Find<TextBlock>(row).FirstOrDefault(t => t.IsVisible && t.ActualWidth > 0) as UIElement ?? row;
|
||||
var down = new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left) { RoutedEvent = Mouse.MouseDownEvent };
|
||||
typeof(MouseButtonEventArgs).GetProperty(nameof(MouseButtonEventArgs.ClickCount))!.SetValue(down, 2);
|
||||
target.RaiseEvent(down);
|
||||
}
|
||||
|
||||
/// <summary>The row of <paramref name="item"/>, scrolled into view.</summary>
|
||||
private static ListBoxItem Cell(ListBox list, object item)
|
||||
{
|
||||
list.ScrollIntoView(item);
|
||||
list.UpdateLayout();
|
||||
return Assert.NotNull(list.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem, "the row is realised");
|
||||
}
|
||||
|
||||
/// <summary>Runs the dispatcher for <paramref name="time"/> (a modal dialog's loop: timers and saves go on meanwhile).</summary>
|
||||
private static void PumpFor(TimeSpan time)
|
||||
{
|
||||
var frame = new DispatcherFrame();
|
||||
var timer = new DispatcherTimer(time, DispatcherPriority.Normal, (_, _) => frame.Continue = false, Dispatcher.CurrentDispatcher);
|
||||
timer.Start();
|
||||
Dispatcher.PushFrame(frame);
|
||||
timer.Stop();
|
||||
}
|
||||
|
||||
private static string Text(string key) => Loc.L(key);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>Counts the confirmations asked and answers them as told (true discards the unsaved edit).</summary>
|
||||
private sealed class CountingDialogs : IAppDialogs
|
||||
{
|
||||
public bool Discard { get; set; }
|
||||
|
||||
public int Asked { get; private set; }
|
||||
|
||||
/// <summary>Runs while the question is open (before the answer), as the user reads it.</summary>
|
||||
public Action? WhileAsked { get; set; }
|
||||
|
||||
public string? PickFolder(string title, string? initialFolder = null) => null;
|
||||
|
||||
public string? PickJsonFile(string title) => null;
|
||||
|
||||
public bool Confirm(ConfirmRequest request)
|
||||
{
|
||||
Asked++;
|
||||
WhileAsked?.Invoke();
|
||||
return Discard;
|
||||
}
|
||||
|
||||
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> signIn) => false;
|
||||
}
|
||||
}
|
||||
@@ -106,8 +106,11 @@ public sealed class ScreenSmokeTests
|
||||
|
||||
shell.Navigate(SectionKey.Import);
|
||||
await app.ExpectAsync<ImportView>("import");
|
||||
shell.Navigate(SectionKey.Sequence);
|
||||
await app.ExpectAsync<SequenceView>("sequence");
|
||||
// Edit with no sequence open: the picker lists the sequences (owner review 1, R7).
|
||||
shell.Navigate(SectionKey.Edit);
|
||||
await shell.Sequence.Picker.Loading;
|
||||
await app.ExpectAsync<SequenceView>("edit-picker");
|
||||
Assert.True(shell.Sequence.ShowsPicker);
|
||||
shell.Navigate(SectionKey.Archive);
|
||||
await app.ExpectAsync<ArchiveView>("archive");
|
||||
});
|
||||
@@ -155,7 +158,7 @@ public sealed class ScreenSmokeTests
|
||||
await app.Shell.Sequence.OpenAsync(id);
|
||||
var editor = Assert.NotNull(app.Shell.Sequence.Editor);
|
||||
Assert.True(await editor.WhenIdleAsync(TimeSpan.FromSeconds(60)), "the editor settled");
|
||||
await app.ExpectAsync<SequenceView>("sequence-ar");
|
||||
await app.ExpectAsync<SequenceView>("edit-ar");
|
||||
|
||||
// Directional glyphs follow the reading direction; the others, the logo, the picture and the charts do not.
|
||||
var back = Assert.NotNull(app.FindAll<Button>().FirstOrDefault(b => b.IsVisible && ReferenceEquals(b.Command, editor.BackCommand)), "the editor's Back button");
|
||||
@@ -272,13 +275,14 @@ public sealed class ScreenSmokeTests
|
||||
/// <param name="language">The UI language, applied before the window is created (as at start-up).</param>
|
||||
/// <param name="firstRun">Opens with the first-run dialog, which keeps the shell behind it disabled.</param>
|
||||
/// <param name="saveSettings">Runs where the app writes its settings file (nothing is written by default).</param>
|
||||
public static async Task<SampleApp> StartAsync(string language = "en", bool firstRun = false, Action? saveSettings = null)
|
||||
/// <param name="dialogs">Answers the app's dialogs (by default every confirmation is declined).</param>
|
||||
public static async Task<SampleApp> StartAsync(string language = "en", bool firstRun = false, Action? saveSettings = null, IAppDialogs? dialogs = null)
|
||||
{
|
||||
var environment = AppEnvironment.ForCapture();
|
||||
UiLanguage.Apply(language);
|
||||
ThemeManager.Apply(AppTheme.Dark);
|
||||
var settings = new AppSettings { Language = language, FirstRunCompleted = !firstRun };
|
||||
var services = new AppServices(environment, settings, saveSettings ?? (() => { }), new NoDialogs());
|
||||
var services = new AppServices(environment, settings, saveSettings ?? (() => { }), dialogs ?? new NoDialogs());
|
||||
var sample = SampleData.Configure(services);
|
||||
var shell = new ShellViewModel(services);
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public sealed class ShellNotificationTests
|
||||
var bindings = app.Window.InputBindings.OfType<KeyBinding>().ToList();
|
||||
var expected = new (Key Key, SectionKey Section)[]
|
||||
{
|
||||
(Key.D1, SectionKey.Library), (Key.D2, SectionKey.Import), (Key.D3, SectionKey.Sequence), (Key.D4, SectionKey.Archive),
|
||||
(Key.D1, SectionKey.Library), (Key.D2, SectionKey.Import), (Key.D3, SectionKey.Edit), (Key.D4, SectionKey.Archive),
|
||||
(Key.D5, SectionKey.Jobs), (Key.D6, SectionKey.Server), (Key.OemComma, SectionKey.Settings),
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user