Files
Chronos/tests/Titano.App.Tests/Server/ServerScreenSmokeTests.cs
T
Claude 55a8989733 fix(app): announce job and transfer states, not progress ticks; smoke tests for the screens
- Jobs and sync rows announce a new state with their job or sequence; the
  update check announces each state, not each download percent. Live
  regions stay quiet when a recycled row shows another item or a language
  switch relabels them.
- The first-run dialog keeps its chosen card as the window's focused element,
  so focus starts inside it even before the window is active.
- Known-server addresses read left to right in the menu.
- Smoke tests: row names and states, row buttons, radio chips, header and
  cell columns, Workers readout, badge and strip counts, Settings values set
  elsewhere, German labels never cut, the cache row at 1200 px, no Reset on
  Advanced, Forget asks first, first-run focus and the RTL window direction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-05 22:14:01 +00:00

208 lines
12 KiB
C#

using System.Windows;
using System.Windows.Automation;
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;
/// <summary>The Server screen's sync table on the capture sample data: comparison, transfers, conflict and the Library's glyphs.</summary>
[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<ServerView>("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<ListBox>().Single(l => l.Name == "SyncList");
Assert.Equal(KeyboardNavigationMode.Continue, KeyboardNavigation.GetTabNavigation(list));
var rowButtons = app.FindAll<Button>().Where(b => b.DataContext is SyncRowAction && b.IsVisible).ToList();
Assert.True(rowButtons.Select(b => b.DataContext).OfType<SyncRowAction>().Count() > 3, "buttons of several rows are on screen");
Assert.True(rowButtons.All(b => b.Focusable && b.IsTabStop), "every row button is a tab stop");
// Screen readers: a row reads as its sequence and state, each of the many "Upload" buttons names its sequence.
foreach (var item in app.FindAll<ListBoxItem>().Where(i => i.DataContext is SyncRow && i.IsVisible))
{
var row = (SyncRow)item.DataContext;
Assert.Equal(row.Title, AutomationProperties.GetName(item));
Assert.Equal(row.StateText, AutomationProperties.GetItemStatus(item));
}
Assert.True(rowButtons.All(b => AutomationProperties.GetName(b) == ((SyncRowAction)b.DataContext).AccessibleName), "row buttons carry their row's name");
Assert.Equal(Loc.L("Server.Sync.ActionFor", Loc.L("Server.Sync.Action.Upload"), "Clouds over the Langhe"),
Row(table, "Clouds over the Langhe").Actions.Single().AccessibleName);
// The filters are a radio group: the chosen one is checked, so its state reaches screen readers.
var chips = app.FindAll<RadioButton>().Where(r => r.DataContext is SyncFilterChip).ToList();
Assert.Count(Enum.GetValues<SyncFilter>().Length, chips);
Assert.True(chips.All(c => c.IsChecked == ((SyncFilterChip)c.DataContext).IsSelected), "the checked chip is the chosen filter");
// While connected the address is read-only text (selectable, not dimmed), kept left to right; status changes are announced.
var address = app.FindAll<TextBox>().Single(t => t.Name == "AddressBox");
Assert.True(address.IsEnabled && address.IsReadOnly, "the connected address is read-only, not disabled");
Assert.Equal(FlowDirection.LeftToRight, address.FlowDirection);
var known = app.FindAll<Button>().Single(b => b.Name == "KnownButton");
Assert.False(string.IsNullOrEmpty(AutomationProperties.GetName(known)), "the icon-only button has a name");
Assert.True(ToolTipService.GetShowOnDisabled(known), "a disabled ▾ still says why");
Assert.Equal(AutomationLiveSetting.Polite, AutomationProperties.GetLiveSetting(
app.FindAll<StatusGlyph>().First(g => g.IsVisible && g.Text == shell.Server.StatusText)));
// The web admin admits administrators only: the sample user is an editor.
Assert.False(table.CanOpenAdmin);
Assert.False(app.FindAll<Button>().Any(b => b.Content as string == Loc.L("Server.Sync.OpenAdmin") && b.IsVisible), "no admin link for an editor");
// Transfers in every state: the rows show what moves and offer Pause or Resume.
await app.Sample.FillSyncAsync();
await table.ReloadAsync();
var comet = Row(table, "Comet over the ridge");
Assert.Equal(SyncStatus.Transferring, comet.Entry.Status);
Assert.SequenceEqual([SyncAction.Pause], Actions(comet));
Assert.Contains("46", comet.ServerText);
Assert.Equal(StatusKind.Queued, Row(table, "Fog lifting, Asti").StateKind);
Assert.Equal((StatusKind.Running, Loc.L("Server.Sync.State.Downloading")), (Row(table, "Sunrise over Superga").StateKind, Row(table, "Sunrise over Superga").StateText));
Assert.SequenceEqual([SyncAction.Resume], Actions(Row(table, "Lake Como storm")));
await app.ExpectAsync<ServerView>("server-sync");
// A reload keeps the row's buttons (focus, tooltips and clicks survive progress and comparisons).
var pause = comet.Actions[0];
await table.ReloadAsync();
Assert.Same(pause, Row(table, "Comet over the ridge").Actions[0]);
// The conflict filter leaves the one row waiting for a choice.
Chip(table, SyncFilter.Conflicts).SelectCommand.Execute(null);
Assert.Equal("Holy grail · Monviso", Assert.Contains(table.Rows, _ => true).Title);
Assert.Count(1, table.Rows);
await app.ExpectAsync<ServerView>("server-conflict");
// One row, no scrolling: the header still lines up with the cells (same padding, constant scroll-bar gutter).
var only = table.Rows[0];
Assert.Approximately(Left(Text(app, Loc.L("Server.Sync.Column.Local"))), Left(Text(app, only.LocalText)), 1.5, "This PC column");
Assert.Approximately(Left(Text(app, Loc.L("Server.Sync.Column.State"))),
Left(app.FindAll<StatusGlyph>().First(g => g.DataContext == only && g.IsVisible)), 1.5, "State column");
// No match: one sentence and its one action, which shows every sequence again.
table.SearchText = "nothing like this";
Assert.False(table.HasRows);
Assert.NotNull(table.EmptyText);
Assert.Equal(SyncEmpty.NoMatch, table.Empty);
table.ClearFiltersCommand.Execute(null);
Assert.Equal(string.Empty, table.SearchText);
Assert.True(Chip(table, SyncFilter.All).IsSelected);
Assert.Equal(Chip(table, SyncFilter.All).Count, table.Rows.Count);
// Another language relabels chips and rows at once.
UiLanguage.Apply("it");
try
{
Assert.Equal("Tutte · 38", Chip(table, SyncFilter.All).Text);
}
finally
{
UiLanguage.Apply("en");
}
});
[Test]
public Task SigningOutEmptiesTheTable() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
var shell = app.Shell;
await app.Sample.FillAsync();
await shell.Services.Server.RestoreAsync();
await shell.Services.Sync.RefreshAsync();
await shell.Server.Sync.ReloadAsync();
Assert.True(shell.Server.Sync.HasRows);
await shell.Services.Server.SignOutAsync();
Assert.Null(await shell.Services.Sync.RefreshAsync());
await shell.Server.Sync.ReloadAsync();
Assert.False(shell.Server.Sync.IsActive);
Assert.False(shell.Server.Sync.HasRows);
Assert.Equal(SyncEmpty.SignedOut, shell.Server.Sync.Empty);
Assert.False(shell.Server.Sync.UploadAllCommand.CanExecute(null));
Assert.Equal(Loc.L("Tooltips.Server.Sync.UploadAll.NotConnected"), shell.Server.Sync.UploadAllToolTip);
shell.Navigate(SectionKey.Server);
await app.ExpectAsync<ServerView>("server-signedout-table");
// Nothing to filter while signed out: chips and search give way to the one action, Connect.
Assert.False(app.FindAll<RadioButton>().Any(r => r.DataContext is SyncFilterChip && r.IsVisible), "no filter chips while signed out");
Assert.False(app.FindAll<TextBox>().Any(t => AutomationProperties.GetName(t) == Loc.L("Server.Sync.Search") && t.IsVisible), "no search while signed out");
Assert.True(app.FindAll<Button>().Any(b => b.Content as string == Loc.L("Server.Connect") && b.IsVisible), "the empty table offers Connect");
});
private static TextBlock Text(ScreenSmokeTests.SampleApp app, string text) => app.FindAll<TextBlock>().First(t => t.Text == text && t.IsVisible);
/// <summary>The left edge of an element in window coordinates.</summary>
private static double Left(FrameworkElement element) => element.TranslatePoint(new Point(0, 0), Window.GetWindow(element)).X;
private static SyncFilterChip Chip(SyncTableViewModel table, SyncFilter filter) => table.Chips.Single(c => c.Filter == filter);
private static SyncRow Row(SyncTableViewModel table, string title) => table.Rows.Single(r => r.Title == title);
private static IEnumerable<SyncAction> Actions(SyncRow row) => row.Actions.Select(a => a.Action);
}