test(import): failure sentences, new cards, RTL text and the screen's accessibility
Logic tests for failure mapping, the folder path in replanning, nickname-less cards, entry tooltips, left-to-right paths and the right-to-left session arrow; the smoke test runs every state at 1200 x 788 and checks names on every button, uncut session times and Show plan names, aligned headers, the folder path error only for Folder with its status action, four-digit number boxes, disabled devices with their reason, live regions and the locked form after an import, plus a right-to-left pass in Arabic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
5 files changed
+322
-2
No files matched your search
@@ -53,6 +53,49 @@ public sealed class CardPoolTests
|
||||
Assert.Equal(@"D:\Shoots\2026", pool[4].Root);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ARememberedCardStaysNewUntilItHasANickname()
|
||||
{
|
||||
var unnamed = Known(GoPro, "GoPro 12", DateTimeOffset.UtcNow) with { Nickname = null };
|
||||
var source = CardPool.Build([GoPro], [unnamed], null).Single();
|
||||
Assert.NotNull(source.Card, "the first plan remembered it");
|
||||
Assert.False(source.IsKnown);
|
||||
Assert.Equal("New card", source.StateText);
|
||||
Assert.Equal("GOPRO", source.Title);
|
||||
|
||||
var named = CardPool.Build([GoPro], [unnamed with { Nickname = "GoPro 12" }], null).Single();
|
||||
Assert.True(named.IsKnown);
|
||||
Assert.Equal("Known card", named.StateText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheEntryTooltipCarriesTheStateAndTheWholeSubtitle()
|
||||
{
|
||||
var pool = CardPool.Build([CardA, Usb], [Known(CardA, "EOS R5 · card A", DateTimeOffset.UtcNow)], @"D:\Shoots\2026");
|
||||
Assert.Equal("Known card · 128 GB · 96.2 GB used", pool[0].ToolTip);
|
||||
Assert.Equal("no DCIM · 1.8 TB free", pool[1].ToolTip);
|
||||
Assert.Equal(@"Folder · D:\Shoots\2026", pool[2].ToolTip);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PathsAndSerialsStayLeftToRightInARightToLeftLanguage()
|
||||
{
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
|
||||
var pool = CardPool.Build([Usb with { Label = string.Empty }, CardA], [], @"D:\Shoots\");
|
||||
Assert.Equal("\u202AG:\\\u202C", pool[1].Title, "a drive root keeps its separator at its end");
|
||||
Assert.Equal("\u202AD:\\Shoots\\\u202C", pool[2].Title);
|
||||
Assert.Equal("\u202AD:\\Shoots\\\u202C", pool[2].Subtitle);
|
||||
Assert.Contains("\u202A3F2A-9C11\u202C", pool[0].IdentityText);
|
||||
Assert.Equal("EOS_DIGITAL", pool[0].Title, "a label is left to bidi");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AKnownCardWithoutDcimIsStillACard()
|
||||
{
|
||||
|
||||
@@ -66,6 +66,10 @@ public sealed class ImportChoicesTests
|
||||
Assert.True((a with { FileTemplate = "{name}" }).NeedsNewPlan(a));
|
||||
Assert.True((a with { Destination = ImportDestinationKind.Folder }).NeedsNewPlan(a));
|
||||
Assert.True((a with { IncludeSubfolders = false }).NeedsNewPlan(a));
|
||||
Assert.False((a with { FolderPath = @"D:\Shoots" }).NeedsNewPlan(a), "the folder path is not used for the archive");
|
||||
var folder = a with { Destination = ImportDestinationKind.Folder, FolderPath = @"D:\Shoots" };
|
||||
Assert.True((folder with { FolderPath = @"E:\Backup" }).NeedsNewPlan(folder));
|
||||
Assert.False((folder with { FolderPath = @"d:\shoots" }).NeedsNewPlan(folder), "paths compare without case");
|
||||
Assert.False(a.TitlesChangeNames);
|
||||
Assert.True((a with { FolderTemplate = "{year}/{Title:upper}" }).TitlesChangeNames);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Titano.App.Import;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Protocol;
|
||||
using Titano.Protocol.Client;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Import;
|
||||
|
||||
/// <summary>A stopped import or plan says what happened in one localized sentence, never the exception's raw text.</summary>
|
||||
public sealed class ImportFailuresTests
|
||||
{
|
||||
public ImportFailuresTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
|
||||
[Test]
|
||||
public void AnImportFailureIsOneSentenceByCause()
|
||||
{
|
||||
const string Card = "EOS R5 · card A";
|
||||
Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Import(new ImportSourceUnavailableException(@"C:\Users\me\AppData\Local\Temp\card\"), Card));
|
||||
Assert.Equal("The destination is full.", ImportFailures.Import(new IOException("There is not enough space on the disk.", unchecked((int)0x80070070)), Card));
|
||||
Assert.Equal("Titano may not write to the destination.", ImportFailures.Import(new UnauthorizedAccessException(@"Access to D:\Shoots is denied."), Card));
|
||||
Assert.Equal("The server did not accept the photos.", ImportFailures.Import(new HttpRequestException("No such host is known."), Card));
|
||||
Assert.Equal("The server did not accept the photos.",
|
||||
ImportFailures.Import(new TitanoApiException(HttpStatusCode.InsufficientStorage, new ApiError("quota", "Quota exceeded", null)), Card));
|
||||
Assert.Equal("The import stopped before the end.", ImportFailures.Import(new InvalidDataException("Bad sidecar. Second sentence."), Card));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APlanningFailureNamesTheSource()
|
||||
{
|
||||
const string Folder = @"D:\Shoots";
|
||||
Assert.Equal(@"D:\Shoots is no longer available.", ImportFailures.Plan(new DirectoryNotFoundException(@"Could not find a part of the path 'D:\Shoots\DCIM'."), Folder));
|
||||
Assert.Equal(@"D:\Shoots could not be read.", ImportFailures.Plan(new UnauthorizedAccessException("Access denied."), Folder));
|
||||
Assert.Equal(@"D:\Shoots could not be read.", ImportFailures.Plan(new IOException("The device is not ready."), Folder));
|
||||
Assert.Equal("The import could not be planned.", ImportFailures.Plan(new InvalidOperationException("Sequence contains no elements"), Folder));
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ public sealed class ImportPlansTests
|
||||
Assert.True(totals.HasEnoughSpace);
|
||||
Assert.Equal(TimeSpan.FromSeconds(3), totals.Estimate);
|
||||
Assert.Equal("3 sessions · 7 photos · 120 MB · about 3 s", totals.Text);
|
||||
Assert.Equal("3 sessions · 7 photos · 120 MB", totals.SummaryText);
|
||||
Assert.Equal("1 duplicate", totals.DuplicatesText);
|
||||
Assert.Equal("Import 5 photos", totals.ImportText);
|
||||
Assert.Equal("80 MB free after import", totals.SpaceText);
|
||||
@@ -124,6 +125,39 @@ public sealed class ImportPlansTests
|
||||
Assert.Equal("2026/2026-09-28 Canon EOS R5/" + plan.Sessions[0].Items[0].FileName, folder.Rows[1].Destination);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShowPlanShowsNamesUnderTheirSessionFolder()
|
||||
{
|
||||
var plan = ThreeSessions();
|
||||
var details = ImportPlans.Details(plan, ImportDestinationKind.Archive, verify: true);
|
||||
var session = details.Rows[0];
|
||||
Assert.True(session.SourceText.StartsWith("Session 1 · ", StringComparison.Ordinal), session.SourceText);
|
||||
Assert.Equal("2026/2026-09-28 Canon EOS R5/originals", session.DestinationText);
|
||||
var file = details.Rows[2];
|
||||
Assert.Equal("IMG_0002.CR2", file.SourceText);
|
||||
Assert.Equal(plan.Sessions[0].Items[1].FileName, file.DestinationText);
|
||||
Assert.Equal("DCIM/100CANON/IMG_0002.CR2", file.Source, "the full path stays for the tooltip");
|
||||
Assert.Equal("Split at IMG_0002.CR2", file.SplitName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ARightToLeftLanguageReadsTheSessionTimesWithItsOwnArrow()
|
||||
{
|
||||
var plan = ThreeSessions();
|
||||
Assert.Contains("→", ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText);
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
|
||||
var time = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText;
|
||||
Assert.Contains("←", time);
|
||||
Assert.False(time.Contains('→'), "a right-to-left reader would see the arrow point back to the start");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheNamePreviewShowsTheFirstThreeCopiedFiles()
|
||||
{
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
using System.Globalization;
|
||||
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.Import;
|
||||
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,8 +18,9 @@ namespace Titano.App.Tests.Import;
|
||||
|
||||
/// <summary>
|
||||
/// Every Import state of <c>--capture</c> (<see cref="ImportScenes"/>) on the simulated cards, rendered in both themes
|
||||
/// in the real main window, with the figures and gates each state must show — and the buttons really enabled, not
|
||||
/// only their commands.
|
||||
/// in the real main window at the 1200 × 788 capture size, with the figures and gates each state must show — and the
|
||||
/// buttons really enabled, named for screen readers, nothing that matters cut off, and paths, numbers and times
|
||||
/// readable in a right-to-left language.
|
||||
/// </summary>
|
||||
[WindowsOnly]
|
||||
[Serial]
|
||||
@@ -26,7 +35,9 @@ public sealed class ImportScreenSmokeTests
|
||||
var import = app.Shell.Import;
|
||||
|
||||
await ShowAsync(app, "inserted");
|
||||
await UseCaptureSizeAsync(app);
|
||||
Assert.NotEmpty(app.FindAll<ToastHost>().SelectMany(host => host.Toasts), "the insertion toast");
|
||||
Assert.False(import.FolderPath.HasErrors, "the folder path is not checked while Archive is the destination");
|
||||
await app.ExpectAsync<ImportView>("import-inserted");
|
||||
|
||||
await ShowAsync(app, "plan");
|
||||
@@ -40,11 +51,29 @@ public sealed class ImportScreenSmokeTests
|
||||
await app.ExpectAsync<ImportView>("import-plan");
|
||||
Assert.True(ButtonFor(app, import.StartCommand).IsEnabled, "the Import button is enabled once the plan is ready");
|
||||
Assert.True(ButtonFor(app, import.Sessions[1].MergeCommand).IsEnabled, "a session can merge into the one before");
|
||||
Assert.False(Validation.GetHasError(Named<TextBox>(app, "FolderPathBox")), "the folder path is not checked while Archive is the destination");
|
||||
foreach (var session in import.Sessions)
|
||||
Assert.True(Fits(TextFor(app, session.Row.TimeText)), $"the session time '{session.Row.TimeText}' is cut at 1200 px");
|
||||
foreach (var item in DeviceItems(app))
|
||||
{
|
||||
Assert.NotNull(item.FocusVisualStyle, "a device shows keyboard focus");
|
||||
Assert.Equal(((ImportSource)item.DataContext).ToolTip, item.ToolTip as string);
|
||||
}
|
||||
AssertEveryButtonIsNamed(app);
|
||||
await AssertFourDigitsFitAsync(app, import);
|
||||
await AssertFolderPathIsCheckedOnlyForFolderAsync(app, import);
|
||||
|
||||
await ShowAsync(app, "showplan");
|
||||
Assert.True(import.IsDetailsOpen);
|
||||
Assert.Equal(50 + 3, import.Details!.Rows.Count);
|
||||
await app.ExpectAsync<ImportView>("import-showplan");
|
||||
var file = import.Details.Rows[2];
|
||||
Assert.True(Fits(TextFor(app, file.SourceText)), "a file's name on the card is shown whole");
|
||||
Assert.True(Fits(TextFor(app, file.DestinationText)), "a file's new name is shown whole");
|
||||
Assert.True(Fits(TextFor(app, import.Details.Rows[0].SourceText)), "a session heading is shown whole");
|
||||
Assert.Within(Left(app, TextFor(app, Loc.L("Import.Details.Column.Action"))), 0, Left(app, TextFor(app, file.ActionText)), 0, 1,
|
||||
"the Action header lines up with its cells");
|
||||
AssertEveryButtonIsNamed(app);
|
||||
|
||||
await ShowAsync(app, "running");
|
||||
Assert.True(import.IsRunning);
|
||||
@@ -52,11 +81,27 @@ public sealed class ImportScreenSmokeTests
|
||||
Assert.False(import.Sessions[0].IsEditable, "titles lock while copying");
|
||||
await app.ExpectAsync<ImportView>("import-running");
|
||||
Assert.True(ButtonFor(app, import.CancelCommand).IsEnabled, "Cancel is enabled while copying");
|
||||
foreach (var item in DeviceItems(app))
|
||||
{
|
||||
Assert.False(item.IsEnabled, "the source of a running import stays selected");
|
||||
Assert.Equal(Loc.L("Import.Blocked.Copying"), item.ToolTip as string);
|
||||
}
|
||||
Assert.Equal(0.4, TextFor(app, Loc.L("Import.Scan.Frames")).Opacity, "unit words dim with their field");
|
||||
var progress = Named<TextBlock>(app, "ProgressLine");
|
||||
Assert.Equal(AutomationLiveSetting.Polite, AutomationProperties.GetLiveSetting(progress));
|
||||
Assert.Same(progress, AutomationProperties.GetLabeledBy(app.FindAll<ProgressBar>().First(p => p.IsVisible && IsInImport(p))));
|
||||
|
||||
await ShowAsync(app, "failed");
|
||||
Assert.True(import.IsFailed);
|
||||
Assert.Equal("EOS R5 · card A is no longer available.", import.ErrorText);
|
||||
Assert.Contains(SampleCards.Card(app.Services.Environment.DataDirectory).Root, import.FailureToolTip);
|
||||
await app.ExpectAsync<ImportView>("import-failed");
|
||||
Assert.True(ButtonFor(app, import.RetryCommand).IsEnabled, "Retry is enabled after a failure");
|
||||
var failure = Named<TextBlock>(app, "FailureLine");
|
||||
Assert.Equal(AutomationLiveSetting.Assertive, AutomationProperties.GetLiveSetting(failure));
|
||||
Assert.True(Fits(failure), "the failure sentence is shown whole");
|
||||
Assert.Null(app.FindAll<Button>().FirstOrDefault(b => b.IsVisible && ReferenceEquals(b.Command, app.Shell.NavigateCommand) && IsInImport(b)),
|
||||
"an error offers one action");
|
||||
|
||||
await ShowAsync(app, "done");
|
||||
Assert.True(import.IsDone);
|
||||
@@ -67,14 +112,55 @@ public sealed class ImportScreenSmokeTests
|
||||
Assert.Equal(49, result.Actions.DeleteCount);
|
||||
Assert.False(result.Actions.CanFormat, "a photo touched since the import keeps the card from being formatted");
|
||||
Assert.Empty(app.FindAll<ToastHost>().SelectMany(host => host.Toasts));
|
||||
Assert.False(import.IsFormEnabled, "a finished import keeps its form until New import");
|
||||
Assert.False(import.TotalsText.Contains(Loc.L("Import.Plan.About", string.Empty).Trim(), StringComparison.Ordinal), "no estimate after the import");
|
||||
Assert.Equal(string.Empty, import.SpaceText);
|
||||
await app.ExpectAsync<ImportView>("import-done");
|
||||
Assert.True(ButtonFor(app, result.DeleteCommand).IsEnabled, "the Delete button follows the dry run");
|
||||
AssertEveryButtonIsNamed(app);
|
||||
|
||||
await ShowAsync(app, "newcard");
|
||||
Assert.True(import.IsNicknameOpen, "a new card asks for its nickname");
|
||||
Assert.Equal("SONY", import.SourceTitle);
|
||||
Assert.False(import.SelectedSource!.IsKnown, "a card without a nickname is still new, though its plan remembered it");
|
||||
Assert.NotEmpty(app.FindAll<ToastHost>().SelectMany(host => host.Toasts));
|
||||
await app.ExpectAsync<ImportView>("import-newcard");
|
||||
AssertEveryButtonIsNamed(app);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task PathsNumbersAndTimesStayReadableRightToLeft() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
await app.Sample.FillAsync();
|
||||
UiLanguage.Apply("ar");
|
||||
try
|
||||
{
|
||||
var import = app.Shell.Import;
|
||||
await ShowAsync(app, "plan");
|
||||
Assert.Equal(ImportPhase.Ready, import.Phase);
|
||||
Assert.Equal(FlowDirection.RightToLeft, Window.GetWindow(View(app))!.FlowDirection);
|
||||
Assert.Equal(FlowDirection.LeftToRight, Named<TextBox>(app, "FolderPathBox").FlowDirection);
|
||||
Assert.Equal(FlowDirection.LeftToRight, Named<TextBox>(app, "GapBox").FlowDirection);
|
||||
foreach (var template in app.FindAll<TextBox>().Where(t => EditBehavior.GetField(t) is { } f && (f == import.FolderTemplate || f == import.FileTemplate)))
|
||||
Assert.Equal(FlowDirection.LeftToRight, template.FlowDirection, "name templates read left to right");
|
||||
Assert.Equal(FlowDirection.LeftToRight, TextFor(app, import.NamePreview).FlowDirection, "the name preview reads left to right");
|
||||
var size = TextFor(app, import.Sessions[0].Row.SizeText);
|
||||
Assert.Equal(FlowDirection.LeftToRight, size.FlowDirection);
|
||||
Assert.Equal(TextAlignment.Right, size.TextAlignment, "numbers stay right-aligned");
|
||||
Assert.Contains("←", import.Sessions[0].Row.TimeText);
|
||||
await app.ExpectAsync<ImportView>("import-plan-ar");
|
||||
|
||||
await ShowAsync(app, "showplan");
|
||||
var file = import.Details!.Rows[2];
|
||||
Assert.Equal(FlowDirection.LeftToRight, TextFor(app, file.SourceText).FlowDirection);
|
||||
Assert.Equal(FlowDirection.LeftToRight, TextFor(app, file.DestinationText).FlowDirection);
|
||||
await app.ExpectAsync<ImportView>("import-showplan-ar");
|
||||
}
|
||||
finally
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>As <c>--capture</c> does: toasts of the previous state go, those of an insertion state stay.</summary>
|
||||
@@ -83,6 +169,7 @@ public sealed class ImportScreenSmokeTests
|
||||
DismissToasts(app);
|
||||
await ImportScenes.ShowAsync(app.Shell, state);
|
||||
if (!ImportScenes.ShowsToast(state)) DismissToasts(app);
|
||||
await SettleAsync(app);
|
||||
}
|
||||
|
||||
private static void DismissToasts(ScreenSmokeTests.SampleApp app)
|
||||
@@ -93,6 +180,117 @@ public sealed class ImportScreenSmokeTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The size CI captures at (and the window's minimum width): nothing may be cut there.</summary>
|
||||
private static async Task UseCaptureSizeAsync(ScreenSmokeTests.SampleApp app)
|
||||
{
|
||||
var window = Window.GetWindow(View(app))!;
|
||||
window.Width = 1200;
|
||||
window.Height = 788;
|
||||
await SettleAsync(app);
|
||||
}
|
||||
|
||||
private static async Task SettleAsync(ScreenSmokeTests.SampleApp app)
|
||||
{
|
||||
var window = Window.GetWindow(View(app))!;
|
||||
window.UpdateLayout();
|
||||
await window.Dispatcher.InvokeAsync(() => { }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
|
||||
window.UpdateLayout();
|
||||
}
|
||||
|
||||
private static async Task WaitUntilAsync(ScreenSmokeTests.SampleApp app, Func<bool> condition, string what)
|
||||
{
|
||||
for (var i = 0; i < 200 && !condition(); i++) await Task.Delay(25);
|
||||
Assert.True(condition(), what);
|
||||
await SettleAsync(app);
|
||||
}
|
||||
|
||||
/// <summary>The empty folder path is fine for the archive; choosing Folder makes it invalid and offers "Choose folder".</summary>
|
||||
private static async Task AssertFolderPathIsCheckedOnlyForFolderAsync(ScreenSmokeTests.SampleApp app, ImportViewModel import)
|
||||
{
|
||||
var box = Named<TextBox>(app, "FolderPathBox");
|
||||
import.IsFolderDestination = true;
|
||||
await WaitUntilAsync(app, () => import.Phase == ImportPhase.NoSource, "the plan stops without a folder");
|
||||
Assert.True(Validation.GetHasError(box), "an empty path is an error once Folder is chosen");
|
||||
Assert.True(import.HasStatusAction);
|
||||
Assert.Equal(Loc.L("Import.Destination.Choose"), import.StatusActionText);
|
||||
Assert.True(Named<Button>(app, "StatusActionButton").IsVisible, "the status sentence comes with its action");
|
||||
import.IsArchiveDestination = true;
|
||||
await WaitUntilAsync(app, () => import.Phase == ImportPhase.Ready, "the archive plan is back");
|
||||
Assert.False(Validation.GetHasError(box));
|
||||
Assert.Equal("Harbour sunset", import.Plan!.Sessions[^1].Title, "typed titles survive the round trip");
|
||||
}
|
||||
|
||||
/// <summary>The 56 px gap box shows its largest value, 1440, whole.</summary>
|
||||
private static async Task AssertFourDigitsFitAsync(ScreenSmokeTests.SampleApp app, ImportViewModel import)
|
||||
{
|
||||
import.GapMinutes.Text = "1440";
|
||||
await SettleAsync(app);
|
||||
var host = Descendants(Named<TextBox>(app, "GapBox")).OfType<ScrollViewer>().First();
|
||||
Assert.LessOrEqual(host.ExtentWidth, host.ViewportWidth + 1, "1440 fits the gap box");
|
||||
import.GapMinutes.Revert();
|
||||
}
|
||||
|
||||
/// <summary>Every button, check box and radio button of the screen has a name screen readers can announce.</summary>
|
||||
private static void AssertEveryButtonIsNamed(ScreenSmokeTests.SampleApp app)
|
||||
{
|
||||
foreach (var button in app.FindAll<ButtonBase>().Where(b => b.IsVisible && b.Focusable && IsInImport(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");
|
||||
}
|
||||
}
|
||||
|
||||
private static ImportView View(ScreenSmokeTests.SampleApp app) => app.FindAll<ImportView>().First(v => v.IsVisible);
|
||||
|
||||
private static bool IsInImport(DependencyObject element) => FindAncestor<ImportView>(element) is not null;
|
||||
|
||||
private static T? FindAncestor<T>(DependencyObject element)
|
||||
where T : DependencyObject
|
||||
{
|
||||
for (var node = VisualTreeHelper.GetParent(element); node is not null; node = VisualTreeHelper.GetParent(node))
|
||||
{
|
||||
if (node is T match) return match;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IEnumerable<DependencyObject> Descendants(DependencyObject root)
|
||||
{
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(root, i);
|
||||
yield return child;
|
||||
foreach (var below in Descendants(child)) yield return below;
|
||||
}
|
||||
}
|
||||
|
||||
private static T Named<T>(ScreenSmokeTests.SampleApp app, string name)
|
||||
where T : FrameworkElement =>
|
||||
Assert.NotNull(app.FindAll<T>().FirstOrDefault(e => e.Name == name), $"{typeof(T).Name} {name}");
|
||||
|
||||
private static TextBlock TextFor(ScreenSmokeTests.SampleApp app, string text) =>
|
||||
Assert.NotNull(app.FindAll<TextBlock>().FirstOrDefault(t => t.IsVisible && t.Text == text && IsInImport(t)), $"a visible text '{text}'");
|
||||
|
||||
private static IEnumerable<ListBoxItem> DeviceItems(ScreenSmokeTests.SampleApp app) =>
|
||||
app.FindAll<ListBoxItem>().Where(i => i.IsVisible && i.DataContext is ImportSource);
|
||||
|
||||
/// <summary>The text is shown whole: its formatted width fits the width the layout gave it.</summary>
|
||||
private static bool Fits(TextBlock text)
|
||||
{
|
||||
var typeface = new Typeface(text.FontFamily, text.FontStyle, text.FontWeight, text.FontStretch);
|
||||
var formatted = new FormattedText(text.Text, CultureInfo.CurrentUICulture, text.FlowDirection, typeface, text.FontSize, Brushes.Black,
|
||||
VisualTreeHelper.GetDpi(text).PixelsPerDip);
|
||||
if (text.TextWrapping != TextWrapping.NoWrap)
|
||||
{
|
||||
formatted.MaxTextWidth = System.Math.Max(1, text.ActualWidth - text.Padding.Left - text.Padding.Right);
|
||||
return formatted.Height <= text.ActualHeight + 0.5;
|
||||
}
|
||||
return formatted.WidthIncludingTrailingWhitespace <= text.ActualWidth - text.Padding.Left - text.Padding.Right + 1;
|
||||
}
|
||||
|
||||
private static double Left(ScreenSmokeTests.SampleApp app, FrameworkElement element) => element.TranslatePoint(new Point(0, 0), View(app)).X;
|
||||
|
||||
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");
|
||||
}
|
||||
Reference in new issue
Block a user