feat: owner review 2 phase 4b: mass conversion after import (#13)
CI / Build and test (push) Failing after 3m1s
CI / PostgreSQL 16 integration (push) Skipped
CI / PostgreSQL 17 integration (push) Skipped
CI / Docker image (push) Skipped
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 10s
Release / Build, test and publish (push) Successful in 15m31s
Release / Server image (push) Successful in 1m13s
CI / Build and test (push) Failing after 3m1s
CI / PostgreSQL 16 integration (push) Skipped
CI / PostgreSQL 17 integration (push) Skipped
CI / Docker image (push) Skipped
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 10s
Release / Build, test and publish (push) Successful in 15m31s
Release / Server image (push) Successful in 1m13s
Convert photos already in the archive to JPEG, TIFF-16 or Linear DNG, from the panel's Library and the desktop's Archive and Library. Each run asks Replace (same frames, originals to the trash, recoverable) or New sequence. A dry run lists what converts, what is skipped and why, size before and after, and free space; the job converts exactly the confirmed photos, resumes, and commits all or nothing per sequence. A conversion never changes what Chronos reads from a photo. Replaced originals are erased only on the archive's own word that their conversion is gone. Desktop TIFFs that WIC showed black or as noise now go to the managed reader; the Edit picker no longer spins a core. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #13.
This commit is contained in:
1 parent
7e4a3b481d
commit
efa87f68ce
354 files changed
+24530
-843
No files matched your search
@@ -11,6 +11,7 @@ using Chronos.App.Sections;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.App.Tests.Windows;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Conversion;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Testing;
|
||||
using Chronos.Ui.Controls;
|
||||
@@ -106,6 +107,21 @@ public sealed class ArchiveScreenSmokeTests
|
||||
AssertEveryButtonIsNamed(app);
|
||||
|
||||
reorganize.CloseCommand.Execute(null);
|
||||
await ArchiveScenes.ShowAsync(app.Shell, "convert");
|
||||
var convert = Assert.NotNull(archive.Dialog as ConvertDialogViewModel);
|
||||
Assert.Equal(ConvertMode.NewSequence, convert.Mode);
|
||||
Assert.Count(6, convert.Rows, "the dry run lists the sequences, each with what converts or why it does not");
|
||||
Assert.True(convert.IsSpaceFine);
|
||||
Assert.Null(convert.ErrorText);
|
||||
await app.ExpectAsync<ArchiveView>("archive-convert");
|
||||
Assert.True(ButtonFor(app, convert.ApplyCommand).IsEnabled, "Apply follows the dry run and the mode chosen");
|
||||
Assert.True(ButtonFor(app, convert.CloseCommand).IsDefault, "Enter takes the safe way out");
|
||||
Assert.True(TextFor(app, convert.SpaceText!).IsVisible, "the free space line shows");
|
||||
foreach (var choice in app.FindAll<RadioButton>().Where(r => r.IsVisible && IsInArchive(r))) Assert.NotNull(choice.ToolTip, "every choice says what it does");
|
||||
AssertNoErrorShown(app);
|
||||
AssertEveryButtonIsNamed(app);
|
||||
convert.CloseCommand.Execute(null);
|
||||
|
||||
archive.RetagSetCommand.Execute(null);
|
||||
var retag = Assert.NotNull(archive.Dialog as RetagDialogViewModel);
|
||||
retag.Add.Text = "sunset";
|
||||
@@ -144,6 +160,13 @@ public sealed class ArchiveScreenSmokeTests
|
||||
Assert.Equal(FlowDirection.LeftToRight, TextFor(app, folder.From).FlowDirection, "a folder before the move reads left to right");
|
||||
Assert.Equal(FlowDirection.LeftToRight, TextFor(app, folder.To).FlowDirection, "a folder after the move reads left to right");
|
||||
reorganize.CloseCommand.Execute(null);
|
||||
|
||||
await ArchiveScenes.ShowAsync(app.Shell, "convert");
|
||||
var convert = Assert.NotNull(archive.Dialog as ConvertDialogViewModel);
|
||||
await app.ExpectAsync<ArchiveView>("archive-convert-ar");
|
||||
var untitled = Assert.NotNull(convert.Rows.FirstOrDefault(r => r.IsNamePath), "a sequence without a title is named by its folder");
|
||||
Assert.Equal(FlowDirection.LeftToRight, TextFor(app, untitled.Name).FlowDirection, "its folder reads left to right");
|
||||
convert.CloseCommand.Execute(null);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -0,0 +1,508 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
using Chronos.App.Archiving;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Tests.Import;
|
||||
using Chronos.App.Tests.Uploader;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Conversion;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Imaging.Decoders;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Archiving.Jobs;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Archiving;
|
||||
|
||||
/// <summary>
|
||||
/// Convert… (owner review 2, R7): the format, the JPEG quality and the mode chosen at every run, the dry run listed sequence
|
||||
/// by sequence with the space line, the typed confirmation of a Replace, Apply queuing the job of exactly the plan on
|
||||
/// screen, and the Undo a finished Replace offers.
|
||||
/// </summary>
|
||||
public sealed class ConvertDialogTests(TestContext context)
|
||||
{
|
||||
private static readonly DateTime Start = new(2026, 9, 28, 18, 0, 0);
|
||||
|
||||
private static ConvertFramePlan Frame(int index, long size = 1_000_000, long estimated = 2_000_000) =>
|
||||
new(Guid.CreateVersion7(), index, $"originals/IMG_{index + 1:0000}.JPG", ImageFileFormat.Jpeg, size, estimated);
|
||||
|
||||
[Test]
|
||||
public void TheDryRunIsListedSequenceBySequence()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
var harbour = new ConvertSequencePlan(Guid.CreateVersion7(), "Harbour sunset", "2026/2026-09-28 Canon EOS R5", 4, [Frame(0), Frame(1), Frame(2)],
|
||||
[new ConvertSkipped(ConvertSkip.SameFormat, 2), new ConvertSkipped(ConvertSkip.Unhashed, 1)], []);
|
||||
var comet = new ConvertSequencePlan(Guid.CreateVersion7(), "Comet", "2025/Comet", 2, [], [], [ConvertBlock.Busy, ConvertBlock.Offline]);
|
||||
var empty = new ConvertSequencePlan(Guid.CreateVersion7(), "Empty", "2025/Empty", 1, [], [], []);
|
||||
var untitled = new ConvertSequencePlan(Guid.CreateVersion7(), string.Empty, "2026/2026-09-29", 1, [Frame(0, 500_000, 700_000)], [], []);
|
||||
var plan = new ConvertPlan(Guid.CreateVersion7(), new ConvertOptions(ConvertTarget.LinearDng), ConvertMode.Replace, [harbour, comet, empty, untitled],
|
||||
new ConvertSpace(ConvertPlanner.Required(6_700_000), 40_000_000_000));
|
||||
|
||||
var rows = ConvertPlans.Rows(plan);
|
||||
|
||||
Assert.SequenceEqual([harbour.SequenceId, comet.SequenceId, untitled.SequenceId], rows.Select(r => r.SequenceId), "a sequence with nothing to say is left out");
|
||||
var first = rows[0];
|
||||
Assert.Equal(("Harbour sunset", false, false), (first.Name, first.IsNamePath, first.IsBlocked));
|
||||
Assert.Equal(Loc.Plural("Shell.Status.Photos", 3) + Loc.Separator + ConvertPlans.Sizes(3_000_000, 6_000_000), first.Note);
|
||||
Assert.SequenceEqual(
|
||||
[
|
||||
Loc.L("Archive.Convert.Skipped.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2),
|
||||
Loc.L("Archive.Convert.Skipped.Unhashed") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 1),
|
||||
],
|
||||
first.Kept);
|
||||
Assert.Contains(first.Note, first.Description);
|
||||
Assert.Contains(first.Kept[1], first.Description);
|
||||
|
||||
var busy = rows[1];
|
||||
Assert.True(busy.IsBlocked);
|
||||
Assert.False(busy.HasNote, "nothing of it converts");
|
||||
Assert.SequenceEqual([Loc.L("Archive.Convert.Blocked.Busy"), Loc.L("Archive.Convert.Blocked.Offline")], busy.Kept);
|
||||
|
||||
var folder = rows[2];
|
||||
Assert.Equal(("2026/2026-09-29", true), (folder.Name, folder.IsNamePath), "without a title, the row is named by its folder, left to right");
|
||||
|
||||
Assert.Equal(string.Join(Loc.Separator, Loc.Plural("Archive.Rename.Summary", 2, 4), Loc.Plural("Shell.Status.Photos", 4), ConvertPlans.Sizes(3_500_000, 6_700_000),
|
||||
Loc.Plural("Archive.Convert.SkippedPhotos", 3)), ConvertPlans.Summary(plan));
|
||||
Assert.Equal(Loc.Plural("Archive.Rename.Summary", 0, 1), ConvertPlans.Summary(plan with { Sequences = [comet] }), "nothing converts, nothing more is said");
|
||||
|
||||
// Into a new sequence, which holds the converted copies alone: the photos skipped are not copied into it. Of a
|
||||
// sequence that converts nothing no copy is made, and its photos stay as they are.
|
||||
var same = new ConvertSequencePlan(Guid.CreateVersion7(), "Lake", "2025/Lake", 1, [], [new ConvertSkipped(ConvertSkip.SameFormat, 2)], []);
|
||||
var copies = plan with { Mode = ConvertMode.NewSequence, Sequences = [harbour, comet, empty, untitled, same] };
|
||||
var copied = ConvertPlans.Rows(copies);
|
||||
Assert.SequenceEqual(
|
||||
[
|
||||
Loc.L("Archive.Convert.NotCopied.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2),
|
||||
Loc.L("Archive.Convert.NotCopied.Unhashed") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 1),
|
||||
],
|
||||
copied[0].Kept);
|
||||
Assert.SequenceEqual(busy.Kept, copied[1].Kept, "what blocks a sequence reads the same");
|
||||
Assert.SequenceEqual([Loc.L("Archive.Convert.Skipped.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2)], copied[3].Kept);
|
||||
Assert.Equal(3, ConvertPlans.LeftOut(copies));
|
||||
Assert.Equal(string.Join(Loc.Separator, Loc.Plural("Archive.Rename.Summary", 2, 5), Loc.Plural("Shell.Status.Photos", 4), ConvertPlans.Sizes(3_500_000, 6_700_000),
|
||||
Loc.Plural("Archive.Convert.NotCopiedPhotos", 3), Loc.Plural("Archive.Convert.SkippedPhotos", 2)), ConvertPlans.Summary(copies));
|
||||
|
||||
// New sequence is confirmed too, before anything is queued: what is copied, nothing to type, and which photos the
|
||||
// new sequences lack, with their count, sequence by sequence.
|
||||
var copy = Assert.NotNull(ConvertPlans.NewRequest(copies));
|
||||
Assert.False(copy.IsDestructive);
|
||||
Assert.Null(copy.TypedConfirmation);
|
||||
Assert.Equal(Loc.Plural("Archive.Convert.NewHeading", 2), copy.Heading);
|
||||
Assert.Equal(Loc.L("Archive.Convert.NewMessage", Loc.Plural("Shell.Status.Photos", 4), Formatting.Bytes(3_500_000), Loc.L("Archive.Convert.Target.LinearDng"))
|
||||
+ " " + Loc.Plural("Archive.Convert.NewLeftOut", 3), copy.Message);
|
||||
Assert.SequenceEqual(
|
||||
[
|
||||
Loc.L("Archive.Delete.Line", "Harbour sunset", Loc.Plural("Shell.Status.Photos", 3), ConvertPlans.Sizes(3_000_000, 6_000_000))
|
||||
+ Loc.Separator + Loc.Plural("Archive.Convert.NotCopiedPhotos", 3),
|
||||
Loc.L("Archive.Delete.Line", "2026/2026-09-29", Loc.Plural("Shell.Status.Photos", 1), ConvertPlans.Sizes(500_000, 700_000)),
|
||||
],
|
||||
copy.Detail!.Split(Environment.NewLine));
|
||||
Assert.Equal((Loc.L("Archive.Convert.Confirm"), Loc.L("Archive.Dialog.Cancel")), (copy.ActionText, copy.SafeText));
|
||||
Assert.Equal(Loc.L("Archive.Convert.NewMessage", Loc.Plural("Shell.Status.Photos", 1), Formatting.Bytes(500_000), Loc.L("Archive.Convert.Target.LinearDng")),
|
||||
ConvertPlans.NewRequest(copies with { Sequences = [untitled, same] })!.Message, "nothing left out, nothing said of it");
|
||||
Assert.Null(ConvertPlans.NewRequest(copies with { Sequences = [comet, empty, same] }), "nothing to copy, nothing to confirm");
|
||||
|
||||
// The space line: enough, short, or not measurable.
|
||||
var required = Formatting.Bytes(plan.Space.Required);
|
||||
Assert.Equal(new ConvertSpaceLine(Loc.L("Archive.Convert.Space", required, Formatting.Bytes(40_000_000_000)), false), ConvertPlans.Space(plan.Space));
|
||||
Assert.Equal(new ConvertSpaceLine(Loc.L("Archive.Convert.SpaceShort", required, Formatting.Bytes(1_000)), true),
|
||||
ConvertPlans.Space(plan.Space with { Free = 1_000 }));
|
||||
Assert.Equal(new ConvertSpaceLine(Loc.L("Archive.Convert.SpaceUnknown", required), false), ConvertPlans.Space(plan.Space with { Free = null }));
|
||||
|
||||
// A Replace is confirmed by typing the number of photos it replaces.
|
||||
var request = Assert.NotNull(ConvertPlans.ReplaceRequest(plan));
|
||||
Assert.True(request.IsDestructive);
|
||||
Assert.Equal("4", request.TypedConfirmation);
|
||||
Assert.Equal(Loc.L("Archive.Delete.Type", "4"), request.TypedPrompt);
|
||||
Assert.Equal(Loc.Plural("Archive.Convert.ReplaceHeading", 2), request.Heading);
|
||||
Assert.Contains(Loc.L("Archive.Convert.Target.LinearDng"), request.Message);
|
||||
Assert.Contains("Harbour sunset", request.Detail!);
|
||||
Assert.False(request.Detail!.Contains("Comet", StringComparison.Ordinal), "a blocked sequence keeps its photos");
|
||||
Assert.Null(ConvertPlans.ReplaceRequest(plan with { Sequences = [comet, empty] }), "nothing to replace, nothing to confirm");
|
||||
|
||||
Assert.Null(ConvertPlans.ValidateQuality("95"));
|
||||
Assert.Null(ConvertPlans.ValidateQuality(" 1 "));
|
||||
Assert.NotNull(ConvertPlans.ValidateQuality("0"));
|
||||
Assert.NotNull(ConvertPlans.ValidateQuality("101"));
|
||||
Assert.NotNull(ConvertPlans.ValidateQuality("high"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheModeIsChosenAtEveryRunAndApplyQueuesExactlyThatPlan()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
var directory = context.CreateTempDirectory("convert-dialog");
|
||||
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(directory, "index.db")), context.Cancellation);
|
||||
var archives = Service(db);
|
||||
var archive = await archives.CreateAsync(Path.Combine(directory, "archive"), "Main", cancellationToken: context.Cancellation);
|
||||
var harbour = await UploadAsync(archives, archive, "harbour", Start, 1);
|
||||
var comet = await UploadAsync(archives, archive, "comet", Start.AddDays(1), 11);
|
||||
|
||||
var queued = new TaskCompletionSource<ArchiveJobRequest>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
List<ConfirmRequest> asked = [];
|
||||
var closed = false;
|
||||
using var dialog = new ConvertDialogViewModel(archives, archive, [harbour, comet], request =>
|
||||
{
|
||||
queued.TrySetResult(request);
|
||||
return Task.CompletedTask;
|
||||
}, request =>
|
||||
{
|
||||
asked.Add(request);
|
||||
return true;
|
||||
}, _ => closed = true);
|
||||
|
||||
// The archival format, the default quality, and no mode: every run chooses it.
|
||||
Assert.Equal(ConvertTarget.LinearDng, dialog.Target);
|
||||
Assert.True(dialog.IsLinearDng);
|
||||
Assert.False(dialog.IsQualityEnabled, "only a JPEG has a quality");
|
||||
Assert.Equal(ConvertOptions.DefaultQuality.ToString(CultureInfo.InvariantCulture), dialog.Quality.Text);
|
||||
Assert.Null(dialog.Mode);
|
||||
Assert.False(dialog.IsReplace || dialog.IsNewSequence);
|
||||
Assert.Equal(Loc.Plural("Archive.Convert.Heading", 2), dialog.Heading);
|
||||
await dialog.PlanAsync();
|
||||
|
||||
var plan = Assert.NotNull(dialog.Plan);
|
||||
Assert.Equal(4, plan.Frames);
|
||||
Assert.Count(2, dialog.Rows);
|
||||
Assert.True(dialog.Rows.All(r => r.HasNote && !r.HasKept));
|
||||
Assert.Equal(Loc.Plural("Archive.Rename.Summary", 2, 2), dialog.SummaryText.Split(Loc.Separator)[0]);
|
||||
Assert.True(dialog.IsSpaceFine);
|
||||
Assert.NotNull(dialog.SpaceText);
|
||||
Assert.Equal(Loc.L("Archive.Blocked.NoMode"), dialog.ApplyToolTip, "the mode is never assumed");
|
||||
Assert.False(dialog.ApplyCommand.CanExecute(null));
|
||||
|
||||
dialog.IsNewSequence = true;
|
||||
Assert.Equal(ConvertMode.NewSequence, dialog.Mode);
|
||||
Assert.Equal(ConvertMode.NewSequence, dialog.Plan!.Mode, "the plan on screen is the mode chosen");
|
||||
Assert.Equal(Loc.L("Tooltips.Archive.ConvertApplyNew"), dialog.ApplyToolTip);
|
||||
Assert.True(dialog.ApplyCommand.CanExecute(null));
|
||||
|
||||
// JPEG to JPEG converts nothing: no new sequence is made of them, so in either mode the rows and the summary say the
|
||||
// photos stay as they are. A quality outside 1-100 blocks a JPEG only.
|
||||
dialog.IsJpeg = true;
|
||||
Assert.Equal(Loc.L("Archive.Blocked.Planning"), dialog.ApplyToolTip, "the dry run on screen is not the one of the format chosen");
|
||||
await dialog.PlanAsync();
|
||||
Assert.SequenceEqual([Loc.L("Archive.Convert.Skipped.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2)], dialog.Rows[0].Kept);
|
||||
Assert.Equal(Loc.Plural("Archive.Convert.SkippedPhotos", 4), dialog.SummaryText.Split(Loc.Separator)[^1]);
|
||||
dialog.IsReplace = true;
|
||||
Assert.SequenceEqual([Loc.L("Archive.Convert.Skipped.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2)], dialog.Rows[0].Kept);
|
||||
Assert.Equal(Loc.Plural("Archive.Convert.SkippedPhotos", 4), dialog.SummaryText.Split(Loc.Separator)[^1]);
|
||||
dialog.IsNewSequence = true;
|
||||
Assert.Equal(Loc.L("Archive.Blocked.NothingToConvert"), dialog.ApplyToolTip);
|
||||
// A click on Apply takes the focus from the quality first, which commits it: the dry run on screen is of that
|
||||
// quality already, so no other one starts under the click.
|
||||
dialog.Quality.Text = "90";
|
||||
await dialog.PlanAsync();
|
||||
Assert.True(dialog.Quality.IsDirty, "typed, not committed");
|
||||
Assert.True(dialog.Quality.Commit());
|
||||
Assert.Null(dialog.BusyText);
|
||||
Assert.Equal(new ConvertOptions(ConvertTarget.Jpeg, 90), dialog.Plan!.Options);
|
||||
dialog.Quality.Text = "0";
|
||||
Assert.Null(dialog.Current());
|
||||
Assert.Equal(dialog.Quality.Error, dialog.ApplyToolTip);
|
||||
dialog.IsTiff16 = true;
|
||||
Assert.Null(dialog.Quality.Error, "a TIFF has no quality");
|
||||
Assert.Equal(new ConvertOptions(ConvertTarget.Tiff16), dialog.Current());
|
||||
await dialog.PlanAsync();
|
||||
plan = Assert.NotNull(dialog.Plan);
|
||||
Assert.Equal(4, plan.Frames);
|
||||
|
||||
dialog.ApplyCommand.Execute(null);
|
||||
var request = await queued.Task.WaitAsync(TimeSpan.FromSeconds(TestTiming.Budget(20)));
|
||||
await UntilAsync(() => closed);
|
||||
// Confirmed first, with what the new sequences hold: the originals stay as they are, so nothing to type.
|
||||
var confirmed = asked.Single();
|
||||
Assert.Equal(ConvertPlans.NewRequest(plan with { Mode = ConvertMode.NewSequence }), confirmed);
|
||||
Assert.Null(confirmed.TypedConfirmation);
|
||||
Assert.Equal(JobKind.Convert, request.Kind);
|
||||
Assert.SequenceEqual(new[] { harbour, comet }.Order(), request.Targets.Order());
|
||||
Assert.Equal(archive.Name, request.Label);
|
||||
Assert.Equal(JobPriority.User, request.Priority);
|
||||
using (var parameters = JsonDocument.Parse(request.ParametersJson!))
|
||||
{
|
||||
var json = parameters.RootElement;
|
||||
Assert.Equal("Tiff16", json.GetProperty("target").GetString());
|
||||
Assert.Equal("NewSequence", json.GetProperty("mode").GetString());
|
||||
var fingerprint = (await archives.PlanConvertAsync(archive.Id, [harbour, comet], new ConvertOptions(ConvertTarget.Tiff16), ConvertMode.NewSequence,
|
||||
context.Cancellation)).Fingerprint();
|
||||
Assert.Equal(fingerprint, json.GetProperty("fingerprint").GetString(), "the job is the plan of the mode chosen");
|
||||
}
|
||||
Assert.Equal(2, (await db.Frames.ListBySequenceAsync(harbour)).Count(f => f.Format == ImageFileFormat.Jpeg), "the job converts, not the dialog");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASecondDialogOnTheSameSequencesIsRefusedAndShowsThemBusy()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
var directory = context.CreateTempDirectory("convert-twice");
|
||||
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(directory, "index.db")), context.Cancellation);
|
||||
var archives = Service(db);
|
||||
var archive = await archives.CreateAsync(Path.Combine(directory, "archive"), "Main", cancellationToken: context.Cancellation);
|
||||
var harbour = await UploadAsync(archives, archive, "harbour", Start, 1);
|
||||
// Queued as the engine does: the job waits in the index.
|
||||
async Task Enqueue(ArchiveJobRequest request) => await db.Jobs.EnqueueAsync(new Job
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Kind = request.Kind,
|
||||
TargetIds = request.Targets,
|
||||
ParametersJson = request.ParametersJson,
|
||||
State = JobState.Queued,
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
}, context.Cancellation);
|
||||
var closed = new List<ArchiveDialogViewModel>();
|
||||
ConvertDialogViewModel Open() => new(archives, archive, [harbour], Enqueue, _ => true, closed.Add) { IsNewSequence = true };
|
||||
|
||||
// The Library's dialog and the Archive manager's, both planned before either applies.
|
||||
using var library = Open();
|
||||
using var manager = Open();
|
||||
await library.PlanAsync();
|
||||
await manager.PlanAsync();
|
||||
library.ApplyCommand.Execute(null);
|
||||
await UntilAsync(() => closed.Contains(library));
|
||||
|
||||
// The second is refused: it says why, plans again with the sequence busy, and stays open.
|
||||
manager.ApplyCommand.Execute(null);
|
||||
await UntilAsync(() => manager.ErrorText is not null && !manager.IsBusy && manager.Plan is not null);
|
||||
Assert.Equal(Loc.L("Archive.Convert.AlreadyQueued"), manager.ErrorText);
|
||||
Assert.SequenceEqual([Loc.L("Archive.Convert.Blocked.Busy")], manager.Rows.Single().Kept);
|
||||
Assert.Equal(Loc.L("Archive.Blocked.NothingToConvert"), manager.ApplyToolTip);
|
||||
Assert.DoesNotContain(manager, closed);
|
||||
Assert.Count(1, (await db.Jobs.ListAsync(JobState.Queued, JobKind.Convert)).Items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply queues the job on the dialog's own thread, the check against the conversions queued already included: the
|
||||
/// desktop's enqueue tells the user with a toast, which only the UI thread may show.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TheJobIsQueuedOnTheDialogsThread() => SingleThreadedContext.Run(async () =>
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
var directory = context.CreateTempDirectory("convert-thread");
|
||||
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(directory, "index.db")), context.Cancellation);
|
||||
var archives = Service(db);
|
||||
var archive = await archives.CreateAsync(Path.Combine(directory, "archive"), "Main", cancellationToken: context.Cancellation);
|
||||
var harbour = await UploadAsync(archives, archive, "harbour", Start, 1);
|
||||
var ui = Environment.CurrentManagedThreadId;
|
||||
int? queuedOn = null;
|
||||
var closed = false;
|
||||
using var dialog = new ConvertDialogViewModel(archives, archive, [harbour], _ =>
|
||||
{
|
||||
queuedOn = Environment.CurrentManagedThreadId;
|
||||
return Task.CompletedTask;
|
||||
}, _ => true, _ => closed = true);
|
||||
dialog.IsNewSequence = true;
|
||||
await dialog.PlanAsync();
|
||||
|
||||
dialog.ApplyCommand.Execute(null);
|
||||
await UntilAsync(() => closed);
|
||||
Assert.Equal<int?>(ui, queuedOn);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public async Task AVolumeWithoutTheSpaceBlocksApply()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
var directory = context.CreateTempDirectory("convert-space");
|
||||
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(directory, "index.db")), context.Cancellation);
|
||||
var archives = Service(db, freeSpace: _ => 1_000);
|
||||
var archive = await archives.CreateAsync(Path.Combine(directory, "archive"), "Main", cancellationToken: context.Cancellation);
|
||||
var harbour = await UploadAsync(archives, archive, "harbour", Start, 1);
|
||||
using var dialog = new ConvertDialogViewModel(archives, archive, null, _ => Task.CompletedTask, _ => true, _ => { });
|
||||
Assert.Equal(Loc.L("Archive.Convert.HeadingAll", "Main"), dialog.Heading, "every sequence of the archive");
|
||||
dialog.Mode = ConvertMode.Replace;
|
||||
await dialog.PlanAsync();
|
||||
|
||||
var plan = Assert.NotNull(dialog.Plan);
|
||||
Assert.SequenceEqual([harbour], plan.Sequences.Select(s => s.SequenceId));
|
||||
Assert.True(dialog.IsSpaceShort);
|
||||
Assert.False(dialog.IsSpaceFine);
|
||||
Assert.Equal(ConvertPlans.Space(plan.Space).Text, dialog.SpaceText);
|
||||
Assert.Equal(dialog.SpaceText, dialog.ApplyToolTip);
|
||||
Assert.False(dialog.ApplyCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AReplaceIsTypedFirstAndItsUndoBringsTheOriginalsBack()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
var directory = context.CreateTempDirectory("convert-replace");
|
||||
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(directory, "index.db")), context.Cancellation);
|
||||
var archives = Service(db);
|
||||
var archive = await archives.CreateAsync(Path.Combine(directory, "archive"), "Main", cancellationToken: context.Cancellation);
|
||||
var harbour = await UploadAsync(archives, archive, "harbour", Start, 1);
|
||||
var comet = await UploadAsync(archives, archive, "comet", Start.AddDays(1), 11);
|
||||
var originals = (await db.Frames.ListBySequenceAsync(harbour)).Select(f => (f.Id, f.Sha256, f.Format)).ToList();
|
||||
|
||||
var queued = new TaskCompletionSource<ArchiveJobRequest>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var answer = false;
|
||||
ConfirmRequest? asked = null;
|
||||
var closed = false;
|
||||
using var dialog = new ConvertDialogViewModel(archives, archive, [harbour, comet], request =>
|
||||
{
|
||||
queued.TrySetResult(request);
|
||||
return Task.CompletedTask;
|
||||
}, request =>
|
||||
{
|
||||
asked = request;
|
||||
return answer;
|
||||
}, _ => closed = true);
|
||||
dialog.IsReplace = true;
|
||||
await dialog.PlanAsync();
|
||||
Assert.Equal(Loc.L("Tooltips.Archive.ConvertApplyReplace"), dialog.ApplyToolTip);
|
||||
|
||||
// Not typed: nothing is queued and the dialog stays.
|
||||
dialog.ApplyCommand.Execute(null);
|
||||
var confirm = Assert.NotNull(asked);
|
||||
Assert.Equal("4", confirm.TypedConfirmation);
|
||||
Assert.True(confirm.IsDestructive);
|
||||
Assert.False(queued.Task.IsCompleted);
|
||||
Assert.False(closed);
|
||||
|
||||
answer = true;
|
||||
dialog.ApplyCommand.Execute(null);
|
||||
var request = await queued.Task.WaitAsync(TimeSpan.FromSeconds(TestTiming.Budget(20)));
|
||||
await UntilAsync(() => closed);
|
||||
using (var parameters = JsonDocument.Parse(request.ParametersJson!))
|
||||
Assert.Equal("Replace", parameters.RootElement.GetProperty("mode").GetString());
|
||||
|
||||
// The job replaces the photos; its end offers Undo, which takes back exactly its originals.
|
||||
Job job;
|
||||
await using (var engine = new JobEngine(db, archives.CreateJobHandlers(),
|
||||
new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) }))
|
||||
{
|
||||
await engine.StartAsync(context.Cancellation);
|
||||
job = await WaitForAsync(db, (await engine.EnqueueAsync(request, cancellationToken: context.Cancellation)).Id);
|
||||
}
|
||||
Assert.True((await db.Frames.ListBySequenceAsync(harbour)).All(f => f.Format == ImageFileFormat.Dng));
|
||||
Assert.True(ConvertUndo.Replaces(job));
|
||||
var parametersOf = Assert.NotNull(ConvertUndo.Parameters(job));
|
||||
Assert.Equal((archive.Id, ConvertMode.Replace, ConvertTarget.LinearDng), (parametersOf.ArchiveId, parametersOf.Mode, parametersOf.Target));
|
||||
var trash = await archives.ListTrashAsync(archive.Id, context.Cancellation);
|
||||
Assert.SequenceEqual(new[] { harbour, comet }.Order(), ConvertUndo.Entries(job, parametersOf, trash).Select(e => e.SequenceId).Order());
|
||||
|
||||
var undone = await ConvertUndo.UndoAsync(archives, [job], null, context.Cancellation);
|
||||
Assert.Equal((2, 0, 2), (undone.Restored, undone.AsNew, undone.Entries));
|
||||
Assert.Null(undone.Failure);
|
||||
Assert.Empty(undone.Kept);
|
||||
Assert.SequenceEqual(originals, (await db.Frames.ListBySequenceAsync(harbour)).Select(f => (f.Id, f.Sha256, f.Format)));
|
||||
Assert.Equal((Loc.Plural("Archive.Convert.Undone", 2), (string?)null, false), ConvertUndo.Words(undone));
|
||||
|
||||
// The converted files are in the trash now: a second undo finds no originals of this job to bring back.
|
||||
Assert.Count(2, (await archives.ListTrashAsync(archive.Id, context.Cancellation)).Where(e => e.Kind == TrashKind.Replaced));
|
||||
var again = await ConvertUndo.UndoAsync(archives, [job], null, context.Cancellation);
|
||||
Assert.Equal(0, again.Entries);
|
||||
Assert.Equal((Loc.L("Archive.Convert.UndoNothing"), (string?)null, true), ConvertUndo.Words(again));
|
||||
Assert.SequenceEqual(originals, (await db.Frames.ListBySequenceAsync(harbour)).Select(f => (f.Id, f.Sha256, f.Format)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheUndoTakesTheReplacedEntriesTheJobMade()
|
||||
{
|
||||
var archive = Guid.CreateVersion7();
|
||||
var (harbour, comet, other) = (Guid.CreateVersion7(), Guid.CreateVersion7(), Guid.CreateVersion7());
|
||||
var created = new DateTimeOffset(2026, 10, 27, 9, 0, 0, TimeSpan.Zero);
|
||||
var parameters = new ConvertJobParameters(archive, ConvertTarget.Jpeg, 90, ConvertMode.Replace, [new ConvertSequence(harbour, 3), new ConvertSequence(comet, 1)], "fp");
|
||||
var job = new Job
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Kind = JobKind.Convert,
|
||||
TargetIds = [harbour, comet],
|
||||
State = JobState.Done,
|
||||
ParametersJson = $$"""{"archiveId":"{{archive}}","target":"Jpeg","quality":90,"mode":"Replace","sequences":[{"id":"{{harbour}}","framesVersion":3},{"id":"{{comet}}","framesVersion":1}],"fingerprint":"fp"}""",
|
||||
Created = created,
|
||||
Finished = created.AddMinutes(10),
|
||||
};
|
||||
TrashEntry Entry(string name, Guid sequence, int minutes, Guid? madeBy, TrashKind kind = TrashKind.Replaced, Guid? owner = null) =>
|
||||
new(owner ?? archive, name, sequence, name, "2026/" + name, 3, 3, 3_000, created.AddMinutes(minutes), null, kind) { JobId = madeBy };
|
||||
TrashEntry[] trash =
|
||||
[
|
||||
Entry("before", harbour, -5, Guid.CreateVersion7()),
|
||||
Entry("harbour", harbour, 2, job.Id),
|
||||
// A restore from Maintenance › Trash while the job ran: the converted files of its swap-back, made by no job.
|
||||
Entry("restored", harbour, 4, null),
|
||||
Entry("comet", comet, 6, job.Id),
|
||||
Entry("deleted", comet, 7, job.Id, TrashKind.Photos),
|
||||
Entry("other", other, 5, job.Id),
|
||||
Entry("elsewhere", harbour, 5, job.Id, owner: Guid.CreateVersion7()),
|
||||
Entry("undo", comet, 12, null),
|
||||
];
|
||||
|
||||
Assert.SequenceEqual(["harbour", "comet"], ConvertUndo.Entries(job, parameters, trash).Select(e => e.Name));
|
||||
Assert.True(ConvertUndo.Replaces(job));
|
||||
Assert.False(ConvertUndo.Replaces(job with { ParametersJson = job.ParametersJson!.Replace("\"Replace\"", "\"NewSequence\"", StringComparison.Ordinal) }));
|
||||
Assert.False(ConvertUndo.Replaces(job with { Kind = JobKind.Move }), "only a conversion");
|
||||
Assert.Null(ConvertUndo.Parameters(job with { ParametersJson = "{ torn" }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnUndoSaysWhatCameBackAndHow()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
var asNew = ConvertUndo.Words(new ConvertUndoResult(2, 1, [], 3, null));
|
||||
Assert.Equal((Loc.Plural("Archive.Convert.Undone", 3), Loc.Plural("Archive.Convert.UndoneNew", 1), false), asNew);
|
||||
var kept = ConvertUndo.Words(new ConvertUndoResult(1, 0, [new KeptPhoto("IMG_0002.JPG", KeptReason.Mismatch)], 1, null));
|
||||
Assert.Equal(TrashDialogViewModel.KeptText([new KeptPhoto("IMG_0002.JPG", KeptReason.Mismatch)]).Text, kept.Message);
|
||||
var failed = ConvertUndo.Words(new ConvertUndoResult(0, 0, [], 1, new UnauthorizedAccessException("denied")));
|
||||
Assert.Equal((Loc.L("Archive.Convert.UndoFailed"), Loc.L("Archive.Failed.Access"), true), failed);
|
||||
}
|
||||
|
||||
private static ArchiveService Service(ChronosDatabase db, Func<string, long?>? freeSpace = null) =>
|
||||
new(db, new ArchiveServiceOptions
|
||||
{
|
||||
Owner = "test",
|
||||
LeaseWait = TimeSpan.FromSeconds(TestTiming.Budget(20)),
|
||||
Decoder = DecoderFactory.CreateServer(),
|
||||
Parallelism = () => 2,
|
||||
FreeSpace = freeSpace,
|
||||
});
|
||||
|
||||
/// <summary>Uploads two photos ten seconds apart into a new sequence filed with the archive's templates; returns its id.</summary>
|
||||
private async Task<Guid> UploadAsync(ArchiveService archives, Core.Model.Archive archive, string key, DateTime start, int seed)
|
||||
{
|
||||
Guid id = default;
|
||||
var staging = Path.Combine(new ArchivePaths(archive.RootPath).StagingDirectory, "uploads");
|
||||
Directory.CreateDirectory(staging);
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
var bytes = ImportTestData.Jpeg(start.AddSeconds(10 * i), seed + i);
|
||||
var path = Path.Combine(staging, $"{Guid.NewGuid():N}.part");
|
||||
await File.WriteAllBytesAsync(path, bytes, context.Cancellation);
|
||||
var request = new IngestRequest(archive.Id, null, null, key, path, $"IMG_{seed + i:0000}.JPG", bytes.Length, Convert.ToHexStringLower(SHA256.HashData(bytes)),
|
||||
null, null);
|
||||
id = (await archives.Ingest.CommitAsync(request, context.Cancellation)).SequenceId;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
private async Task<Job> WaitForAsync(ChronosDatabase db, Guid jobId)
|
||||
{
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(TestTiming.Budget(60));
|
||||
Job? job = null;
|
||||
while (DateTime.UtcNow < until)
|
||||
{
|
||||
job = await db.Jobs.GetAsync(jobId, context.Cancellation);
|
||||
if (job?.State == JobState.Done) return job;
|
||||
if (job?.State is JobState.Failed or JobState.Cancelled) Assert.Fail($"The conversion job ended {job.State}: {job.Error}\n{job.LogTail}");
|
||||
await Task.Delay(20, context.Cancellation);
|
||||
}
|
||||
Assert.Fail($"The conversion job did not finish (now {job?.State}).");
|
||||
return job!;
|
||||
}
|
||||
|
||||
private static async Task UntilAsync(Func<bool> condition)
|
||||
{
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(TestTiming.Budget(20));
|
||||
while (!condition())
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < until, "timed out");
|
||||
await Task.Delay(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,46 @@ public sealed class TrashDialogTests(TestContext context)
|
||||
var lines = request.Detail!.Split(Environment.NewLine);
|
||||
Assert.Equal(2, lines.Length);
|
||||
Assert.Contains(Loc.L("Archive.Trash.Kind.Photos"), lines[0]);
|
||||
Assert.False(request.Detail!.Contains(Loc.L("Archive.Trash.ConversionDeleted"), StringComparison.Ordinal), "no conversion was deleted");
|
||||
Assert.Null(TrashEmptyPlans.Request(plan with { Entries = [] }), "nothing to erase: no confirmation");
|
||||
|
||||
// Replaced originals whose conversion was deleted since: the line says so, as the dry run found it.
|
||||
var replaced = Entry("Etna", TrashKind.Replaced, 3, 90_000_000) with { ConversionDeleted = true };
|
||||
var lone = Assert.NotNull(TrashEmptyPlans.Request(plan with { Entries = [replaced] }));
|
||||
Assert.Contains(Loc.L("Archive.Trash.Kind.Replaced") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 3) + Loc.Separator
|
||||
+ Loc.L("Archive.Trash.ConversionDeleted"), lone.Detail!);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EveryEntryThatMayHoldTheLastCopyIsNamedBeforeTheTypedConfirmation()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
// The trash lists newest first: ten deletions since two old conversions whose converted photos were deleted.
|
||||
var newer = Enumerable.Range(1, 10).Select(i => Entry($"Deleted {i}", TrashKind.Photos, 1, 1_000_000)).ToList();
|
||||
var oldest = new[]
|
||||
{
|
||||
Entry("Etna", TrashKind.Replaced, 3, 90_000_000) with { ConversionDeleted = true },
|
||||
Entry("Stromboli", TrashKind.Replaced, 2, 60_000_000) with { ConversionDeleted = true },
|
||||
};
|
||||
var plan = new TrashEmptyPlan(Guid.CreateVersion7(), [.. newer, .. oldest], 160_000_000, "f1", []);
|
||||
|
||||
var lines = Assert.NotNull(TrashEmptyPlans.Request(plan)).Detail!.Split(Environment.NewLine);
|
||||
|
||||
var why = Loc.Separator + Loc.L("Archive.Trash.ConversionDeleted");
|
||||
Assert.True(lines[0].Contains("Etna", StringComparison.Ordinal) && lines[0].Contains(why, StringComparison.Ordinal), lines[0]);
|
||||
Assert.True(lines[1].Contains("Stromboli", StringComparison.Ordinal) && lines[1].Contains(why, StringComparison.Ordinal), lines[1]);
|
||||
// The other entries fill the lines left, and the rest are counted.
|
||||
Assert.Equal(DeletePlans.ListedLines + 1, lines.Length);
|
||||
Assert.Equal(Loc.Plural("Archive.Delete.More", newer.Count - (DeletePlans.ListedLines - oldest.Length)), lines[^1]);
|
||||
|
||||
// More of them than lines: every one is named all the same.
|
||||
var many = Enumerable.Range(1, DeletePlans.ListedLines + 3).Select(i => Entry($"Converted {i}", TrashKind.Replaced, 1, 1_000_000) with { ConversionDeleted = true })
|
||||
.ToList();
|
||||
lines = Assert.NotNull(TrashEmptyPlans.Request(plan with { Entries = [.. newer, .. many] })).Detail!.Split(Environment.NewLine);
|
||||
Assert.Equal(many.Count + 1, lines.Length);
|
||||
for (var i = 0; i < many.Count; i++)
|
||||
Assert.True(lines[i].StartsWith(many[i].Title + " ", StringComparison.Ordinal) && lines[i].Contains(why, StringComparison.Ordinal), lines[i]);
|
||||
Assert.Equal(Loc.Plural("Archive.Delete.More", newer.Count), lines[^1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -103,7 +142,8 @@ public sealed class TrashDialogTests(TestContext context)
|
||||
|
||||
// Kept: the confirmation was dismissed, nothing is queued.
|
||||
dialog.EmptyCommand.Execute(null);
|
||||
await UntilAsync(() => asked is not null && !dialog.IsBusy);
|
||||
// Until the command has ended, not only the dialog's work: a command still running ignores the next Execute.
|
||||
await UntilAsync(() => asked is not null && !dialog.IsBusy && dialog.EmptyCommand.CanExecute(null));
|
||||
Assert.Equal("1", asked!.TypedConfirmation);
|
||||
Assert.False(queued.Task.IsCompleted);
|
||||
Assert.False(closed);
|
||||
|
||||
@@ -16,6 +16,7 @@ public sealed class JobNoticesTests
|
||||
[Case(JobKind.UploadCommit)]
|
||||
[Case(JobKind.Move)]
|
||||
[Case(JobKind.Adopt)]
|
||||
[Case(JobKind.Convert)]
|
||||
public void ALongOperationThatEndsSaysSo(JobKind kind)
|
||||
{
|
||||
Assert.Equal(JobNotice.Done, JobNotices.For(JobState.Running, Job(kind, JobState.Done)));
|
||||
|
||||
@@ -143,6 +143,46 @@ public sealed class LibraryPagerTests
|
||||
}
|
||||
|
||||
/// <summary>An in-memory library: cursors are offsets, optionally held back by a gate.</summary>
|
||||
[Test]
|
||||
public async Task APageInFlightIsWaitedForNotAskedForAgain()
|
||||
{
|
||||
// The Edit picker reads on until a sequence is listed; the list may ask for a page as it scrolls meanwhile.
|
||||
var source = new FakeSource(30);
|
||||
var pager = new LibraryPager(source.FetchAsync, pageSize: 10);
|
||||
await pager.ResetAsync(new LibraryFilter());
|
||||
Assert.True(pager.WhenLoadedAsync().IsCompleted, "nothing is loading");
|
||||
|
||||
source.Gate = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var scrolled = pager.LoadMoreAsync();
|
||||
var again = pager.LoadMoreAsync();
|
||||
Assert.True(again.IsCompletedSuccessfully && again.Result is null, "asking again gets nothing at once");
|
||||
var loaded = pager.WhenLoadedAsync();
|
||||
Assert.False(loaded.IsCompleted, "the page in flight is waited for");
|
||||
|
||||
source.Gate.SetResult();
|
||||
await loaded;
|
||||
Assert.True(scrolled.IsCompleted, "the wait ends with that page");
|
||||
Assert.Equal(10, Assert.NotNull(await scrolled).Items.Count);
|
||||
Assert.Equal(2, source.Queries.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task WaitingForAPageThatFailsDoesNotFail()
|
||||
{
|
||||
var source = new FakeSource(30);
|
||||
var pager = new LibraryPager(source.FetchAsync, pageSize: 10);
|
||||
await pager.ResetAsync(new LibraryFilter());
|
||||
source.Gate = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
source.Fail = true;
|
||||
var page = pager.LoadMoreAsync();
|
||||
var loaded = pager.WhenLoadedAsync();
|
||||
|
||||
source.Gate.SetResult();
|
||||
await loaded;
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => page);
|
||||
Assert.False(pager.HasMore, "a failing page stops the reading");
|
||||
}
|
||||
|
||||
private sealed class FakeSource(int count)
|
||||
{
|
||||
private readonly Guid _archive = Guid.CreateVersion7();
|
||||
|
||||
@@ -65,7 +65,10 @@ public sealed class MassActionsTests
|
||||
var remote = Remote("Sunrise over Superga");
|
||||
SelectedSequence[] mixed = [harbour, remote];
|
||||
|
||||
foreach (var action in new[] { MassAction.Analyse, MassAction.Proxies, MassAction.Verify, MassAction.Tag, MassAction.Rate, MassAction.Reorganize, MassAction.Delete })
|
||||
foreach (var action in new[]
|
||||
{
|
||||
MassAction.Analyse, MassAction.Proxies, MassAction.Verify, MassAction.Tag, MassAction.Rate, MassAction.Reorganize, MassAction.Convert, MassAction.Delete,
|
||||
})
|
||||
{
|
||||
Assert.Null(MassActions.Blocker(action, mixed, SignedIn), action.ToString());
|
||||
Assert.SequenceEqual([harbour], MassActions.Targets(action, mixed, SignedIn), action.ToString());
|
||||
@@ -93,6 +96,25 @@ public sealed class MassActionsTests
|
||||
Assert.Equal(Loc.Plural("Tooltips.Library.Mass.Reorganize", 2), MassActions.ToolTip(MassAction.Reorganize, 2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertStaysInsideOneArchive()
|
||||
{
|
||||
SelectedSequence[] two = [Only("Harbour sunset"), new(Local("Aurora", Guid.CreateVersion7()), null)];
|
||||
Assert.Equal(Loc.L("Library.Blocked.OneArchiveConvert"), MassActions.Blocker(MassAction.Convert, two, Offline), "one plan and one job per archive");
|
||||
Assert.Equal(Loc.L("Library.Blocked.OneArchive"), MassActions.Blocker(MassAction.Reorganize, two, Offline), "each says which action it is");
|
||||
|
||||
// A server card is left out: the photos converted are those on this PC.
|
||||
var remote = Remote("Sunrise over Superga");
|
||||
SelectedSequence[] withCard = [two[0], Only("Comet"), remote];
|
||||
Assert.Null(MassActions.Blocker(MassAction.Convert, withCard, SignedIn));
|
||||
Assert.SequenceEqual(withCard[..2], MassActions.Targets(MassAction.Convert, withCard, SignedIn));
|
||||
Assert.Equal(Loc.L("Library.Blocked.ServerOnly"), MassActions.Blocker(MassAction.Convert, [remote], SignedIn));
|
||||
Assert.Equal(Loc.L("Library.Blocked.NoIndex"), MassActions.Blocker(MassAction.Convert, [two[0]], new SelectionContext(HasEngine: false, IsSignedIn: false, default)),
|
||||
"the dry run and the job need the engine");
|
||||
Assert.Equal(Loc.L("Library.Blocked.NoSelection"), MassActions.Blocker(MassAction.Convert, [], SignedIn));
|
||||
Assert.Equal(Loc.Plural("Tooltips.Library.Mass.Convert", 2), MassActions.ToolTip(MassAction.Convert, 2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TransfersNeedASessionAndTheRight()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Archiving;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Windows;
|
||||
|
||||
/// <summary>
|
||||
/// The confirmation dialog's detail (BRIEF §12.1): one longer than its card (an emptying of the trash that names every entry
|
||||
/// that may hold the last copy of its photos) scrolls, and since it holds no control the focus could move to, the keyboard
|
||||
/// reaches it and scrolls it; one that fits is no tab stop.
|
||||
/// </summary>
|
||||
[WindowsOnly]
|
||||
[Serial]
|
||||
[Timeout(120_000)]
|
||||
public sealed class ConfirmDialogTests
|
||||
{
|
||||
[Test]
|
||||
public Task ALongDetailTakesTheKeyboardAndScrolls() => ScreenHost.RunAsync(() =>
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
var flagged = Enumerable.Range(1, 40).Select(i => Entry($"Converted {i}") with { ConversionDeleted = true }).ToList();
|
||||
var dialog = Open(Plan(flagged));
|
||||
try
|
||||
{
|
||||
var detail = (ScrollViewer)dialog.FindName("DetailScroll");
|
||||
Assert.True(detail.ScrollableHeight > 0, "the detail is longer than its card");
|
||||
Assert.True(detail.Focusable && detail.IsTabStop, "Tab reaches it");
|
||||
Assert.Equal(Loc.L("Tooltips.Archive.TrashEmptyPlan"), detail.ToolTip);
|
||||
Assert.Equal(Loc.L("Tooltips.Archive.TrashEmptyPlan"), System.Windows.Automation.AutomationProperties.GetName(detail));
|
||||
|
||||
Press(detail, Key.PageDown);
|
||||
dialog.UpdateLayout();
|
||||
var paged = detail.VerticalOffset;
|
||||
Assert.True(paged > 0, "Page Down scrolls it");
|
||||
Press(detail, Key.Down);
|
||||
dialog.UpdateLayout();
|
||||
Assert.True(detail.VerticalOffset > paged, "and so does the arrow");
|
||||
}
|
||||
finally
|
||||
{
|
||||
dialog.Close();
|
||||
}
|
||||
|
||||
var fits = Open(Plan([Entry("Etna")]));
|
||||
try
|
||||
{
|
||||
var detail = (ScrollViewer)fits.FindName("DetailScroll");
|
||||
Assert.Equal(0d, detail.ScrollableHeight);
|
||||
Assert.False(detail.Focusable || detail.IsTabStop, "a detail that fits is no stop");
|
||||
}
|
||||
finally
|
||||
{
|
||||
fits.Close();
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
private static TrashEntry Entry(string title) =>
|
||||
new(Guid.CreateVersion7(), FrameTrash.EntryPrefix + Guid.CreateVersion7().ToString("N"), Guid.CreateVersion7(), title, "2026/" + title, 3, 3, 90_000_000,
|
||||
new DateTimeOffset(2026, 10, 27, 9, 30, 0, TimeSpan.Zero), "alberto", TrashKind.Replaced);
|
||||
|
||||
private static TrashEmptyPlan Plan(IReadOnlyList<TrashEntry> entries) => new(Guid.CreateVersion7(), entries, entries.Sum(e => e.Bytes), "f1", []);
|
||||
|
||||
/// <summary>The confirmation of emptying <paramref name="plan"/>, shown off screen and laid out.</summary>
|
||||
private static ConfirmDialog Open(TrashEmptyPlan plan)
|
||||
{
|
||||
var dialog = new ConfirmDialog(Assert.NotNull(TrashEmptyPlans.Request(plan)))
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.Manual,
|
||||
Left = -20000,
|
||||
Top = -20000,
|
||||
ShowActivated = false,
|
||||
};
|
||||
dialog.Show();
|
||||
dialog.UpdateLayout();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private static void Press(UIElement target, Key key) =>
|
||||
target.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target)!, 0, key) { RoutedEvent = Keyboard.KeyDownEvent });
|
||||
}
|
||||
@@ -255,6 +255,50 @@ public sealed class ShellNotificationTests
|
||||
Assert.Null(failures.Message);
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Owner review 2, R7: a conversion that replaced the photos ends with Undo, which brings the originals back from the
|
||||
/// trash and never runs from the Windows notification; one into new sequences ends as any other job.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public Task AReplaceConversionThatEndsOffersUndo() => 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>() ?? []);
|
||||
|
||||
foreach (var mode in new[] { "Replace", "NewSequence" })
|
||||
{
|
||||
raised.Clear();
|
||||
var target = Guid.CreateVersion7();
|
||||
var convert = Job(JobKind.Convert, JobState.Running, target) with
|
||||
{
|
||||
ParametersJson = $$"""{"archiveId":"{{Guid.CreateVersion7()}}","target":"LinearDng","quality":95,"mode":"{{mode}}","sequences":[{"id":"{{target}}","framesVersion":1}],"fingerprint":"fp"}""",
|
||||
};
|
||||
jobs.OnJobChanged(convert);
|
||||
jobs.Flush();
|
||||
jobs.OnJobChanged(convert with { State = JobState.Done, Finished = DateTimeOffset.UtcNow });
|
||||
jobs.Flush();
|
||||
var toast = raised.Single();
|
||||
if (mode == "Replace")
|
||||
{
|
||||
Assert.Equal(Loc.Plural("Archive.Convert.Done", 1), toast.Title);
|
||||
Assert.Equal(Loc.L("Archive.Delete.Undo"), toast.ActionText);
|
||||
Assert.Equal(Loc.L("Tooltips.Archive.ConvertUndo"), toast.ActionToolTip);
|
||||
Assert.False(toast.RunsFromNotification, "a click on the Windows notification never undoes");
|
||||
Assert.False(toast.IsError);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal(Loc.L("Shell.Job.Done"), toast.Title);
|
||||
Assert.Equal(Loc.L("Jobs.Action.Open"), toast.ActionText);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task ToastsBecomeWindowsNotificationsOnlyWhileNobodySeesTheWindow() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user