- a card that leaves needs a new check; formatting re-lists the card and refuses one that changed since its check; files that are not photos are named in the format confirmation - an import never stays stuck in Running; Retry never resumes an older job - server imports list refused files and keep what was uploaded when stopped - the archive result matches each copy to its job's record and shows the job's own error per file - refreshing devices keeps typed titles and choices; titles lock while copying - three destination names, merge and split of sessions, camera profiles shared by the cards of a camera, photo counts and a new-card toast - disabled controls say why; keyboard focus follows the nickname field and Show plan (Esc closes it); label column fits longer languages - capture states for insertion, running, failed and a new card Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
171 lines
8.7 KiB
C#
171 lines
8.7 KiB
C#
using System.Globalization;
|
|
using Titano.App.Import;
|
|
using Titano.Core.Import;
|
|
using Titano.Core.Localization;
|
|
using Titano.Testing;
|
|
using static Titano.App.Tests.Import.ImportTestData;
|
|
|
|
namespace Titano.App.Tests.Import;
|
|
|
|
public sealed class ImportPlansTests
|
|
{
|
|
public ImportPlansTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
|
|
|
private 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)));
|
|
}
|
|
|
|
[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 MB · about 3 s", totals.Text);
|
|
Assert.Equal("1 duplicate", totals.DuplicatesText);
|
|
Assert.Equal("Import 5 photos", totals.ImportText);
|
|
Assert.Equal("80 MB 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 MB 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 MB", 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 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 MB) · 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 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 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);
|
|
}
|
|
}
|