diff --git a/src/Titano.App/Sections/ArchiveView.xaml.cs b/src/Titano.App/Sections/ArchiveView.xaml.cs index bc05c161..e819e86d 100644 --- a/src/Titano.App/Sections/ArchiveView.xaml.cs +++ b/src/Titano.App/Sections/ArchiveView.xaml.cs @@ -80,22 +80,26 @@ public partial class ArchiveView : UserControl }); } - /// - /// 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. - /// 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; } + /// + /// Whether 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. + /// + 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; + } + /// /// 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. diff --git a/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs index 9db10c3f..cda498ce 100644 --- a/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs +++ b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs @@ -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] diff --git a/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs b/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs index 0074623c..65cd10d1 100644 --- a/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs +++ b/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs @@ -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; /// /// Every Archive view of --capture () 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. /// [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("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().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("archive-maintenance"); + Assert.False(app.FindAll