fix(app): notification clicks run only what the toast names, batches speak once, warnings get badges
- Toast.RunsFromNotification: a click on a Windows notification restores the window and runs the toast's
action only when the toast opts in (card detected: Import; interrupted import: Resume; job finished: Open;
navigation to Import or Jobs) and it is the only notification shown since the icon appeared. Cancel, Undo
and Retry stay in the window, and the notification text no longer offers them.
- Job endings are coalesced: finished jobs of one kind wait until no job of that kind the user waits for is
queued or running, then one toast says how many finished ("12 jobs finished", action Jobs); failures of one
update share one toast. Server > Upload all no longer raises one toast and one notification per sequence.
- Every failure that is not upkeep (scan, thumbnails, proxies, light analysis) is announced, including move,
adopt and user downloads; finished moves and adoptions are announced too.
- Rail badges: Library counts the sequences with warnings (the Warnings filter), refreshed after analyses;
Archive counts the index health lines that need attention.
- Tests: the balloon click path, the --minimized restore to a saved maximised window, batch and failure
coalescing, and the new badges.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
15 files changed
+438
-64
No files matched your search
@@ -4,7 +4,7 @@ using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Jobs;
|
||||
|
||||
/// <summary>UI-08: which job endings raise the shell's toast, whichever screen started the job.</summary>
|
||||
/// <summary>UI-08: which job endings raise the shell's toast, whichever screen started the job, and how a batch speaks once.</summary>
|
||||
public sealed class JobNoticesTests
|
||||
{
|
||||
[Theory]
|
||||
@@ -14,6 +14,8 @@ public sealed class JobNoticesTests
|
||||
[Case(JobKind.Rebuild)]
|
||||
[Case(JobKind.Maintenance)]
|
||||
[Case(JobKind.UploadCommit)]
|
||||
[Case(JobKind.Move)]
|
||||
[Case(JobKind.Adopt)]
|
||||
public void ALongOperationThatEndsSaysSo(JobKind kind)
|
||||
{
|
||||
Assert.Equal(JobNotice.Done, JobNotices.For(JobState.Running, Job(kind, JobState.Done)));
|
||||
@@ -28,26 +30,30 @@ public sealed class JobNoticesTests
|
||||
[Case(JobKind.LightAnalyse)]
|
||||
[Case(JobKind.Thumbs)]
|
||||
[Case(JobKind.Proxies)]
|
||||
[Case(JobKind.Download)]
|
||||
public void BackgroundWorkAndScansEndSilently(JobKind kind)
|
||||
public void UpkeepAndScansEndSilently(JobKind kind)
|
||||
{
|
||||
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(kind, JobState.Done)));
|
||||
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(kind, JobState.Failed)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnImportSaysOnlyThatItFailed()
|
||||
[Theory]
|
||||
[Case(JobKind.Import)]
|
||||
[Case(JobKind.Download)]
|
||||
[Case(JobKind.Duplicates)]
|
||||
[Case(JobKind.Orphans)]
|
||||
public void EveryOtherFailureIsSaid(JobKind kind)
|
||||
{
|
||||
// The Import screen announces a finished import with its result.
|
||||
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(JobKind.Import, JobState.Done)));
|
||||
Assert.Equal(JobNotice.Failed, JobNotices.For(JobState.Running, Job(JobKind.Import, JobState.Failed)));
|
||||
// An import announces its result on the Import screen, a download on its Library card and Server row.
|
||||
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(kind, JobState.Done)));
|
||||
Assert.Equal(JobNotice.Failed, JobNotices.For(JobState.Running, Job(kind, JobState.Failed)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BackgroundPriorityCancelledAndRepeatedEndingsSayNothing()
|
||||
{
|
||||
// The deep analysis queued after an import runs in the background.
|
||||
// The deep analysis queued after an import, and the proxies sync fetches, run in the background.
|
||||
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(JobKind.DeepAnalyse, JobState.Done, JobPriority.Background)));
|
||||
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(JobKind.Download, JobState.Failed, JobPriority.Background)));
|
||||
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(JobKind.Render, JobState.Cancelled)));
|
||||
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Done, Job(JobKind.Render, JobState.Done)));
|
||||
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Failed, Job(JobKind.Render, JobState.Failed)));
|
||||
@@ -56,6 +62,84 @@ public sealed class JobNoticesTests
|
||||
Assert.Equal(JobNotice.Done, JobNotices.For(JobState.Running, Job(JobKind.Render, JobState.Done, JobPriority.Normal)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ABatchOfOneKindSpeaksOnceWhenItsLastJobEnds()
|
||||
{
|
||||
// Server › Upload all: 100 uploads queued; each one that ends waits for the rest.
|
||||
var endings = new JobEndings();
|
||||
var model = new JobListModel();
|
||||
var uploads = Enumerable.Range(0, 100).Select(_ => Job(JobKind.UploadCommit, JobState.Queued)).ToList();
|
||||
foreach (var upload in uploads) model.Apply(upload);
|
||||
for (var i = 0; i < 99; i++)
|
||||
{
|
||||
var done = uploads[i] with { State = JobState.Done };
|
||||
model.Apply(done);
|
||||
endings.Add(JobNotices.For(JobState.Running, done), done);
|
||||
Assert.Empty(endings.Take(model.IsBusy));
|
||||
}
|
||||
Assert.Equal(99, endings.Waiting);
|
||||
|
||||
// A render of the same flush is its own kind: it is said at once.
|
||||
var render = Job(JobKind.Render, JobState.Done);
|
||||
model.Apply(render);
|
||||
endings.Add(JobNotice.Done, render);
|
||||
var due = endings.Take(model.IsBusy);
|
||||
Assert.Count(1, due);
|
||||
Assert.Equal(JobNotice.Done, due[0].Notice);
|
||||
Assert.SequenceEqual([render.Id], due[0].Jobs.Select(j => j.Id));
|
||||
|
||||
var last = uploads[99] with { State = JobState.Done };
|
||||
model.Apply(last);
|
||||
endings.Add(JobNotice.Done, last);
|
||||
due = endings.Take(model.IsBusy);
|
||||
Assert.Count(1, due);
|
||||
Assert.SequenceEqual(uploads.Select(u => u.Id), due[0].Jobs.Select(j => j.Id));
|
||||
Assert.Equal(0, endings.Waiting);
|
||||
Assert.Empty(endings.Take(model.IsBusy));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PausedAndBackgroundJobsDoNotHoldABatch()
|
||||
{
|
||||
var endings = new JobEndings();
|
||||
var model = new JobListModel();
|
||||
// An upload paused on a metered network, and the proxies sync fetches in the background, wait for something else.
|
||||
model.Apply(Job(JobKind.UploadCommit, JobState.Paused));
|
||||
model.Apply(Job(JobKind.Download, JobState.Running, JobPriority.Background));
|
||||
var upload = Job(JobKind.UploadCommit, JobState.Done);
|
||||
model.Apply(upload);
|
||||
endings.Add(JobNotice.Done, upload);
|
||||
Assert.Count(1, endings.Take(model.IsBusy));
|
||||
Assert.False(model.IsBusy(JobKind.UploadCommit));
|
||||
Assert.False(model.IsBusy(JobKind.Download));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailuresAreSaidAtTheEndOfTheirFlushTogether()
|
||||
{
|
||||
var endings = new JobEndings();
|
||||
var model = new JobListModel();
|
||||
// More uploads still run: failures do not wait for them.
|
||||
model.Apply(Job(JobKind.UploadCommit, JobState.Running));
|
||||
var first = Job(JobKind.UploadCommit, JobState.Failed);
|
||||
var second = Job(JobKind.Verify, JobState.Failed);
|
||||
endings.Add(JobNotice.Failed, first);
|
||||
endings.Add(JobNotice.Failed, second);
|
||||
endings.Add(JobNotice.None, Job(JobKind.Scan, JobState.Done));
|
||||
var due = endings.Take(model.IsBusy);
|
||||
Assert.Count(1, due);
|
||||
Assert.Equal(JobNotice.Failed, due[0].Notice);
|
||||
Assert.SequenceEqual([first.Id, second.Id], due[0].Jobs.Select(j => j.Id));
|
||||
|
||||
// The next flush starts again.
|
||||
var third = Job(JobKind.UploadCommit, JobState.Failed);
|
||||
endings.Add(JobNotice.Failed, third);
|
||||
due = endings.Take(model.IsBusy);
|
||||
Assert.Count(1, due);
|
||||
Assert.SequenceEqual([third.Id], due[0].Jobs.Select(j => j.Id));
|
||||
Assert.Empty(endings.Take(model.IsBusy));
|
||||
}
|
||||
|
||||
private static Job Job(JobKind kind, JobState state, JobPriority priority = JobPriority.User) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
|
||||
@@ -8,6 +8,7 @@ using Titano.App.Settings;
|
||||
using Titano.App.Shell;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Repositories;
|
||||
using Titano.Testing;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Ui.Mvvm;
|
||||
@@ -110,6 +111,7 @@ public sealed class ShellNotificationTests
|
||||
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();
|
||||
@@ -124,6 +126,7 @@ public sealed class ShellNotificationTests
|
||||
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);
|
||||
@@ -150,6 +153,37 @@ public sealed class ShellNotificationTests
|
||||
jobs.Flush();
|
||||
Assert.Equal(1, raised.Count(t => t.Title == Loc.L("Shell.Job.Done")));
|
||||
await shell.Sequence.CloseAsync();
|
||||
|
||||
// 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]
|
||||
@@ -161,9 +195,12 @@ public sealed class ShellNotificationTests
|
||||
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" };
|
||||
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"]));
|
||||
@@ -184,6 +221,80 @@ public sealed class ShellNotificationTests
|
||||
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 () =>
|
||||
{
|
||||
@@ -244,6 +355,31 @@ public sealed class ShellNotificationTests
|
||||
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 read its first page (it would set the job bar and the badge again).</summary>
|
||||
private static async Task JobsLoadedAsync(ShellViewModel shell)
|
||||
{
|
||||
@@ -251,6 +387,13 @@ public sealed class ShellNotificationTests
|
||||
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(),
|
||||
|
||||
Reference in new issue
Block a user