merge: integration branch claude/keen-knuth-uhxv8w (Archive manager and UI kit review) into the Library workstream
The Archive manager's reviewed dialogs (live status lines, one-sentence errors, growing label columns, left-to-right paths) move into the shared ArchiveDialogs.xaml with their styles, so the Library's Delete and the Trash dialog use them too. Delete, Restore and Rate failures read as one sentence through ArchiveFailures, which now knows a stale delete plan, a newer sidecar and a sequence already back in the library (SequenceInLibraryException). The confirmation's plan lines in the UI font follow the reading direction; fingerprints stay left to right. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
77 files changed
+1966
-468
No files matched your search
@@ -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,17 @@
|
||||
using System.IO;
|
||||
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.Archiving;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Testing;
|
||||
using Titano.Ui.Controls;
|
||||
|
||||
@@ -10,7 +19,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 +46,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 +73,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 +108,113 @@ 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 async Task RebuildCountsSayWhyInsteadOfCountingForever()
|
||||
{
|
||||
var offline = new RebuildDialogViewModel(Archive("/nowhere"), ArchiveAvailability.Offline, 3, () => Task.CompletedTask, _ => { });
|
||||
await offline.CountAsync();
|
||||
var sidecars = Fact(offline, "Archive.Rebuild.Sidecars");
|
||||
Assert.Equal("—", sidecars.Value);
|
||||
Assert.Equal(Loc.L("Archive.Error.Offline", Formatting.LeftToRight("/nowhere")), sidecars.ToolTip);
|
||||
Assert.True(Fact(offline, "Archive.Rebuild.Root").IsPath, "the archive folder is shown left to right");
|
||||
|
||||
var missing = Path.Combine(Path.GetTempPath(), "titano-missing-" + Guid.NewGuid().ToString("N"));
|
||||
var unreadable = new RebuildDialogViewModel(Archive(missing), ArchiveAvailability.Online, 3, () => Task.CompletedTask, _ => { });
|
||||
await unreadable.CountAsync();
|
||||
Assert.Equal("—", Fact(unreadable, "Archive.Rebuild.Metadata").Value);
|
||||
Assert.Equal(Loc.L("Archive.Failed.Files"), Fact(unreadable, "Archive.Rebuild.Metadata").ToolTip);
|
||||
Assert.Null(unreadable.BusyText, "nothing is counting any more");
|
||||
|
||||
static Core.Model.Archive Archive(string root) => new() { Id = Guid.CreateVersion7(), Name = "TitanoArchive", RootPath = root };
|
||||
static DialogFact Fact(RebuildDialogViewModel dialog, string label) => dialog.FactRows.Single(f => f.Label == Loc.L(label));
|
||||
}
|
||||
|
||||
[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");
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public sealed class UploaderScreenSmokeTests
|
||||
Assert.Null(vm.Connect.ErrorText);
|
||||
foreach (var box in screen.Visible<TextBox>())
|
||||
Assert.False(Validation.GetHasError(box), $"{AutomationProperties.GetName(box)} shows an error before use");
|
||||
Assert.False(screen.Named<Border>("PasswordErrorRing").IsVisible, "the password box shows no error before use");
|
||||
Assert.False(Field.GetHasError(screen.Named<PasswordBox>("Password")), "the password box shows no error before use");
|
||||
screen.AssertIconButtonsNamed("connect");
|
||||
|
||||
// Enter signs in from the form, not from the settings panel drawn over it.
|
||||
|
||||
@@ -73,6 +73,32 @@ public sealed class CurveMathTests
|
||||
Assert.False(CurveMath.CanRemove(3, 2, pinEnds: true));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KeyboardInsertionUsesThePlayheadWhenAPointFitsThere()
|
||||
{
|
||||
double[] xs = [0, 0.4, 1];
|
||||
Assert.Approximately(0.7, CurveMath.KeyboardInsertionX(xs, 1, 0.7, Gap, pinEnds: true), 0);
|
||||
// On a point, past a pinned end or unset: the middle of the gap after the selection (before it for the last point).
|
||||
Assert.Approximately(0.7, CurveMath.KeyboardInsertionX(xs, 1, 0.4, Gap, pinEnds: true), 1e-12);
|
||||
Assert.Approximately(0.2, CurveMath.KeyboardInsertionX(xs, 0, double.NaN, Gap, pinEnds: true), 1e-12);
|
||||
Assert.Approximately(0.7, CurveMath.KeyboardInsertionX(xs, 2, double.NaN, Gap, pinEnds: true), 1e-12);
|
||||
Assert.Approximately(0.2, CurveMath.KeyboardInsertionX(xs, -1, double.NaN, Gap, pinEnds: true), 1e-12);
|
||||
Assert.Approximately(0.5, CurveMath.KeyboardInsertionX([], -1, double.NaN, Gap, pinEnds: false), 0);
|
||||
Assert.Approximately(0.6, CurveMath.KeyboardInsertionX([0.2], 0, double.NaN, Gap, pinEnds: false), 1e-12);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InterpolationFollowsTheSegmentsAndIsFlatBeyondTheEnds()
|
||||
{
|
||||
double[] xs = [0.2, 0.6, 1];
|
||||
double[] ys = [0.1, 0.5, 0.3];
|
||||
Assert.Approximately(0.3, CurveMath.Interpolate(xs, ys, 0.4), 1e-12);
|
||||
Assert.Approximately(0.4, CurveMath.Interpolate(xs, ys, 0.8), 1e-12);
|
||||
Assert.Approximately(0.1, CurveMath.Interpolate(xs, ys, 0), 0);
|
||||
Assert.Approximately(0.3, CurveMath.Interpolate(xs, ys, 1), 0);
|
||||
Assert.Approximately(0.25, CurveMath.Interpolate([], [], 0.25), 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HitTestPicksTheNearestPointWithinRadius()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Automation.Peers;
|
||||
using System.Windows.Automation.Provider;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
@@ -8,8 +13,10 @@ using Titano.App.Sections;
|
||||
using Titano.App.Server;
|
||||
using Titano.App.Settings;
|
||||
using Titano.App.Shell;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Testing;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Ui.Mvvm;
|
||||
using Titano.Ui.Theming;
|
||||
using Titano.Ui.Visuals;
|
||||
|
||||
@@ -121,6 +128,111 @@ public sealed class ScreenSmokeTests
|
||||
Assert.Equal(english, app.Shell.Library.Title);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task ArabicMirrorsTheShellFromStartButNotItsPicturesOrLogo() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
// The language is applied before the window exists, as at start-up with Arabic saved in the settings.
|
||||
await using var app = await SampleApp.StartAsync("ar");
|
||||
try
|
||||
{
|
||||
var window = app.Window;
|
||||
Assert.Equal(FlowDirection.RightToLeft, window.FlowDirection, "the main window opens mirrored");
|
||||
var rail = (FrameworkElement)window.FindName("Rail");
|
||||
Assert.Equal(FlowDirection.RightToLeft, rail.FlowDirection, "the rail mirrors with the window");
|
||||
// The window's content carries the mirror (a capture of it alone reads right to left, as on screen).
|
||||
Assert.Greater(rail.TranslatePoint(new Point(rail.ActualWidth / 2, 0), window).X, window.ActualWidth / 2, "the rail starts on the right");
|
||||
|
||||
// The first-run dialog keeps the shell behind it out of reach.
|
||||
Assert.True(app.Shell.IsWelcomeOpen);
|
||||
Assert.False(rail.IsEnabled, "the rail behind the first-run dialog takes no input");
|
||||
app.Shell.CompleteWelcome();
|
||||
Assert.True(rail.IsEnabled);
|
||||
|
||||
var id = await app.Sample.FillEditorAsync();
|
||||
app.Shell.OpenSequence(id);
|
||||
await app.Shell.Sequence.OpenAsync(id);
|
||||
var editor = Assert.NotNull(app.Shell.Sequence.Editor);
|
||||
Assert.True(await editor.WhenIdleAsync(TimeSpan.FromSeconds(60)), "the editor settled");
|
||||
await app.ExpectAsync<SequenceView>("sequence-ar");
|
||||
|
||||
// Directional glyphs follow the reading direction; the others, the logo, the picture and the charts do not.
|
||||
var back = Assert.NotNull(app.FindAll<Button>().FirstOrDefault(b => b.IsVisible && ReferenceEquals(b.Command, editor.BackCommand)), "the editor's Back button");
|
||||
var arrow = Descendants<Icon>(back).Single();
|
||||
Assert.True(arrow.Glyph!.IsDirectional);
|
||||
Assert.Equal(FlowDirection.RightToLeft, arrow.FlowDirection, "Back points the way Arabic reads");
|
||||
foreach (var icon in app.FindAll<Icon>().Where(i => i.Glyph is { IsDirectional: false } && Bidi.GetIsDirectional(i) is null))
|
||||
Assert.Equal(FlowDirection.LeftToRight, icon.FlowDirection, "a glyph that does not point anywhere keeps its drawing");
|
||||
Assert.True(app.FindAll<BrandMarkIcon>().All(m => m.FlowDirection == FlowDirection.LeftToRight), "the logo never mirrors");
|
||||
var viewport = app.FindAll<PreviewViewport>().Single(v => v.IsVisible);
|
||||
Assert.Equal(FlowDirection.LeftToRight, ((FrameworkElement)viewport.Template.FindName(PreviewViewport.PartSurface, viewport)).FlowDirection, "the photo is not mirrored");
|
||||
Assert.Equal(FlowDirection.RightToLeft, ((FrameworkElement)viewport.Template.FindName(PreviewViewport.PartTools, viewport)).FlowDirection, "the preview tools follow the layout");
|
||||
Assert.True(app.FindAll<DrawingElement>().All(d => d.FlowDirection == FlowDirection.LeftToRight), "charts, filmstrip and curves keep their time axis");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await app.Shell.Sequence.CloseAsync();
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task ToastsDrawSpeakAndCloseAfterTheirAction() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await SampleApp.StartAsync();
|
||||
app.Shell.CompleteWelcome();
|
||||
var ran = false;
|
||||
app.Shell.ShowToast(new Toast { Title = "Harbour sunset rendered", ActionText = "Open", ActionCommand = new RelayCommand(() => ran = true) });
|
||||
await app.ExpectAsync<LibraryView>("library-toast");
|
||||
var host = app.Window.Toasts;
|
||||
Assert.Equal(1, host.Toasts.Count);
|
||||
var toast = Assert.NotNull(host.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement, "the toast's container");
|
||||
Assert.Greater(toast.ActualHeight, 0, "the toast is drawn");
|
||||
Assert.Equal("Harbour sunset rendered", AutomationProperties.GetName(toast));
|
||||
var dismiss = Descendants<Button>(toast).Single(b => ReferenceEquals(b.Command, ToastHost.DismissCommand));
|
||||
Assert.Equal(Loc.L("Tooltips.Common.Dismiss"), AutomationProperties.GetName(dismiss));
|
||||
|
||||
var action = Descendants<Button>(toast).Single(b => b.IsVisible && !ReferenceEquals(b.Command, ToastHost.DismissCommand));
|
||||
Assert.True(action.Command!.CanExecute(null));
|
||||
((IInvokeProvider)new ButtonAutomationPeer(action)).Invoke();
|
||||
await app.ExpectAsync<LibraryView>("library-toast-done");
|
||||
Assert.True(ran, "the action ran");
|
||||
Assert.Equal(0, host.Toasts.Count, "the toast closes once its action has run");
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task TheChromeAndTheJobBarHaveNamesAndStates() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await SampleApp.StartAsync();
|
||||
app.Shell.CompleteWelcome();
|
||||
await app.ExpectAsync<LibraryView>("library-empty");
|
||||
var window = app.Window;
|
||||
var captions = Descendants<Button>(window).Where(b => b.Command is RoutedCommand).ToList();
|
||||
Assert.Equal(Loc.L("Tooltips.Window.Minimize"), AutomationProperties.GetName(captions.Single(b => b.Command == SystemCommands.MinimizeWindowCommand)));
|
||||
Assert.Equal(Loc.L("Tooltips.Window.Maximize"), AutomationProperties.GetName(captions.Single(b => b.Command == SystemCommands.MaximizeWindowCommand)));
|
||||
Assert.Equal(Loc.L("Tooltips.Window.Close"), AutomationProperties.GetName(captions.Single(b => b.Command == SystemCommands.CloseWindowCommand)));
|
||||
|
||||
var bar = (JobBar)window.FindName("JobBar");
|
||||
Assert.Equal(AutomationLiveSetting.Polite, AutomationProperties.GetLiveSetting(bar));
|
||||
Assert.Equal(app.Shell.JobAnnouncement, AutomationProperties.GetName(bar), "screen readers hear the job state, not its progress");
|
||||
Assert.Equal(AutomationControlType.StatusBar, UIElementAutomationPeer.CreatePeerForElement(bar).GetAutomationControlType());
|
||||
var pause = Descendants<Button>(bar).Single();
|
||||
Assert.Equal(Loc.L("Shell.JobBar.Pause"), AutomationProperties.GetName(pause), "a short name; the sentence is the tooltip");
|
||||
|
||||
// A text box hands its padding to the text itself; the template adds none (8 px after a leading icon).
|
||||
app.Shell.Navigate(SectionKey.Settings);
|
||||
await app.ExpectAsync<SettingsView>("settings");
|
||||
var boxes = app.FindAll<TextBox>().Where(t => t.IsVisible).ToList();
|
||||
Assert.Contains(boxes, t => Field.GetGlyph(t) is not null);
|
||||
Assert.Contains(boxes, t => Field.GetGlyph(t) is null);
|
||||
foreach (var box in boxes)
|
||||
{
|
||||
var host = (ScrollViewer)box.Template.FindName("PART_ContentHost", box);
|
||||
Assert.Equal(box.Padding, host.Padding);
|
||||
Assert.Equal(new Thickness(0), ((FrameworkElement)VisualTreeHelper.GetParent(host)).Margin, "no second padding around the text");
|
||||
Assert.Equal(Field.GetGlyph(box) is null ? 0.0 : 22.0, host.Margin.Left);
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>A <see cref="MainWindow"/> on capture services and sample data, shown off screen like <c>--capture</c>.</summary>
|
||||
internal sealed class SampleApp : IAsyncDisposable
|
||||
{
|
||||
@@ -143,13 +255,15 @@ public sealed class ScreenSmokeTests
|
||||
public AppServices Services { get; }
|
||||
public SampleData Sample { get; }
|
||||
public ShellViewModel Shell { get; }
|
||||
public MainWindow Window => _window;
|
||||
|
||||
public static async Task<SampleApp> StartAsync()
|
||||
/// <param name="language">The UI language, applied before the window is created (as at start-up).</param>
|
||||
public static async Task<SampleApp> StartAsync(string language = "en")
|
||||
{
|
||||
var environment = AppEnvironment.ForCapture();
|
||||
UiLanguage.Apply("en");
|
||||
UiLanguage.Apply(language);
|
||||
ThemeManager.Apply(AppTheme.Dark);
|
||||
var services = new AppServices(environment, new AppSettings { Language = "en" }, () => { }, new NoDialogs());
|
||||
var services = new AppServices(environment, new AppSettings { Language = language }, () => { }, new NoDialogs());
|
||||
var sample = SampleData.Configure(services);
|
||||
var shell = new ShellViewModel(services);
|
||||
|
||||
@@ -273,6 +387,19 @@ public sealed class ScreenSmokeTests
|
||||
}
|
||||
}
|
||||
|
||||
private static List<T> Descendants<T>(DependencyObject root)
|
||||
where T : DependencyObject
|
||||
{
|
||||
var found = new List<T>();
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(root, i);
|
||||
if (child is T match) found.Add(match);
|
||||
found.AddRange(Descendants<T>(child));
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>Dialogs that answer like a user who cancels everything.</summary>
|
||||
private sealed class NoDialogs : IAppDialogs
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user