Files
Chronos/tests/Chronos.App.Tests/Server/CopyScreenSmokeTests.cs
T
Alby96andClaude Opus 5.5 b34b6b6fe0 fix(copies): close the owner review 6 verification findings
A merge could still trash photos it never verified, resume against a
pair the user had answered meanwhile, and take different unhashed
photos for copies; the dialog and the lists worded several facts
wrongly or lost them on refresh.

- Merge: a retry resumes only while the pair is still the job's;
  Verify requires the other archive online and its folder in place,
  stops on an unreadable photo, files a differing unhashed photo as a
  second version and must cover every frame before Trash; the plan
  hashes unmatched unhashed photos first, lists "Deleted in the other"
  and names the relinked servers; second versions stay discoverable
  (CopySides.VersionsAsync).
- Integrate: a retry after a failure before the journal runs again.
- Sync: a sequence back after a 404 stays Linked while its link holds;
  a local cull no longer asks for attention.
- Block lines of both planners name the right sequence, archive,
  server and space through one formatter.
- Compare dialog: one Details row per setting with worded values,
  Projects headings, Choose focuses the kept-sequence radios, the
  photo selection reaches rows outside the viewport, the Replace
  confirmation lists the losers per side, plan lines read as queued.
- Matches and Library: counts first and grouped, integrating shown as
  a share, local matches name the other archive, the Library keeps its
  match and "deleted on server" statuses across a refresh.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 15:02:39 +01:00

