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>
181 lines
11 KiB
C#
181 lines
11 KiB
C#
using Chronos.App.Library;
|
|
using Chronos.App.Server;
|
|
using Chronos.Core.Localization;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Data.Sync;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.App.Tests.Library;
|
|
|
|
/// <summary>Which selected sequences each button of the mass actions bar works on, and why a button is off (BRIEF §12.2, DESIGN §4).</summary>
|
|
public sealed class MassActionsTests
|
|
{
|
|
private const string Server = "https://nas.local:8443";
|
|
private static readonly SyncRights Editor = SyncRights.Of((long)RolePermissions.Default(UserRole.Editor));
|
|
private static readonly SyncRights Viewer = SyncRights.Of((long)RolePermissions.Default(UserRole.Viewer));
|
|
private static readonly Guid MainArchive = Guid.CreateVersion7();
|
|
|
|
private static readonly SelectionContext Offline = new(HasEngine: true, IsSignedIn: false, default);
|
|
private static readonly SelectionContext SignedIn = new(HasEngine: true, IsSignedIn: true, Editor);
|
|
|
|
private static Sequence Local(string title, Guid? archive = null) => new()
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
ArchiveId = archive ?? MainArchive,
|
|
Title = title,
|
|
Folder = "2026/" + title,
|
|
FrameCount = 120,
|
|
};
|
|
|
|
private static SyncLink Link(Sequence sequence) => new() { Server = Server, RemoteId = Guid.CreateVersion7(), Title = sequence.DisplayTitle };
|
|
|
|
private static SelectedSequence Remote(string title)
|
|
{
|
|
var link = new SyncLink { Server = Server, RemoteId = Guid.CreateVersion7(), Title = title, FrameCount = 300 };
|
|
var card = RemoteCards.FromLink(link);
|
|
return new SelectedSequence(card, new SyncEntry(null, link, SyncStatus.RemoteOnly));
|
|
}
|
|
|
|
private static SelectedSequence Linked(string title, SyncStatus status, Func<SyncLink, SyncLink>? change = null)
|
|
{
|
|
var local = Local(title);
|
|
var link = Link(local);
|
|
return new SelectedSequence(local, new SyncEntry(local, change?.Invoke(link) ?? link, status));
|
|
}
|
|
|
|
private static SelectedSequence Only(string title) => new(Local(title), null);
|
|
|
|
[Test]
|
|
public void NothingRunsWithoutASelectionOrAnIndexButTheListExport()
|
|
{
|
|
foreach (var action in Enum.GetValues<MassAction>())
|
|
Assert.Equal(Loc.L("Library.Blocked.NoSelection"), MassActions.Blocker(action, [], SignedIn));
|
|
|
|
SelectedSequence[] one = [Only("Harbour sunset")];
|
|
var noIndex = new SelectionContext(HasEngine: false, IsSignedIn: false, default);
|
|
Assert.Equal(Loc.L("Library.Blocked.NoIndex"), MassActions.Blocker(MassAction.Analyse, one, noIndex));
|
|
Assert.Equal(Loc.L("Library.Blocked.NoIndex"), MassActions.Blocker(MassAction.Delete, one, noIndex));
|
|
Assert.Null(MassActions.Blocker(MassAction.ExportList, one, noIndex), "a CSV needs only the rows on screen");
|
|
}
|
|
|
|
[Test]
|
|
public void ArchiveActionsWorkOnTheSequencesOfThisPc()
|
|
{
|
|
var harbour = Only("Harbour sunset");
|
|
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.Convert, MassAction.Delete,
|
|
})
|
|
{
|
|
Assert.Null(MassActions.Blocker(action, mixed, SignedIn), action.ToString());
|
|
Assert.SequenceEqual([harbour], MassActions.Targets(action, mixed, SignedIn), action.ToString());
|
|
Assert.Equal(Loc.L("Library.Blocked.ServerOnly"), MassActions.Blocker(action, [remote], SignedIn));
|
|
}
|
|
Assert.SequenceEqual(mixed, MassActions.Targets(MassAction.ExportList, mixed, SignedIn), "the CSV lists remote cards too");
|
|
Assert.Equal(Loc.Plural("Tooltips.Library.Mass.Delete", 1), MassActions.ToolTip(MassAction.Delete, 1));
|
|
}
|
|
|
|
[Test]
|
|
public void ReorganizeStaysInsideOneArchive()
|
|
{
|
|
SelectedSequence[] two = [Only("Harbour sunset"), new(Local("Aurora", Guid.CreateVersion7()), null)];
|
|
Assert.Equal(Loc.L("Library.Blocked.OneArchive"), MassActions.Blocker(MassAction.Reorganize, two, Offline));
|
|
Assert.Null(MassActions.Blocker(MassAction.Delete, two, Offline), "the trash of each archive takes its own sequences");
|
|
|
|
// A server card in the selection is left out: the archive of the sequences here is still one.
|
|
var remote = Remote("Sunrise over Superga");
|
|
SelectedSequence[] withCard = [two[0], Only("Comet"), remote];
|
|
Assert.Null(MassActions.Blocker(MassAction.Reorganize, withCard, SignedIn));
|
|
Assert.SequenceEqual(withCard[..2], MassActions.Targets(MassAction.Reorganize, withCard, SignedIn));
|
|
Assert.Equal(Loc.L("Library.Blocked.ServerOnly"), MassActions.Blocker(MassAction.Reorganize, [remote], SignedIn));
|
|
Assert.Equal(Loc.L("Library.Blocked.NoIndex"), MassActions.Blocker(MassAction.Reorganize, [two[0]], new SelectionContext(HasEngine: false, IsSignedIn: false, default)),
|
|
"the dry run and the job need the engine");
|
|
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()
|
|
{
|
|
SelectedSequence[] one = [Only("Harbour sunset")];
|
|
Assert.Equal(Loc.L("Library.Blocked.NotConnected"), MassActions.Blocker(MassAction.Upload, one, Offline));
|
|
Assert.Equal(Loc.L("Library.Blocked.NotConnected"), MassActions.Blocker(MassAction.Download, one, Offline));
|
|
Assert.Equal(Loc.L("Library.Blocked.NoUploadRight"), MassActions.Blocker(MassAction.Upload, one, SignedIn with { Rights = Viewer }));
|
|
Assert.Equal(Loc.L("Library.Blocked.NoDownloadRight"), MassActions.Blocker(MassAction.Download, one, SignedIn with { Rights = Viewer }));
|
|
Assert.Null(MassActions.Blocker(MassAction.Upload, one, SignedIn), "a sequence only here uploads before the table compares it");
|
|
Assert.Equal(Loc.L("Library.Blocked.NothingToDownload"), MassActions.Blocker(MassAction.Download, one, SignedIn));
|
|
}
|
|
|
|
[Test]
|
|
public void EachTransferTakesWhatItsSyncRowOffers()
|
|
{
|
|
var only = Only("Harbour sunset");
|
|
var ahead = Linked("Comet over the ridge", SyncStatus.LocalAhead, l => l with { MissingRemote = 4 });
|
|
var renders = Linked("Star trails", SyncStatus.InSync, l => l with { ExportsToSend = 1, ExportsToGet = 2 });
|
|
var same = Linked("Aurora, Tromsø", SyncStatus.InSync);
|
|
var behind = Linked("Fog lifting", SyncStatus.ServerAhead, l => l with { MissingLocal = 12 });
|
|
var remote = Remote("Sunrise over Superga");
|
|
SelectedSequence[] all = [only, ahead, renders, same, behind, remote];
|
|
|
|
Assert.SequenceEqual([only, ahead, renders], MassActions.Targets(MassAction.Upload, all, SignedIn));
|
|
Assert.Equal(SyncAction.Upload, MassActions.UploadStep(only, Editor));
|
|
Assert.Equal(SyncAction.Upload, MassActions.UploadStep(ahead, Editor));
|
|
Assert.Equal(SyncAction.SendExports, MassActions.UploadStep(renders, Editor));
|
|
Assert.Null(MassActions.UploadStep(same, Editor));
|
|
Assert.Null(MassActions.UploadStep(remote, Editor), "a remote card has nothing here to send");
|
|
|
|
Assert.SequenceEqual([renders, behind, remote], MassActions.Targets(MassAction.Download, all, SignedIn));
|
|
Assert.Equal(SyncAction.GetExports, MassActions.DownloadStep(renders, Editor));
|
|
Assert.Equal(SyncAction.DownloadOriginals, MassActions.DownloadStep(behind, Editor));
|
|
Assert.Equal(SyncAction.DownloadOriginals, MassActions.DownloadStep(remote, Editor));
|
|
Assert.Null(MassActions.DownloadStep(only, Editor));
|
|
|
|
Assert.Equal(Loc.L("Library.Blocked.NothingToUpload"), MassActions.Blocker(MassAction.Upload, [same, remote], SignedIn));
|
|
}
|
|
|
|
[Test]
|
|
public void TheCardsSyncDoesTheFirstThingItsRowOffers()
|
|
{
|
|
Assert.Null(MassActions.QuickSync(Only("Harbour sunset"), Offline, out var why));
|
|
Assert.Equal(Loc.L("Library.Blocked.NotConnected"), why);
|
|
|
|
Assert.Equal(SyncAction.Upload, MassActions.QuickSync(Only("Harbour sunset"), SignedIn, out why));
|
|
Assert.Null(why);
|
|
Assert.Null(MassActions.QuickSync(Only("Harbour sunset"), SignedIn with { Rights = Viewer }, out why));
|
|
Assert.Equal(Loc.L("Library.Blocked.NoUploadRight"), why);
|
|
|
|
Assert.Equal(SyncAction.DownloadOriginals, MassActions.QuickSync(Remote("Sunrise over Superga"), SignedIn, out _));
|
|
Assert.Equal(SyncAction.SyncSettings, MassActions.QuickSync(Linked("Holy grail", SyncStatus.ServerAhead), SignedIn, out _));
|
|
Assert.Equal(SyncAction.KeepMine, MassActions.QuickSync(Linked("Holy grail", SyncStatus.Conflict), SignedIn, out _), "a conflict goes to the Server screen");
|
|
|
|
Assert.Null(MassActions.QuickSync(Linked("Aurora, Tromsø", SyncStatus.InSync), SignedIn, out why));
|
|
Assert.Equal(Loc.L("Library.Blocked.InSync"), why);
|
|
|
|
var moving = Linked("Comet over the ridge", SyncStatus.LocalAhead);
|
|
var transferring = moving with { Sync = moving.Sync! with { Transfer = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.UploadCommit, State = JobState.Running } } };
|
|
Assert.Null(MassActions.QuickSync(transferring, SignedIn, out why));
|
|
Assert.Equal(Loc.L("Library.Blocked.Transferring"), why);
|
|
}
|
|
}
|