From c00290ffcce4e177ae7097dad54bd9656e004ab7 Mon Sep 17 00:00:00 2001 From: Tig Date: Sat, 17 Aug 2024 09:22:52 -0600 Subject: [PATCH] Added unit test & fixed bug (#3666) --- Terminal.Gui/Views/Shortcut.cs | 2 ++ UnitTests/Views/ShortcutTests.cs | 46 +++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Terminal.Gui/Views/Shortcut.cs b/Terminal.Gui/Views/Shortcut.cs index 6530d71bc..0ce5da072 100644 --- a/Terminal.Gui/Views/Shortcut.cs +++ b/Terminal.Gui/Views/Shortcut.cs @@ -806,6 +806,8 @@ public class Shortcut : View, IOrientation, IDesignable if (HasFocus) { + base.ColorScheme ??= new (Attribute.Default); + // When we have focus, we invert the colors base.ColorScheme = new (base.ColorScheme) { diff --git a/UnitTests/Views/ShortcutTests.cs b/UnitTests/Views/ShortcutTests.cs index e46e7f199..e2e9afbc7 100644 --- a/UnitTests/Views/ShortcutTests.cs +++ b/UnitTests/Views/ShortcutTests.cs @@ -38,9 +38,6 @@ public class ShortcutTests Assert.IsType (shortcut.Width); Assert.IsType (shortcut.Height); - //shortcut.BeginInit(); - //shortcut.EndInit (); - // shortcut.LayoutSubviews (); shortcut.SetRelativeLayout (new (100, 100)); // |0123456789 @@ -256,19 +253,6 @@ public class ShortcutTests Assert.True (actionInvoked); } - [Fact] - public void ColorScheme_SetsAndGetsCorrectly () - { - var colorScheme = new ColorScheme (); - - var shortcut = new Shortcut - { - ColorScheme = colorScheme - }; - - Assert.Same (colorScheme, shortcut.ColorScheme); - } - [Fact] public void Subview_Visibility_Controlled_By_Removal () { @@ -600,5 +584,35 @@ public class ShortcutTests } + [Fact] + public void ColorScheme_SetsAndGetsCorrectly () + { + var colorScheme = new ColorScheme (); + + var shortcut = new Shortcut + { + ColorScheme = colorScheme + }; + + Assert.Same (colorScheme, shortcut.ColorScheme); + } + + // https://github.com/gui-cs/Terminal.Gui/issues/3664 + [Fact] + public void ColorScheme_SetColorScheme_Does_Not_Fault_3664 () + { + Application.Current = new Toplevel (); + Shortcut shortcut = new Shortcut (); + + Application.Current.ColorScheme = null; + + Assert.Null (shortcut.ColorScheme); + + shortcut.HasFocus = true; + + Assert.NotNull (shortcut.ColorScheme); + + Application.Current.Dispose (); + } }