using Titano.App.Jobs; using Titano.Core.Model; using Titano.Testing; namespace Titano.App.Tests.Jobs; /// UI-08: which job endings raise the shell's toast, whichever screen started the job. public sealed class JobNoticesTests { [Theory] [Case(JobKind.Render)] [Case(JobKind.DeepAnalyse)] [Case(JobKind.Verify)] [Case(JobKind.Rebuild)] [Case(JobKind.Maintenance)] [Case(JobKind.UploadCommit)] public void ALongOperationThatEndsSaysSo(JobKind kind) { Assert.Equal(JobNotice.Done, JobNotices.For(JobState.Running, Job(kind, JobState.Done))); Assert.Equal(JobNotice.Failed, JobNotices.For(JobState.Running, Job(kind, JobState.Failed))); // Queued and finished between two flushes of the Jobs screen: still one notice. Assert.Equal(JobNotice.Done, JobNotices.For(JobState.Queued, Job(kind, JobState.Done))); Assert.Equal(JobNotice.Done, JobNotices.For(null, Job(kind, JobState.Done))); } [Theory] [Case(JobKind.Scan)] [Case(JobKind.LightAnalyse)] [Case(JobKind.Thumbs)] [Case(JobKind.Proxies)] [Case(JobKind.Download)] public void BackgroundWorkAndScansEndSilently(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() { // 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))); } [Test] public void BackgroundPriorityCancelledAndRepeatedEndingsSayNothing() { // The deep analysis queued after an import runs 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.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))); Assert.Equal(JobNotice.None, JobNotices.For(JobState.Queued, Job(JobKind.Render, JobState.Running))); // "Add to queue" renders have Normal priority: they are announced too. Assert.Equal(JobNotice.Done, JobNotices.For(JobState.Running, Job(JobKind.Render, JobState.Done, JobPriority.Normal))); } private static Job Job(JobKind kind, JobState state, JobPriority priority = JobPriority.User) => new() { Id = Guid.CreateVersion7(), Kind = kind, State = state, Priority = priority, TargetLabel = "Harbour sunset", Created = DateTimeOffset.UtcNow, }; }