Owner review 1, phase 3a (docs/requests/2026-10-15-owner-review-1.md, R1). The desktop rail is 200 px wide, so the section names fit in every language, and collapses to 48 px of icons with its ≡ button or Ctrl+B. Collapsed, each icon's tooltip names its section before saying what it is for, while screen readers keep the name and the description. The choice is written to the settings file the moment it changes (nothing else restarts) and survives Settings › Reset all and Import; Ctrl+B waits behind the first-run dialog like Ctrl+1…6, and a held key toggles once. The admin panel's sidebar is 256 px and collapses to icons the same way, with its own ≡ button or Ctrl+B (on the physical key where the layout's B types no Latin letter, so Cyrillic, Greek, Hebrew and Arabic layouts work). The choice is kept in the browser, for the page when the browser refuses storage, and the tables fit their columns again after each toggle. At 900 px and below it stays the top bar and Ctrl+B stays the browser's. The wider rail leaves 49-72 px less for every screen at the 1200 px minimum. Six adversarial review rounds found what that cut, and in every shipped language no action is cut off now: the Jobs columns share their width (Target and Progress give way first, Kind/Where/State capped on wide windows), the editor's preview tools take a second line, a server job's Cancel has its own header column, the Archive tree keeps a year's label, the Import rows and result, the certificates and cache rows and the frame table fit. Headers, titles and cells that may be shortened end in an ellipsis and show their text in their tooltip; state tooltips start with the state, and their explanations were reworded not to repeat it (a queued job "waits for its turn", jobs running one at a time). The crop-result tool sits beside Crop mask, disabled with its reason while the mask is off. Tests check these rows in all 38 languages at 1200 px; the App test program now shuts WPF down in order, so its exit no longer crashes after every test passed. Phase 3 lands as two commits: R7 (the Edit section) edits the same shell files and follows. Also updates BRIEF (12.1, 14.8, 24), DECISIONS, CHANGELOG, STATUS, the request file, DESIGN and the mockups; every new or reworded string is in all 38 languages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
609 lines
32 KiB
C#
609 lines
32 KiB
C#
using System.IO;
|
||
using System.Windows;
|
||
using System.Windows.Automation;
|
||
using System.Windows.Automation.Peers;
|
||
using System.Windows.Automation.Provider;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Input;
|
||
using System.Windows.Shell;
|
||
using System.Windows.Threading;
|
||
using Titano.App.Editor;
|
||
using Titano.App.Infrastructure;
|
||
using Titano.App.Library;
|
||
using Titano.App.Sections;
|
||
using Titano.App.Settings;
|
||
using Titano.App.Shell;
|
||
using Titano.App.Tests.Editor;
|
||
using Titano.Core.Export;
|
||
using Titano.Core.Localization;
|
||
using Titano.Core.Model;
|
||
using Titano.Data.Repositories;
|
||
using Titano.Testing;
|
||
using Titano.Ui.Controls;
|
||
using Titano.Ui.Mvvm;
|
||
using Titano.Ui.Visuals;
|
||
|
||
namespace Titano.App.Tests.Windows;
|
||
|
||
/// <summary>
|
||
/// The shell's ways of telling what happens outside the screen in front: the taskbar button (UI-05), Windows
|
||
/// notifications (UI-06), section shortcuts (UI-07), job toasts (UI-08), rail badges (UI-10), and the General settings
|
||
/// that drive them; the usage counts consent stays hidden in builds without monetization (RF-3).
|
||
/// </summary>
|
||
[WindowsOnly]
|
||
[Serial]
|
||
[Timeout(300_000)]
|
||
public sealed class ShellNotificationTests
|
||
{
|
||
[Test]
|
||
public Task TheTaskbarButtonMirrorsTheJobBar() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
await JobsLoadedAsync(shell);
|
||
var taskbar = Assert.NotNull(app.Window.TaskbarItemInfo);
|
||
|
||
shell.SetJob("Render · Harbour sunset", 0.25, name: "Render: Harbour sunset");
|
||
Assert.Equal(TaskbarItemProgressState.Normal, taskbar.ProgressState);
|
||
Assert.Approximately(0.25, taskbar.ProgressValue, 1e-9);
|
||
|
||
shell.SetJob("Scan · Archive", 0, indeterminate: true);
|
||
Assert.Equal(TaskbarItemProgressState.Indeterminate, taskbar.ProgressState);
|
||
|
||
shell.SetJob(null, 0);
|
||
Assert.Equal(TaskbarItemProgressState.None, taskbar.ProgressState);
|
||
|
||
// A failure nobody has seen on the Jobs screen turns the idle button red.
|
||
shell.SetUnseenFailures(1);
|
||
Assert.Equal(TaskbarItemProgressState.Error, taskbar.ProgressState);
|
||
Assert.Approximately(1, taskbar.ProgressValue, 1e-9);
|
||
shell.SetJob("Render · Harbour sunset", 0.5);
|
||
Assert.Equal(TaskbarItemProgressState.Normal, taskbar.ProgressState, "a running job comes first");
|
||
shell.SetUnseenFailures(0);
|
||
shell.SetJob(null, 0);
|
||
Assert.Equal(TaskbarItemProgressState.None, taskbar.ProgressState);
|
||
});
|
||
|
||
[Test]
|
||
public Task TheRailShortcutsOfTheTooltipsNavigate() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync(firstRun: true);
|
||
var shell = app.Shell;
|
||
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.D5, SectionKey.Jobs), (Key.D6, SectionKey.Server), (Key.OemComma, SectionKey.Settings),
|
||
};
|
||
|
||
// The first-run dialog keeps the shell behind it: no shortcut moves it, nor folds its rail.
|
||
var library = bindings.Single(b => b.Key == Key.D1 && b.Modifiers == ModifierKeys.Control);
|
||
Assert.False(library.Command.CanExecute(library.CommandParameter), "no navigation behind the first-run dialog");
|
||
var rail = bindings.Single(b => b.Key == Key.B && b.Modifiers == ModifierKeys.Control);
|
||
Assert.False(rail.Command.CanExecute(rail.CommandParameter), "Ctrl+B waits for the first-run dialog too");
|
||
shell.CompleteWelcome();
|
||
Assert.True(rail.Command.CanExecute(rail.CommandParameter));
|
||
|
||
foreach (var (key, section) in expected)
|
||
{
|
||
var binding = bindings.Single(b => b.Key == key && b.Modifiers == ModifierKeys.Control);
|
||
Assert.True(binding.Command.CanExecute(binding.CommandParameter), $"Ctrl+{key}");
|
||
binding.Command.Execute(binding.CommandParameter);
|
||
Assert.Equal(section, shell.Current.Key, $"Ctrl+{key}");
|
||
// The rail tooltip lists the shortcut it answers to.
|
||
var shortcut = key == Key.OemComma ? "Ctrl+," : "Ctrl+" + (char)('1' + (key - Key.D1));
|
||
Assert.True(shell.Current.ToolTip.EndsWith(shortcut, StringComparison.Ordinal), $"{section} tooltip ends with {shortcut}");
|
||
}
|
||
|
||
// The editor's 1:1 view no longer takes Ctrl+1 from the Library.
|
||
var gestures = PreviewViewport.ActualSizeCommand.InputGestures.OfType<KeyGesture>().ToList();
|
||
Assert.True(gestures.All(g => g is not { Key: Key.D1, Modifiers: ModifierKeys.Control }), "the preview keeps away from Ctrl+1");
|
||
Assert.Contains(gestures, g => g is { Key: Key.D1, Modifiers: ModifierKeys.Control | ModifierKeys.Shift });
|
||
Assert.Contains("Ctrl+Shift+1", Loc.L("Tooltips.Editor.Preview.OneToOne"));
|
||
});
|
||
|
||
[Test]
|
||
public Task TheRailCollapsesToIconsThatNameTheirSectionByCtrlB() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
// Owner review 1: 200 px with names, 48 px of icons whose tooltips name their section, by the button or Ctrl+B.
|
||
var saves = 0;
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync(saveSettings: () => saves++);
|
||
var shell = app.Shell;
|
||
var rail = (FrameworkElement)app.Window.FindName("Rail");
|
||
var toggle = app.Window.InputBindings.OfType<KeyBinding>().Single(b => b.Key == Key.B && b.Modifiers == ModifierKeys.Control);
|
||
Assert.False(shell.IsRailCollapsed);
|
||
app.Window.UpdateLayout();
|
||
Assert.Approximately(200, rail.ActualWidth, 0.5);
|
||
var buttons = app.FindAll<NavRailButton>().Where(b => b.IsVisible).ToList();
|
||
Assert.Count(shell.AllSections.Count(), buttons);
|
||
foreach (var button in buttons) Assert.Equal(((SectionViewModel)button.DataContext).ToolTip, button.ToolTip);
|
||
|
||
toggle.Command.Execute(toggle.CommandParameter);
|
||
app.Window.UpdateLayout();
|
||
Assert.True(shell.IsRailCollapsed);
|
||
Assert.True(shell.Services.Settings.RailCollapsed);
|
||
Assert.Equal(1, saves, "the choice is written at once");
|
||
Assert.Approximately(48, rail.ActualWidth, 0.5);
|
||
foreach (var button in buttons)
|
||
{
|
||
var section = (SectionViewModel)button.DataContext;
|
||
// The icon's tooltip names the section; screen readers hear the name once (the name, then what it is for).
|
||
Assert.Equal($"{section.Label} · {section.ToolTip}", button.ToolTip);
|
||
Assert.Equal(section.Label, AutomationProperties.GetName(button));
|
||
Assert.Equal(section.ToolTip, AutomationProperties.GetHelpText(button));
|
||
}
|
||
Assert.Contains("Ctrl+B", shell.RailToggleToolTip);
|
||
|
||
// The ≡ button does the same, and the choice is written again.
|
||
var menu = app.FindAll<Button>().Single(b => b.IsVisible && ReferenceEquals(b.Command, shell.ToggleRailCommand));
|
||
((IInvokeProvider)new ButtonAutomationPeer(menu)).Invoke();
|
||
await app.Window.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle);
|
||
app.Window.UpdateLayout();
|
||
Assert.False(shell.IsRailCollapsed);
|
||
Assert.Equal(2, saves);
|
||
Assert.Approximately(200, rail.ActualWidth, 0.5);
|
||
foreach (var button in buttons) Assert.Equal(((SectionViewModel)button.DataContext).ToolTip, button.ToolTip);
|
||
});
|
||
|
||
[Test]
|
||
public Task JobsThatEndRaiseOneToastAndFailuresCountUntilSeen() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
shell.CompleteWelcome();
|
||
await JobsLoadedAsync(shell);
|
||
var jobs = shell.Jobs;
|
||
var raised = new List<Toast>();
|
||
shell.PendingToasts.CollectionChanged += (_, e) => raised.AddRange(e.NewItems?.Cast<Toast>() ?? []);
|
||
var badge = jobs.Badge;
|
||
|
||
// A deep analysis started from the Library ends: one toast whose action opens what it worked on.
|
||
var analysis = Job(JobKind.DeepAnalyse, JobState.Running, Guid.CreateVersion7());
|
||
jobs.OnJobChanged(analysis);
|
||
jobs.Flush();
|
||
jobs.OnJobChanged(analysis with { State = JobState.Done });
|
||
jobs.Flush();
|
||
var done = raised.Single(t => t.Title == Loc.L("Shell.Job.Done"));
|
||
Assert.Equal(Loc.L("Jobs.Action.Open"), done.ActionText);
|
||
Assert.False(done.IsError);
|
||
Assert.True(done.RunsFromNotification, "a click on the Windows notification opens what the job worked on");
|
||
// The same ending reported again says nothing more.
|
||
jobs.OnJobChanged(analysis with { State = JobState.Done });
|
||
jobs.Flush();
|
||
Assert.Equal(1, raised.Count(t => t.Title == Loc.L("Shell.Job.Done")));
|
||
|
||
// A failed verify: an error toast with Retry, a badge on the rail and a red taskbar button until Jobs is opened.
|
||
var verify = Job(JobKind.Verify, JobState.Running, Guid.CreateVersion7());
|
||
jobs.OnJobChanged(verify);
|
||
jobs.Flush();
|
||
jobs.OnJobChanged(verify with { State = JobState.Failed, Error = "Disk read error" });
|
||
jobs.Flush();
|
||
var failed = raised.Single(t => t.Title == Loc.L("Shell.Job.Failed"));
|
||
Assert.True(failed.IsError);
|
||
Assert.Equal(Loc.L("Jobs.Action.Retry"), failed.ActionText);
|
||
Assert.False(failed.RunsFromNotification, "a click on the Windows notification does not retry before the user sees why");
|
||
Assert.Equal(badge + 1, jobs.Badge);
|
||
Assert.Equal(TaskbarItemProgressState.Error, shell.TaskbarState);
|
||
shell.Navigate(SectionKey.Jobs);
|
||
Assert.Equal(badge, jobs.Badge);
|
||
Assert.NotEqual(TaskbarItemProgressState.Error, shell.TaskbarState);
|
||
|
||
// The editor says the renders it followed to their end, with their output: the shell says nothing then. It says them
|
||
// also when the sequence cannot be read again (that error is said too), without Show in folder then.
|
||
var content = EditorFixture.Content(EditorFixture.Sunset);
|
||
var source = new FakeSequenceSource(EditorFixture.Sunset, content);
|
||
var editor = new EditorViewModel(shell, new EditorSession(source, content, []), [], EncoderHost.Client);
|
||
await using (editor)
|
||
{
|
||
foreach (var readable in new[] { true, false })
|
||
{
|
||
raised.Clear();
|
||
var render = Job(JobKind.Render, JobState.Running, content.Sequence.Id);
|
||
source.Report(render);
|
||
jobs.OnJobChanged(render);
|
||
await UntilAsync(() => editor.IsBusy);
|
||
jobs.Flush();
|
||
if (!readable) source.FailNextLoad = new IOException("The specified network name is no longer available.");
|
||
source.Report(render with { State = JobState.Done });
|
||
jobs.OnJobChanged(render with { State = JobState.Done });
|
||
await UntilAsync(() => raised.Any(t => t.Title == Loc.L("Editor.Render.Done")));
|
||
jobs.Flush();
|
||
var finished = Assert.Contains(raised, t => t.Title == Loc.L("Editor.Render.Done"));
|
||
Assert.False(raised.Any(t => t.Title == Loc.L("Shell.Job.Done")), "the editor's own render toast is not doubled");
|
||
Assert.Equal(readable ? 0 : 1, raised.Count(t => t.IsError), "a failed read is said beside the render's end");
|
||
if (!readable) Assert.Null(finished.ActionCommand, "without the sequence read again, there is no output to show");
|
||
}
|
||
}
|
||
// A render the editor did not follow (of another sequence) is the shell's to announce.
|
||
raised.Clear();
|
||
var other = Job(JobKind.Render, JobState.Running, Guid.CreateVersion7());
|
||
jobs.OnJobChanged(other);
|
||
jobs.Flush();
|
||
jobs.OnJobChanged(other with { State = JobState.Done });
|
||
jobs.Flush();
|
||
Assert.Equal(1, raised.Count(t => t.Title == Loc.L("Shell.Job.Done")));
|
||
|
||
// Server › Upload all: the batch speaks once, when its last upload ends.
|
||
raised.Clear();
|
||
var uploads = Enumerable.Range(0, 3).Select(_ => Job(JobKind.UploadCommit, JobState.Queued, Guid.CreateVersion7())).ToList();
|
||
foreach (var upload in uploads) jobs.OnJobChanged(upload);
|
||
jobs.Flush();
|
||
foreach (var upload in uploads)
|
||
{
|
||
Assert.Empty(raised);
|
||
jobs.OnJobChanged(upload with { State = JobState.Done });
|
||
jobs.Flush();
|
||
}
|
||
var batch = raised.Single();
|
||
Assert.Equal(Loc.Plural("Shell.Job.DonePlural", 3), batch.Title);
|
||
Assert.Equal(Loc.L("Jobs.Kind.UploadCommit"), batch.Message);
|
||
Assert.Equal(Loc.L("Shell.Nav.Jobs"), batch.ActionText);
|
||
shell.Navigate(SectionKey.Library);
|
||
batch.ActionCommand!.Execute(null);
|
||
Assert.Equal(SectionKey.Jobs, shell.Current.Key);
|
||
|
||
// Two failures of one update: one error toast that leads to the Jobs screen.
|
||
raised.Clear();
|
||
var broken = new[] { Job(JobKind.Move, JobState.Running, Guid.CreateVersion7()), Job(JobKind.Adopt, JobState.Running, Guid.CreateVersion7()) };
|
||
foreach (var job in broken) jobs.OnJobChanged(job);
|
||
jobs.Flush();
|
||
foreach (var job in broken) jobs.OnJobChanged(job with { State = JobState.Failed });
|
||
jobs.Flush();
|
||
var failures = raised.Single();
|
||
Assert.True(failures.IsError);
|
||
Assert.Equal(Loc.Plural("Shell.Job.FailedPlural", 2), failures.Title);
|
||
Assert.Null(failures.Message);
|
||
});
|
||
|
||
[Test]
|
||
public Task ToastsBecomeWindowsNotificationsOnlyWhileNobodySeesTheWindow() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
Assert.True(OsNotifications.IsUnseen(WindowState.Minimized, isVisible: true, anyWindowActive: true));
|
||
Assert.True(OsNotifications.IsUnseen(WindowState.Normal, isVisible: true, anyWindowActive: false));
|
||
Assert.True(OsNotifications.IsUnseen(WindowState.Maximized, isVisible: false, anyWindowActive: true));
|
||
Assert.False(OsNotifications.IsUnseen(WindowState.Maximized, isVisible: true, anyWindowActive: true));
|
||
|
||
// The card prompt of BRIEF §12.4 reads "Card X detected", then its action, which a click runs.
|
||
var card = new Toast { Title = "EOS R5 card A inserted", Message = "SD 128 GB", ActionText = "Import", RunsFromNotification = true };
|
||
Assert.Equal("SD 128 GB" + Environment.NewLine + "Import", OsNotifications.BalloonText(card));
|
||
Assert.Equal("Job finished", OsNotifications.BalloonText(new Toast { Title = "Job finished" }));
|
||
// An action a click does not run (the auto-import's Cancel) waits in the window.
|
||
var auto = new Toast { Title = "EOS R5 card A inserted", Message = "Importing into the archive", ActionText = "Cancel" };
|
||
Assert.Equal("Importing into the archive", OsNotifications.BalloonText(auto));
|
||
|
||
Assert.True(MainWindow.StartsMinimized(["Titano.exe", "--minimized"]));
|
||
Assert.False(MainWindow.StartsMinimized(["Titano.exe"]));
|
||
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
app.Shell.CompleteWelcome();
|
||
// Minimised: nobody sees the window.
|
||
app.Window.WindowState = WindowState.Minimized;
|
||
var enabled = false;
|
||
using var notifications = new OsNotifications(app.Window, () => enabled, _ => { });
|
||
Assert.False(notifications.Show(card), "Settings › General › Notifications is off");
|
||
Assert.False(notifications.HasTrayIcon);
|
||
enabled = true;
|
||
Assert.True(notifications.Show(new Toast { Title = "Job finished", Message = "Render · Harbour sunset", ActionCommand = new RelayCommand(() => { }) }));
|
||
Assert.True(notifications.HasTrayIcon, "the notification area holds the icon while a notification can be clicked");
|
||
notifications.Dispose();
|
||
Assert.False(notifications.HasTrayIcon);
|
||
app.Window.WindowState = WindowState.Normal;
|
||
});
|
||
|
||
[Test]
|
||
public Task AClickOnANotificationBringsTheWindowBackAndRunsOnlyWhatItNames() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
app.Shell.CompleteWelcome();
|
||
var window = app.Window;
|
||
var imported = 0;
|
||
var cancelled = 0;
|
||
var dismissed = new List<Toast>();
|
||
Toast Import() => new() { Title = "EOS R5 card A inserted", ActionText = "Import", ActionCommand = new RelayCommand(() => imported++), RunsFromNotification = true };
|
||
|
||
// "Card X detected — Import": the click restores the window, opens the card and closes the in-window toast.
|
||
using (var notifications = new OsNotifications(window, () => true, dismissed.Add))
|
||
{
|
||
window.WindowState = WindowState.Minimized;
|
||
var card = Import();
|
||
Assert.True(notifications.Show(card));
|
||
notifications.OnBalloonClicked();
|
||
await StateAsync(window, WindowState.Normal);
|
||
Assert.Equal(1, imported);
|
||
Assert.SequenceEqual([card], dismissed);
|
||
}
|
||
|
||
// The auto-import's toast offers Cancel: the click only brings the window back.
|
||
using (var notifications = new OsNotifications(window, () => true, dismissed.Add))
|
||
{
|
||
window.WindowState = WindowState.Minimized;
|
||
Assert.True(notifications.Show(new Toast { Title = "EOS R5 card A inserted", ActionText = "Cancel", ActionCommand = new RelayCommand(() => cancelled++) }));
|
||
notifications.OnBalloonClicked();
|
||
await StateAsync(window, WindowState.Normal);
|
||
Assert.Equal(0, cancelled);
|
||
Assert.Count(1, dismissed);
|
||
}
|
||
|
||
// Two notifications: Windows does not say which one was clicked, so neither action runs.
|
||
using (var notifications = new OsNotifications(window, () => true, dismissed.Add))
|
||
{
|
||
window.WindowState = WindowState.Minimized;
|
||
Assert.True(notifications.Show(Import()));
|
||
Assert.True(notifications.Show(Import()));
|
||
notifications.OnBalloonClicked();
|
||
await StateAsync(window, WindowState.Normal);
|
||
Assert.Equal(1, imported);
|
||
Assert.Count(1, dismissed);
|
||
}
|
||
});
|
||
|
||
[Test]
|
||
public Task AWindowStartedMinimisedComesBackAsItWasSaved() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
// Closed while still minimised from the start: the saved state stays the one it would have come back to.
|
||
Assert.True(MainWindow.SavesMaximized(WindowState.Maximized, restoreTo: null));
|
||
Assert.True(MainWindow.SavesMaximized(WindowState.Minimized, WindowState.Maximized));
|
||
Assert.False(MainWindow.SavesMaximized(WindowState.Minimized, WindowState.Normal));
|
||
Assert.False(MainWindow.SavesMaximized(WindowState.Normal, restoreTo: null));
|
||
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
app.Shell.CompleteWelcome();
|
||
var window = app.Window;
|
||
// Started at sign-in with the window saved maximised: it waits on the taskbar.
|
||
window.WaitMinimized(maximized: true);
|
||
Assert.Equal(WindowState.Minimized, window.WindowState);
|
||
// The user opens it from the taskbar: it comes back maximised.
|
||
window.WindowState = WindowState.Normal;
|
||
await StateAsync(window, WindowState.Maximized);
|
||
// Only that first restore: later ones are the user's.
|
||
window.WindowState = WindowState.Normal;
|
||
window.WindowState = WindowState.Minimized;
|
||
window.WindowState = WindowState.Normal;
|
||
await StateAsync(window, WindowState.Normal);
|
||
await Task.Delay(100);
|
||
Assert.Equal(WindowState.Normal, window.WindowState);
|
||
});
|
||
|
||
[Test]
|
||
public Task GeneralSettingsHoldStartupAndNotificationsButNoConsent() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
// Monetization (BRIEF §21) ships disabled: the default build offers no usage counts consent.
|
||
Assert.False(ProductFeatures.AdsEnabled);
|
||
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync(firstRun: true);
|
||
var shell = app.Shell;
|
||
await app.ExpectAsync<WelcomeView>("welcome");
|
||
Assert.False(app.FindAll<CheckBox>().Any(c => c.IsVisible && Equals(c.Content, Loc.L("Settings.General.UsageCounts"))), "no consent on the first-run dialog");
|
||
shell.CompleteWelcome();
|
||
|
||
var settings = shell.Settings;
|
||
var startup = new MemoryStartWithWindows();
|
||
settings.Startup = startup;
|
||
shell.Navigate(SectionKey.Settings);
|
||
settings.Page = SettingsPage.General;
|
||
await app.ExpectAsync<SettingsView>("settings-general");
|
||
var boxes = app.FindAll<CheckBox>().Where(c => c.IsVisible).ToList();
|
||
Assert.False(boxes.Any(c => Equals(c.Content, Loc.L("Settings.General.UsageCounts"))), "no consent in Settings");
|
||
var start = boxes.Single(c => Equals(c.Content, Loc.L("Settings.General.StartWithWindows")));
|
||
Assert.Equal(Loc.L("Tooltips.Settings.StartWithWindows"), start.ToolTip);
|
||
var notify = boxes.Single(c => Equals(c.Content, Loc.L("Settings.General.OsNotifications")));
|
||
Assert.Equal(Loc.L("Tooltips.Settings.OsNotifications"), notify.ToolTip);
|
||
Assert.True(notify.IsChecked == true, "Windows notifications are on by default");
|
||
|
||
settings.StartWithWindows = true;
|
||
Assert.True(startup.IsEnabled);
|
||
settings.OsNotifications = false;
|
||
Assert.False(shell.Services.Settings.OsNotifications);
|
||
settings.ResetSectionCommand.Execute(null);
|
||
Assert.False(startup.IsEnabled, "Reset section turns Start with Windows off");
|
||
Assert.True(shell.Services.Settings.OsNotifications, "Reset section turns notifications back on");
|
||
// Reset section also returned the language to the system's.
|
||
UiLanguage.Apply("en");
|
||
|
||
// The search finds General by its new rows, not by the hidden consent.
|
||
settings.SearchText = Loc.L("Settings.General.Startup");
|
||
Assert.Contains(settings.VisiblePages, p => p.Page == SettingsPage.General);
|
||
settings.SearchText = Loc.L("Settings.General.Usage");
|
||
Assert.False(settings.VisiblePages.Any(p => p.Page == SettingsPage.General), "the hidden consent does not match");
|
||
settings.SearchText = string.Empty;
|
||
});
|
||
|
||
[Test]
|
||
public Task TheServerBadgeCountsConflicts() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
shell.CompleteWelcome();
|
||
Assert.Equal(0, shell.Server.Badge);
|
||
await app.Sample.FillAsync();
|
||
await shell.Services.Server.RestoreAsync();
|
||
Assert.NotNull(await shell.Services.Sync.RefreshAsync());
|
||
await shell.Server.Sync.ReloadAsync();
|
||
// The sample server holds one sequence whose settings changed on both sides.
|
||
Assert.Equal(1, shell.Server.Sync.Chips.Single(c => c.Filter == Titano.App.Server.SyncFilter.Conflicts).Count);
|
||
Assert.Equal(1, shell.Server.Badge);
|
||
});
|
||
|
||
[Test]
|
||
public Task TheLibraryAndArchiveBadgesCountWarnings() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
shell.CompleteWelcome();
|
||
await app.Sample.FillAsync();
|
||
var db = Assert.NotNull(shell.Services.Database);
|
||
|
||
// Library: the sequences the Warnings filter shows; an analysis that finds warnings adds one.
|
||
await shell.Library.RefreshAsync();
|
||
var warned = await db.Sequences.CountAsync(new SequenceQuery { WithStatus = SequenceStatus.HasWarnings });
|
||
Assert.Equal(warned, shell.Library.Badge);
|
||
var clean = (await db.Sequences.ListAsync(new SequenceQuery { WithoutStatus = SequenceStatus.HasWarnings, Limit = 1 })).Items[0];
|
||
await db.Sequences.RecordAnalysisAsync(clean.Id, SequenceStatus.AnalyzedLight | SequenceStatus.HasWarnings, SequenceStatus.None, 2, null);
|
||
await shell.Library.RefreshAsync();
|
||
Assert.Equal(warned + 1, shell.Library.Badge);
|
||
|
||
// Archive: the index health lines that need attention (the sample has unverified sequences).
|
||
shell.Navigate(SectionKey.Archive);
|
||
await shell.Archive.LoadAsync();
|
||
Assert.Greater(shell.Archive.Badge, 0);
|
||
Assert.Equal(shell.Archive.Health.Count(h => !h.IsOk), shell.Archive.Badge);
|
||
});
|
||
|
||
/// <summary>
|
||
/// The Jobs screen's flush can take a render's end before the editor that followed the render has seen it: it leaves
|
||
/// the toast to the editor, which says it once with its output, and once without it when it closed in between.
|
||
/// </summary>
|
||
[Test]
|
||
public Task TheEditorSaysTheRenderItFollowedAlsoWhenTheJobsScreenSeesItsEndFirst() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
shell.CompleteWelcome();
|
||
await JobsLoadedAsync(shell);
|
||
var jobs = shell.Jobs;
|
||
var raised = new List<Toast>();
|
||
shell.PendingToasts.CollectionChanged += (_, e) => raised.AddRange(e.NewItems?.Cast<Toast>() ?? []);
|
||
var content = EditorFixture.Content(EditorFixture.Sunset);
|
||
var source = new FakeSequenceSource(EditorFixture.Sunset, content);
|
||
var editor = new EditorViewModel(shell, new EditorSession(source, content, []), [], EncoderHost.Client);
|
||
shell.Sequence.Attach(editor);
|
||
|
||
foreach (var closes in new[] { false, true })
|
||
{
|
||
raised.Clear();
|
||
var render = Job(JobKind.Render, JobState.Running, content.Sequence.Id);
|
||
source.Report(render);
|
||
jobs.OnJobChanged(render);
|
||
await UntilAsync(() => editor.FollowsRender(render.Id));
|
||
jobs.Flush();
|
||
|
||
// The end reaches the Jobs screen first; the editor's own callback runs after its flush.
|
||
jobs.OnJobChanged(render with { State = JobState.Done });
|
||
jobs.Flush();
|
||
Assert.False(raised.Any(t => t.Title == Loc.L("Shell.Job.Done")), "the Jobs screen leaves the end of a followed render to the editor");
|
||
source.Report(render with { State = JobState.Done });
|
||
if (closes)
|
||
{
|
||
await shell.Sequence.CloseAsync();
|
||
Assert.Null(shell.Sequence.Editor);
|
||
}
|
||
await UntilAsync(() => raised.Any(t => t.Title == Loc.L("Editor.Render.Done")));
|
||
jobs.Flush();
|
||
var finished = Assert.Contains(raised, t => t.Title == Loc.L("Editor.Render.Done"));
|
||
Assert.Equal(1, raised.Count(t => t.Title == Loc.L("Editor.Render.Done")), "said once");
|
||
Assert.False(raised.Any(t => t.Title == Loc.L("Shell.Job.Done")), "and never by the Jobs screen as well");
|
||
if (closes) Assert.Null(finished.ActionCommand, "a closed editor does not read the sequence again for the output");
|
||
}
|
||
});
|
||
|
||
/// <summary>
|
||
/// Open on a job that worked on several sequences (a deep analysis of a Library selection) shows every one of them
|
||
/// selected in the Library: also those a search hides, whether it is still pending or applied, and those beyond the
|
||
/// pages read so far. A job over more sequences than a page leaves the Library as it is; a job on an archive opens
|
||
/// the Archive screen.
|
||
/// </summary>
|
||
[Test]
|
||
public Task OpenOnAJobOverSeveralSequencesSelectsThemAllInTheLibrary() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
shell.CompleteWelcome();
|
||
await app.Sample.FillAsync();
|
||
var db = Assert.NotNull(shell.Services.Database);
|
||
var library = shell.Library;
|
||
await library.RefreshAsync();
|
||
var ids = (await db.Sequences.ListAsync(new SequenceQuery { Sort = SequenceSort.Oldest, Limit = 3 })).Items.Select(s => s.Id).ToList();
|
||
Assert.Count(3, ids);
|
||
bool Listed(Guid id) => library.Items.Any(i => i.Sequence.Id == id);
|
||
Job Analysis(IReadOnlyList<Guid> targets) =>
|
||
Job(JobKind.DeepAnalyse, JobState.Done, targets[0]) with { TargetIds = targets, TargetLabel = Loc.Plural("Library.Selection.Count", targets.Count) };
|
||
|
||
// A search still waiting to apply.
|
||
library.SearchText = "no such sequence";
|
||
await shell.Jobs.OpenTargetAsync(Analysis(ids));
|
||
Assert.Equal(SectionKey.Library, shell.Current.Key);
|
||
Assert.Equal(string.Empty, library.SearchText, "the search that hid them is cleared");
|
||
Assert.Equal(ids.Count, library.SelectionCount, "every sequence the job worked on, not only the first");
|
||
Assert.SequenceEqual(ids.Order(), library.SelectedItems().Select(i => i.Sequence.Id).Order());
|
||
|
||
// A search applied: the list no longer holds them.
|
||
library.SearchText = "no such sequence";
|
||
await UntilAsync(() => !ids.Any(Listed));
|
||
Assert.False(ids.Any(Listed), "the search hides them");
|
||
await shell.Jobs.OpenTargetAsync(Analysis(ids));
|
||
Assert.Equal(string.Empty, library.SearchText);
|
||
Assert.SequenceEqual(ids.Order(), library.SelectedItems().Select(i => i.Sequence.Id).Order());
|
||
|
||
// More sequences than a page: those beyond the first page are read until each is listed.
|
||
var archiveId = Assert.NotNull(await db.Sequences.GetAsync(ids[0])).ArchiveId;
|
||
var bulk = new List<Guid>();
|
||
for (var i = 0; i < LibraryPager.DefaultPageSize + 10; i++)
|
||
{
|
||
var sequence = new Sequence
|
||
{
|
||
Id = Guid.CreateVersion7(),
|
||
ArchiveId = archiveId,
|
||
Folder = $"2021/2021-03-01 Bulk {i:000}",
|
||
Title = $"Bulk {i:000}",
|
||
FirstCapture = new DateTime(2021, 3, 1).AddHours(i),
|
||
LastCapture = new DateTime(2021, 3, 1).AddHours(i + 1),
|
||
FrameCount = 10,
|
||
UpdatedAt = DateTimeOffset.UtcNow,
|
||
};
|
||
await db.Sequences.UpsertAsync(sequence);
|
||
bulk.Add(sequence.Id);
|
||
}
|
||
await library.RefreshAsync();
|
||
var beyond = bulk.Where(id => !Listed(id)).Take(3).ToList();
|
||
Assert.Count(3, beyond);
|
||
await shell.Jobs.OpenTargetAsync(Analysis(beyond));
|
||
Assert.Greater(library.Items.Count, LibraryPager.DefaultPageSize, "the next pages were read");
|
||
Assert.SequenceEqual(beyond.Order(), library.SelectedItems().Select(i => i.Sequence.Id).Order());
|
||
|
||
// A job over more sequences than a page (a maintenance run over the archive) opens the Library as it is.
|
||
shell.Navigate(SectionKey.Jobs);
|
||
library.SearchText = "Bulk";
|
||
await shell.Jobs.OpenTargetAsync(Analysis(bulk));
|
||
Assert.Equal(SectionKey.Library, shell.Current.Key);
|
||
Assert.Equal("Bulk", library.SearchText, "its search is not cleared");
|
||
Assert.SequenceEqual(beyond.Order(), library.SelectedItems().Select(i => i.Sequence.Id).Order(), "nor its selection replaced");
|
||
|
||
await shell.Jobs.OpenTargetAsync(Job(JobKind.Verify, JobState.Done, Guid.CreateVersion7()));
|
||
Assert.Equal(SectionKey.Archive, shell.Current.Key);
|
||
// The Archive screen reads its figures when it opens: let that end before the app closes.
|
||
await shell.Archive.LoadAsync();
|
||
});
|
||
|
||
/// <summary>Lets the dispatcher run what was posted to it (the editor's job events and reload) until <paramref name="done"/> holds.</summary>
|
||
private static async Task UntilAsync(Func<bool> done)
|
||
{
|
||
for (var i = 0; i < 250 && !done(); i++) await Task.Delay(20);
|
||
}
|
||
|
||
/// <summary>The Jobs screen read its first page (it would set the job bar and the badge again).</summary>
|
||
private static async Task JobsLoadedAsync(ShellViewModel shell)
|
||
{
|
||
for (var i = 0; i < 200 && !shell.Jobs.IsEmpty && !shell.Jobs.HasRows; i++) await Task.Delay(20);
|
||
Assert.True(shell.Jobs.IsEmpty || shell.Jobs.HasRows, "the job list loaded");
|
||
}
|
||
|
||
/// <summary>The window reached <paramref name="state"/> (a restore from a notification is a posted system command).</summary>
|
||
private static async Task StateAsync(Window window, WindowState state)
|
||
{
|
||
for (var i = 0; i < 250 && window.WindowState != state; i++) await Task.Delay(20);
|
||
Assert.Equal(state, window.WindowState);
|
||
}
|
||
|
||
private static Job Job(JobKind kind, JobState state, Guid target) => new()
|
||
{
|
||
Id = Guid.CreateVersion7(),
|
||
Kind = kind,
|
||
State = state,
|
||
Priority = JobPriority.User,
|
||
TargetIds = [target],
|
||
TargetLabel = "Harbour sunset",
|
||
Created = DateTimeOffset.UtcNow,
|
||
Started = DateTimeOffset.UtcNow,
|
||
};
|
||
}
|