test(archive): month columns per culture, failure sentences, health against duplicates, RTL paths and keys, named buttons and focus

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-06 08:16:03 +00:00
1 parent 2f0a7562db
commit b7cf8e8faf
3 files changed
+216 -14

No files matched your search

+13 -9
View File
@@ -80,22 +80,26 @@ public partial class ArchiveView : UserControl
});
}
/// <summary>
/// On a year: the arrow towards the indented side opens it (Right, or Left in a right-to-left layout, as a tree
/// view does), the other arrow closes it, Enter toggles it.
/// </summary>
private void OnTreeKeyDown(object sender, KeyEventArgs e)
{
if (Model is not { } model || Keyboard.FocusedElement is not ListBoxItem { DataContext: ArchiveTreeRowViewModel row } || !row.HasChildren || row.IsArchive) return;
var (open, close) = Tree.FlowDirection == FlowDirection.RightToLeft ? (Key.Left, Key.Right) : (Key.Right, Key.Left);
var toggle = e.Key == open ? !row.IsExpanded
: e.Key == close ? row.IsExpanded
: e.Key == Key.Enter;
if (!toggle) return;
if (!Toggles(e.Key, Tree.FlowDirection, row.IsExpanded)) return;
model.Toggle(row);
e.Handled = true;
}
/// <summary>
/// Whether <paramref name="key"/> opens or closes a year: the arrow towards the indented side opens it (Right, or
/// Left in a right-to-left layout, as a tree view does), the other arrow closes it, Enter toggles it.
/// </summary>
internal static bool Toggles(Key key, FlowDirection direction, bool isExpanded)
{
var (open, close) = direction == FlowDirection.RightToLeft ? (Key.Left, Key.Right) : (Key.Right, Key.Left);
return key == open ? !isExpanded
: key == close ? isExpanded
: key == Key.Enter;
}
/// <summary>
/// A dialog that opens takes the keyboard (its first field or button); when it closes, the keyboard goes back to the
/// control that opened it, or to the tree when that control can no longer take it.
@@ -1,13 +1,17 @@
using System.Globalization;
using System.IO;
using Titano.App.Archiving;
using Titano.App.Infrastructure;
using Titano.App.Library;
using Titano.Core.Archiving;
using Titano.Core.Imaging;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Data;
using Titano.Data.Archiving;
using Titano.Data.Repositories;
using Titano.Testing;
using Titano.Ui.Controls;
namespace Titano.App.Tests.Archiving;
@@ -163,11 +167,31 @@ public sealed class ArchiveLogicTests
Assert.True(double.IsNaN(rows[2].Values[10]));
Assert.Null(rows[2].ToolTips[11]);
Assert.Equal("July 2026 · 5,000 photos · 5 sequences", rows[2].ToolTips[6]);
Assert.Equal(12, ArchiveFigures.MonthLabels().Count);
Assert.Equal("J", ArchiveFigures.MonthLabels()[0]);
Assert.Empty(ArchiveFigures.PhotosPerMonth(Stats() with { ByMonth = [] }, DateTime.Today));
}
[Test]
public void MonthColumnsAreInitialsOnlyWhereTheyAreLetters()
{
var numbers = Enumerable.Range(1, 12).Select(m => m.ToString(CultureInfo.InvariantCulture)).ToArray();
try
{
Assert.Equal("J F M A M J J A S O N D", string.Join(' ', ArchiveFigures.MonthLabels()));
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
Assert.Equal("G F M A M G L A S O N D", string.Join(' ', ArchiveFigures.MonthLabels()));
// Numbered abbreviations ("10月", "Tháng 10") would read "1" for October to December, or "T" for every month.
foreach (var culture in new[] { "ja", "ko", "zh-Hans", "zh-Hant", "vi", "th", "ar", "he" })
{
Loc.SetCulture(CultureInfo.GetCultureInfo(culture));
Assert.SequenceEqual(numbers, ArchiveFigures.MonthLabels(), culture);
}
}
finally
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
}
[Test]
public void TilesAndHealthSummariseTheIndex()
{
@@ -177,7 +201,7 @@ public sealed class ArchiveLogicTests
Assert.Equal("9.4 TB", tiles[2].Value);
Assert.Equal("6", tiles[3].Value);
Assert.Equal("cameras · 8 formats", tiles[3].Caption);
Assert.Equal("2024 – 2026", tiles[4].Value);
Assert.Equal(Formatting.LeftToRight("2024 – 2026"), tiles[4].Value, "a year range keeps its order in right-to-left text");
var health = ArchiveFigures.Health(Stats(), withoutProxies: 0);
Assert.Equal(HealthAction.Verify, health[0].Action);
@@ -187,6 +211,59 @@ public sealed class ArchiveLogicTests
Assert.True(health[2].IsOk);
Assert.Equal(HealthAction.Analyse, health[3].Action);
Assert.Equal(HealthAction.Duplicates, health[4].Action);
Assert.Equal("5 duplicate frames", health[4].Text);
}
[Test]
public void HealthDuplicatesFollowTheLastDuplicatesSearch()
{
var unflagged = Stats() with { Health = Stats().Health with { DuplicateFrames = 0 } };
var before = ArchiveFigures.Health(unflagged, withoutProxies: 0)[4];
Assert.True(before.IsOk);
Assert.Equal("No copies flagged", before.Text, "before a search the line says what it measures");
var found = ArchiveFigures.Health(unflagged, withoutProxies: 0, duplicateGroups: 1)[4];
Assert.False(found.IsOk, "never a tick while the Duplicates card lists groups");
Assert.Equal("1 duplicate group", found.Text);
Assert.Equal(HealthAction.MarkDuplicates, found.Action);
var none = ArchiveFigures.Health(Stats(), withoutProxies: 0, duplicateGroups: 0)[4];
Assert.True(none.IsOk);
Assert.Equal(HealthAction.None, none.Action);
}
[Test]
public void FailuresAreOneLocalizedSentenceByCause()
{
Assert.Equal("The archive " + Formatting.LeftToRight("/archive") + " is offline.",
ArchiveFailures.Cause(new ArchiveOfflineException("/archive", ArchiveAvailability.Offline)));
Assert.Equal("The archive " + Formatting.LeftToRight("/archive") + " is read-only.",
ArchiveFailures.Cause(new ArchiveOfflineException("/archive", ArchiveAvailability.ReadOnly)));
Assert.Equal("Titano was denied access to the archive.", ArchiveFailures.Cause(new UnauthorizedAccessException("Access to '/x' is denied.")));
Assert.Equal("The index could not be read or written.", ArchiveFailures.Cause(new DatabaseConnectionException("socket closed")));
Assert.Equal("The sequence is no longer in the index.", ArchiveFailures.Cause(new ArgumentException("Unknown sequence 42.")));
Assert.Equal("A file of the archive could not be read or written.", ArchiveFailures.Cause(new IOException("The device is not ready.")));
Assert.Equal(Loc.L("Archive.Error.StalePlan"), ArchiveFailures.Cause(new StaleRenamePlanException(Guid.NewGuid())));
}
[Test]
public void TreeRowsShowTheirWholeTitleAndTheKeysOfTheReadingDirection()
{
var harbour = Seq("Construction cam · weekly", new DateTime(2026, 9, 28), 3_600, 72_000_000_000);
var tree = ArchiveTree.Build(Main, ArchiveAvailability.Online, [harbour]);
var year = new ArchiveTreeRowViewModel(tree.Root.Children[0], ArchiveAvailability.Online, _ => { });
var sequence = new ArchiveTreeRowViewModel(tree.Root.Children[0].Children[0], ArchiveAvailability.Online, _ => { });
Assert.Equal("Construction cam · weekly · 3,600 photos · 72 GB", sequence.RowToolTip);
Assert.Equal("2026 · 1 sequence · 72 GB · Right arrow opens the year, Left arrow closes it", year.RowToolTip);
try
{
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
Assert.Equal(Loc.L("Tooltips.Archive.YearRowRtl", "2026 · " + year.Detail), year.RowToolTip, "the arrow keys of a mirrored tree");
}
finally
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
}
[Test]
@@ -257,6 +334,11 @@ public sealed class ArchiveLogicTests
Assert.Equal("2 photos not in sidecar", orphans[0].Detail);
Assert.Equal(a.Id, orphans[0].SequenceId);
Assert.Null(orphans[2].SequenceId);
// Folders stay left to right inside right-to-left text.
Assert.Equal("No sidecar in " + Formatting.LeftToRight("2024/Gone"), orphans[1].Detail);
Assert.Equal(Formatting.LeftToRight("2026/New shoot"), orphans[2].Title);
Assert.True(duplicates.Single().Places[1].EndsWith(Formatting.LeftToRight(b.Folder + "/originals/IMG_9.CR2"), StringComparison.Ordinal),
"a duplicate's path stays left to right");
var now = DateTimeOffset.UtcNow;
var jobs = new[]
@@ -267,7 +349,9 @@ public sealed class ArchiveLogicTests
var recent = MaintenanceReports.Recent(jobs, 5);
Assert.Equal("Verify · TitanoArchive", recent[0].Text);
Assert.Equal("71 %", recent[0].StateText);
Assert.Equal(StatusKind.Running, recent[0].StateKind);
Assert.Equal(JobState.Done, recent[1].State);
Assert.Equal(StatusKind.Done, recent[1].StateKind, "a finished run is a green dot, a failed one a red cross");
}
[Test]
@@ -1,8 +1,15 @@
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using Titano.App.Archiving;
using Titano.App.Infrastructure;
using Titano.App.Sections;
using Titano.App.Shell;
using Titano.App.Tests.Windows;
using Titano.Core.Localization;
using Titano.Testing;
using Titano.Ui.Controls;
@@ -10,7 +17,9 @@ namespace Titano.App.Tests.Archiving;
/// <summary>
/// Every Archive view of <c>--capture</c> (<see cref="ArchiveScenes"/>) on the sample archive, rendered in both themes
/// in the real main window, with what each view must show — and the buttons really enabled, not only their commands.
/// in the real main window, with what each view must show — the buttons really enabled and named for screen readers,
/// keyboard focus visible, no error or busy state left over — and paths and templates readable in a right-to-left
/// language.
/// </summary>
[WindowsOnly]
[Serial]
@@ -35,14 +44,21 @@ public sealed class ArchiveScreenSmokeTests
Assert.NotEmpty(archive.StorageBars);
Assert.NotEmpty(archive.CameraBars);
Assert.NotEmpty(archive.FormatBars);
Assert.True(archive.HasMonthScale, "the heatmap's scale sits in its header");
Assert.Contains(archive.CameraBars[0].ToolTip!, archive.CamerasDescription);
Assert.True(archive.ScanCommand.CanExecute(null), "an online archive can be scanned");
await app.ExpectAsync<ArchiveView>("archive-overview");
Assert.True(ButtonFor(app, archive.ScanCommand).IsEnabled, "the Scan button is enabled once the archive is read");
Assert.True(ButtonFor(app, archive.AnalyseSetCommand).IsEnabled, "mass operations are enabled on the whole archive");
AssertEveryButtonIsNamed(app);
Assert.Contains(archive.SetText, AutomationProperties.GetName(SetButton(app)));
foreach (var row in TreeItems(app)) Assert.NotNull(row.FocusVisualStyle, "a tree row shows keyboard focus");
var sequence = archive.TreeRows.First(r => r.Node.Kind == TreeNodeKind.Sequence);
Assert.Contains(sequence.Title, sequence.RowToolTip);
// Expanding another year keeps the selection: the set stays what the user chose.
var year = archive.TreeRows[1];
var tree = app.FindAll<ListBox>().Single(l => l.Name == "Tree");
var tree = Tree(app);
tree.SelectedItems.Add(year);
var chosen = archive.SetText;
archive.Toggle(archive.TreeRows.Last(r => r.IsYear));
@@ -55,19 +71,34 @@ public sealed class ArchiveScreenSmokeTests
Assert.Equal(5, archive.Health.Count);
Assert.Equal(1, archive.Duplicates!.Count);
Assert.Equal(3, archive.Orphans!.Count, "unlisted photos, a row without sidecar, a folder not indexed");
var duplicatesLine = archive.Health[4].Line;
Assert.False(duplicatesLine.IsOk, "index health agrees with the duplicate groups listed beside it");
Assert.Equal(HealthAction.MarkDuplicates, duplicatesLine.Action);
await app.ExpectAsync<ArchiveView>("archive-maintenance");
Assert.False(app.FindAll<Button>().Any(b => b.IsVisible && ReferenceEquals(b.Command, archive.CancelSearchCommand)), "no Cancel without a search");
Assert.Equal(AutomationLiveSetting.Polite, AutomationProperties.GetLiveSetting(TextFor(app, archive.DuplicatesText)), "search results are announced");
AssertEveryButtonIsNamed(app);
await ArchiveScenes.ShowAsync(app.Shell, "rebuild");
var rebuild = Assert.NotNull(archive.Dialog as RebuildDialogViewModel);
Assert.True(rebuild.RebuildCommand.CanExecute(null));
Assert.False(archive.IsContentEnabled, "the screen behind a dialog takes no input");
Assert.False(rebuild.FactRows.Any(f => f.Value == Loc.L("Archive.Rebuild.Counting")), "counted, the facts no longer say Counting…");
await app.ExpectAsync<ArchiveView>("archive-rebuild");
Assert.False(tree.IsEnabled);
var frame = Assert.NotNull(VisualTreeHelper.GetChild(tree, 0) as Border);
Assert.Equal(0, ((SolidColorBrush)frame.Background).Color.A, "the disabled tree keeps its panel's fill instead of the system's white");
AssertNoErrorShown(app);
await ArchiveScenes.ShowAsync(app.Shell, "move");
var move = Assert.NotNull(archive.Dialog as RenameDialogViewModel);
Assert.NotEmpty(move.Rows, "the dry run lists the folders that change");
Assert.Null(move.ErrorText);
await app.ExpectAsync<ArchiveView>("archive-move");
Assert.True(ButtonFor(app, move.ApplyCommand).IsEnabled, "Apply follows the dry run");
Assert.True(ButtonFor(app, move.CloseCommand).IsDefault, "Enter takes the safe way out");
AssertNoErrorShown(app);
AssertEveryButtonIsNamed(app);
move.CloseCommand.Execute(null);
archive.RetagSetCommand.Execute(null);
@@ -75,9 +106,92 @@ public sealed class ArchiveScreenSmokeTests
retag.Add.Text = "sunset";
await app.ExpectAsync<ArchiveView>("archive-retag");
Assert.True(ButtonFor(app, retag.ApplyCommand).IsEnabled, "Apply follows the typed tags");
AssertNoErrorShown(app);
retag.CloseCommand.Execute(null);
});
[Test]
public Task PathsTemplatesAndMonthsStayReadableRightToLeft() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
await app.Sample.FillAsync();
UiLanguage.Apply("ar");
try
{
var archive = app.Shell.Archive;
await ArchiveScenes.ShowAsync(app.Shell, "overview");
Assert.Equal(12.ToString("N0", Loc.Culture), archive.MonthLabels[^1], "Arabic month names have no initials: the columns are numbered");
var year = archive.TreeRows[1];
Assert.Equal(Loc.L("Tooltips.Archive.YearRowRtl", year.Title + " · " + year.Detail), year.RowToolTip, "the tooltip names the mirrored arrow keys");
await app.ExpectAsync<ArchiveView>("archive-overview-ar");
await ArchiveScenes.ShowAsync(app.Shell, "rebuild");
Assert.Equal(FlowDirection.LeftToRight, TextFor(app, archive.SelectedArchive!.RootPath).FlowDirection, "the archive folder reads left to right");
await app.ExpectAsync<ArchiveView>("archive-rebuild-ar");
await ArchiveScenes.ShowAsync(app.Shell, "move");
var move = Assert.NotNull(archive.Dialog as RenameDialogViewModel);
var template = Assert.NotNull(app.FindAll<TextBox>().FirstOrDefault(t => t.IsVisible && EditBehavior.GetField(t) == move.Template));
Assert.Equal(FlowDirection.LeftToRight, template.FlowDirection, "the naming template reads left to right");
Assert.Equal(FlowDirection.LeftToRight, TextFor(app, move.Rows[0].From).FlowDirection, "a folder before the move reads left to right");
Assert.Equal(FlowDirection.LeftToRight, TextFor(app, move.Rows[0].To).FlowDirection, "a folder after the move reads left to right");
await app.ExpectAsync<ArchiveView>("archive-move-ar");
move.CloseCommand.Execute(null);
}
finally
{
UiLanguage.Apply("en");
}
});
[Test]
public void TheArrowTowardsTheIndentOpensAYearInEitherDirection()
{
Assert.True(ArchiveView.Toggles(Key.Right, FlowDirection.LeftToRight, isExpanded: false));
Assert.False(ArchiveView.Toggles(Key.Right, FlowDirection.LeftToRight, isExpanded: true));
Assert.True(ArchiveView.Toggles(Key.Left, FlowDirection.LeftToRight, isExpanded: true));
Assert.True(ArchiveView.Toggles(Key.Left, FlowDirection.RightToLeft, isExpanded: false), "a mirrored tree opens with Left");
Assert.True(ArchiveView.Toggles(Key.Right, FlowDirection.RightToLeft, isExpanded: true), "and closes with Right");
Assert.False(ArchiveView.Toggles(Key.Right, FlowDirection.RightToLeft, isExpanded: false));
Assert.True(ArchiveView.Toggles(Key.Enter, FlowDirection.RightToLeft, isExpanded: true));
Assert.False(ArchiveView.Toggles(Key.Down, FlowDirection.LeftToRight, isExpanded: false));
}
/// <summary>Every button of the screen has a name screen readers can announce, menu buttons with drawn chevrons included.</summary>
private static void AssertEveryButtonIsNamed(ScreenSmokeTests.SampleApp app)
{
foreach (var button in app.FindAll<ButtonBase>().Where(b => b.IsVisible && b.Focusable && IsInArchive(b)))
{
var name = AutomationProperties.GetName(button);
if (string.IsNullOrEmpty(name)) name = button.Content as string;
Assert.False(string.IsNullOrWhiteSpace(name), $"{button.GetType().Name} '{button.Name}' bound to {button.Command} has no accessible name");
}
}
/// <summary>A dialog that has not failed shows no error line.</summary>
private static void AssertNoErrorShown(ScreenSmokeTests.SampleApp app) =>
Assert.False(app.FindAll<StatusGlyph>().Any(g => g.IsVisible && g.Kind == StatusKind.Error && IsInArchive(g)), "no error state before anything failed");
private static ListBox Tree(ScreenSmokeTests.SampleApp app) => app.FindAll<ListBox>().Single(l => l.Name == "Tree");
private static IEnumerable<ListBoxItem> TreeItems(ScreenSmokeTests.SampleApp app) =>
app.FindAll<ListBoxItem>().Where(i => i.IsVisible && i.DataContext is ArchiveTreeRowViewModel);
private static Button SetButton(ScreenSmokeTests.SampleApp app) =>
Assert.NotNull(app.FindAll<Button>().FirstOrDefault(b => b.IsVisible && b.ToolTip as string == Loc.L("Tooltips.Archive.Set")), "the set filter button");
private static bool IsInArchive(DependencyObject element)
{
for (var node = VisualTreeHelper.GetParent(element); node is not null; node = VisualTreeHelper.GetParent(node))
{
if (node is ArchiveView) return true;
}
return false;
}
private static TextBlock TextFor(ScreenSmokeTests.SampleApp app, string text) =>
Assert.NotNull(app.FindAll<TextBlock>().FirstOrDefault(t => t.IsVisible && t.Text == text && IsInArchive(t)), $"a visible text '{text}'");
private static Button ButtonFor(ScreenSmokeTests.SampleApp app, ICommand command) =>
Assert.NotNull(app.FindAll<Button>().FirstOrDefault(b => ReferenceEquals(b.Command, command) && b.IsVisible), "a visible button bound to the command");
}