using System.Windows.Controls; using System.Windows.Input; using Titano.App.Infrastructure; using Titano.App.Sections; using Titano.App.Server; using Titano.App.Shell; using Titano.App.Tests.Windows; using Titano.Core.Localization; using Titano.Core.Model; using Titano.Data.Sync; using Titano.Testing; using Titano.Ui.Controls; namespace Titano.App.Tests.Server; /// The Server screen's sync table on the capture sample data: comparison, transfers, conflict and the Library's glyphs. [WindowsOnly] [Serial] [Timeout(300_000)] public sealed class ServerScreenSmokeTests { [Test] public Task TheSyncTableShowsEveryStateOfTheSample() => ScreenHost.RunAsync(async () => { await using var app = await ScreenSmokeTests.SampleApp.StartAsync(); var shell = app.Shell; await app.Sample.FillAsync(); await shell.Library.RefreshAsync(); await shell.Services.Server.RestoreAsync(); Assert.NotNull(await shell.Services.Sync.RefreshAsync()); await app.Sample.CacheProxiesAsync(); var table = shell.Server.Sync; await table.ReloadAsync(); // 36 sequences here (6 also on the server) and 2 only on the server; the conflict is listed first. Assert.True(table.IsActive); Assert.Equal(38, table.Rows.Count); Assert.Equal("Holy grail · Monviso", table.Rows[0].Title); Assert.True(table.Rows[0].IsConflict); Assert.Equal(1, Chip(table, SyncFilter.Conflicts).Count); Assert.Equal(2, Chip(table, SyncFilter.Remote).Count); Assert.Equal(30, Chip(table, SyncFilter.LocalOnly).Count); Assert.Equal(SyncStatus.InSync, Row(table, "Harbour sunset").Entry.Status); Assert.Equal(SyncStatus.ServerAhead, Row(table, "Construction cam · week 38").Entry.Status); Assert.SequenceEqual([SyncAction.DownloadOriginals], Actions(Row(table, "Construction cam · week 38"))); Assert.SequenceEqual([SyncAction.Upload], Actions(Row(table, "Milan skyline dusk"))); Assert.SequenceEqual([SyncAction.GetExports], Actions(Row(table, "Star trails, Colle del Nivolet"))); var sunrise = Row(table, "Sunrise over Superga"); Assert.Equal(SyncStatus.ProxiesOnly, sunrise.Entry.Status); Assert.Equal(Loc.L("Server.Sync.Proxies"), sunrise.LocalText); Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.DownloadOriginals], Actions(sunrise)); Assert.SequenceEqual([SyncAction.Upload], Actions(Row(table, "Clouds over the Langhe"))); var conflict = Row(table, "Holy grail · Monviso"); Assert.Equal(StatusKind.Warning, conflict.StateKind); Assert.SequenceEqual([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth], Actions(conflict)); Assert.Equal(Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.DeflickerWindow"), "41", "33"), conflict.StateToolTip); Assert.NotNull(table.LastSyncText); Assert.NotNull(table.ArchiveText); Assert.True(table.UploadAllCommand.CanExecute(null), "the table filled after the view bound"); // Resolving shows the plan first: what differs and which side is overwritten. var keepMine = SyncTableViewModel.ConflictRequest(conflict.Entry, SyncAction.KeepMine); Assert.True(keepMine.IsDestructive); Assert.Contains(Loc.L("Server.Setting.DeflickerWindow"), keepMine.Detail); Assert.False(SyncTableViewModel.ConflictRequest(conflict.Entry, SyncAction.SaveBoth).IsDestructive); // The Library shows the real sync state of each local copy, in one word. var holyGrail = shell.Library.Items.Single(i => i.Title == "Holy grail · Monviso"); Assert.Equal(SyncState.Conflict, holyGrail.Sequence.SyncState); Assert.Equal(StatusKind.Warning, holyGrail.Statuses[^1].Kind); Assert.Contains(shell.Library.Items.Single(i => i.Title == "Harbour sunset").Statuses, s => s.Kind == StatusKind.Synced); var milan = shell.Library.Items.Single(i => i.Title == "Milan skyline dusk").Statuses[^1]; Assert.Equal((StatusKind.Synced, Loc.L("Library.Status.Synced")), (milan.Kind, milan.Text)); shell.Navigate(SectionKey.Server); await app.ExpectAsync("server"); // Tab walks the row buttons of every row: the rows take no focus, the list passes Tab on to their content. var list = app.FindAll().Single(l => l.Name == "SyncList"); Assert.Equal(KeyboardNavigationMode.Continue, KeyboardNavigation.GetTabNavigation(list)); var rowButtons = app.FindAll