Add comprehensive test coverage for many controls (#737)
Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Headless;
|
||||
using Avalonia.Headless.XUnit;
|
||||
using Avalonia.Input;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace HeadlessTest.Ursa.Controls.TimeBoxTests;
|
||||
|
||||
public class TimeBoxInputTests
|
||||
{
|
||||
[AvaloniaFact]
|
||||
public void TimeBox_Should_Handle_Focus()
|
||||
{
|
||||
var window = new Window();
|
||||
var timeBox = new TimeBox();
|
||||
window.Content = timeBox;
|
||||
window.Show();
|
||||
|
||||
timeBox.Focus();
|
||||
|
||||
// Control should accept focus
|
||||
Assert.True(timeBox.IsFocused);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void TimeBox_Should_Handle_Tab_Key_Press()
|
||||
{
|
||||
var window = new Window();
|
||||
var timeBox = new TimeBox();
|
||||
window.Content = timeBox;
|
||||
window.Show();
|
||||
|
||||
timeBox.Focus();
|
||||
|
||||
// Simulate tab key press to move between sections
|
||||
window.KeyPressQwerty(PhysicalKey.Tab, RawInputModifiers.None);
|
||||
|
||||
// Control should remain focused (internal section navigation)
|
||||
Assert.True(timeBox.IsFocused);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void TimeBox_Should_Handle_Arrow_Key_Press()
|
||||
{
|
||||
var window = new Window();
|
||||
var timeBox = new TimeBox();
|
||||
window.Content = timeBox;
|
||||
window.Show();
|
||||
|
||||
timeBox.Focus();
|
||||
|
||||
// Simulate arrow key navigation
|
||||
window.KeyPressQwerty(PhysicalKey.ArrowRight, RawInputModifiers.None);
|
||||
window.KeyPressQwerty(PhysicalKey.ArrowLeft, RawInputModifiers.None);
|
||||
|
||||
// Control should remain focused and handle the navigation
|
||||
Assert.True(timeBox.IsFocused);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void TimeBox_Should_Handle_Backspace_Key_Press()
|
||||
{
|
||||
var window = new Window();
|
||||
var timeBox = new TimeBox();
|
||||
window.Content = timeBox;
|
||||
window.Show();
|
||||
|
||||
timeBox.Focus();
|
||||
|
||||
// Simulate backspace key press
|
||||
window.KeyPressQwerty(PhysicalKey.Backspace, RawInputModifiers.None);
|
||||
|
||||
// Control should handle the backspace
|
||||
Assert.True(timeBox.IsFocused);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void TimeBox_Should_Handle_Enter_Key_Press()
|
||||
{
|
||||
var window = new Window();
|
||||
var timeBox = new TimeBox();
|
||||
window.Content = timeBox;
|
||||
window.Show();
|
||||
|
||||
timeBox.Focus();
|
||||
|
||||
// Simulate enter key press
|
||||
window.KeyPressQwerty(PhysicalKey.Enter, RawInputModifiers.None);
|
||||
|
||||
// Control should process the enter key
|
||||
Assert.True(timeBox.IsFocused);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void TimeBox_Fast_Mode_Should_Be_Configurable()
|
||||
{
|
||||
var window = new Window();
|
||||
var timeBox = new TimeBox { InputMode = TimeBoxInputMode.Fast };
|
||||
window.Content = timeBox;
|
||||
window.Show();
|
||||
|
||||
timeBox.Focus();
|
||||
|
||||
// Verify the mode is set correctly
|
||||
Assert.Equal(TimeBoxInputMode.Fast, timeBox.InputMode);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void TimeBox_Normal_Mode_Should_Be_Default()
|
||||
{
|
||||
var window = new Window();
|
||||
var timeBox = new TimeBox();
|
||||
window.Content = timeBox;
|
||||
window.Show();
|
||||
|
||||
timeBox.Focus();
|
||||
|
||||
// Verify the default mode
|
||||
Assert.Equal(TimeBoxInputMode.Normal, timeBox.InputMode);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void TimeBox_Should_Handle_Focus_Loss()
|
||||
{
|
||||
var window = new Window();
|
||||
var timeBox = new TimeBox();
|
||||
var otherControl = new TextBox();
|
||||
var panel = new StackPanel();
|
||||
panel.Children.Add(timeBox);
|
||||
panel.Children.Add(otherControl);
|
||||
window.Content = panel;
|
||||
window.Show();
|
||||
|
||||
timeBox.Focus();
|
||||
Assert.True(timeBox.IsFocused);
|
||||
|
||||
// Move focus to another control
|
||||
otherControl.Focus();
|
||||
|
||||
// In headless mode, focus behavior might be different
|
||||
// Just verify that otherControl can be focused
|
||||
Assert.True(otherControl.IsFocused);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user