Fixed Dialog/MessageBox tests

This commit is contained in:
Tig
2024-10-02 13:32:32 -06:00
parent a33ef5ad9a
commit 1cfe81a28a
6 changed files with 47 additions and 27 deletions

View File

@@ -344,8 +344,8 @@ public partial class View // Drawing APIs
{
DrawHotString (
text,
Enabled ? GetHotNormalColor () : ColorScheme.Disabled,
Enabled ? GetNormalColor () : ColorScheme.Disabled
Enabled ? GetHotNormalColor () : ColorScheme!.Disabled,
Enabled ? GetNormalColor () : ColorScheme!.Disabled
);
}
}

View File

@@ -47,7 +47,7 @@ public partial class View // Keyboard APIs
/// opened.
/// </para>
/// <para>
/// View subclasses can use< see cref="View.AddCommand(Command,Func{CommandContext,System.Nullable{bool}})"/> to
/// View subclasses can use <see cref="View.AddCommand(Command,Func{CommandContext,System.Nullable{bool}})"/> to
/// define the
/// behavior of the hot key.
/// </para>

View File

@@ -130,8 +130,10 @@ public class RadioGroup : View, IDesignable, IOrientation
return true;
});
_orientationHelper = new (this);
_orientationHelper.Orientation = Orientation.Vertical;
_orientationHelper = new (this)
{
Orientation = Orientation.Vertical
};
_orientationHelper.OrientationChanging += (sender, e) => OrientationChanging?.Invoke (this, e);
_orientationHelper.OrientationChanged += (sender, e) => OrientationChanged?.Invoke (this, e);
@@ -181,7 +183,7 @@ public class RadioGroup : View, IDesignable, IOrientation
/// </remarks>
public bool DoubleClickAccepts { get; set; } = true;
private void RadioGroup_MouseClick (object sender, MouseEventEventArgs e)
private void RadioGroup_MouseClick (object? sender, MouseEventEventArgs e)
{
if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked))
{
@@ -191,13 +193,13 @@ public class RadioGroup : View, IDesignable, IOrientation
int pos = Orientation == Orientation.Horizontal ? viewportX : viewportY;
int rCount = Orientation == Orientation.Horizontal
? _horizontal.Last ().pos + _horizontal.Last ().length
? _horizontal!.Last ().pos + _horizontal!.Last ().length
: _radioLabels.Count;
if (pos < rCount)
{
int c = Orientation == Orientation.Horizontal
? _horizontal.FindIndex (x => x.pos <= viewportX && x.pos + x.length - 2 >= viewportX)
? _horizontal!.FindIndex (x => x.pos <= viewportX && x.pos + x.length - 2 >= viewportX)
: viewportY;
if (c > -1)
@@ -229,7 +231,7 @@ public class RadioGroup : View, IDesignable, IOrientation
}
private List<(int pos, int length)> _horizontal;
private List<(int pos, int length)>? _horizontal;
private int _horizontalSpace = 2;
/// <summary>
@@ -344,7 +346,7 @@ public class RadioGroup : View, IDesignable, IOrientation
break;
case Orientation.Horizontal:
Move (_horizontal [i].pos, 0);
Move (_horizontal! [i].pos, 0);
break;
}
@@ -366,7 +368,7 @@ public class RadioGroup : View, IDesignable, IOrientation
{
Application.Driver?.SetAttribute (
HasFocus
? ColorScheme.HotFocus
? ColorScheme!.HotFocus
: GetHotNormalColor ()
);
}
@@ -388,7 +390,7 @@ public class RadioGroup : View, IDesignable, IOrientation
{
Application.Driver?.SetAttribute (
HasFocus
? ColorScheme.HotFocus
? ColorScheme!.HotFocus
: GetHotNormalColor ()
);
}
@@ -424,10 +426,10 @@ public class RadioGroup : View, IDesignable, IOrientation
private readonly OrientationHelper _orientationHelper;
/// <inheritdoc/>
public event EventHandler<CancelEventArgs<Orientation>> OrientationChanging;
public event EventHandler<CancelEventArgs<Orientation>>? OrientationChanging;
/// <inheritdoc/>
public event EventHandler<EventArgs<Orientation>> OrientationChanged;
public event EventHandler<EventArgs<Orientation>>? OrientationChanged;
/// <summary>Called when <see cref="Orientation"/> has changed.</summary>
/// <param name="newOrientation"></param>
@@ -469,7 +471,7 @@ public class RadioGroup : View, IDesignable, IOrientation
break;
case Orientation.Horizontal:
if (_horizontal.Count > 0)
if (_horizontal!.Count > 0)
{
x = _horizontal [Cursor].pos;
}
@@ -490,7 +492,7 @@ public class RadioGroup : View, IDesignable, IOrientation
// TODO: This should use StateEventArgs<int> and should be cancelable.
/// <summary>Invoked when the selected radio label has changed.</summary>
public event EventHandler<SelectedItemChangedArgs> SelectedItemChanged;
public event EventHandler<SelectedItemChangedArgs>? SelectedItemChanged;
private bool MoveDownRight ()
{
@@ -523,7 +525,7 @@ public class RadioGroup : View, IDesignable, IOrientation
return false;
}
private void RadioGroup_LayoutStarted (object sender, EventArgs e) { SetContentSize (); }
private void RadioGroup_LayoutStarted (object? sender, EventArgs e) { SetContentSize (); }
private void SetContentSize ()
{

View File

@@ -697,7 +697,7 @@ public class MainLoopTests
{
Assert.Null (btn);
Assert.Equal (zero, total);
Assert.True (btnLaunch.NewKeyDownEvent (Key.Space));
Assert.False (btnLaunch.NewKeyDownEvent (Key.Space));
if (btn == null)
{
@@ -714,7 +714,7 @@ public class MainLoopTests
{
Assert.Equal (clickMe, btn.Text);
Assert.Equal (zero, total);
Assert.True (btn.NewKeyDownEvent (Key.Space));
Assert.False (btn.NewKeyDownEvent (Key.Space));
Assert.Equal (cancel, btn.Text);
Assert.Equal (one, total);
}

View File

@@ -1095,7 +1095,7 @@ public class DialogTests
if (iterations == 0)
{
Assert.True (btn1.NewKeyDownEvent (Key.Space));
Assert.False (btn1.NewKeyDownEvent (Key.Space));
}
else if (iterations == 1)
{
@@ -1110,7 +1110,7 @@ public class DialogTests
└───────────────────────┘";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.True (btn2.NewKeyDownEvent (Key.Space));
Assert.False (btn2.NewKeyDownEvent (Key.Space));
}
else if (iterations == 2)
{
@@ -1127,13 +1127,13 @@ public class DialogTests
_output
);
Assert.True (Top!.NewKeyDownEvent (Key.Enter));
Assert.False (Top!.NewKeyDownEvent (Key.Enter));
}
else if (iterations == 3)
{
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.True (btn3.NewKeyDownEvent (Key.Space));
Assert.False (btn3.NewKeyDownEvent (Key.Space));
}
else if (iterations == 4)
{

View File

@@ -11,12 +11,14 @@ public class MessageBoxTests
[Fact]
[AutoInitShutdown]
public void KeyBindings_Enter_Causes_Focused_Button_Click ()
public void KeyBindings_Enter_Causes_Focused_Button_Click_No_Accept ()
{
int result = -1;
var iteration = 0;
int btnAcceptCount = 0;
Application.Iteration += (s, a) =>
{
iteration++;
@@ -32,6 +34,12 @@ public class MessageBoxTests
case 2:
// Tab to btn2
Application.OnKeyDown (Key.Tab);
Button btn = Application.Navigation!.GetFocused () as Button;
btn.Accept += (sender, e) => { btnAcceptCount++; };
// Click
Application.OnKeyDown (Key.Enter);
break;
@@ -44,7 +52,8 @@ public class MessageBoxTests
};
Application.Run ().Dispose ();
Assert.Equal (1, result);
Assert.Equal (0, result);
Assert.Equal (btnAcceptCount, 1);
}
[Fact]
@@ -85,12 +94,14 @@ public class MessageBoxTests
[Fact]
[AutoInitShutdown]
public void KeyBindings_Space_Causes_Focused_Button_Click ()
public void KeyBindings_Space_Causes_Focused_Button_Click_No_Accept ()
{
int result = -1;
var iteration = 0;
int btnAcceptCount = 0;
Application.Iteration += (s, a) =>
{
iteration++;
@@ -106,6 +117,11 @@ public class MessageBoxTests
case 2:
// Tab to btn2
Application.OnKeyDown (Key.Tab);
Button btn = Application.Navigation!.GetFocused () as Button;
btn.Accept += (sender, e) => { btnAcceptCount++; };
Application.OnKeyDown (Key.Space);
break;
@@ -118,7 +134,9 @@ public class MessageBoxTests
};
Application.Run ().Dispose ();
Assert.Equal (1, result);
Assert.Equal (0, result);
Assert.Equal (btnAcceptCount, 1);
}
[Theory]