Files
Chronos/tests/Chronos.App.Tests/Import/ImportPlansTests.cs
T
Alby96andClaude Opus 5.5 0075065884
CI / Build and test (push) Successful in 10m37s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 9s
Release / Build, test and publish (push) Successful in 16m19s
CI / PostgreSQL 16 integration (push) Successful in 10m19s
CI / PostgreSQL 17 integration (push) Successful in 11m27s
CI / Docker image (push) Successful in 57s
Release / Server image (push) Successful in 1m34s
feat: work board, no usage data, archive folder tree, deploy guide (owner review 4 + owner review 1 phase 6) (#62)
Owner review 4 and owner review 1 phase 6.

- Work board in Videos (desktop and admin panel): Published and Workspace lanes (#29).
- Anonymous usage counts removed: Chronos sends nothing about its use (#30).
- The archive's whole folder tree is created inside any archive root, on the server and the desktop (#31).
- Video cards start with the preset; sizes keep number and unit together (#28).
- Deploy guide docs/deploy (Docker, Unraid, desktop), BRIEF §24, original documentation in docs/reference/original (#22).

Closes #22 #28 #29 #30 #31

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-06 18:46:22 +01:00

253 lines
13 KiB
C#

using System.Globalization;
using Chronos.App.Import;
using Chronos.App.Infrastructure;
using Chronos.Core.Imaging;
using Chronos.Core.Import;
using Chronos.Core.Localization;
using Chronos.Testing;
using static Chronos.App.Tests.Import.ImportTestData;
namespace Chronos.App.Tests.Import;
public sealed class ImportPlansTests
{
public ImportPlansTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
internal static ImportPlan ThreeSessions(long? available = 200_000_000)
{
var duplicate = Guid.CreateVersion7();
return Plan(available, [new ImportProblem("DCIM/100CANON/IMG_0099.CR2", "Access denied")],
Session(1, "2026/2026-09-28 Canon EOS R5", Item(1, Start), Item(2, Start.AddSeconds(2)), Item(3, Start.AddSeconds(4)), Item(4, Start.AddSeconds(8))),
Session(2, "2026/2026-09-29 Canon EOS R5", Item(5, Start.AddDays(1)), Item(6, Start.AddDays(1).AddSeconds(120), action: ImportAction.SkipInArchive, existing: duplicate)),
Session(3, "2026/2026-09-30 Canon EOS R5", Item(7, Start.AddDays(2), action: ImportAction.SkipImported)));
}
/// <summary>A whole folder shot over eight days, as one sequence.</summary>
internal static ImportPlan OverEightDays() =>
Plan(null, null, Session(1, "2026/Construction", Item(1, Start), Item(2, Start.AddDays(8).AddMinutes(3)))) with { Grouping = ImportGrouping.WholeFolder };
[Test]
public void TotalsCountWhatIsCopiedSkippedAndDuplicated()
{
var totals = ImportPlans.Totals(ThreeSessions(), verify: true);
Assert.Equal(3, totals.Sessions);
Assert.Equal(7, totals.Photos);
Assert.Equal(5, totals.CopyCount);
Assert.Equal(5 * 24_000_000L, totals.CopyBytes);
Assert.Equal(1, totals.Duplicates);
Assert.Equal(1, totals.ImportedBefore);
Assert.Equal(1, totals.Problems);
Assert.Equal(80_000_000L, totals.FreeAfter);
Assert.True(totals.HasEnoughSpace);
Assert.Equal(TimeSpan.FromSeconds(3), totals.Estimate);
Assert.Equal("3 sessions · 7 photos · 120\u00A0MB · about 3 s", totals.Text);
Assert.Equal("3 sessions · 7 photos · 120\u00A0MB", totals.SummaryText);
Assert.Equal("1 duplicate", totals.DuplicatesText);
Assert.Equal("Import 5 photos", totals.ImportText);
Assert.Equal("80\u00A0MB free after import", totals.SpaceText);
}
[Test]
public void ASmallDestinationReportsTheMissingSpace()
{
var totals = ImportPlans.Totals(ThreeSessions(available: 100_000_000), verify: false);
Assert.False(totals.HasEnoughSpace);
Assert.Equal("20\u00A0MB missing", totals.SpaceText);
Assert.Equal(string.Empty, ImportPlans.Totals(ThreeSessions(available: null), verify: false).SpaceText);
Assert.Equal(TimeSpan.FromSeconds(2), ImportPlans.Totals(ThreeSessions(), verify: false).Estimate);
}
[Test]
public void TheDuplicateChoiceFlipsOnlyPhotosAlreadyInTheArchive()
{
var plan = ThreeSessions();
var again = ImportPlans.WithDuplicates(plan, DuplicatePolicy.ImportAgain);
Assert.Equal(6, again.CopyCount);
var duplicate = again.Sessions[1].Items[1];
Assert.Equal(ImportAction.Copy, duplicate.Action);
Assert.NotNull(duplicate.ExistingFrameId);
Assert.Equal(ImportAction.SkipImported, again.Sessions[2].Items[0].Action);
var skipped = ImportPlans.WithDuplicates(again, DuplicatePolicy.Skip);
Assert.Equal(ImportAction.SkipInArchive, skipped.Sessions[1].Items[1].Action);
Assert.Equal(plan.CopyCount, skipped.CopyCount);
Assert.Equal("Import again", ImportPlans.Details(again, ImportDestinationKind.Archive, true).Rows.Single(r => r.Source.EndsWith("0006.CR2", StringComparison.Ordinal)).ActionText);
}
[Test]
public void TypedTitlesNameTheirSessions()
{
var plan = ThreeSessions();
var titled = ImportPlans.WithTitles(plan, new Dictionary<string, string>
{
[plan.Sessions[0].SessionKey] = " Harbour sunset ",
[plan.Sessions[1].SessionKey] = " ",
["unknown"] = "ignored",
});
Assert.Equal("Harbour sunset", titled.Sessions[0].Title);
Assert.Null(titled.Sessions[1].Title);
Assert.Null(titled.Sessions[2].Title);
Assert.SequenceEqual(plan.Items.Select(i => i.FileName), titled.Items.Select(i => i.FileName));
}
[Test]
public void SessionRowsShowTimesIntervalsAndWhereTheyGo()
{
var plan = ThreeSessions();
var rows = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>(["2026/2026-09-29 Canon EOS R5"], StringComparer.OrdinalIgnoreCase));
Assert.Equal(3, rows.Count);
Assert.Equal("4 · 2 s", rows[0].FramesText);
Assert.Equal("2 · 2 min", rows[1].FramesText);
Assert.Equal("1", rows[2].FramesText);
Assert.True(rows[0].IsNew);
Assert.Equal("New · 2026/2026-09-28 Canon EOS R5", rows[0].TargetText);
Assert.False(rows[1].IsNew);
Assert.Equal("Adds to · 2026/2026-09-29 Canon EOS R5", rows[1].TargetText);
Assert.Equal("2026-09-28 Canon EOS R5", rows[0].DefaultTitle);
Assert.Equal("Canon EOS R5", rows[0].CameraText);
Assert.Equal("96\u00A0MB", rows[0].SizeText);
Assert.Contains("6:02", rows[0].TimeText);
Assert.Equal("Server", ImportPlans.Sessions(plan, ImportDestinationKind.Server, new HashSet<string>())[0].TargetText);
}
[Test]
public void ASessionThatEndsOnAnotherDayShowsBothDates()
{
var plan = OverEightDays();
var end = Start.AddDays(8).AddMinutes(3);
var time = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText;
Assert.Equal($"{Formatting.Date(Start)} {Start.ToString("t", Loc.Culture)} → {Formatting.Date(end)} {end.ToString("t", Loc.Culture)}", time);
Assert.Equal(Loc.L("Import.Details.Session", 1, time), ImportPlans.Details(plan, ImportDestinationKind.Archive, verify: true).Rows[0].SourceText,
"the Show plan heading reads the same");
var sameDay = ImportPlans.Sessions(ThreeSessions(), ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText;
Assert.Equal($"{Formatting.Date(Start)} · {Start.ToString("t", Loc.Culture)} → {Start.AddSeconds(8).ToString("t", Loc.Culture)}", sameDay,
"a session within one day shows its date once");
}
[Test]
public void ShowPlanListsEveryFileItsDestinationAndTheConflicts()
{
var plan = ThreeSessions(available: 100_000_000);
var details = ImportPlans.Details(plan, ImportDestinationKind.Archive, verify: true);
Assert.Equal(plan.FileCount + plan.Sessions.Count, details.Rows.Count);
Assert.Equal(3, details.Rows.Count(r => r.Kind == PlanRowKind.Session));
var first = details.Rows[1];
Assert.Equal("DCIM/100CANON/IMG_0001.CR2", first.Source);
Assert.Equal("2026/2026-09-28 Canon EOS R5/originals/" + plan.Sessions[0].Items[0].FileName, first.Destination);
Assert.Equal("Copy", first.ActionText);
Assert.False(first.IsSkipped);
Assert.True(details.Rows.Single(r => r.Source.EndsWith("0007.CR2", StringComparison.Ordinal)).IsSkipped);
Assert.Equal(3, details.Conflicts.Count);
Assert.Contains("IMG_0099.CR2", details.Conflicts[0]);
Assert.Equal("7 files · copy 5 (120\u00A0MB) · 1 imported before · 1 duplicate", details.TotalsText);
var folder = ImportPlans.Details(plan, ImportDestinationKind.Folder, verify: true);
Assert.Equal("2026/2026-09-28 Canon EOS R5/" + plan.Sessions[0].Items[0].FileName, folder.Rows[1].Destination);
}
[Test]
public void ShowPlanShowsNamesUnderTheirSessionFolder()
{
var plan = ThreeSessions();
var details = ImportPlans.Details(plan, ImportDestinationKind.Archive, verify: true);
var session = details.Rows[0];
Assert.True(session.SourceText.StartsWith("Session 1 · ", StringComparison.Ordinal), session.SourceText);
Assert.Equal("2026/2026-09-28 Canon EOS R5/originals", session.DestinationText);
var file = details.Rows[2];
Assert.Equal("IMG_0002.CR2", file.SourceText);
Assert.Equal(plan.Sessions[0].Items[1].FileName, file.DestinationText);
Assert.Equal("DCIM/100CANON/IMG_0002.CR2", file.Source, "the full path stays for the tooltip");
Assert.Equal("Split at IMG_0002.CR2", file.SplitName);
}
[Test]
public void TheNamePreviewShowsTheFirstThreeCopiedFiles()
{
var plan = ThreeSessions();
var names = ImportPlans.FirstDestinations(plan, ImportDestinationKind.Archive);
Assert.Equal(3, names.Count);
Assert.Equal("2026/2026-09-28 Canon EOS R5/" + plan.Sessions[0].Items[0].FileName, names[0]);
Assert.Equal("→ " + names[0] + " · " + plan.Sessions[0].Items[1].FileName + " · " + plan.Sessions[0].Items[2].FileName, ImportPlans.NamePreview(names));
Assert.Equal(plan.Sessions[0].Items[0].FileName, ImportPlans.FirstDestinations(plan, ImportDestinationKind.Server)[0]);
// A name in another folder keeps its folder.
var across = ImportPlans.FirstDestinations(plan, ImportDestinationKind.Archive, 5);
Assert.Equal(5, across.Count);
Assert.True(ImportPlans.NamePreview(across).EndsWith(" · " + across[4], StringComparison.Ordinal), "the third session's folder is shown");
var nothing = ImportPlans.WithDuplicates(Plan(null, null, Session(1, "x", Item(1, Start, action: ImportAction.SkipImported))), DuplicatePolicy.Skip);
Assert.Empty(ImportPlans.FirstDestinations(nothing, ImportDestinationKind.Archive));
Assert.Equal(string.Empty, ImportPlans.NamePreview([]));
}
[Test]
public void ASessionMergesOnlyIntoTheEarlierSessionOfTheSameCameraAndFormat()
{
var plan = ThreeSessions();
var rows = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>());
Assert.Null(rows[0].MergesInto);
Assert.Equal(1, rows[1].MergesInto);
Assert.Equal(2, rows[2].MergesInto);
Assert.Equal("DCIM/100CANON/IMG_0005.CR2", rows[1].FirstPath);
var otherBody = plan with { Sessions = [plan.Sessions[0], plan.Sessions[1] with { CameraSerial = "9999" }, plan.Sessions[2]] };
var split = ImportPlans.Sessions(otherBody, ImportDestinationKind.Archive, new HashSet<string>());
Assert.Null(split[1].MergesInto, "another camera body never merges");
Assert.Equal(1, split[2].MergesInto, "the earlier session of the same body, skipping the other camera");
}
[Test]
public void AWholeFolderRowShowsItsFormatAndCamerasWithTheFolderNameAsDefaultTitle()
{
var jpeg = Session(1, "2026/2026-09-28 Canon EOS R5", Item(1, Start), Item(2, Start.AddHours(5))) with
{
SessionKey = "folder-jpeg",
Format = ImageFileFormat.Jpeg,
Cameras = 2,
Title = "Etna",
DefaultTitle = "Etna",
};
var raw = Session(2, "2026/2026-09-28 Canon EOS R5 (2)", Item(3, Start), Item(4, Start.AddHours(5))) with
{
SessionKey = "folder-raw",
Title = "Etna",
DefaultTitle = "Etna",
};
var plan = Plan(null, null, jpeg, raw) with { Grouping = ImportGrouping.WholeFolder };
var rows = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>());
Assert.Equal("2 cameras · JPEG", rows[0].CameraText);
Assert.Equal("Canon EOS R5 · CR2", rows[1].CameraText);
Assert.Null(rows[0].Title, "the folder's name is the placeholder, not typed text");
Assert.Equal("Etna", rows[0].DefaultTitle);
Assert.Null(rows[1].MergesInto, "another format never merges");
var bySessions = ImportPlans.Sessions(plan with { Grouping = ImportGrouping.Sessions }, ImportDestinationKind.Archive, new HashSet<string>());
Assert.Equal("Canon EOS R5", bySessions[1].CameraText);
var titled = ImportPlans.WithTitles(plan, new Dictionary<string, string> { ["folder-jpeg"] = "Etna at night" });
Assert.Equal("Etna at night", titled.Sessions[0].Title);
Assert.Equal("Etna", titled.Sessions[1].Title, "a sequence without a typed title keeps the folder's name");
Assert.Equal("Etna at night", ImportPlans.Sessions(titled, ImportDestinationKind.Archive, new HashSet<string>())[0].Title);
}
[Test]
public void AWholeFolderPartMergesBackIntoThePartBeforeItOfTheSameFormatWhateverItsCamera()
{
var first = Session(1, "2026/Etna", Item(1, Start));
var second = Session(2, "2026/Etna (2)", Item(2, Start.AddHours(1))) with { CameraMake = "Nikon", CameraModel = "NIKON Z 8" };
var plan = Plan(null, null, first, second) with { Grouping = ImportGrouping.WholeFolder };
Assert.Equal(1, ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[1].MergesInto);
Assert.Null(ImportPlans.Sessions(plan with { Grouping = ImportGrouping.Sessions }, ImportDestinationKind.Archive, new HashSet<string>())[1].MergesInto,
"sessions of another camera never merge");
}
[Test]
public void ShowPlanOffersASplitOnEveryPhotoButTheFirstOfItsSession()
{
var details = ImportPlans.Details(ThreeSessions(), ImportDestinationKind.Archive, verify: true);
Assert.False(details.Rows[0].CanSplit, "a session heading");
Assert.False(details.Rows[1].CanSplit, "the first photo already starts the session");
Assert.True(details.Rows[2].CanSplit);
}
}