330 lines
16 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Windows.Controls;
using Chronos.App.Infrastructure;
using Chronos.App.Library;
using Chronos.App.Sections;
using Chronos.App.Server;
using Chronos.App.Server.Copies;
using Chronos.App.Settings;
using Chronos.App.Shell;
using Chronos.App.Tests.Windows;
using Chronos.Core.Localization;
using Chronos.Data.Copies;
using Chronos.Data.Sync;
using Chronos.Testing;
using Chronos.Ui.Controls;
namespace Chronos.App.Tests.Server;
/// <summary>
/// Server › Matches on the capture sample pairs (owner review 6, #73): the list and its chip, the Compare dialog in the
/// window, its plan and blocks, the confirmations, the Library's match cards and the Settings rows.
/// </summary>
[WindowsOnly]
[Serial]
[Timeout(300_000)]
public sealed class CopyScreenSmokeTests
{
[Test]
public Task TheMatchesListOrdersThePairsAndEveryActionSaysWhatItDoes() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var table = shell.Server.Sync;
var list = table.Copies;
await CopyScenes.ShowAsync(shell, "server-copies");
Assert.True(table.IsMatches);
Assert.True(table.ShowCopyList, "the Matches list replaces the sync table");
Assert.GreaterOrEqual(list.Count, 5);
Assert.Equal(list.Count, table.Chips.Single(c => c.Filter == SyncFilter.FoundCopies).Count);
Assert.True(list.AttentionCount > 0);
// Pairs that ask for a choice come first.
Assert.True(list.Rows[0].IsConflict);
Assert.True(list.Rows.SkipWhile(r => r.IsConflict).All(r => !r.IsConflict), "attention first, then the rest");
foreach (var row in list.Rows)
{
Assert.False(string.IsNullOrWhiteSpace(row.StateToolTip), $"{row.Title}: the state has a tooltip");
foreach (var action in row.Actions)
{
Assert.False(string.IsNullOrWhiteSpace(action.ToolTip), $"{row.Title}: {action.Text} has a tooltip");
Assert.LessOrEqual(action.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length, 3, $"\"{action.Text}\" is at most three words");
}
}
var lighthouse = list.Rows.Single(r => r.Title == CopyScenes.Lighthouse);
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Integrate, CopyAction.KeepApart], lighthouse.Actions.Select(a => a.Action));
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Merge, CopyAction.KeepApart],
list.Rows.Single(r => r.Title == CopyScenes.Alps).Actions.Select(a => a.Action));
await app.ExpectAsync<ServerView>("server-copies");
// The search narrows the pairs, by either title.
table.SearchText = "Alps";
Assert.Count(1, list.Rows);
table.SearchText = string.Empty;
// The sync table marks the sequence of an unanswered pair and offers Compare… first.
table.ShowFilter(SyncFilter.All);
var marked = table.Rows.First(r => r.Title == CopyScenes.Lighthouse);
Assert.Equal(Loc.L("Server.Sync.State.CopyFound"), marked.StateText);
Assert.Equal(SyncAction.Compare, marked.Actions[0].Action);
CopyScenes.Reset(shell);
});
[Test]
public Task TheCompareDialogWaitsForTheDetailsAndConfirmsWhatItReplaces() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var server = shell.Server;
var list = server.Sync.Copies;
await CopyScenes.ShowAsync(shell, "server-copies");
// Integrate… opens on the details while one waits for a choice.
var pair = list.Pairs.Single(p => p.Here.Title == CopyScenes.Lighthouse);
var dialog = Assert.NotNull(list.Open(pair, CopyDialogPart.Plan, integrate: true));
await dialog.LoadAsync();
Assert.True(server.IsDialogOpen);
Assert.False(server.IsContentEnabled, "the screen behind the dialog takes no input");
Assert.Equal(CopyDialogPart.Details, dialog.Part);
Assert.Equal(3, dialog.Unchosen);
await app.ExpectAsync<ServerView>("server-copies-details");
// The footer: one primary action, Cancel answers Esc; both say what they do.
var cancel = app.FindAll<Button>().Single(b => b.IsVisible && b.IsCancel);
Assert.Equal(Loc.L("Tooltips.Server.Copies.Cancel"), cancel.ToolTip);
Assert.Contains(app.FindAll<Button>(), b => b.IsVisible && b.Content as string == dialog.ApplyText && b.ToolTip is not null);
// The plan is blocked until every detail is chosen; the block line offers Choose.
dialog.Part = CopyDialogPart.Plan;
await dialog.PlanNowAsync();
var block = Assert.Contains(dialog.Blocks, b => b.Block == CopyBlock.DetailsUnchosen);
Assert.True(block.HasChoose);
Assert.False(dialog.ApplyCommand.CanExecute(null));
Assert.Equal(block.Text, dialog.ApplyToolTip);
dialog.AllHereCommand.Execute(null);
Assert.Equal(0, dialog.Unchosen);
await dialog.PlanNowAsync();
Assert.False(dialog.Blocks.Any(b => b.Block == CopyBlock.DetailsUnchosen), "every detail chosen");
Assert.True(dialog.ApplyCommand.CanExecute(null));
Assert.NotEmpty(dialog.HereLines);
await app.ExpectAsync<ServerView>("server-copies-plan");
// This PC's version wins: the server's versions go to its trash, so the confirmation is destructive.
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ThisPcWins);
await dialog.PlanNowAsync();
var replace = CopyDialogViewModel.ReplaceRequest(Assert.NotNull(dialog.Plan));
Assert.True(replace.IsDestructive);
Assert.Equal(Loc.L("Server.Copies.Confirm.Replace.Title"), replace.Heading);
// Cancel closes the dialog and gives the screen back.
dialog.CloseCommand.Execute(null);
Assert.False(server.IsDialogOpen);
Assert.True(server.IsContentEnabled);
// A local pair merges into the kept copy, preselected; the confirmation asks for the dropped photo count.
var merge = Assert.NotNull(await CopyScenes.ShowAsync(shell, "server-copies-merge"));
Assert.True(merge.IsMerge);
Assert.Count(2, merge.KeepOptions);
Assert.Count(1, merge.KeepOptions.Where(o => o.IsChecked));
merge.AllHereCommand.Execute(null);
await merge.PlanNowAsync();
var plan = Assert.NotNull(merge.MergePlan);
var request = merge.MergeRequest(plan);
Assert.True(request.IsDestructive);
var dropped = list.Pairs.Single(p => p.Here.Title == CopyScenes.Alps) is var alps && plan.KeepId == alps.Copy.LocalId ? alps.There : alps.Here;
Assert.Equal(dropped.Photos.ToString(Loc.Culture), request.TypedConfirmation);
await app.ExpectAsync<ServerView>("server-copies-merge");
// Choose on "choose the sequence to keep" takes the keyboard to the first Kept radio of the Plan part.
merge.Part = CopyDialogPart.Plan;
var view = app.FindAll<ServerView>().First(v => v.IsVisible);
for (var i = 0; i < 80 && ServerView.FirstKeepOption(view) is null; i++)
{
view.UpdateLayout();
await Task.Delay(25);
}
Assert.NotNull(ServerView.FirstKeepOption(view), "the Kept sequence radios are on the Plan part");
CopyScenes.Reset(shell);
Assert.False(server.IsDialogOpen);
});
[Test]
public Task AMergeKeepingThePairsOtherCopyShowsItFirstAndKeepsItsValues() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var merge = Assert.NotNull(await CopyScenes.ShowAsync(shell, "server-copies-merge"));
Assert.Equal(Loc.L("Server.Copies.Detail.AllKept"), merge.AllHereText);
Assert.Equal(Loc.L("Server.Copies.Detail.AllOther"), merge.AllThereText);
Assert.True(merge.Details.Count > 0, "the Alps pair has details that differ");
// Kept: the pair's other sequence. Its values move to the first column, and "kept" stays the kept one's.
merge.KeepOptions.Single(o => o.SequenceId == merge.Copy.OtherId).IsChecked = true;
var detail = merge.Details[0];
Assert.Equal(detail.Line.There ?? Loc.L("Server.Sync.None"), detail.HereToolTip);
Assert.Equal(detail.Line.Here ?? Loc.L("Server.Sync.None"), detail.ThereToolTip);
detail.ChoiceIndex = 0;
await merge.PlanNowAsync();
var plan = Assert.NotNull(merge.MergePlan);
Assert.Equal(CopySide.ThisPc, plan.Choices.Details[detail.Path]);
CopyScenes.Reset(shell);
});
[Test]
public Task TheLibraryAndSettingsShowTheMatches() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
// A card in a pair that asks for a choice carries the match status and offers Compare….
await LibraryScenes.ShowCopiesAsync(shell, CopyScenes.Alps);
var item = Assert.Contains(shell.Library.Items, i => i.HasMatch && i.Title == CopyScenes.Alps);
Assert.NotNull(item.MatchStatus);
Assert.Contains(item.Statuses, s => s == item.MatchStatus);
Assert.True(shell.Library.CompareItemCommand.CanExecute(item));
// A refresh builds new cards: the match status stays on them.
await shell.Library.RefreshAsync();
item = Assert.Contains(shell.Library.Items, i => i.HasMatch && i.Title == CopyScenes.Alps);
Assert.NotNull(item.MatchStatus);
await app.ExpectAsync<LibraryView>("library-copies", waitForThumbnails: true);
shell.Library.CompareItemCommand.Execute(item);
Assert.Equal(SectionKey.Server, shell.Current.Key);
Assert.True(shell.Server.Sync.IsMatches);
Assert.Equal(CopyScenes.Alps, shell.Server.Sync.SearchText);
CopyScenes.Reset(shell);
// Settings › Server: three rows, every option with its tooltip, each choice saved at once.
var rows = shell.Settings.CopyRows;
foreach (var option in rows.LinkingOptions.Cast<object>().Concat(rows.PhotoOptions).Concat(rows.ProjectOptions))
{
var (label, tip) = option switch
{
SettingsOption<CopyLinking> o => (o.Label, o.ToolTip),
SettingsOption<CopyPhotoPolicy> o => (o.Label, o.ToolTip),
SettingsOption<CopyProjects> o => (o.Label, o.ToolTip),
_ => (string.Empty, null),
};
Assert.False(string.IsNullOrWhiteSpace(tip), $"{label} has a tooltip");
Assert.LessOrEqual(label.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length, 3, $"\"{label}\" is at most three words");
}
rows.Linking = rows.LinkingOptions.First(o => o.Value == CopyLinking.WhenIdentical);
Assert.Equal(CopyLinking.WhenIdentical, shell.Services.Settings.CopyLinking);
shell.Navigate(SectionKey.Settings);
shell.Settings.Page = SettingsPage.Server;
await app.ExpectAsync<SettingsView>("settings-server");
Assert.Contains(app.FindAll<ComboBox>(), c => c.IsVisible && Equals(c.SelectedItem, rows.Linking) && c.ToolTip is not null);
});
[Test]
public Task TheDialogStartsFromTheSettingsAndChooseEachPreselectsNothing() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var settings = shell.Services.Settings;
var list = shell.Server.Sync.Copies;
var pair = list.Pairs.Single(p => p.Here.Title == CopyScenes.Lighthouse);
var (photos, projects) = (settings.CopyPhotos, settings.CopyProjects);
try
{
// Owner review 6 (#73): the dialog opens on Settings › Server's choices, whatever they are.
settings.CopyPhotos = CopyPhotoPolicy.ThisPcWins;
settings.CopyProjects = CopyProjects.Leave;
var dialog = Assert.NotNull(list.Open(pair, CopyDialogPart.Photos));
await dialog.LoadAsync();
Assert.Equal((CopyPhotoPolicy.ThisPcWins, 1), (dialog.Policy.Value, dialog.ProjectsIndex));
dialog.CloseCommand.Execute(null);
settings.CopyPhotos = CopyPhotoPolicy.Union;
settings.CopyProjects = CopyProjects.CopyAcross;
dialog = Assert.NotNull(list.Open(pair, CopyDialogPart.Photos));
await dialog.LoadAsync();
Assert.Equal((CopyPhotoPolicy.Union, 0), (dialog.Policy.Value, dialog.ProjectsIndex));
// Choose each: every photo row of every class starts unticked and without a version chosen.
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ChoosePerPhoto);
Assert.True(dialog.IsChoosing);
var offered = 0;
foreach (var cls in dialog.Classes)
{
dialog.SelectedClass = cls;
foreach (var row in dialog.Photos)
{
if (row.CanBring || row.CanChoose) offered++;
Assert.Null(row.Chosen);
Assert.False(row.Bring, $"{row.Name} is not ticked");
Assert.Null(row.Choice);
}
}
Assert.True(offered > 0, "the Lighthouse pair has photos to choose");
dialog.CloseCommand.Execute(null);
}
finally
{
(settings.CopyPhotos, settings.CopyProjects) = (photos, projects);
CopyScenes.Reset(shell);
}
});
[Test]
public Task MatchesFoundInTheBackgroundAndPhotosNotSentAreTold() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var table = shell.Server.Sync;
var raised = new List<Toast>();
shell.PendingToasts.CollectionChanged += (_, e) => raised.AddRange(e.NewItems?.OfType<Toast>() ?? []);
var pair = table.Copies.Pairs.Single(p => p.Here.Title == CopyScenes.Lighthouse);
shell.Navigate(SectionKey.Library);
// A detection that ran by itself (after a refresh, a scan, an import): "1 match found" · Review (design §8.4).
var engine = Assert.NotNull(shell.Services.Sync.Copies as Chronos.App.DesignTime.SampleCopyEngine);
engine.RaiseFound(new CopyFindResult([pair.Copy], [], []));
var found = await ToastAsync(raised, Loc.Plural("Server.Copies.Found", 1));
Assert.Equal(Loc.L("Server.Copies.Action.Review"), found.ActionText);
Assert.False(string.IsNullOrWhiteSpace(found.ActionToolTip));
Assert.True(found.RunsFromNotification, "a click on the Windows notification opens the matches");
found.ActionCommand!.Execute(null);
Assert.Equal(SectionKey.Server, shell.Current.Key);
Assert.True(table.IsMatches);
// A detection that found nothing tells nothing.
shell.Navigate(SectionKey.Library);
raised.Clear();
engine.RaiseFound(CopyFindResult.Empty);
await Task.Delay(200);
Assert.Empty(raised.Where(t => t.Title == Loc.Plural("Server.Copies.Found", 1)));
// Automatic photos of an integrated pair failed three times: "{title}: photos not sent" · Show, an error (design §6.1).
shell.Services.Sync.TellPhotosNotSent("server", pair.Copy.LocalId, new AutoPhotoFailure(SyncAgent.NotSentAfter, "Quota reached"));
var notSent = await ToastAsync(raised, Loc.L("Server.Sync.NotSentToast", CopyScenes.Lighthouse));
Assert.True(notSent.IsError);
Assert.Equal((Loc.L("Server.Sync.Show"), Loc.L("Tooltips.Server.Sync.ShowNotSent")), (notSent.ActionText, notSent.ActionToolTip));
Assert.True(notSent.RunsFromNotification);
notSent.ActionCommand!.Execute(null);
Assert.Equal(SectionKey.Server, shell.Current.Key);
Assert.False(table.IsMatches);
Assert.Equal(CopyScenes.Lighthouse, table.SearchText);
Assert.Contains(table.Rows, r => r.Title == CopyScenes.Lighthouse);
CopyScenes.Reset(shell);
});
private static async Task<Toast> ToastAsync(List<Toast> raised, string title)
{
for (var i = 0; i < 250 && !raised.Any(t => t.Title == title); i++) await Task.Delay(20);
return Assert.Contains(raised, t => t.Title == title);
}
private static async Task<ScreenSmokeTests.SampleApp> StartAsync()
{
var app = await ScreenSmokeTests.SampleApp.StartAsync();
var shell = app.Shell;
await app.Sample.FillAsync();
await shell.Services.Server.RestoreAsync();
Assert.NotNull(await shell.Services.Sync.RefreshAsync());
await app.Sample.FillCopiesAsync();
await shell.Library.RefreshAsync();
await shell.Server.Sync.ReloadAsync();
return app;
}
}