From 845ff07f1fc8d0f31836f73133487a8fb0ce245a Mon Sep 17 00:00:00 2001 From: abdesol Date: Sun, 19 Dec 2021 09:55:59 +0300 Subject: [PATCH] Button_Invokes_Doesnt_Execute_When_Button_Disabled test added --- samples/Sandbox/MainWindow.axaml.cs | 27 ++----------------- .../ButtonTests.cs | 14 ++++++++++ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/samples/Sandbox/MainWindow.axaml.cs b/samples/Sandbox/MainWindow.axaml.cs index 93378dd736..3d54036d29 100644 --- a/samples/Sandbox/MainWindow.axaml.cs +++ b/samples/Sandbox/MainWindow.axaml.cs @@ -5,40 +5,17 @@ using Avalonia.Win32.WinRT.Composition; namespace Sandbox { - public partial class MainWindow : Window + public class MainWindow : Window { public MainWindow() { - InitializeComponent(); -#if DEBUG + this.InitializeComponent(); this.AttachDevTools(); -#endif } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); - - var button = new Button - { - Content = "Tabulate to this button" - }; - - Content = button; - button.GotFocus += (_, _) => - { - button.IsEnabled = false; - button.Content = - $"Now this button is disabled ({nameof(IsEnabled)}:{button.IsEnabled},{nameof(IsEffectivelyEnabled)}:{button.IsEffectivelyEnabled}), but you can still press Enter"; - button.KeyDown += (_, _) => - { - button.Content = "button got fired by KeyDown event"; - }; - }; - button.Click += (_, _) => - { - button.Content = "It just has been clicked."; - }; } } } diff --git a/tests/Avalonia.Controls.UnitTests/ButtonTests.cs b/tests/Avalonia.Controls.UnitTests/ButtonTests.cs index e7a42c2d93..dcef91589d 100644 --- a/tests/Avalonia.Controls.UnitTests/ButtonTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ButtonTests.cs @@ -295,6 +295,20 @@ namespace Avalonia.Controls.UnitTests target.CommandParameter = false; Assert.False(target.IsEffectivelyEnabled); } + + [Fact] + public void Button_Invokes_Doesnt_Execute_When_Button_Disabled() + { + var target = new Button(); + var raised = 0; + + target.IsEnabled = false; + target.Click += (s, e) => ++raised; + + target.RaiseEvent(new RoutedEventArgs(AccessKeyHandler.AccessKeyPressedEvent)); + + Assert.Equal(1, raised); + } private class TestButton : Button, IRenderRoot {