|
|
|
@ -239,7 +239,7 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
bool clicked = false; |
|
|
|
|
|
|
|
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
target.Click += (s, e) => clicked = true; |
|
|
|
|
|
|
|
RaisePointerEntered(target); |
|
|
|
@ -295,9 +295,9 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
var raised = 0; |
|
|
|
|
|
|
|
target.Click += (s, e) => ++raised; |
|
|
|
|
|
|
|
|
|
|
|
target.RaiseEvent(new AccessKeyEventArgs("b", false)); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, raised); |
|
|
|
} |
|
|
|
|
|
|
|
@ -357,7 +357,7 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
RaiseAccessKey(root, accessKey, accessKeySymbol); |
|
|
|
|
|
|
|
Assert.Equal(1, raised); |
|
|
|
|
|
|
|
|
|
|
|
static FuncControlTemplate<TestTopLevel> CreateTemplate() |
|
|
|
{ |
|
|
|
return new FuncControlTemplate<TestTopLevel>((x, scope) => |
|
|
|
@ -458,7 +458,7 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Equal(2, raised); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Button_IsDefault_Should_Not_Work_When_Button_Is_Not_Effectively_Visible() |
|
|
|
{ |
|
|
|
@ -472,7 +472,7 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
window.Show(); |
|
|
|
|
|
|
|
target.Click += (s, e) => ++raised; |
|
|
|
|
|
|
|
|
|
|
|
target.IsDefault = true; |
|
|
|
panel.IsVisible = false; |
|
|
|
window.RaiseEvent(CreateKeyDownEvent(Key.Enter)); |
|
|
|
@ -513,7 +513,7 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Equal(2, raised); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Button_IsCancel_Should_Not_Work_When_Button_Is_Not_Effectively_Visible() |
|
|
|
{ |
|
|
|
@ -527,7 +527,7 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
window.Show(); |
|
|
|
|
|
|
|
target.Click += (s, e) => ++raised; |
|
|
|
|
|
|
|
|
|
|
|
target.IsCancel = true; |
|
|
|
panel.IsVisible = false; |
|
|
|
window.RaiseEvent(CreateKeyDownEvent(Key.Escape)); |
|
|
|
@ -564,7 +564,7 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
void Should_Not_Fire_Click_Event_On_Space_Key_When_It_Is_Not_Focus() |
|
|
|
public void Should_Not_Fire_Click_Event_On_Space_Key_When_It_Is_Not_Focus() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
@ -586,6 +586,51 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Button_Unpressed_When_Disabled() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var target = new Button() |
|
|
|
{ |
|
|
|
// Disabling a control implies focus loss, and focus loss
|
|
|
|
// has its own code path to un-press the button. So we have
|
|
|
|
// to avoid hitting that path to get an accurate result.
|
|
|
|
Focusable = false, |
|
|
|
}; |
|
|
|
|
|
|
|
var window = new Window { Content = target }; |
|
|
|
window.Show(); |
|
|
|
|
|
|
|
RaisePointerPressed(target, 1, MouseButton.Left, new Point(50, 50)); |
|
|
|
|
|
|
|
Assert.True(target.IsPressed); |
|
|
|
Assert.False(target.IsFocused); |
|
|
|
target.IsEnabled = false; |
|
|
|
Assert.False(target.IsPressed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Button_Unpressed_When_Focus_Lost() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.FocusableWindow)) |
|
|
|
{ |
|
|
|
var target = new Button(); |
|
|
|
var other = new Button(); |
|
|
|
|
|
|
|
var window = new Window { Content = new StackPanel { Children = { target, other } } }; |
|
|
|
window.Show(); |
|
|
|
|
|
|
|
RaisePointerPressed(target, 1, MouseButton.Left, new Point(50, 50)); |
|
|
|
|
|
|
|
Assert.True(target.IsPressed); |
|
|
|
Assert.True(target.IsFocused); |
|
|
|
Assert.True(other.Focus()); |
|
|
|
Assert.False(target.IsPressed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private KeyEventArgs CreateKeyDownEvent(Key key, Interactive? source = null) |
|
|
|
{ |
|
|
|
return new KeyEventArgs { RoutedEvent = InputElement.KeyDownEvent, Key = key, Source = source }; |
|
|
|
|