Files
Chronos/tests/Titano.App.Tests/Library/DeletePlansTests.cs
T
Claude 007c5b281d fix(app): the view-name dialog and remote cards follow the reviewed dialog kit
Save view and Rename view use the growing label column and show a failed
save as one sentence in the dialog. The Library reads a remote card's
proxy cache off the UI thread, sets a sequence's folder left to right and
centres the Rating chevron. A sequence back in the index refuses a
restore with SequenceInLibraryException, tested with the one-sentence
causes of a refused delete or restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-06 20:42:36 +00:00

93 lines
5.1 KiB
C#

using System.Globalization;
using System.IO;
using Titano.App.Archiving;
using Titano.App.Infrastructure;
using Titano.Core.Archiving;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Data.Archiving;
using Titano.Testing;
namespace Titano.App.Tests.Library;
/// <summary>The confirmation of Delete in the Library and the Archive manager: the engine's dry run behind a typed confirmation (DESIGN §4).</summary>
public sealed class DeletePlansTests
{
private static Sequence Sequence(string title, int frames) => new()
{
Id = Guid.CreateVersion7(),
ArchiveId = Guid.CreateVersion7(),
Title = title,
Folder = "2026/" + title,
FrameCount = frames,
};
private static DeleteStep Step(string title, int frames, int files, long bytes) =>
new(Sequence(title, frames), $".titano/trash/{Guid.CreateVersion7():N}", files, bytes);
[Test]
public void ThePlanAsksToTypeHowManySequencesMove()
{
var plan = new DeletePlan(
[Step("Harbour sunset", 3_600, 3_640, 96_200_000_000), Step("Comet over the ridge", 1_005, 1_020, 21_000_000_000)],
[new BlockedDelete(Sequence("Fog lifting", 980), DeleteBlock.Busy)]);
var request = Assert.NotNull(DeletePlans.Request(plan));
Assert.True(request.IsDestructive, "the action is outlined, never primary");
Assert.Equal("2", request.TypedConfirmation);
Assert.Equal(Loc.L("Archive.Delete.Type", "2"), request.TypedPrompt);
Assert.Equal(Loc.Plural("Archive.Delete.Heading", 2), request.Heading);
Assert.Equal(Loc.L("Archive.Delete.Message", Loc.Plural("Shell.Status.Photos", 4_605), Loc.Plural("Archive.Delete.Files", 4_660),
Formatting.Bytes(117_200_000_000)), request.Message);
var lines = request.Detail!.Split(Environment.NewLine);
Assert.Equal(3, lines.Length);
Assert.Equal(Loc.L("Archive.Delete.Line", "Harbour sunset", Loc.Plural("Shell.Status.Photos", 3_600), Formatting.Bytes(96_200_000_000)), lines[0]);
Assert.Equal(Loc.L("Archive.Delete.Blocked", "Fog lifting", Loc.L("Archive.Delete.Reason.Busy")), lines[2]);
Assert.Equal(Loc.L("Archive.Delete.Keep"), request.SafeText);
Assert.Equal(Loc.Plural("Tooltips.Archive.DeleteAction", 2), request.ActionToolTip);
}
[Test]
public void LongPlansAreCountedAndEmptyOnesAskNothing()
{
var many = Enumerable.Range(1, DeletePlans.ListedLines + 3).Select(i => Step("Sequence " + i.ToString(CultureInfo.InvariantCulture), 10, 10, 1_000)).ToList();
var request = Assert.NotNull(DeletePlans.Request(new DeletePlan(many, [])));
var lines = request.Detail!.Split(Environment.NewLine);
Assert.Equal(DeletePlans.ListedLines + 1, lines.Length);
Assert.Equal(Loc.Plural("Archive.Delete.More", 3), lines[^1]);
Assert.Equal((DeletePlans.ListedLines + 3).ToString(CultureInfo.InvariantCulture), request.TypedConfirmation);
var blocked = new DeletePlan([], [new BlockedDelete(Sequence("Root", 2), DeleteBlock.ArchiveRoot)]);
Assert.Null(DeletePlans.Request(blocked), "nothing can move: no confirmation");
Assert.SequenceEqual([Loc.L("Archive.Delete.Blocked", "Root", Loc.L("Archive.Delete.Reason.ArchiveRoot"))], DeletePlans.Blocked(blocked, 8));
foreach (var reason in Enum.GetValues<DeleteBlock>())
Assert.NotEqual("Archive.Delete.Reason." + reason, Loc.L("Archive.Delete.Reason." + reason), "every reason has words");
}
[Test]
public void TheConfirmationStaysShortEnoughForASmallScreen()
{
var steps = Enumerable.Range(1, 20).Select(i => Step("Sequence " + i.ToString(CultureInfo.InvariantCulture), 10, 10, 1_000)).ToList();
var blocked = Enumerable.Range(1, 9).Select(i => new BlockedDelete(Sequence("Busy " + i.ToString(CultureInfo.InvariantCulture), 5), DeleteBlock.Busy)).ToList();
var request = Assert.NotNull(DeletePlans.Request(new DeletePlan(steps, blocked)));
var lines = request.Detail!.Split(Environment.NewLine);
Assert.Equal(DeletePlans.ListedLines + 1 + DeletePlans.BlockedLines + 1, lines.Length, "named lines plus one count for each part");
Assert.Equal(Loc.Plural("Archive.Delete.More", 14), lines[DeletePlans.ListedLines]);
Assert.Equal(Loc.Plural("Archive.Delete.More", 6), lines[^1]);
Assert.False(request.IsDetailMonospaced, "names read in the UI font, not the fingerprint font");
}
[Test]
public void ARefusedDeleteOrRestoreSaysWhyInOneSentence()
{
Assert.Equal(Loc.L("Archive.Error.StalePlan"), ArchiveFailures.Cause(new StaleDeletePlanException(Guid.NewGuid())));
Assert.Equal(Loc.L("Archive.Error.InLibrary", "Harbour sunset"), ArchiveFailures.Cause(new SequenceInLibraryException(Guid.NewGuid(), "Harbour sunset")));
Assert.Equal(Loc.L("Archive.Error.NewerFormat", "sequence.json", 9), ArchiveFailures.Cause(new NewerFormatException("/a/2026/x/.titano/sequence.json", 9)));
Assert.Equal(Loc.L("Archive.Failed.Files"), ArchiveFailures.Cause(new DirectoryNotFoundException("/a/.titano/trash/0123 is not in the trash")),
"the engine's own words stay in the log");
}
}