merge: desktop section fixes (V-0, V-12, V-13, V-14)
Merge branch fix2/desktop-sections into the verification branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
23 files changed
+609
-75
No files matched your search
@@ -182,17 +182,38 @@ public sealed class ArchiveScreenSmokeTests
|
||||
var archive = app.Shell.Archive;
|
||||
await ArchiveScenes.ShowAsync(app.Shell, "overview");
|
||||
Assert.Contains(archive.TreeRows, r => r.Node.Kind == TreeNodeKind.Sequence);
|
||||
Assert.NotEmpty(archive.Tiles);
|
||||
Assert.NotEmpty(archive.CameraBars);
|
||||
var first = archive.SelectedArchive!;
|
||||
var second = await app.Services.Archives!.CreateAsync(Path.Combine(app.Services.Environment.DataDirectory, "second-archive"), "Second");
|
||||
|
||||
var reading = archive.LoadAsync();
|
||||
archive.SelectedArchive = second;
|
||||
Assert.Empty(archive.TreeRows);
|
||||
// None of the first archive's figures stays on screen under the picked one's name while it is read (or if its read fails).
|
||||
Assert.Empty(archive.Tiles);
|
||||
Assert.Empty(archive.MonthRows);
|
||||
Assert.Empty(archive.StorageBars);
|
||||
Assert.Empty(archive.CameraBars);
|
||||
Assert.Empty(archive.FormatBars);
|
||||
Assert.Empty(archive.Recent);
|
||||
Assert.False(archive.HasRecent);
|
||||
Assert.Equal(string.Empty, archive.LastScanText);
|
||||
Assert.Equal(0, archive.Badge, "the rail badge counts the picked archive's health, which is not read yet");
|
||||
Assert.False(archive.AnalyseSetCommand.CanExecute(null), "nothing of the first archive can be acted on while the picked one is read");
|
||||
Assert.False(archive.ScanCommand.CanExecute(null), "the picked archive is not known to be online yet");
|
||||
Assert.Equal(Loc.L("Archive.Blocked.Reading"), archive.ScanToolTip, "not yet read is not offline");
|
||||
Assert.False(archive.RebuildCommand.CanExecute(null), "the rebuild dialog waits for the picked archive's own state and figures");
|
||||
Assert.Null(await archive.OpenRebuildDialogAsync());
|
||||
Assert.Empty(archive.Health);
|
||||
// Back to the first archive before the picked one is read: it was read before, but none of its figures is left.
|
||||
archive.SelectedArchive = first;
|
||||
Assert.Empty(archive.TreeRows);
|
||||
Assert.False(archive.RebuildCommand.CanExecute(null), "the first archive is not read again yet");
|
||||
Assert.False(archive.ScanCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Archive.Blocked.Reading"), archive.ScanToolTip);
|
||||
Assert.Null(await archive.OpenRebuildDialogAsync());
|
||||
archive.SelectedArchive = second;
|
||||
await reading;
|
||||
|
||||
Assert.Equal(second.Id, archive.SelectedArchive!.Id);
|
||||
|
||||
@@ -111,7 +111,15 @@ internal sealed class FakeSequenceSource(SyntheticSequence sequence, SequenceCon
|
||||
/// <summary>Awaited by every decode (tests of cancellation).</summary>
|
||||
public Task DecodeGate { get; set; } = Task.CompletedTask;
|
||||
|
||||
public Task<SequenceContent> LoadAsync(CancellationToken cancellationToken) => Task.FromResult(Content with { Project = Stored });
|
||||
/// <summary>Thrown by the next load (the sequence read again after a job).</summary>
|
||||
public Exception? FailNextLoad { get; set; }
|
||||
|
||||
public Task<SequenceContent> LoadAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (FailNextLoad is not { } failure) return Task.FromResult(Content with { Project = Stored });
|
||||
FailNextLoad = null;
|
||||
return Task.FromException<SequenceContent>(failure);
|
||||
}
|
||||
|
||||
public async ValueTask<ImageBuffer?> DecodeAsync(int index, int maxLongEdge, DecodePurpose purpose, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@@ -31,6 +31,24 @@ public sealed class ImportFailuresTests
|
||||
Assert.Equal("The import stopped before the end.", ImportFailures.Import(new InvalidDataException("Bad sidecar. Second sentence."), Card));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheCopiesAStoppedImportNeverReachedSayWhyInOneSentence()
|
||||
{
|
||||
const string Card = "EOS R5 · card A";
|
||||
Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Stop(new ImportSourceUnavailableException(@"E:\"), Card));
|
||||
Assert.Equal("The destination is full.", ImportFailures.Stop(new IOException("There is not enough space on the disk.", unchecked((int)0x80070070)), Card));
|
||||
Assert.Equal("Titano may not write to the destination.", ImportFailures.Stop(new UnauthorizedAccessException(@"Access to D:\Shoots is denied."), Card));
|
||||
Assert.Equal("The import stopped before the end.", ImportFailures.Stop(new IOException("The specified network name is no longer available."), Card));
|
||||
// The server's own sentence, else why it could not be asked.
|
||||
Assert.Equal("Sign in again",
|
||||
ImportFailures.Stop(new TitanoApiException(HttpStatusCode.Unauthorized, new ApiError("unauthorized", "Sign in again", null)), Card));
|
||||
Assert.Equal(Loc.L("Server.Error.Unreachable"), ImportFailures.Stop(new HttpRequestException("An error occurred while sending the request."), Card));
|
||||
// A reverse proxy answered while the server restarted: its reason phrase is English, never the server's sentence.
|
||||
Assert.Equal(Loc.L("Server.Error.Unreachable"), ImportFailures.Stop(new TitanoApiException(HttpStatusCode.BadGateway, new ApiError("http_502", "Bad Gateway")), Card));
|
||||
Assert.Equal(Loc.L("Server.Error.Unreachable"), ImportFailures.Stop(new TaskCanceledException("The operation was canceled."), Card));
|
||||
Assert.Equal(Loc.L("Server.Error.Untrusted"), ImportFailures.Stop(new UntrustedCertificateException("AB:CD"), Card));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APlanningFailureNamesTheSource()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Titano.App.Import;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Localization;
|
||||
@@ -111,7 +112,7 @@ public sealed class ImportFlowTests(TestContext context)
|
||||
Assert.Equal(16, plan.CopyCount);
|
||||
|
||||
var reports = new List<ImportProgress>();
|
||||
var outcome = await LocalImport.RunAsync(plan, new FolderImportSink(target), verify: true, new Progress(reports), context.Cancellation);
|
||||
var outcome = await LocalImport.RunAsync(plan, new FolderImportSink(target), "EOS R5 · card A", verify: true, new Progress(reports), context.Cancellation);
|
||||
Assert.Equal(16, outcome.Copied);
|
||||
Assert.True(outcome.IsComplete);
|
||||
Assert.True(outcome.Verified);
|
||||
@@ -120,7 +121,7 @@ public sealed class ImportFlowTests(TestContext context)
|
||||
Assert.FileExists(Path.Combine(target, folder, name));
|
||||
|
||||
var again = await LocalImport.RunAsync(await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation),
|
||||
new FolderImportSink(target), verify: true, null, context.Cancellation);
|
||||
new FolderImportSink(target), "EOS R5 · card A", verify: true, null, context.Cancellation);
|
||||
Assert.Equal(0, again.Copied);
|
||||
Assert.Equal(16, again.Duplicates);
|
||||
Assert.False(new CardActions(ImportDestinationKind.Folder, false, true, true, outcome, null, null).CanCheck);
|
||||
@@ -164,6 +165,21 @@ public sealed class ImportFlowTests(TestContext context)
|
||||
outcome.Failures);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARunTheServerStopsListsEveryPhotoLeftWithASentenceNotTheExceptionText()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
var card = Card(context.CreateTempDirectory("card"), 8, Start);
|
||||
var staging = context.CreateTempDirectory("staging");
|
||||
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null,
|
||||
context.Cancellation);
|
||||
|
||||
var outcome = await LocalImport.RunAsync(plan, new UnreachableSink(staging), "EOS R5 · card A", verify: true, null, context.Cancellation);
|
||||
Assert.Equal(0, outcome.Imported);
|
||||
Assert.Equal(8, outcome.Failures.Count);
|
||||
Assert.True(outcome.Failures.All(f => f.Message == Loc.L("Server.Error.Unreachable")), "the stop reason is the catalog's, never the exception's text");
|
||||
}
|
||||
|
||||
private async Task WaitDoneAsync(TitanoDatabase db, Guid jobId)
|
||||
{
|
||||
var until = DateTime.UtcNow.AddSeconds(60);
|
||||
@@ -177,6 +193,15 @@ public sealed class ImportFlowTests(TestContext context)
|
||||
Assert.Fail("The import job did not finish");
|
||||
}
|
||||
|
||||
/// <summary>A server destination whose connection is gone: every commit fails as the HTTP stack reports it.</summary>
|
||||
private sealed class UnreachableSink(string staging) : IImportSink
|
||||
{
|
||||
public string StagingDirectory { get; } = staging;
|
||||
|
||||
public Task<IReadOnlyList<SinkCommit>> CommitAsync(PlannedSession session, IReadOnlyList<StagedFile> files, CancellationToken cancellationToken) =>
|
||||
throw new HttpRequestException("An error occurred while sending the request.");
|
||||
}
|
||||
|
||||
/// <summary>Collects reports synchronously (System.Progress posts to the thread pool).</summary>
|
||||
private sealed class Progress(List<ImportProgress> into) : IProgress<ImportProgress>
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
|
||||
plan = plan with { Sessions = [plan.Sessions[0] with { Title = "Harbour sunset" }, .. plan.Sessions.Skip(1)] };
|
||||
|
||||
var outcome = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), verify: true, null, context.Cancellation);
|
||||
var outcome = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), "EOS R5 · card A", verify: true, null, context.Cancellation);
|
||||
|
||||
Assert.Equal(16, outcome.Copied);
|
||||
Assert.True(outcome.IsComplete);
|
||||
@@ -55,10 +55,10 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
using var client = new TitanoClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" };
|
||||
var destination = new UnindexedDestination(ImportDestinationKind.Server, staging);
|
||||
var plan = await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
|
||||
await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), verify: true, null, context.Cancellation);
|
||||
await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), "EOS R5 · card A", verify: true, null, context.Cancellation);
|
||||
var chunks = server.ChunkCount;
|
||||
|
||||
var again = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), verify: true, null, context.Cancellation);
|
||||
var again = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), "EOS R5 · card A", verify: true, null, context.Cancellation);
|
||||
Assert.Equal(0, again.Copied);
|
||||
Assert.Equal(8, again.Duplicates);
|
||||
Assert.Equal(chunks, server.ChunkCount);
|
||||
@@ -74,13 +74,29 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
|
||||
var sink = new ServerImportSink(client, staging);
|
||||
|
||||
var outcome = await LocalImport.RunAsync(plan, sink, true, null, context.Cancellation, sink.Report);
|
||||
var outcome = await LocalImport.RunAsync(plan, sink, "EOS R5 · card A", true, null, context.Cancellation, sink.Report);
|
||||
Assert.Equal(7, outcome.Copied);
|
||||
Assert.Equal(7, server.Committed.Count);
|
||||
Assert.Equal(new ImportFailure("DCIM/100CANON/IMG_0003.JPG", "Hash mismatch"), outcome.Failures.Single());
|
||||
Assert.Empty(Directory.EnumerateFileSystemEntries(staging));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFileAProxyRefusesIsListedWithTheCatalogsSentence()
|
||||
{
|
||||
var card = Card(context.CreateTempDirectory("card"), 8, Start);
|
||||
var staging = context.CreateTempDirectory("staging");
|
||||
var server = new FakeUploadServer(chunkSize: 4096) { ProxyRefusesFile = "IMG_0005.JPG" };
|
||||
using var client = new TitanoClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" };
|
||||
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
|
||||
var sink = new ServerImportSink(client, staging);
|
||||
|
||||
var outcome = await LocalImport.RunAsync(plan, sink, "EOS R5 · card A", true, null, context.Cancellation, sink.Report);
|
||||
Assert.Equal(7, outcome.Copied);
|
||||
// The proxy's page says "Request Entity Too Large" in English: the photo reads the catalog's sentence instead.
|
||||
Assert.Equal(new ImportFailure("DCIM/100CANON/IMG_0005.JPG", Titano.Core.Localization.Loc.L("Server.Error.TooLarge")), outcome.Failures.Single());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALostSignInStopsTheImportAndKeepsWhatWasUploaded()
|
||||
{
|
||||
@@ -91,7 +107,7 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
|
||||
var sink = new ServerImportSink(client, staging);
|
||||
|
||||
var outcome = await LocalImport.RunAsync(plan, sink, true, null, context.Cancellation, sink.Report);
|
||||
var outcome = await LocalImport.RunAsync(plan, sink, "EOS R5 · card A", true, null, context.Cancellation, sink.Report);
|
||||
Assert.Equal(3, outcome.Copied, "the uploads the server committed before the sign-in was lost");
|
||||
Assert.Equal(5, outcome.Failures.Count);
|
||||
Assert.Equal("Sign in again", outcome.Failures[0].Message, "the server's sentence");
|
||||
@@ -231,6 +247,9 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
/// <summary>Flip a byte of every chunk of this file (a damaged transfer).</summary>
|
||||
public string? CorruptFile { get; init; }
|
||||
|
||||
/// <summary>A reverse proxy in front of the server refuses the chunks of this file: 413 with its own HTML page.</summary>
|
||||
public string? ProxyRefusesFile { get; init; }
|
||||
|
||||
/// <summary>Answer 401 to new uploads once this many were committed (the sign-in expired).</summary>
|
||||
public int? SignedOutAfter { get; init; }
|
||||
|
||||
@@ -276,6 +295,13 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
if (request.Method == HttpMethod.Put && path is ["api", "v1", "uploads", var id, "chunks", var n])
|
||||
{
|
||||
var upload = _open[Guid.Parse(id)];
|
||||
if (upload.FileName == ProxyRefusesFile)
|
||||
{
|
||||
return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge)
|
||||
{
|
||||
Content = new StringContent("<html><body><h1>413 Request Entity Too Large</h1></body></html>", System.Text.Encoding.UTF8, "text/html"),
|
||||
};
|
||||
}
|
||||
var bytes = await request.Content!.ReadAsByteArrayAsync(cancellationToken);
|
||||
if (upload.FileName == CorruptFile) bytes[0] ^= 0xFF;
|
||||
upload.Parts[int.Parse(n, System.Globalization.CultureInfo.InvariantCulture)] = bytes;
|
||||
|
||||
@@ -30,7 +30,27 @@ public sealed class ErrorTextTests
|
||||
// Failures that already carry a catalog sentence keep it.
|
||||
Assert.Equal(@"The archive D:\Shoots is offline.", ErrorText.ForServer(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.Offline)));
|
||||
Assert.Equal("Something went wrong.", ErrorText.ForServer(new InvalidOperationException("Sequence contains no elements")));
|
||||
Assert.Equal("Something went wrong.", ErrorText.ForServer(new TitanoApiException(HttpStatusCode.BadGateway, new ApiError("bad_gateway", " ", null))));
|
||||
Assert.Equal("Something went wrong.", ErrorText.ForServer(new TitanoApiException(HttpStatusCode.Conflict, new ApiError("conflict", " ", null))));
|
||||
Assert.Equal(Unreachable, ErrorText.ForServer(new TitanoApiException(HttpStatusCode.BadGateway, new ApiError("bad_gateway", " ", null))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AReplyThatIsNotTheServersOwnSaysWhatItsStatusMeans()
|
||||
{
|
||||
// A reverse proxy answers for the server (the NAS setup): its page is no Titano JSON, so TitanoClient keeps only
|
||||
// the reason phrase, in English, which never reaches the screen.
|
||||
static TitanoApiException Proxy(HttpStatusCode status, string reason) => new(status, new ApiError("http_" + (int)status, reason));
|
||||
const string Unreachable = "The server does not answer; check the address and the network.";
|
||||
Assert.Equal(Unreachable, ErrorText.ForServer(Proxy(HttpStatusCode.BadGateway, "Bad Gateway")));
|
||||
Assert.Equal(Unreachable, ErrorText.ForServer(Proxy(HttpStatusCode.ServiceUnavailable, "Service Unavailable")));
|
||||
Assert.Equal(Unreachable, ErrorText.ForServer(Proxy(HttpStatusCode.GatewayTimeout, "Gateway Timeout")));
|
||||
Assert.Equal(Unreachable, ErrorText.For(Proxy(HttpStatusCode.BadGateway, "Bad Gateway")));
|
||||
Assert.Equal("The request is larger than the server accepts.", ErrorText.ForServer(Proxy(HttpStatusCode.RequestEntityTooLarge, "Request Entity Too Large")));
|
||||
Assert.Equal("Too many attempts; wait a minute and try again.", ErrorText.ForServer(Proxy(HttpStatusCode.TooManyRequests, "Too Many Requests")));
|
||||
Assert.Equal("Unexpected server error; try again.", ErrorText.ForServer(Proxy(HttpStatusCode.InternalServerError, "Internal Server Error")));
|
||||
Assert.Equal("Something went wrong.", ErrorText.ForServer(Proxy(HttpStatusCode.NotFound, "Not Found")));
|
||||
// JSON of another shape has no code: its message is not the server's either.
|
||||
Assert.Equal(Unreachable, ErrorText.ForServer(new TitanoApiException(HttpStatusCode.BadGateway, new ApiError(null!, "upstream connect error"))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Shell;
|
||||
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;
|
||||
@@ -133,26 +138,40 @@ public sealed class ShellNotificationTests
|
||||
Assert.Equal(badge, jobs.Badge);
|
||||
Assert.NotEqual(TaskbarItemProgressState.Error, shell.TaskbarState);
|
||||
|
||||
// The editor announces the renders of its own sequence, with their output: the shell says nothing then.
|
||||
var id = await app.Sample.FillEditorAsync();
|
||||
shell.OpenSequence(id);
|
||||
await shell.Sequence.OpenAsync(id);
|
||||
Assert.NotNull(shell.Sequence.Editor);
|
||||
// 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 render = Job(JobKind.Render, JobState.Running, id);
|
||||
jobs.OnJobChanged(render);
|
||||
jobs.Flush();
|
||||
jobs.OnJobChanged(render with { State = JobState.Done });
|
||||
jobs.Flush();
|
||||
Assert.False(raised.Any(t => t.Title == Loc.L("Shell.Job.Done")), "the editor's own render toast is not doubled");
|
||||
// A render of another sequence is the shell's to announce.
|
||||
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")));
|
||||
await shell.Sequence.CloseAsync();
|
||||
|
||||
// Server › Upload all: the batch speaks once, when its last upload ends.
|
||||
raised.Clear();
|
||||
@@ -380,6 +399,137 @@ public sealed class ShellNotificationTests
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Tests.Archiving;
|
||||
using Titano.Testing;
|
||||
using static Titano.Core.Tests.Import.ImportTestKit;
|
||||
@@ -141,6 +142,41 @@ public sealed class ImportExecutorTests(TestContext context)
|
||||
Assert.Equal(19, final.Copied);
|
||||
Assert.Equal(1, final.Failed);
|
||||
Assert.Equal(plan.Sessions[0].Items[5].SourcePath, failed.Single().Item.SourcePath);
|
||||
Assert.Equal(Loc.L("Archive.Error.SourceChanged", plan.Sessions[0].Items[5].SourcePath), failed.Single().Error);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ACopyTheSystemRefusesFailsAloneWithACatalogSentence()
|
||||
{
|
||||
var card = Card(10);
|
||||
var destination = context.CreateTempDirectory("dest");
|
||||
var plan = await PlanAsync(card, destination);
|
||||
var sink = new FolderImportSink(destination);
|
||||
// A folder squats the staging name of the fourth copy: creating that copy fails with the system's own text.
|
||||
var item = plan.Sessions[0].Items[3];
|
||||
Directory.CreateDirectory(Path.Combine(sink.StagingDirectory, $"{plan.Id:N}-{3:D6}{Path.GetExtension(item.FileName)}"));
|
||||
var failed = new List<ImportItemResult>();
|
||||
var final = await RunAsync(plan, sink, committed: b =>
|
||||
{
|
||||
failed.AddRange(b.Results.Where(r => r.Status == ImportItemStatus.Failed));
|
||||
return ValueTask.CompletedTask;
|
||||
});
|
||||
Assert.Equal(9, final.Copied);
|
||||
Assert.Equal(item.SourcePath, failed.Single().Item.SourcePath);
|
||||
Assert.Contains(failed.Single().Error, new[] { Loc.L("Import.Failed.Photo"), Loc.L("Import.Failed.PhotoAccess") });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AFailedCopySaysWhyInOneLocalizedSentence()
|
||||
{
|
||||
Assert.Equal(Loc.L("Import.Failed.Full"), ImportExecutor.FailureText(new IOException("There is not enough space on the disk.", unchecked((int)0x80070070))));
|
||||
Assert.Equal(Loc.L("Import.Failed.Full"), ImportExecutor.FailureText(new IOException("The disk is full.", unchecked((int)0x80070027))));
|
||||
Assert.Equal(Loc.L("Import.Failed.PhotoAccess"), ImportExecutor.FailureText(new UnauthorizedAccessException(@"Access to the path 'E:\DCIM\IMG_0001.CR3' is denied.")));
|
||||
Assert.Equal(Loc.L("Import.Failed.Photo"), ImportExecutor.FailureText(new IOException("The semaphore timeout period has expired.")));
|
||||
Assert.Equal(Loc.L("Import.Failed.Photo"), ImportExecutor.FailureText(new FileNotFoundException(@"Could not find file 'E:\DCIM\IMG_0001.CR3'.")));
|
||||
// The executor's own checks are one sentence each already.
|
||||
Assert.Equal(Loc.L("Archive.Error.CopyMismatch", "IMG_0001.CR3"), ImportExecutor.FailureText(new CopyVerificationException("/staging/IMG_0001.CR3")));
|
||||
Assert.Equal(Loc.L("Archive.Error.SourceChanged", "DCIM/IMG_0001.CR3"), ImportExecutor.FailureText(new ImportSourceChangedException("DCIM/IMG_0001.CR3")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Tests.Archiving;
|
||||
using Titano.Testing;
|
||||
using static Titano.Core.Tests.Import.ImportTestKit;
|
||||
@@ -35,6 +36,25 @@ public sealed class ImportPlannerTests(TestContext context)
|
||||
Assert.Empty(plan.Problems);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AFileThatCannotBeReadIsAProblemWithOneLocalizedSentence()
|
||||
{
|
||||
var card = context.CreateTempDirectory("card");
|
||||
TestPhotos.WriteSeries(Path.Combine(card, "DCIM", "100CANON"), Start, 3, Interval);
|
||||
var files = CardScanner.Find(card, includeSubfolders: true);
|
||||
// A photo leaves the card between listing and reading; another name is a folder the system refuses to read as a file.
|
||||
File.Delete(Path.Combine(card, files[1].RelativePath));
|
||||
Directory.CreateDirectory(Path.Combine(card, "DCIM", "100CANON", "IMG_9999.JPG"));
|
||||
var problems = new List<ImportProblem>();
|
||||
|
||||
var photos = CardScanner.ReadMetadata(card, [.. files, new CardFile("DCIM/100CANON/IMG_9999.JPG", 0, Start)], problems);
|
||||
Assert.Equal(2, photos.Count);
|
||||
Assert.SequenceEqual([files[1].RelativePath, "DCIM/100CANON/IMG_9999.JPG"], problems.Select(p => p.RelativePath));
|
||||
Assert.Equal(Loc.L("Import.Failed.Photo"), problems[0].Message);
|
||||
Assert.Contains(problems[1].Message, new[] { Loc.L("Import.Failed.Photo"), Loc.L("Import.Failed.PhotoAccess") });
|
||||
Assert.False(problems.Any(p => p.Message.Contains(card, StringComparison.Ordinal)), "the system's text, with the card's path, stays in the log");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFlatFolderIncludesSubfoldersOnlyWhenAsked()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user