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;
///
/// 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);
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