Index restore (ENG-06, UI-09): - A staged restore now runs on the files before the index is opened, so it also recovers an index that no longer opens; Settings > Advanced > Restore works without an open index (the current one is shown as unreadable). - The staged copy passes PRAGMA quick_check (before migration, in a scratch copy) ahead of any backup: a damaged copy is set aside as .failed and never renews the daily copies. The index it replaces is kept as a VACUUM INTO copy, or, when it cannot be read, copied whole with its WAL as titano-replaced-<stamp>.db outside the rotation. The staged file is renamed over the index, so it is never applied twice. - Archive > Maintenance gains Restore database..., which opens Settings > Advanced. Archive settings (UI-03, ENG-03): - An archive.json with an empty or overlong name (drive roots) can be edited again: the name read is made usable as at creation. - Proxy and thumbnail sizes outside the presets (an admin's 3840) are listed and shown with their number. - Changing the archive folder retargets the rows: an archive there is registered and rescanned; with none, the rows edit only the defaults of new archives. The rows never fall back to another archive of the index. - Reset all and Import settings no longer rewrite the shared archive.json; Archive > Reset section asks first, naming the archive. - PUT /api/v1/archive/settings: 409 archive_busy on a lease conflict, 409 archive_manifest for a damaged, newer or foreign archive.json (was 500). Parallelism (UI-02): - Auto is the job engine's default, half the logical cores (BRIEF 14.6), with each job's own decode and analysis threads; a value the user sets is the number of workers and caps those threads. The memory budget is shared: each job's frame window gets budget / workers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
280 lines
15 KiB
C#
280 lines
15 KiB
C#
using System.Windows;
|
||
using System.Windows.Automation;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Input;
|
||
using System.Windows.Media;
|
||
using Titano.App.Infrastructure;
|
||
using Titano.App.Sections;
|
||
using Titano.App.Server;
|
||
using Titano.App.Settings;
|
||
using Titano.App.Shell;
|
||
using Titano.App.Tests.Windows;
|
||
using Titano.Core.Localization;
|
||
using Titano.Testing;
|
||
|
||
namespace Titano.App.Tests.Settings;
|
||
|
||
/// <summary>
|
||
/// Settings, the first-run dialog and the reading direction on the capture sample: values other screens set, labels and
|
||
/// paths that survive long translations and right-to-left text, keyboard focus and the questions before forgetting.
|
||
/// </summary>
|
||
[WindowsOnly]
|
||
[Serial]
|
||
[Timeout(300_000)]
|
||
public sealed class SettingsScreenSmokeTests
|
||
{
|
||
[Test]
|
||
public Task SettingsShowCurrentValuesAndNeverCutLabelsOrRows() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
await app.Sample.FillAsync();
|
||
await shell.Services.Server.RestoreAsync();
|
||
var settings = shell.Settings;
|
||
|
||
// The open archive and the server connected to were set after Settings was built: it shows them when opened.
|
||
shell.Navigate(SectionKey.Settings);
|
||
Assert.Equal(@"D:\TitanoArchive", settings.ArchiveRoot.Text);
|
||
Assert.Equal("https://nas.local:8443", settings.DefaultServer.Text);
|
||
Assert.False(settings.ArchiveRoot.IsDirty || settings.DefaultServer.IsDirty, "values loaded, not edits");
|
||
|
||
// The section list shows where keyboard focus is.
|
||
await app.ExpectAsync<SettingsView>("settings-general");
|
||
Assert.True(app.FindAll<ListBoxItem>().Where(i => i.DataContext is SettingsPageItem).All(i => i.FocusVisualStyle is not null), "sections have a focus ring");
|
||
|
||
// At the minimum window width the cache folder row stays one line: Clear beside the path, not under it.
|
||
settings.Page = SettingsPage.Storage;
|
||
await app.ExpectAsync<SettingsView>("settings-storage");
|
||
var window = Window.GetWindow(app.FindAll<SettingsView>().First(v => v.IsVisible));
|
||
var width = window.Width;
|
||
window.Width = 1200;
|
||
window.UpdateLayout();
|
||
var cache = Field(app, Loc.L("Settings.Storage.Folder"));
|
||
var clear = app.FindAll<Button>().First(b => b.Content as string == Loc.L("Settings.Storage.Clear") && b.IsVisible);
|
||
Assert.Approximately(Middle(cache), Middle(clear), 2, "Clear is on the path's line");
|
||
Assert.Equal(FlowDirection.LeftToRight, cache.FlowDirection);
|
||
window.Width = width;
|
||
|
||
// Long translations are never cut: German labels show whole (or wrap) in the shared label column.
|
||
UiLanguage.Apply("de");
|
||
try
|
||
{
|
||
await app.ExpectAsync<SettingsView>("settings-storage-de");
|
||
foreach (var label in Labels(app)) Assert.True(IsWhole(label), $"\"{label.Text}\" is shown whole");
|
||
}
|
||
finally
|
||
{
|
||
UiLanguage.Apply("en");
|
||
}
|
||
|
||
// Auto values are text with their reason in the tooltip, not buttons that do nothing.
|
||
settings.Page = SettingsPage.Rendering;
|
||
await app.ExpectAsync<SettingsView>("settings-rendering");
|
||
Assert.False(app.FindAll<Button>().Any(b => b.Content is string text && (text == settings.MemoryAutoText || text == settings.ParallelismAutoText)), "no dead Auto buttons");
|
||
|
||
// Paths, addresses and fingerprints read left to right; read-only paths show whole in their tooltip.
|
||
settings.Page = SettingsPage.Advanced;
|
||
await app.ExpectAsync<SettingsView>("settings-advanced");
|
||
var data = Field(app, Loc.L("Settings.Advanced.DataFolder"));
|
||
Assert.Equal(FlowDirection.LeftToRight, data.FlowDirection);
|
||
Assert.Equal(settings.DataFolder, data.ToolTip);
|
||
// Advanced has nothing to reset: no Reset section there.
|
||
Assert.False(settings.CanResetSection);
|
||
Assert.False(settings.ResetSectionCommand.CanExecute(null));
|
||
Assert.False(app.FindAll<Button>().Any(b => b.Content as string == Loc.L("Settings.ResetSection") && b.IsVisible), "no Reset section on Advanced");
|
||
|
||
// Forgetting a trusted certificate asks first, as on the Server screen; a "no" keeps it and the session.
|
||
settings.Page = SettingsPage.Server;
|
||
await app.ExpectAsync<SettingsView>("settings-server");
|
||
Assert.True(settings.CanResetSection);
|
||
Assert.Equal(FlowDirection.LeftToRight, Field(app, Loc.L("Settings.Server.Default")).FlowDirection);
|
||
var certificate = Assert.Contains(settings.Certificates, _ => true);
|
||
Assert.Contains(certificate.Server, certificate.ForgetName);
|
||
certificate.ForgetCommand.Execute(null);
|
||
Assert.Count(1, settings.Certificates);
|
||
Assert.True(shell.Server.IsConnected, "the session on the certificate stays");
|
||
Assert.True(ServerSession.ForgetRequest(certificate.FullFingerprint).IsDestructive);
|
||
});
|
||
|
||
[Test]
|
||
public Task ImportAnalysisAndFormatsAreRealSettings() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
await app.Sample.FillAsync();
|
||
var settings = shell.Settings;
|
||
// The open archive's own thumbnail size (archive.json) is what Settings › Archive shows.
|
||
var archive = Assert.NotNull(await Titano.App.Archiving.CurrentArchive.FindAsync(shell.Services.Database!, shell.Services.Settings.LastArchivePath));
|
||
var manifestPath = new Titano.Core.Archiving.ArchivePaths(archive.RootPath).ManifestPath;
|
||
var manifest = Titano.Core.Archiving.ManifestStore.ReadArchive(manifestPath);
|
||
Titano.Core.Archiving.ManifestStore.WriteArchive(manifestPath, manifest with { ThumbnailPolicy = new Titano.Core.Archiving.ThumbnailPolicy { LongEdge = 240 } });
|
||
|
||
shell.Navigate(SectionKey.Settings);
|
||
settings.Page = SettingsPage.Archive;
|
||
await WaitAsync(() => settings.SelectedThumbnailSize.Value == 240, "the archive's thumbnail size is shown");
|
||
await app.ExpectAsync<SettingsView>("settings-archive");
|
||
settings.SelectedThumbnailSize = settings.ThumbnailSizes.Single(s => s.Value == 480);
|
||
await WaitAsync(() => Titano.Core.Archiving.ManifestStore.ReadArchive(manifestPath).ThumbnailPolicy.LongEdge == 480, "written into archive.json");
|
||
Assert.Equal(480, shell.Services.Settings.ThumbnailLongEdge);
|
||
|
||
// A proxy size the admin panel set (3840 is none of the presets) is shown as it is, not as 1920.
|
||
manifest = Titano.Core.Archiving.ManifestStore.ReadArchive(manifestPath);
|
||
Titano.Core.Archiving.ManifestStore.WriteArchive(manifestPath, manifest with { ProxyPolicy = manifest.ProxyPolicy with { LongEdge = 3840 } });
|
||
shell.Navigate(SectionKey.Library);
|
||
shell.Navigate(SectionKey.Settings);
|
||
await WaitAsync(() => settings.SelectedProxySize.Value == 3840, "the archive's own proxy size is shown");
|
||
Assert.Equal("3840", settings.SelectedProxySize.Label);
|
||
Assert.SequenceEqual([1280, 1920, 2560, 3840, Titano.Core.Archiving.ProxyPolicy.FullSize, Titano.Core.Archiving.ProxyPolicy.Disabled],
|
||
settings.ProxySizes.Select(s => s.Value));
|
||
|
||
// Reset section on Archive changes the archive everyone shares: it asks first, and a "no" leaves archive.json alone.
|
||
settings.ResetSectionCommand.Execute(null);
|
||
Assert.Equal((480, 3840), (Titano.Core.Archiving.ManifestStore.ReadArchive(manifestPath).ThumbnailPolicy.LongEdge,
|
||
Titano.Core.Archiving.ManifestStore.ReadArchive(manifestPath).ProxyPolicy.LongEdge));
|
||
Assert.Equal(480, settings.SelectedThumbnailSize.Value);
|
||
|
||
// Import: the defaults of new cards.
|
||
settings.Page = SettingsPage.Import;
|
||
await app.ExpectAsync<SettingsView>("settings-import");
|
||
settings.SessionGap.Text = "90";
|
||
Assert.True(settings.SessionGap.Commit());
|
||
settings.IsFormatCard = true;
|
||
Assert.Equal((90, Titano.Data.Archiving.AfterImport.FormatCard), (shell.Services.Settings.ImportSessionGapMinutes, shell.Services.Settings.ImportAfter));
|
||
Assert.True(settings.CanResetSection);
|
||
settings.ResetSectionCommand.Execute(null);
|
||
Assert.Equal(("45", true), (settings.SessionGap.Text, settings.IsKeepCard));
|
||
|
||
// Analysis: thresholds in the language's own decimals, checked against their range.
|
||
settings.Page = SettingsPage.Analysis;
|
||
await app.ExpectAsync<SettingsView>("settings-analysis");
|
||
Assert.Equal(6.25.ToString("0.##", System.Globalization.CultureInfo.CurrentCulture), settings.NightBrightness.Text);
|
||
settings.NightBrightness.Text = "80";
|
||
Assert.True(settings.NightBrightness.HasErrors, "beyond 50 %");
|
||
settings.NightBrightness.Revert();
|
||
settings.DeepAnalysisAfterScan = true;
|
||
Assert.True(shell.Services.Settings.DeepAnalysisAfterScan);
|
||
|
||
// Formats: the tier of every format and a notice with Install per missing extension.
|
||
settings.Page = SettingsPage.Formats;
|
||
await WaitAsync(() => settings.Formats.Count > 0 && !settings.IsDetectingFormats, "formats listed");
|
||
await app.ExpectAsync<SettingsView>("settings-formats");
|
||
Assert.Count(3, settings.MissingExtensions);
|
||
var installs = app.FindAll<Button>().Where(b => b.IsVisible && b.Content as string == Loc.L("Settings.Formats.Install")).ToList();
|
||
Assert.Count(3, installs);
|
||
Assert.True(installs.All(b => AutomationProperties.GetName(b).StartsWith(Loc.L("Settings.Formats.InstallName", string.Empty), StringComparison.Ordinal)), "named after the extension");
|
||
Assert.Contains(settings.Formats, f => f.Row.Tier == Titano.Core.Imaging.DecodeTier.Native);
|
||
Assert.False(settings.CanResetSection, "Formats only shows this PC");
|
||
installs[0].Command.Execute(null);
|
||
});
|
||
|
||
[Test]
|
||
public Task TheFirstRunDialogKeepsTheKeyboardInside() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
app.Shell.ShowWelcome();
|
||
await app.ExpectAsync<WelcomeView>("welcome");
|
||
|
||
var welcome = app.FindAll<WelcomeView>().First(v => v.IsVisible);
|
||
var dialog = (FrameworkElement)welcome.Content;
|
||
Assert.Equal(KeyboardNavigationMode.Cycle, KeyboardNavigation.GetTabNavigation(dialog));
|
||
Assert.Equal(KeyboardNavigationMode.Cycle, KeyboardNavigation.GetControlTabNavigation(dialog));
|
||
Assert.Equal(KeyboardNavigationMode.Contained, KeyboardNavigation.GetDirectionalNavigation(dialog));
|
||
// It opens with focus on the chosen card (a local archive by default).
|
||
var focused = FocusManager.GetFocusedElement(Window.GetWindow(welcome)) as RadioButton;
|
||
Assert.NotNull(focused, "a card has focus");
|
||
Assert.True(focused.IsChecked == true && welcome.IsAncestorOf(focused), "the chosen card of the dialog has focus");
|
||
// The logo is not mirrored in right-to-left languages.
|
||
Assert.True(app.FindAll<Titano.Ui.Controls.BrandMarkIcon>().Where(b => b.IsVisible).All(b => b.FlowDirection == FlowDirection.LeftToRight));
|
||
app.Shell.CompleteWelcome();
|
||
});
|
||
|
||
[Test]
|
||
public Task ARightToLeftLanguageMirrorsEveryWindowAlsoThoseOpenedLater() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
app.Shell.About.SetResult(null);
|
||
app.Shell.Navigate(SectionKey.About);
|
||
await app.ExpectAsync<AboutView>("about");
|
||
var main = Window.GetWindow(app.FindAll<AboutView>().First(v => v.IsVisible));
|
||
Assert.Equal(FlowDirection.LeftToRight, main.FlowDirection);
|
||
|
||
UiLanguage.Apply("ar");
|
||
var dialog = new Window
|
||
{
|
||
WindowStartupLocation = WindowStartupLocation.Manual,
|
||
Left = -20000,
|
||
Top = -20000,
|
||
Width = 320,
|
||
Height = 200,
|
||
ShowActivated = false,
|
||
ShowInTaskbar = false,
|
||
};
|
||
try
|
||
{
|
||
Assert.Equal(FlowDirection.RightToLeft, main.FlowDirection);
|
||
// Loaded comes with the first render, which can follow an idle tick; class handlers run before this one.
|
||
var loaded = new TaskCompletionSource();
|
||
dialog.Loaded += (_, _) => loaded.TrySetResult();
|
||
dialog.Show();
|
||
await loaded.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
||
Assert.Equal(FlowDirection.RightToLeft, dialog.FlowDirection, "a window opened after the switch (a dialog) is mirrored too");
|
||
await app.ExpectAsync<AboutView>("about-ar");
|
||
|
||
// Inside the mirrored window, paths and the logo keep their left-to-right order.
|
||
var path = app.FindAll<TextBlock>().First(t => t.IsVisible && t.Text == app.Shell.About.DataFolder);
|
||
Assert.Equal(FlowDirection.LeftToRight, path.FlowDirection);
|
||
Assert.Equal(app.Shell.About.DataFolder, path.ToolTip);
|
||
// The update result is a live region: screen readers hear each new state.
|
||
var update = app.FindAll<Titano.Ui.Controls.StatusGlyph>().First(g => g.IsVisible && g.Text == app.Shell.About.UpdateText);
|
||
Assert.Equal(AutomationLiveSetting.Polite, AutomationProperties.GetLiveSetting(update));
|
||
Assert.Equal(app.Shell.About.UpdateAnnouncement, AutomationProperties.GetName(update));
|
||
}
|
||
finally
|
||
{
|
||
dialog.Close();
|
||
UiLanguage.Apply("en");
|
||
}
|
||
Assert.Equal(FlowDirection.LeftToRight, main.FlowDirection);
|
||
});
|
||
|
||
/// <summary>Waits (on the UI thread, letting it run) until <paramref name="condition"/> holds.</summary>
|
||
private static async Task WaitAsync(Func<bool> condition, string what)
|
||
{
|
||
var until = DateTime.UtcNow.AddSeconds(20);
|
||
while (!condition())
|
||
{
|
||
Assert.True(DateTime.UtcNow < until, what);
|
||
await Task.Delay(50);
|
||
}
|
||
}
|
||
|
||
private static TextBox Field(ScreenSmokeTests.SampleApp app, string name) =>
|
||
app.FindAll<TextBox>().First(t => t.IsVisible && AutomationProperties.GetName(t) == name);
|
||
|
||
private static double Middle(FrameworkElement element) =>
|
||
element.TranslatePoint(new Point(0, element.ActualHeight / 2), Window.GetWindow(element)).Y;
|
||
|
||
/// <summary>The label of every visible Settings row (the first text of the row template).</summary>
|
||
private static IEnumerable<TextBlock> Labels(ScreenSmokeTests.SampleApp app) =>
|
||
app.FindAll<HeaderedContentControl>().Where(h => h.IsVisible).Select(h => Descendants<TextBlock>(h).First());
|
||
|
||
/// <summary>The label's text fits its width on one line, or wraps onto more lines; never trimmed.</summary>
|
||
private static bool IsWhole(TextBlock label)
|
||
{
|
||
var probe = new TextBlock { Text = label.Text, FontFamily = label.FontFamily, FontSize = label.FontSize, FontWeight = label.FontWeight };
|
||
probe.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||
return label.TextTrimming == TextTrimming.None || probe.DesiredSize.Width <= label.ActualWidth + 0.5;
|
||
}
|
||
|
||
private static IEnumerable<T> Descendants<T>(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 nested in Descendants<T>(child)) yield return nested;
|
||
}
|
||
}
|
||
}
|