Browse Source

Merge branch 'fixes_2140_onselectedchange' of tig:tig/Terminal.Gui into fixes_2140_onselectedchange

Charlie Kindel 2 years ago
parent
commit
b6299a3d2a
3 changed files with 43 additions and 19 deletions
  1. 1 1
      Terminal.Gui/Core/View.cs
  2. 18 18
      UnitTests/ComboBoxTests.cs
  3. 24 0
      UnitTests/ViewTests.cs

+ 1 - 1
Terminal.Gui/Core/View.cs

@@ -3080,7 +3080,7 @@ namespace Terminal.Gui {
 		/// <param name="view">The view.</param>
 		/// <param name="method">The method name.</param>
 		/// <returns><see langword="true"/> if it's overridden, <see langword="false"/> otherwise.</returns>
-		public bool IsOverridden (View view, string method)
+		public static bool IsOverridden (View view, string method)
 		{
 			MethodInfo m = view.GetType ().GetMethod (method,
 				BindingFlags.Instance

+ 18 - 18
UnitTests/ComboBoxTests.cs

@@ -826,9 +826,9 @@ Three ", output);
 
 			TestHelpers.AssertDriverColorsAre (@"
 000000
-00000
-22222
-22222", attributes);
+222222
+222222
+222222", attributes);
 
 			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
 			Assert.Equal ("", selected);
@@ -838,9 +838,9 @@ Three ", output);
 			cb.Redraw (cb.Bounds);
 			TestHelpers.AssertDriverColorsAre (@"
 000000
-22222
-00000
-22222", attributes);
+222222
+000002
+222222", attributes);
 
 			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
 			Assert.Equal ("", selected);
@@ -850,9 +850,9 @@ Three ", output);
 			cb.Redraw (cb.Bounds);
 			TestHelpers.AssertDriverColorsAre (@"
 000000
-22222
-22222
-00000", attributes);
+222222
+222222
+000002", attributes);
 
 			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
 			Assert.Equal ("Three", selected);
@@ -868,9 +868,9 @@ Three ", output);
 			cb.Redraw (cb.Bounds);
 			TestHelpers.AssertDriverColorsAre (@"
 000000
-22222
-22222
-00000", attributes);
+222222
+222222
+000002", attributes);
 
 			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
 			Assert.Equal ("Three", selected);
@@ -880,9 +880,9 @@ Three ", output);
 			cb.Redraw (cb.Bounds);
 			TestHelpers.AssertDriverColorsAre (@"
 000000
-22222
-00000
-11111", attributes);
+222222
+000002
+111112", attributes);
 
 			Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
 			Assert.Equal ("Three", selected);
@@ -892,9 +892,9 @@ Three ", output);
 			cb.Redraw (cb.Bounds);
 			TestHelpers.AssertDriverColorsAre (@"
 000000
-00000
-22222
-11111", attributes);
+000002
+222222
+111112", attributes);
 
 			Assert.True (cb.ProcessKey (new KeyEvent (Key.F4, new KeyModifiers ())));
 			Assert.Equal ("Three", selected);

+ 24 - 0
UnitTests/ViewTests.cs

@@ -4062,5 +4062,29 @@ This is a tes
 			Assert.False (view.IsKeyPress);
 			Assert.True (view.IsKeyUp);
 		}
+
+		[Fact, AutoInitShutdown]
+		public void IsOverridden_False_IfNotOverriden ()
+		{
+			var view = new DerivedView () { Text = "DerivedView does not override MouseEvent", Width = 10, Height = 10 };
+
+			Assert.False (View.IsOverridden (view, "MouseEvent"));
+
+			var view2 = new Button () { Text = "Button does not overrides OnKeyDown", Width = 10, Height = 10 };
+
+			Assert.False (View.IsOverridden (view2, "OnKeyDown"));
+		}
+
+		[Fact, AutoInitShutdown]
+		public void IsOverridden_True_IfOverriden ()
+		{
+			var view = new Button () { Text = "Button overrides MouseEvent", Width = 10, Height = 10 };
+
+			Assert.True (View.IsOverridden (view, "MouseEvent"));
+
+			var view2 = new DerivedView () { Text = "DerivedView overrides OnKeyDown", Width = 10, Height = 10 };
+
+			Assert.True (View.IsOverridden (view2, "OnKeyDown"));
+		}
 	}
 }