mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-19 06:55:59 +01:00
fix: Sonar's remarks on the screen reader work, and tests for it
The cab panel's drawing and the consist narration are split into smaller steps, with plain switches and concrete return types where Sonar asked. Tests drive the black box panels, both tape views, the key bindings, the windows opened over another, the search count and the themed tree entries, sliders, number boxes, pickers and settings sections headless, as someone at the keyboard with a screen reader meets them.
This commit is contained in:
@@ -2,6 +2,7 @@ using Avalonia.Automation;
|
||||
using Avalonia.Automation.Peers;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.VisualTree;
|
||||
using StarterNG.Controls;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
@@ -49,7 +50,12 @@ public class AnnouncerTests
|
||||
[Fact]
|
||||
public void A_control_outside_any_announcer_is_not_heard()
|
||||
{
|
||||
Announcer.Say(new Button(), "Godzina: 07:05");
|
||||
var button = new Button();
|
||||
|
||||
var thrown = Record.Exception(() => Announcer.Say(button, "Godzina: 07:05"));
|
||||
|
||||
Assert.Null(thrown);
|
||||
Assert.Null(button.FindAncestorOfType<Announcer>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
284
StarterNG.Tests/BlackBox/BlackBoxViewsTests.cs
Normal file
284
StarterNG.Tests/BlackBox/BlackBoxViewsTests.cs
Normal file
@@ -0,0 +1,284 @@
|
||||
using Avalonia.Automation;
|
||||
using Avalonia.Automation.Peers;
|
||||
using Avalonia.Automation.Provider;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.VisualTree;
|
||||
using Eu07.BlackBox;
|
||||
using Eu07.BlackBox.Views;
|
||||
|
||||
namespace StarterNG.Tests.BlackBox;
|
||||
|
||||
/// <summary>
|
||||
/// The black box's own drawn panels as a screen reader user meets them: reached with Tab,
|
||||
/// walked with the keys, their value and description read, what they show said aloud.
|
||||
/// </summary>
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class BlackBoxViewsTests
|
||||
{
|
||||
private const uint Head = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The user in vehicle 1 from t = 0 to 120: timetable ROJ1 standing at A, stopping at B
|
||||
/// from 60 to 70, passing C at 100; the clock at 10:34 (634 min).
|
||||
/// </summary>
|
||||
private static Recording Journey(bool extended = true, byte? engine = null)
|
||||
{
|
||||
var f = new BlackBoxFile().Info()
|
||||
.Vehicle(Head, "EU07-005", "ROJ1")
|
||||
.User(0, Head, true, 1)
|
||||
.Timetable(0, Head, "ROJ1", "A", "C", ("A", -1, 634), ("Stacja_B", 635, 635.5f), ("C", 637.5f, 638))
|
||||
.Station(1, Head, 4, 1, "A", 1150);
|
||||
for (double t = 0; t <= 120; t += 0.5)
|
||||
{
|
||||
float speed = t is >= 55 and < 70 ? 0 : 40;
|
||||
f.Cab(t, Head, 1150 + t * 10, speed, extended: extended, engine: engine, nextLimit: 60, nextDistance: 500,
|
||||
brakeCylinder: t is >= 50 and < 70 ? 2.5f : 0, devices: 0x0207);
|
||||
}
|
||||
f.Station(60, Head, 1, 2, "Stacja_B", 1300)
|
||||
.Station(100, Head, 3, 3, "C", 2150);
|
||||
return BlackBoxReader.Read(f.End(120).Stream());
|
||||
}
|
||||
|
||||
private static IValueProvider Value(Control control) =>
|
||||
Assert.IsAssignableFrom<IValueProvider>(Controls.Peer(control));
|
||||
|
||||
// --- timeline ---
|
||||
|
||||
[Fact]
|
||||
public void The_timeline_is_a_slider_read_as_the_moment_with_how_to_walk_it()
|
||||
{
|
||||
var timeline = new TimelineView { Spoken = "10:35:12, 40 km/h" };
|
||||
var peer = Controls.Peer(timeline);
|
||||
var value = Value(timeline);
|
||||
|
||||
Assert.Equal(AutomationControlType.Slider, peer.GetAutomationControlType());
|
||||
Assert.Equal("10:35:12, 40 km/h", value.Value);
|
||||
Assert.True(value.IsReadOnly);
|
||||
Assert.False(string.IsNullOrEmpty(peer.GetHelpText()));
|
||||
Assert.True(peer.IsContentElement());
|
||||
Assert.True(peer.IsControlElement());
|
||||
Assert.Throws<InvalidOperationException>(() => value.SetValue("x"));
|
||||
|
||||
timeline.Spoken = "10:35:22, 40 km/h";
|
||||
Assert.Equal("10:35:22, 40 km/h", value.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_description_set_on_the_timeline_wins_over_its_own()
|
||||
{
|
||||
var timeline = new TimelineView();
|
||||
AutomationProperties.SetHelpText(timeline, "own words");
|
||||
|
||||
Assert.Equal("own words", Controls.Peer(timeline).GetHelpText());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(Key.Right, KeyModifiers.None, 70)]
|
||||
[InlineData(Key.Left, KeyModifiers.None, 50)]
|
||||
[InlineData(Key.Right, KeyModifiers.Control, 120)]
|
||||
[InlineData(Key.Left, KeyModifiers.Control, 0)]
|
||||
[InlineData(Key.PageDown, KeyModifiers.None, 120)]
|
||||
[InlineData(Key.PageUp, KeyModifiers.None, 0)]
|
||||
[InlineData(Key.Home, KeyModifiers.None, 0)]
|
||||
[InlineData(Key.End, KeyModifiers.None, 120)]
|
||||
public void The_keys_take_the_timeline_through_the_recording(Key key, KeyModifiers modifiers, double expected)
|
||||
{
|
||||
var timeline = new TimelineView { Recording = Journey(), Time = 60 };
|
||||
double? sought = null;
|
||||
timeline.Seek += t => sought = t;
|
||||
|
||||
Assert.True(Controls.Press(timeline, key, modifiers));
|
||||
Assert.Equal(expected, sought);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Other_keys_and_an_empty_timeline_are_left_alone()
|
||||
{
|
||||
var empty = new TimelineView();
|
||||
var timeline = new TimelineView { Recording = Journey(), Time = 60 };
|
||||
bool sought = false;
|
||||
empty.Seek += _ => sought = true;
|
||||
timeline.Seek += _ => sought = true;
|
||||
|
||||
Assert.False(Controls.Press(empty, Key.Right));
|
||||
Assert.False(Controls.Press(timeline, Key.A));
|
||||
Assert.False(sought);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_timeline_draws_with_and_without_the_focus()
|
||||
{
|
||||
var timeline = new TimelineView { Recording = Journey(), Time = 60 };
|
||||
var window = Controls.Show(timeline, 900, 300);
|
||||
try
|
||||
{
|
||||
timeline.Fit();
|
||||
Controls.Draw(timeline);
|
||||
Assert.True(timeline.IsFocused);
|
||||
timeline.Time = 119;
|
||||
Controls.Draw(timeline);
|
||||
window.Focus();
|
||||
Controls.Draw(timeline);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
// --- timetable ---
|
||||
|
||||
[Fact]
|
||||
public void The_timetable_is_a_list_read_row_by_row_from_the_keys()
|
||||
{
|
||||
var table = new TimetablePanel { Recording = Journey(), Time = 30 };
|
||||
var peer = Controls.Peer(table);
|
||||
var value = Value(table);
|
||||
|
||||
Assert.Equal(AutomationControlType.List, peer.GetAutomationControlType());
|
||||
Assert.False(string.IsNullOrEmpty(peer.GetHelpText()));
|
||||
Assert.StartsWith("1/3. A", value.Value);
|
||||
|
||||
Assert.True(Controls.Press(table, Key.Down));
|
||||
Assert.StartsWith("2/3. Stacja B", value.Value);
|
||||
Assert.True(Controls.Press(table, Key.Up));
|
||||
Assert.StartsWith("1/3. A", value.Value);
|
||||
Assert.True(Controls.Press(table, Key.End));
|
||||
Assert.StartsWith("3/3. C", value.Value);
|
||||
Assert.True(Controls.Press(table, Key.Down));
|
||||
Assert.StartsWith("3/3. C", value.Value);
|
||||
Assert.True(Controls.Press(table, Key.Home));
|
||||
Assert.StartsWith("1/3. A", value.Value);
|
||||
Assert.Contains("km 2.5", value.Value.Replace(',', '.'));
|
||||
Assert.False(Controls.Press(table, Key.A));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Enter_on_a_station_passed_goes_to_a_little_before_it()
|
||||
{
|
||||
var table = new TimetablePanel { Recording = Journey(), Time = 110 };
|
||||
double? sought = null;
|
||||
table.Seek += t => sought = t;
|
||||
|
||||
Controls.Press(table, Key.Home);
|
||||
Controls.Press(table, Key.Down);
|
||||
|
||||
Assert.True(Controls.Press(table, Key.Enter));
|
||||
Assert.Equal(55, sought);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_recording_without_a_timetable_says_so_and_ignores_the_keys()
|
||||
{
|
||||
var recording = BlackBoxReader.Read(new BlackBoxFile().Info().Vehicle(Head, "EU07-005")
|
||||
.Cab(0, Head, 1150, 40).End(1).Stream());
|
||||
var table = new TimetablePanel { Recording = recording, Time = 0 };
|
||||
|
||||
Assert.False(string.IsNullOrEmpty(Value(table).Value));
|
||||
Assert.False(Controls.Press(table, Key.Down));
|
||||
table.Recording = null;
|
||||
Controls.Lay(table);
|
||||
Controls.Draw(table);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_timetable_draws_its_rows_and_the_one_the_keys_stand_at()
|
||||
{
|
||||
var table = new TimetablePanel { Recording = Journey(), Time = 65 };
|
||||
var window = Controls.Show(table, 600, 400);
|
||||
try
|
||||
{
|
||||
Controls.Draw(table);
|
||||
Controls.Press(table, Key.Down);
|
||||
Controls.Draw(table);
|
||||
window.Focus();
|
||||
Controls.Draw(table);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
// --- cab ---
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, null)]
|
||||
[InlineData(true, (byte)1)]
|
||||
[InlineData(true, (byte)2)]
|
||||
[InlineData(false, null)]
|
||||
public void The_cab_says_what_it_draws(bool extended, byte? engine)
|
||||
{
|
||||
var cab = new CabPanel { Recording = Journey(extended, engine), Time = 30 };
|
||||
Controls.Lay(cab, 600, 900);
|
||||
|
||||
Controls.Draw(cab);
|
||||
|
||||
Assert.NotNull(cab.Said);
|
||||
Assert.Contains("EU07-005", cab.Said);
|
||||
Assert.Contains("40 km/h", cab.Said);
|
||||
Assert.Equal(AutomationControlType.Pane, Controls.Peer(cab).GetAutomationControlType());
|
||||
Assert.Equal(cab.Said, Controls.Peer(cab).GetHelpText());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_cab_stopped_under_the_brakes_and_out_of_the_recording()
|
||||
{
|
||||
var cab = new CabPanel { Recording = Journey(), Time = 60 };
|
||||
var window = Controls.Show(cab, 600, 900);
|
||||
try
|
||||
{
|
||||
Controls.Draw(cab);
|
||||
Assert.Contains("0 km/h", cab.Said);
|
||||
|
||||
cab.Time = 500;
|
||||
Controls.Draw(cab);
|
||||
Assert.DoesNotContain("km/h", cab.Said);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_empty_cab_says_there_is_nothing_to_show()
|
||||
{
|
||||
var cab = new CabPanel();
|
||||
Controls.Lay(cab);
|
||||
|
||||
Controls.Draw(cab);
|
||||
|
||||
Assert.False(string.IsNullOrEmpty(cab.Said));
|
||||
}
|
||||
|
||||
// --- segmented choice ---
|
||||
|
||||
[Fact]
|
||||
public void A_segmented_choice_is_a_row_of_tabs_one_of_them_selected()
|
||||
{
|
||||
var choice = new UiKit.Segmented("Mapa", "Profil", "Rozkład");
|
||||
int? picked = null;
|
||||
choice.SelectedChanged += i => picked = i;
|
||||
var tabs = choice.GetVisualDescendants().OfType<Button>().ToList();
|
||||
if (tabs.Count == 0)
|
||||
tabs = ((Panel)choice.Child!).Children.OfType<Button>().ToList();
|
||||
|
||||
var second = Assert.IsAssignableFrom<ISelectionItemProvider>(Controls.Peer(tabs[1]));
|
||||
Assert.Equal(AutomationControlType.TabItem, Controls.Peer(tabs[1]).GetAutomationControlType());
|
||||
Assert.Null(second.SelectionContainer);
|
||||
|
||||
second.Select();
|
||||
Assert.Equal(1, picked);
|
||||
Assert.True(second.IsSelected);
|
||||
Assert.Equal(1, choice.Selected);
|
||||
|
||||
var third = Assert.IsAssignableFrom<ISelectionItemProvider>(Controls.Peer(tabs[2]));
|
||||
third.AddToSelection();
|
||||
Assert.Equal(2, choice.Selected);
|
||||
Assert.False(second.IsSelected);
|
||||
third.RemoveFromSelection();
|
||||
Assert.Equal(2, choice.Selected);
|
||||
}
|
||||
}
|
||||
75
StarterNG.Tests/Controls.cs
Normal file
75
StarterNG.Tests/Controls.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Automation.Peers;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Themes.Fluent;
|
||||
using Avalonia.Threading;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>Keys, focus, layout and drawing for the tests of controls, with no one at the keyboard.</summary>
|
||||
internal static class Controls
|
||||
{
|
||||
/// <summary>Presses a key on the control as the keyboard would; true when the control took it.</summary>
|
||||
public static bool Press(Control control, Key key, KeyModifiers modifiers = KeyModifiers.None)
|
||||
{
|
||||
var e = new KeyEventArgs { RoutedEvent = InputElement.KeyDownEvent, Key = key, KeyModifiers = modifiers, Source = control };
|
||||
control.RaiseEvent(e);
|
||||
return e.Handled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The control in a window of its own, shown, laid out and focused if it can be;
|
||||
/// themed, its parts are built from the templates the application uses.
|
||||
/// </summary>
|
||||
public static Window Show(Control control, double width = 640, double height = 720, bool themed = false)
|
||||
{
|
||||
HeadlessDrawing.Ensure();
|
||||
if (themed)
|
||||
Theme();
|
||||
var window = new Window { Width = width, Height = height, Content = control };
|
||||
window.Show();
|
||||
window.UpdateLayout();
|
||||
Settle();
|
||||
if (control.Focusable)
|
||||
control.Focus();
|
||||
return window;
|
||||
}
|
||||
|
||||
/// <summary>Lays the control out alone at the size given.</summary>
|
||||
public static void Lay(Control control, double width = 640, double height = 720)
|
||||
{
|
||||
HeadlessDrawing.Ensure();
|
||||
control.Measure(new Size(width, height));
|
||||
control.Arrange(new Rect(0, 0, width, height));
|
||||
}
|
||||
|
||||
/// <summary>Has the control draw itself once.</summary>
|
||||
public static void Draw(Control control)
|
||||
{
|
||||
HeadlessDrawing.Ensure();
|
||||
var group = new DrawingGroup();
|
||||
using var context = group.Open();
|
||||
control.Render(context);
|
||||
}
|
||||
|
||||
private static bool _themed;
|
||||
|
||||
// Where the application keeps it: given to a window alone, a slider or a number box was left without its parts.
|
||||
private static void Theme()
|
||||
{
|
||||
if (_themed)
|
||||
return;
|
||||
Avalonia.Application.Current!.Styles.Add(new FluentTheme());
|
||||
_themed = true;
|
||||
}
|
||||
|
||||
/// <summary>Runs what was left for the dispatcher to do later, such as naming a row once it is laid out.</summary>
|
||||
public static void Settle() => Dispatcher.UIThread.RunJobs();
|
||||
|
||||
public static AutomationPeer Peer(Control control) => ControlAutomationPeer.CreatePeerForElement(control);
|
||||
|
||||
public static RoutedEventArgs Click() => new(Button.ClickEvent);
|
||||
}
|
||||
376
StarterNG.Tests/DialogControlsTests.cs
Normal file
376
StarterNG.Tests/DialogControlsTests.cs
Normal file
@@ -0,0 +1,376 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Automation;
|
||||
using Avalonia.Automation.Peers;
|
||||
using Avalonia.Automation.Provider;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.VisualTree;
|
||||
using StarterNG.Controls;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Windows opened over another, searches and the starter's own controls as someone at the
|
||||
/// keyboard with a screen reader meets them, in windows built as the application builds them.
|
||||
/// </summary>
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class DialogControlsTests
|
||||
{
|
||||
static DialogControlsTests()
|
||||
{
|
||||
HeadlessDrawing.Ensure();
|
||||
DialogKeyboard.Install();
|
||||
ScreenReaderNames.Install();
|
||||
}
|
||||
|
||||
private static (Window Owner, Window Dialog) Dialog(Control content, bool escapeCloses = true)
|
||||
{
|
||||
var owner = new Window();
|
||||
owner.Show();
|
||||
var dialog = new Window { Width = 300, Height = 200, Content = content };
|
||||
DialogKeyboard.SetEscapeCloses(dialog, escapeCloses);
|
||||
_ = dialog.ShowDialog(owner);
|
||||
// Headless a window says it opened before it is given its owner; it says so again once it has one.
|
||||
Assert.Same(owner, dialog.Owner);
|
||||
dialog.RaiseEvent(new Avalonia.Interactivity.RoutedEventArgs(Window.WindowOpenedEvent));
|
||||
Controls.Settle();
|
||||
return (owner, dialog);
|
||||
}
|
||||
|
||||
// --- windows over another ---
|
||||
|
||||
[Fact]
|
||||
public void A_dialog_opens_on_its_default_button_and_esc_closes_it()
|
||||
{
|
||||
var other = new Button { Content = "Nie" };
|
||||
var yes = new Button { Content = "Tak", IsDefault = true };
|
||||
var (owner, dialog) = Dialog(new StackPanel { Children = { other, yes } });
|
||||
bool closed = false;
|
||||
dialog.Closed += (_, _) => closed = true;
|
||||
|
||||
Assert.True(yes.IsFocused);
|
||||
Assert.False(Controls.Press(dialog, Key.Escape, KeyModifiers.Shift));
|
||||
Assert.True(Controls.Press(dialog, Key.Escape));
|
||||
Assert.True(closed);
|
||||
owner.Close();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_a_default_button_focus_goes_to_the_first_control()
|
||||
{
|
||||
var first = new TextBox();
|
||||
var (owner, dialog) = Dialog(new StackPanel { Children = { first, new Button { Content = "OK" } } });
|
||||
|
||||
Assert.True(first.IsFocused);
|
||||
dialog.Close();
|
||||
owner.Close();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_window_that_placed_the_focus_itself_keeps_it()
|
||||
{
|
||||
var first = new Button { Content = "1" };
|
||||
var chosen = new Button { Content = "2" };
|
||||
var (owner, dialog) = Dialog(new StackPanel { Children = { first, chosen } });
|
||||
chosen.Focus();
|
||||
Assert.False(first.IsFocused);
|
||||
|
||||
DialogKeyboard.FocusFirst(dialog);
|
||||
|
||||
Assert.True(chosen.IsFocused);
|
||||
dialog.Close();
|
||||
owner.Close();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Esc_does_not_close_a_window_that_stays_beside_the_main_one()
|
||||
{
|
||||
var (owner, dialog) = Dialog(new Button { Content = "OK" }, escapeCloses: false);
|
||||
bool closed = false;
|
||||
dialog.Closed += (_, _) => closed = true;
|
||||
|
||||
Assert.False(DialogKeyboard.GetEscapeCloses(dialog));
|
||||
Assert.False(Controls.Press(dialog, Key.Escape));
|
||||
Assert.False(closed);
|
||||
dialog.Close();
|
||||
owner.Close();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Tab_with_only_the_window_focused_starts_from_the_first_control()
|
||||
{
|
||||
var first = new Button { Content = "1" };
|
||||
// Opened with nothing to focus, its controls put in afterwards.
|
||||
var (owner, dialog) = Dialog(new TextBlock { Text = "…" });
|
||||
dialog.Content = new StackPanel { Children = { first, new Button { Content = "2" } } };
|
||||
dialog.UpdateLayout();
|
||||
Assert.False(first.IsFocused);
|
||||
|
||||
Assert.True(Controls.Press(dialog, Key.Tab));
|
||||
Assert.True(first.IsFocused);
|
||||
dialog.Close();
|
||||
owner.Close();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_window_of_its_own_is_left_to_its_own_ways()
|
||||
{
|
||||
var button = new Button { Content = "1" };
|
||||
var window = Controls.Show(button);
|
||||
|
||||
Assert.False(Controls.Press(window, Key.Escape));
|
||||
window.Close();
|
||||
}
|
||||
|
||||
// --- searches ---
|
||||
|
||||
[Fact]
|
||||
public void A_search_says_how_many_entries_are_left_once_typing_pauses()
|
||||
{
|
||||
var box = new TextBox();
|
||||
var announcer = new Announcer { Child = box };
|
||||
var window = Controls.Show(announcer);
|
||||
try
|
||||
{
|
||||
var teller = new SearchResultsTeller(box, () => 3);
|
||||
box.Focus();
|
||||
box.Text = "EU07";
|
||||
teller.Changed();
|
||||
Thread.Sleep(SearchResultsTeller.Pause + TimeSpan.FromMilliseconds(300));
|
||||
Controls.Settle();
|
||||
|
||||
Assert.NotNull(announcer.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_empty_search_or_one_left_says_nothing()
|
||||
{
|
||||
var box = new TextBox();
|
||||
var elsewhere = new Button { Content = "x" };
|
||||
var announcer = new Announcer { Child = new StackPanel { Children = { box, elsewhere } } };
|
||||
var window = Controls.Show(announcer);
|
||||
try
|
||||
{
|
||||
var teller = new SearchResultsTeller(box, () => 3);
|
||||
box.Focus();
|
||||
box.Text = " ";
|
||||
teller.Changed();
|
||||
Thread.Sleep(SearchResultsTeller.Pause + TimeSpan.FromMilliseconds(300));
|
||||
Controls.Settle();
|
||||
Assert.Null(announcer.Message);
|
||||
|
||||
box.Text = "EU07";
|
||||
elsewhere.Focus();
|
||||
teller.Changed();
|
||||
Thread.Sleep(SearchResultsTeller.Pause + TimeSpan.FromMilliseconds(300));
|
||||
Controls.Settle();
|
||||
Assert.Null(announcer.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
// --- tree entries ---
|
||||
|
||||
[Fact]
|
||||
public void Every_part_of_a_row_tells_whether_the_entry_is_open()
|
||||
{
|
||||
var words = ExpandableTreeViewItem.StateWords;
|
||||
ExpandableTreeViewItem.StateWords = s => s switch
|
||||
{
|
||||
ExpandCollapseState.Expanded => "rozwinięte",
|
||||
ExpandCollapseState.Collapsed => "zwinięte",
|
||||
_ => null
|
||||
};
|
||||
var child = new ExpandableTreeViewItem { Header = "test32" };
|
||||
var group = new ExpandableTreeViewItem { Header = "Całkowo", Items = { child } };
|
||||
AutomationProperties.SetName(group, "Całkowo");
|
||||
var tree = new TreeView { Items = { group } };
|
||||
var window = Controls.Show(tree, themed: true);
|
||||
try
|
||||
{
|
||||
var row = group.GetVisualDescendants().OfType<Control>().First(c => c.Name == "PART_LayoutRoot");
|
||||
Assert.Equal("zwinięte", AutomationProperties.GetHelpText(row));
|
||||
Assert.Equal("Całkowo", AutomationProperties.GetName(row));
|
||||
|
||||
var peer = Controls.Peer(group);
|
||||
((IExpandCollapseProvider)peer).Expand();
|
||||
Controls.Settle();
|
||||
Assert.Equal("rozwinięte", AutomationProperties.GetHelpText(row));
|
||||
|
||||
AutomationProperties.SetName(group, "Całkowo i okolice");
|
||||
Assert.Equal("Całkowo i okolice", AutomationProperties.GetName(row));
|
||||
|
||||
group.Header = "Całkowo 2";
|
||||
Controls.Settle();
|
||||
window.UpdateLayout();
|
||||
Assert.Same(group, child.ReadableParent);
|
||||
Assert.Same(peer, Controls.Peer(child).GetParent());
|
||||
|
||||
var leafRow = child.GetVisualDescendants().OfType<Control>().First(c => c.Name == "PART_LayoutRoot");
|
||||
Assert.Null(AutomationProperties.GetHelpText(leafRow));
|
||||
|
||||
tree.Items.Clear();
|
||||
Controls.Settle();
|
||||
}
|
||||
finally
|
||||
{
|
||||
ExpandableTreeViewItem.StateWords = words;
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
// --- sliders and number boxes ---
|
||||
|
||||
[Fact]
|
||||
public void The_track_and_knob_of_a_slider_are_named_with_its_value()
|
||||
{
|
||||
var fog = new ReadableSlider { Minimum = 0, Maximum = 1000, Value = 500, ValueText = "2,4 km" };
|
||||
AutomationProperties.SetName(fog, "Widoczność");
|
||||
var window = Controls.Show(fog, themed: true);
|
||||
try
|
||||
{
|
||||
var track = fog.GetVisualDescendants().OfType<Avalonia.Controls.Primitives.Track>().Single();
|
||||
Assert.Equal("Widoczność: 2,4 km", AutomationProperties.GetName(track));
|
||||
|
||||
fog.ValueText = "3 km";
|
||||
Assert.Equal("Widoczność: 3 km", AutomationProperties.GetName(track));
|
||||
|
||||
var value = Assert.IsAssignableFrom<IValueProvider>(Controls.Peer(fog));
|
||||
Assert.False(value.IsReadOnly);
|
||||
Assert.Equal("Slider", Controls.Peer(fog).GetClassName());
|
||||
Assert.Throws<ArgumentException>(() => value.SetValue("duĹĽo"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_number_box_gives_its_name_to_the_text_inside_and_its_arrows_say_what_they_do()
|
||||
{
|
||||
var box = new NumericUpDown { Value = 3 };
|
||||
AutomationProperties.SetName(box, "Liczba wagonĂłw");
|
||||
var window = Controls.Show(box, themed: true);
|
||||
try
|
||||
{
|
||||
var text = box.GetVisualDescendants().OfType<TextBox>().Single();
|
||||
Assert.Equal("Liczba wagonĂłw", AutomationProperties.GetName(text));
|
||||
|
||||
var arrows = box.GetVisualDescendants().OfType<Control>()
|
||||
.Where(c => c.Name is "PART_IncreaseButton" or "PART_DecreaseButton").ToList();
|
||||
Assert.NotEmpty(arrows);
|
||||
Assert.All(arrows, a => Assert.False(KeyboardNavigation.GetIsTabStop(a)));
|
||||
Assert.All(arrows, a => Assert.False(string.IsNullOrEmpty(AutomationProperties.GetName(a))));
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_picker_is_reached_through_its_button_named_with_the_label_and_value()
|
||||
{
|
||||
var date = new DatePicker { SelectedDate = new DateTimeOffset(2026, 11, 15, 0, 0, 0, TimeSpan.Zero) };
|
||||
var time = new TimePicker { SelectedTime = new TimeSpan(7, 5, 0) };
|
||||
AutomationProperties.SetName(date, "Data");
|
||||
AutomationProperties.SetName(time, "Godzina");
|
||||
var window = Controls.Show(new StackPanel { Children = { date, time } }, themed: true);
|
||||
try
|
||||
{
|
||||
var dateButton = date.GetVisualDescendants().OfType<Button>().First(b => b.Name == "PART_FlyoutButton");
|
||||
var timeButton = time.GetVisualDescendants().OfType<Button>().First(b => b.Name == "PART_FlyoutButton");
|
||||
Assert.StartsWith("Data", AutomationProperties.GetName(dateButton));
|
||||
Assert.StartsWith("Godzina", AutomationProperties.GetName(timeButton));
|
||||
|
||||
time.SelectedTime = new TimeSpan(8, 0, 0);
|
||||
Assert.StartsWith("Godzina", AutomationProperties.GetName(timeButton));
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_list_says_its_new_choice_when_the_arrows_change_it()
|
||||
{
|
||||
var combo = new ComboBox { ItemsSource = new[] { "Niska", "Ĺšrednia", "Wysoka" }, SelectedIndex = 0 };
|
||||
var announcer = new Announcer { Child = combo };
|
||||
var window = Controls.Show(announcer, themed: true);
|
||||
try
|
||||
{
|
||||
combo.Focus();
|
||||
combo.SelectedIndex = 2;
|
||||
|
||||
Assert.Equal("Wysoka", announcer.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
// --- settings sections ---
|
||||
|
||||
private static SettingsSection Section() => new()
|
||||
{
|
||||
Template = new FuncControlTemplate<SettingsSection>((_, scope) =>
|
||||
{
|
||||
var reset = new Button { Name = "PART_Reset" };
|
||||
scope.Register(reset.Name, reset);
|
||||
return reset;
|
||||
})
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void A_sections_reset_button_says_which_section_it_puts_back()
|
||||
{
|
||||
var section = Section();
|
||||
section.Header = "Grafika";
|
||||
section.ResetLabel = "Przywróć";
|
||||
SettingsSection? asked = null;
|
||||
section.ResetRequested += s => asked = s;
|
||||
Controls.Lay(section);
|
||||
section.ApplyTemplate();
|
||||
var reset = (Button)section.GetVisualChildren().Single();
|
||||
|
||||
Assert.Equal("Przywróć: Grafika", AutomationProperties.GetName(reset));
|
||||
section.Header = "Dźwięk";
|
||||
Assert.Equal("Przywróć: Dźwięk", AutomationProperties.GetName(reset));
|
||||
|
||||
section.ResetLabel = null;
|
||||
section.Header = null;
|
||||
Assert.True(string.IsNullOrEmpty(AutomationProperties.GetName(reset)));
|
||||
|
||||
reset.RaiseEvent(Controls.Click());
|
||||
Assert.Same(section, asked);
|
||||
|
||||
section.Template = Section().Template;
|
||||
section.ApplyTemplate();
|
||||
Assert.Null(section.ToggleKey);
|
||||
Assert.Null(section.Toggle);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_sections_list_of_levels_is_named_as_the_level_of_that_section()
|
||||
{
|
||||
var level = new ComboBox();
|
||||
var section = new SettingsSection { Level = level, Header = "Grafika", ToggleKey = "shadows", Toggle = new CheckBox() };
|
||||
|
||||
Assert.EndsWith("Grafika", AutomationProperties.GetName(level));
|
||||
Assert.Same(level, section.Level);
|
||||
Assert.Equal("shadows", section.ToggleKey);
|
||||
}
|
||||
}
|
||||
27
StarterNG.Tests/HeadlessDrawing.cs
Normal file
27
StarterNG.Tests/HeadlessDrawing.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Headless;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Text and drawing for tests of controls that draw themselves: the headless platform
|
||||
/// with its stand-in fonts, set up once, on the thread the control tests run on.
|
||||
/// </summary>
|
||||
public static class HeadlessDrawing
|
||||
{
|
||||
private static readonly object Gate = new();
|
||||
private static bool _ready;
|
||||
|
||||
public static void Ensure()
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
if (_ready)
|
||||
return;
|
||||
AppBuilder.Configure<Avalonia.Application>()
|
||||
.UseHeadless(new AvaloniaHeadlessPlatformOptions { UseHeadlessDrawing = true })
|
||||
.SetupWithoutStarting();
|
||||
_ready = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
105
StarterNG.Tests/KeyBindingsTabTests.cs
Normal file
105
StarterNG.Tests/KeyBindingsTabTests.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using Avalonia.Automation;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.VisualTree;
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Classes;
|
||||
using StarterNG.Controls;
|
||||
using StarterNG.Tests.Fakes;
|
||||
using StarterNG.Views;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>The key bindings as someone at the keyboard binds a key: the list of commands, and the keyboard drawn beside it walked with the arrows.</summary>
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class KeyBindingsTabTests
|
||||
{
|
||||
static KeyBindingsTabTests()
|
||||
{
|
||||
if (AppServices.CurrentOrNull is null)
|
||||
{
|
||||
var installation = new TestInstallation(new InMemoryFileSystem());
|
||||
AppServices.Initialize(installation.Paths, installation.Files, installation.Clock, installation.Environment);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed record Shown(Window Window, KeyBindingsTab Tab, Grid Host, Announcer Announcer) : IDisposable
|
||||
{
|
||||
public List<Border> Caps() =>
|
||||
Host.GetVisualDescendants().OfType<Border>().Where(b => b.Classes.Contains("KeyCap")).ToList();
|
||||
|
||||
public void Dispose() => Window.Close();
|
||||
}
|
||||
|
||||
private static Shown Open()
|
||||
{
|
||||
KeyboardConfig.Instance.Parse("hornhighactivate a\nhornlowactivate none\n");
|
||||
var host = new Grid();
|
||||
var search = new TextBox();
|
||||
var tab = new KeyBindingsTab(host, search);
|
||||
var announcer = new Announcer { Child = new DockPanel { Children = { search, host } } };
|
||||
var window = Controls.Show(announcer, 1600, 1000, themed: true);
|
||||
window.AddHandler(InputElement.KeyDownEvent, tab.OnKeyDown, Avalonia.Interactivity.RoutingStrategies.Tunnel);
|
||||
tab.Build();
|
||||
window.UpdateLayout();
|
||||
Controls.Settle();
|
||||
return new Shown(window, tab, host, announcer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_arrows_walk_the_keys_as_they_lie()
|
||||
{
|
||||
using var shown = Open();
|
||||
var caps = shown.Caps();
|
||||
Assert.True(caps.Count > 50);
|
||||
Assert.All(caps, c => Assert.False(string.IsNullOrEmpty(AutomationProperties.GetName(c))));
|
||||
|
||||
caps[0].Focus();
|
||||
Assert.True(Controls.Press(caps[0], Key.Right));
|
||||
Assert.True(caps[1].IsFocused);
|
||||
Assert.True(Controls.Press(caps[1], Key.Left));
|
||||
Assert.True(caps[0].IsFocused);
|
||||
Assert.True(Controls.Press(caps[0], Key.Left));
|
||||
Assert.True(caps[0].IsFocused);
|
||||
|
||||
Assert.True(Controls.Press(caps[0], Key.End));
|
||||
Assert.True(caps[^1].IsFocused);
|
||||
Assert.True(Controls.Press(caps[^1], Key.Right));
|
||||
Assert.True(caps[^1].IsFocused);
|
||||
Assert.True(Controls.Press(caps[^1], Key.Home));
|
||||
Assert.True(caps[0].IsFocused);
|
||||
|
||||
Assert.True(Controls.Press(caps[0], Key.Down));
|
||||
var below = caps.Single(c => c.IsFocused);
|
||||
Assert.NotSame(caps[0], below);
|
||||
Assert.True(Controls.Press(below, Key.Up));
|
||||
var above = caps.Single(c => c.IsFocused);
|
||||
Assert.NotSame(below, above);
|
||||
Assert.True(Controls.Press(above, Key.Up));
|
||||
Assert.True(above.IsFocused);
|
||||
|
||||
Assert.False(Controls.Press(caps[0], Key.F24));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_binding_takes_the_next_key_pressed_and_esc_gives_up_waiting()
|
||||
{
|
||||
using var shown = Open();
|
||||
Assert.True(shown.Tab.ShownCount >= 2);
|
||||
var combos = shown.Host.GetVisualDescendants().OfType<Button>()
|
||||
.Where(b => b.Classes.Contains("Flat") && b.MinWidth == 140).ToList();
|
||||
Assert.NotEmpty(combos);
|
||||
|
||||
combos[0].RaiseEvent(Controls.Click());
|
||||
Assert.True(shown.Tab.IsCapturing);
|
||||
Assert.True(Controls.Press(combos[0], Key.Escape));
|
||||
Assert.False(shown.Tab.IsCapturing);
|
||||
|
||||
combos[0].RaiseEvent(Controls.Click());
|
||||
Assert.False(Controls.Press(combos[0], Key.LeftShift));
|
||||
Assert.True(shown.Tab.IsCapturing);
|
||||
Assert.True(Controls.Press(combos[0], Key.J, KeyModifiers.Control | KeyModifiers.Shift));
|
||||
Assert.False(shown.Tab.IsCapturing);
|
||||
Assert.True(KeyboardConfig.Instance.Dirty);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia.Headless" Version="12.1.4" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
|
||||
175
StarterNG.Tests/TapeViewTests.cs
Normal file
175
StarterNG.Tests/TapeViewTests.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using Avalonia.Automation.Peers;
|
||||
using Avalonia.Automation.Provider;
|
||||
using Avalonia.Input;
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Domain.Tapes;
|
||||
using StarterNG.Tests.Fakes;
|
||||
using StarterNG.Views.Tapes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>A recorded trip walked from the keyboard and read by a screen reader, on both ways of drawing it.</summary>
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class TapeViewTests
|
||||
{
|
||||
// The electronic tape writes its legend in the starter's language.
|
||||
static TapeViewTests()
|
||||
{
|
||||
if (AppServices.CurrentOrNull is null)
|
||||
{
|
||||
var installation = new TestInstallation(new InMemoryFileSystem());
|
||||
AppServices.Initialize(installation.Paths, installation.Files, installation.Clock, installation.Environment);
|
||||
}
|
||||
}
|
||||
|
||||
public static TheoryData<string> Views => new() { "hasler", "electronic" };
|
||||
|
||||
private static TapeView View(string kind) => kind == "hasler" ? new HaslerTapeView() : new ElectronicTapeView();
|
||||
|
||||
/// <summary>Two minutes, a sample a second, 15 m a second; running from 10 s to 110 s, braking after 100 s.</summary>
|
||||
private static HaslerTape Trip() =>
|
||||
new(Enumerable.Range(0, 121)
|
||||
.Select(i => new TapeSample(i, i is > 10 and < 110 ? 54 : 0, i * 15.0, i > 100 ? 2 : 0, 5,
|
||||
i < 50 ? 300 : 0, i == 70))
|
||||
.ToList());
|
||||
|
||||
private static (TapeView View, List<TapeSample?> Hovered) Walking(string kind, bool byDistance = true)
|
||||
{
|
||||
var view = View(kind);
|
||||
view.Tape = Trip();
|
||||
view.ByDistance = byDistance;
|
||||
var hovered = new List<TapeSample?>();
|
||||
view.Hovered += s => hovered.Add(s);
|
||||
return (view, hovered);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Views))]
|
||||
public void The_trip_is_a_slider_read_as_the_moment_under_the_cursor(string kind)
|
||||
{
|
||||
var view = View(kind);
|
||||
var peer = Controls.Peer(view);
|
||||
var value = Assert.IsAssignableFrom<IValueProvider>(peer);
|
||||
|
||||
view.Spoken = "10:00:12, km 0,2, 54 km/h";
|
||||
|
||||
Assert.Equal(AutomationControlType.Slider, peer.GetAutomationControlType());
|
||||
Assert.True(peer.IsContentElement());
|
||||
Assert.True(peer.IsControlElement());
|
||||
Assert.Equal("10:00:12, km 0,2, 54 km/h", value.Value);
|
||||
Assert.True(value.IsReadOnly);
|
||||
Assert.Throws<InvalidOperationException>(() => value.SetValue("x"));
|
||||
|
||||
view.Spoken = "10:00:13, km 0,2, 54 km/h";
|
||||
Assert.Equal("10:00:13, km 0,2, 54 km/h", value.Value);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Views))]
|
||||
public void The_first_arrow_starts_at_the_beginning_and_the_next_go_a_hundred_metres(string kind)
|
||||
{
|
||||
var (view, hovered) = Walking(kind);
|
||||
|
||||
Assert.True(Controls.Press(view, Key.Right));
|
||||
Assert.Equal(0, hovered[^1]!.Value.Time);
|
||||
|
||||
Assert.True(Controls.Press(view, Key.Right));
|
||||
Assert.InRange(hovered[^1]!.Value.DistanceM, TapeView.DistanceStep - 15, TapeView.DistanceStep + 15);
|
||||
|
||||
Assert.True(Controls.Press(view, Key.Right, KeyModifiers.Control));
|
||||
Assert.True(hovered[^1]!.Value.DistanceM >= TapeView.DistanceStep * TapeView.CtrlTimes - 15);
|
||||
|
||||
Assert.True(Controls.Press(view, Key.Left, KeyModifiers.Control));
|
||||
Assert.True(hovered[^1]!.Value.DistanceM <= TapeView.DistanceStep + 15);
|
||||
|
||||
Assert.True(Controls.Press(view, Key.End));
|
||||
Assert.Equal(120, hovered[^1]!.Value.Time);
|
||||
Assert.True(Controls.Press(view, Key.Right));
|
||||
Assert.Equal(120, hovered[^1]!.Value.Time);
|
||||
|
||||
Assert.True(Controls.Press(view, Key.Home));
|
||||
Assert.Equal(0, hovered[^1]!.Value.Time);
|
||||
Assert.True(Controls.Press(view, Key.Left));
|
||||
Assert.Equal(0, hovered[^1]!.Value.Time);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Views))]
|
||||
public void By_time_an_arrow_goes_ten_seconds(string kind)
|
||||
{
|
||||
var (view, hovered) = Walking(kind, byDistance: false);
|
||||
|
||||
Controls.Press(view, Key.Left);
|
||||
Assert.Equal(0, hovered[^1]!.Value.Time);
|
||||
Controls.Press(view, Key.Right);
|
||||
Assert.Equal(TapeView.TimeStep, hovered[^1]!.Value.Time);
|
||||
Controls.Press(view, Key.Left);
|
||||
Assert.Equal(0, hovered[^1]!.Value.Time);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Views))]
|
||||
public void Enter_picks_the_sample_the_keys_stand_at_once_they_have_moved(string kind)
|
||||
{
|
||||
var (view, _) = Walking(kind);
|
||||
TapeSample? picked = null;
|
||||
view.Picked += s => picked = s;
|
||||
|
||||
Assert.False(Controls.Press(view, Key.Enter));
|
||||
Assert.Null(picked);
|
||||
|
||||
Controls.Press(view, Key.End);
|
||||
Assert.True(Controls.Press(view, Key.Enter));
|
||||
Assert.Equal(120, picked!.Value.Time);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Views))]
|
||||
public void A_new_trip_starts_the_keys_from_its_beginning(string kind)
|
||||
{
|
||||
var (view, hovered) = Walking(kind);
|
||||
Controls.Press(view, Key.End);
|
||||
|
||||
view.Tape = Trip();
|
||||
Controls.Press(view, Key.Right);
|
||||
|
||||
Assert.Equal(0, hovered[^1]!.Value.Time);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Views))]
|
||||
public void Other_keys_and_an_empty_trip_are_left_alone(string kind)
|
||||
{
|
||||
var (view, hovered) = Walking(kind);
|
||||
var empty = View(kind);
|
||||
var blank = View(kind);
|
||||
blank.Tape = new HaslerTape([]);
|
||||
|
||||
Assert.False(Controls.Press(view, Key.A));
|
||||
Assert.False(Controls.Press(empty, Key.Right));
|
||||
Assert.False(Controls.Press(blank, Key.Right));
|
||||
Assert.Empty(hovered);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Views))]
|
||||
public void The_trip_draws_with_and_without_the_focus(string kind)
|
||||
{
|
||||
var (view, _) = Walking(kind);
|
||||
view.Mark = 60;
|
||||
var window = Controls.Show(view, 1200, 600);
|
||||
try
|
||||
{
|
||||
Assert.True(view.Focusable);
|
||||
view.Focus();
|
||||
Controls.Press(view, Key.Right);
|
||||
Controls.Settle();
|
||||
window.Focus();
|
||||
Controls.Settle();
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user