Files
Chronos/tests/Chronos.App.Tests/Library/MassActionsTests.cs
T
Alby96 ad72501f11 feat(app): Reorganize existing sequences from the Archive manager, the Library and Settings
Owner review 2, R7 asks to rename and move sequences after import on the desktop too.
The desktop now uses the engine's Reorganize, the same plan and job as the web panel.

- One Reorganize… dialog replaces Rename… and Move… in the Archive manager and Move… in
  the Library. It has three templates: folders, file names and titles. Each one has a
  switch and is checked as it is typed. Folders and file names start on, filled from the
  archive's settings; titles start off as {title}. Renaming only titles is the Titles
  switch alone.
- The dry run stays in the dialog and follows the typing. Each sequence shows its folder,
  title and first file names before and after. Sequences carried along with a folder are
  marked, and photos that keep their names are listed with the reason. A summary counts
  the sequences that change, the files renamed and the names kept.
- Apply no longer changes the archive from the dialog. It queues the engine's move job
  with exactly the plan shown (its fingerprint), so the work can be paused, resumed after
  a restart and followed in Jobs. The job refuses the plan if the archive changed after
  the dry run.
- The Library's Reorganize… works on the selected sequences of one archive. The Archive
  screen reads the archive again when a move job ends.
- After Settings › Archive saves a new folder or file template to an archive that holds
  sequences, a toast offers Reorganize… for every sequence. Its templates are the ones
  changed since; a second change made while the toast is up adds to that toast instead of
  opening another.
- Strings in en and it. The keys of the old Rename and Move were removed and pruned from
  every translation, so the 36 other languages show the new keys as untranslated instead
  of keeping "Move".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 7bbf451f737a71b768dcd70a77b998daaef851f3)
2026-10-27 14:04:37 +01:00

159 lines
9.1 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.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 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);
}
}