using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Media;
using Chronos.App.DesignTime;
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;
///
/// 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.
///
[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("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);
// A match the server deleted: the local row offers what the Matches row does (design §6.3), each with a tooltip.
await CopyScenes.ShowAsync(shell, "server-copies-gone");
var gone = table.Rows.Single(r => r.Title == "Garden 2026");
Assert.SequenceEqual([SyncAction.KeepHere, SyncAction.UploadAgain, SyncAction.ToTrash], gone.Actions.Select(a => a.Action));
foreach (var action in gone.Actions)
{
Assert.False(string.IsNullOrWhiteSpace(action.ToolTip), $"{action.Text} has a tooltip");
Assert.Equal(Loc.L("Server.Copies.Action." + action.Action), action.Text);
}
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("server-copies-details");
// The footer: one primary action, Cancel answers Esc; both say what they do.
var cancel = app.FindAll().Single(b => b.IsVisible && b.IsCancel);
Assert.Equal(Loc.L("Tooltips.Server.Copies.Cancel"), cancel.ToolTip);
Assert.Contains(app.FindAll(), 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("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 = dialog.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(System.Globalization.CultureInfo.InvariantCulture), request.TypedConfirmation);
Assert.Contains(request.TypedConfirmation!, request.TypedPrompt!);
// Its first line is the dropped sequence's fact, not a photo held elsewhere.
Assert.False(request.Detail!.StartsWith(Loc.L("Server.Copies.Confirm.Elsewhere", string.Empty).Trim(), StringComparison.Ordinal),
"a merge's facts carry no Held elsewhere prefix");
await app.ExpectAsync("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().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);
// The segments say what choosing them does, with the worded value each takes, not the raw value.
Assert.Equal(Loc.L("Tooltips.Server.Copies.Detail.UseKept", detail.HereText), detail.HereChoiceToolTip);
Assert.Equal(Loc.L("Tooltips.Server.Copies.Detail.UseOther", detail.ThereText), detail.ThereChoiceToolTip);
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 EditsPickerMarksAProjectWhoseTimeLapseHasATwin() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
// A workspace project of this PC: the sample reads it as a linked pair's, with a project on the server.
var id = await app.Sample.FillEditorAsync();
shell.OpenSequence(id);
await shell.Sequence.OpenAsync(id);
Assert.Contains(CopyScenes.Views, v => v == "edit-picker-twins");
await CopyScenes.ShowAsync(shell, "edit-picker-twins");
var twin = Assert.Contains(shell.Sequence.Picker.WorkspaceItems, i => i.HasTwin);
Assert.False(string.IsNullOrWhiteSpace(twin.TwinToolTip), "the Twin chip says where the other project is");
await app.ExpectAsync("edit-picker-twins", waitForThumbnails: true);
CopyScenes.Reset(shell);
});
[Test]
public Task ManyProjectsScrollInsideTheDialog() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var dialog = Assert.NotNull(await CopyScenes.ShowAsync(shell, "server-copies-projects-many"));
Assert.True(dialog.IsProjects);
Assert.Equal((CopyScenes.ManyProjects, CopyScenes.ManyProjects), (dialog.HereProjects.Count, dialog.ThereProjects.Count));
await app.ExpectAsync("server-copies-projects-many");
// Both lists sit in one scroll viewer that holds more than it shows: the dialog's footer stays in view.
var scroll = Assert.Contains(app.FindAll(), s => s.IsVisible && s.ScrollableHeight > 0
&& s.Content is Grid grid && grid.Children.OfType().Count() == 2);
Assert.True(scroll.ViewportHeight > 0);
// Each heading shares its list's column, so the scroll bar never moves a list off its heading.
var lists = ((Grid)scroll.Content).Children.OfType().ToList();
var headings = ((Grid)scroll.Content).Children.OfType().ToList();
Assert.Count(2, headings);
for (var i = 0; i < 2; i++)
{
var window = Window.GetWindow(scroll);
Assert.Approximately(lists[i].TranslatePoint(new Point(0, 0), window).X, headings[i].TranslatePoint(new Point(0, 0), window).X, 0.5,
$"heading {i} starts where its list does");
}
// The sample pair has its own projects back for the other scenes.
var lighthouse = shell.Server.Sync.Copies.Pairs.Single(p => p.Here.Title == CopyScenes.Lighthouse);
Assert.Equal(2, (await shell.Services.Sync.Copies!.CompareAsync(lighthouse.Copy.Id, null, CancellationToken.None)).Projects.Here.Count);
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);
// Second, right after the analysis status, so a narrow card cuts the others first.
Assert.Equal(item.MatchStatus, item.Statuses[1]);
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("library-copies", waitForThumbnails: true);
// Two versions… lists the photos the sequence keeps in two versions (a Union merge's), here none, and says so.
Assert.True(shell.Library.VersionsItemCommand.CanExecute(item));
await shell.Library.ShowVersionsAsync(item.Id);
var versions = Assert.NotNull(shell.Library.Dialog as VersionsDialogViewModel);
Assert.True(versions.IsEmpty && !versions.HasRows);
Assert.Contains(CopyScenes.Alps, versions.Heading);
versions.CloseCommand.Execute(null);
Assert.Null(shell.Library.Dialog);
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().Concat(rows.PhotoOptions).Concat(rows.ProjectOptions))
{
var (label, tip) = option switch
{
SettingsOption o => (o.Label, o.ToolTip),
SettingsOption o => (o.Label, o.ToolTip),
SettingsOption 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("settings-server");
Assert.Contains(app.FindAll(), 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();
shell.PendingToasts.CollectionChanged += (_, e) => raised.AddRange(e.NewItems?.OfType() ?? []);
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);
});
[Test]
public Task ASwappedMergeOffersToTrashOnDeletedInOtherFromTheKeptSequenceOnly() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var engine = (SampleCopyEngine)shell.Services.Sync.Copies!;
var list = shell.Server.Sync.Copies;
await CopyScenes.ShowAsync(shell, "server-copies");
var alps = list.Pairs.Single(p => p.Here.Title == CopyScenes.Alps);
var start = new DateTime(2025, 7, 14, 5, 30, 0);
// The pair's first deleted 3 photos its other still holds (Deleted here), and the other deleted 2 the first holds.
var restore = engine.With(alps.Copy.Id, p => p with
{
Photos = [.. p.Photos, .. SampleCopies.Photos(PhotoClass.DeletedHere, 3, start, 950, here: false, there: true),
.. SampleCopies.Photos(PhotoClass.DeletedThere, 2, start, 960, here: true, there: false)],
});
try
{
var dialog = Assert.NotNull(list.Open(alps, CopyDialogPart.Photos, PhotoClass.DeletedHere));
await dialog.LoadAsync();
Assert.Equal(alps.Copy.OtherId, dialog.KeepOptions.Single(o => o.IsChecked).SequenceId);
// Kept: the pair's other. Its "Deleted in other" (the first deleted them) offers To trash…, from the kept one.
var deletedInOther = dialog.Classes.Single(c => c.Class == PhotoClass.DeletedHere);
Assert.Equal(CopyText.Class(PhotoClass.DeletedThere, merge: true), deletedInOther.Text);
dialog.SelectedClass = deletedInOther;
Assert.True(dialog.CanTrashHere);
var plan = await dialog.PlanTrashHereAsync([dialog.Photos[0].Key]);
Assert.Equal(alps.Copy.OtherId, plan.Plan.Sequence.Id);
// "Deleted in kept": its frames are the dropped sequence's, which go with the merge; no To trash….
var deletedInKept = dialog.Classes.Single(c => c.Class == PhotoClass.DeletedThere);
Assert.Equal(CopyText.Class(PhotoClass.DeletedHere, merge: true), deletedInKept.Text);
dialog.SelectedClass = deletedInKept;
Assert.False(dialog.CanTrashHere);
// Kept: the pair's first. Now Deleted there reads "Deleted in other" and trashes from the first.
dialog.KeepOptions.Single(o => o.SequenceId == alps.Copy.LocalId).IsChecked = true;
dialog.SelectedClass = dialog.Classes.Single(c => c.Class == PhotoClass.DeletedThere);
Assert.True(dialog.CanTrashHere);
Assert.Equal(alps.Copy.LocalId, (await dialog.PlanTrashHereAsync([dialog.Photos[0].Key])).Plan.Sequence.Id);
dialog.SelectedClass = dialog.Classes.Single(c => c.Class == PhotoClass.DeletedHere);
Assert.False(dialog.CanTrashHere);
}
finally
{
restore();
CopyScenes.Reset(shell);
}
});
[Test]
public Task InMainMarksTheVersionTheKeptSequencesMainUses() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var dialog = Assert.NotNull(await CopyScenes.ShowAsync(shell, "server-copies-versions"));
var alps = shell.Server.Sync.Copies.Pairs.Single(p => p.Here.Title == CopyScenes.Alps);
var review = await shell.Services.Sync.Copies!.CompareAsync(alps.Copy.Id, null, CancellationToken.None);
Assert.Equal(alps.Copy.OtherId, dialog.KeepOptions.Single(o => o.IsChecked).SequenceId);
// The two Mains use different versions: the kept sequence's (the pair's other) is marked.
Assert.Count(1, dialog.Photos.Where(p => p.InMain));
foreach (var marked in dialog.Photos.Where(x => x.InMain)) Assert.DoesNotContain(marked.Key, review.ExcludedThere);
await app.ExpectAsync("server-copies-versions");
// Both sides hold both versions: the side reads whole beside "In Main", and Drop… keeps its gap.
var view = app.FindAll().First(v => v.IsVisible);
foreach (var row in app.FindAll().Where(i => i is { DataContext: CopyPhotoRow, IsVisible: true }))
{
var photo = (CopyPhotoRow)row.DataContext;
var side = Descendants(row).Single(t => t.Text == photo.SideText);
// Layout rounding may take under a pixel; a trimmed text loses a whole character to the ellipsis.
Assert.True(Needed(side, side.Text) <= side.ActualWidth + 1.0, $"'{side.Text}' needs {Needed(side, side.Text):0.0} px, has {side.ActualWidth:0.0}");
var drop = Descendants(row).Single(b => b.IsVisible);
Assert.True(drop.Margin.Left >= 10, "Drop… keeps a gap from the side cell");
}
Assert.NotNull(view);
// Kept: the pair's first. The marker follows its Main.
dialog.KeepOptions.Single(o => o.SequenceId == alps.Copy.LocalId).IsChecked = true;
Assert.Count(1, dialog.Photos.Where(p => p.InMain));
foreach (var marked in dialog.Photos.Where(x => x.InMain)) Assert.DoesNotContain(marked.Key, review.ExcludedHere);
CopyScenes.Reset(shell);
});
[Test]
public Task ATwinNeedsItsSiblingAtTheOtherHome() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var engine = (SampleCopyEngine)shell.Services.Sync.Copies!;
// The integrated pair: Main and Vertical on this PC, only Main on the server.
var bridge = engine.Pairs.Single(p => p.Copy is { Kind: CopyKind.LocalServer, State: CopyState.Integrated });
Assert.SequenceEqual(["Main", "Vertical"], bridge.Projects.Here.Select(p => p.Name));
Assert.SequenceEqual(["Main"], bridge.Projects.There.Select(p => p.Name));
await CopyScenes.ShowAsync(shell, "edit-picker-twins");
var picker = shell.Sequence.Picker;
var home = Chronos.App.Workspace.WorkspaceHost.ArchiveHome(bridge.Copy.LocalId);
IReadOnlyList entries =
[
new(Guid.CreateVersion7(), bridge.Copy.LocalId, "Main", true, home, bridge.Here.Title, HasMedia: true, SampleData.Now),
new(Guid.CreateVersion7(), bridge.Copy.LocalId, "Vertical", false, home, bridge.Here.Title, HasMedia: true, SampleData.Now),
];
await picker.ShowSampleWorkspaceAsync(entries, new Chronos.Data.Workspaces.WorkspaceStatus(Chronos.Data.Workspaces.WorkspaceState.InSync, false, 0, 0,
false, false, false, null, null, null));
var main = picker.WorkspaceItems.Single(i => i.Entry.Name == "Main");
var vertical = picker.WorkspaceItems.Single(i => i.Entry.Name == "Vertical");
Assert.True(main.HasTwin, "Main has its sibling on the server");
Assert.Contains(main.Name, main.TwinToolTip!);
Assert.False(vertical.HasTwin, "Vertical is only on this PC");
CopyScenes.Reset(shell);
});
[Test]
public Task TheDialogsPolicyAndVersionChoicesFitTheirBoxesInEveryLanguage() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var dialog = Assert.NotNull(await CopyScenes.ShowAsync(shell, "server-copies-choose"));
await app.ExpectAsync("server-copies-choose");
var policy = app.FindAll().Single(c => c.IsVisible && AutomationProperties.GetName(c) == Loc.L("Server.Copies.Policy.Label"));
var version = app.FindAll().First(c => c.IsVisible && c.DataContext is CopyPhotoRow);
List misses = [];
try
{
foreach (var language in Languages.Shipped)
{
UiLanguage.Apply(language);
app.Window.UpdateLayout();
await app.Window.Dispatcher.InvokeAsync(() => { }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
foreach (var merge in new[] { false, true })
{
Fits(misses, language, policy, CopyDialogViewModel.PolicyOptions(merge).Select(o => o.Label));
Fits(misses, language, version, CopyDialogViewModel.VersionChoices(merge).Select(o => o.Label));
}
}
}
finally
{
UiLanguage.Apply("en");
}
Assert.True(misses.Count == 0, string.Join(Environment.NewLine, misses));
Assert.NotNull(dialog);
CopyScenes.Reset(shell);
});
[Test]
public Task TheMatchesSettingsFitTheirBoxesInEveryLanguage() => ScreenHost.RunAsync(async () =>
{
await using var app = await StartAsync();
var shell = app.Shell;
var settings = shell.Settings;
shell.Navigate(SectionKey.Settings);
settings.Page = SettingsPage.Server;
await app.ExpectAsync("settings-server");
string[] names = ["Settings.Server.CopyLinking", "Settings.Server.CopyPhotos", "Settings.Server.CopyProjects"];
List misses = [];
try
{
foreach (var language in Languages.Shipped)
{
UiLanguage.Apply(language);
settings.CopyRows.Refresh();
app.Window.UpdateLayout();
await app.Window.Dispatcher.InvokeAsync(() => { }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
foreach (var name in names)
{
var box = app.FindAll().Single(c => c.IsVisible && AutomationProperties.GetName(c) == Loc.L(name));
var labels = box.ItemsSource.Cast().Select(o => (string)o.GetType().GetProperty("Label")!.GetValue(o)!);
Fits(misses, language, box, labels);
}
}
}
finally
{
UiLanguage.Apply("en");
settings.CopyRows.Refresh();
}
Assert.True(misses.Count == 0, string.Join(Environment.NewLine, misses));
});
///
/// Adds to each label that does not show whole in 's selection box (its
/// content site, inside the margins).
///
private static void Fits(List misses, string language, ComboBox box, IEnumerable labels)
{
box.ApplyTemplate();
var site = (FrameworkElement)box.Template.FindName("ContentSite", box);
var room = box.ActualWidth - site.Margin.Left - site.Margin.Right - box.BorderThickness.Left - box.BorderThickness.Right;
var probe = new TextBlock { FontFamily = box.FontFamily, FontSize = box.FontSize, FontWeight = box.FontWeight, FlowDirection = box.FlowDirection };
foreach (var label in labels.Where(l => Needed(probe, l) > room + 0.5))
misses.Add($"{language}: '{label}' needs {Needed(probe, label):0.0} px, its box has {room:0.0}");
}
/// The width takes in 's font.
private static double Needed(TextBlock cell, string text) => new FormattedText(text, System.Globalization.CultureInfo.CurrentUICulture, cell.FlowDirection,
new Typeface(cell.FontFamily, cell.FontStyle, cell.FontWeight, cell.FontStretch), cell.FontSize, Brushes.Black, 1.0).WidthIncludingTrailingWhitespace;
private static IEnumerable Descendants(DependencyObject node)
where T : DependencyObject
{
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(node); i++)
{
var child = VisualTreeHelper.GetChild(node, i);
if (child is T match) yield return match;
foreach (var inner in Descendants(child)) yield return inner;
}
}
private static async Task ToastAsync(List 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 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;
}
}