From 236374b8c034b14136a4d6970682ad3747eac0ea Mon Sep 17 00:00:00 2001 From: Tig Date: Sat, 8 Jun 2024 09:56:16 -0600 Subject: [PATCH] Fixed AllviewsTester issue - not aware of Pos.Align --- UICatalog/Scenarios/AllViewsTester.cs | 19 +++++++++++++++---- UnitTests/UICatalog/ScenarioTests.cs | 25 ++++++++++++++++++------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index a80b088dd..4971ba0b3 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Reflection; using Terminal.Gui; @@ -516,15 +517,25 @@ public class AllViewsTester : Scenario var x = view.X.ToString (); var y = view.Y.ToString (); - _xRadioGroup.SelectedItem = _posNames.IndexOf (_posNames.Where (s => x.Contains (s)).First ()); - _yRadioGroup.SelectedItem = _posNames.IndexOf (_posNames.Where (s => y.Contains (s)).First ()); + + try + { + _xRadioGroup.SelectedItem = _posNames.IndexOf (_posNames.First (s => x.Contains (s))); + _yRadioGroup.SelectedItem = _posNames.IndexOf (_posNames.First (s => y.Contains (s))); + } + catch (InvalidOperationException e) + { + // This is a hack to work around the fact that the Pos enum doesn't have an "Align" value yet + Debug.WriteLine($"{e}"); + } + _xText.Text = $"{view.Frame.X}"; _yText.Text = $"{view.Frame.Y}"; var w = view.Width.ToString (); var h = view.Height.ToString (); - _wRadioGroup.SelectedItem = _dimNames.IndexOf (_dimNames.Where (s => w.Contains (s)).First ()); - _hRadioGroup.SelectedItem = _dimNames.IndexOf (_dimNames.Where (s => h.Contains (s)).First ()); + _wRadioGroup.SelectedItem = _dimNames.IndexOf (_dimNames.First (s => w.Contains (s))); + _hRadioGroup.SelectedItem = _dimNames.IndexOf (_dimNames.First (s => h.Contains (s))); if (view.Width is DimAuto) { diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index d5388a0cf..97519da06 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Reflection; using Xunit.Abstractions; @@ -39,9 +40,6 @@ public class ScenarioTests : TestsAllViews // Press QuitKey Assert.Empty (FakeConsole.MockKeyPresses); - // BUGBUG: (#2474) For some reason ReadKey is not returning the QuitKey for some Scenarios - // by adding this Space it seems to work. - //FakeConsole.PushMockKeyPress (Key.Space); FakeConsole.PushMockKeyPress ((KeyCode)Application.QuitKey); uint abortTime = 500; @@ -69,6 +67,7 @@ public class ScenarioTests : TestsAllViews // Press QuitKey Assert.Empty (FakeConsole.MockKeyPresses); FakeConsole.PushMockKeyPress ((KeyCode)Application.QuitKey); + //output.WriteLine ($" iteration {++iterations}"); if (Application.Top.Running && FakeConsole.MockKeyPresses.Count == 0) { @@ -417,15 +416,27 @@ public class ScenarioTests : TestsAllViews { var x = view.X.ToString (); var y = view.Y.ToString (); - _xRadioGroup.SelectedItem = posNames.IndexOf (posNames.Where (s => x.Contains (s)).First ()); - _yRadioGroup.SelectedItem = posNames.IndexOf (posNames.Where (s => y.Contains (s)).First ()); + + try + { + _xRadioGroup.SelectedItem = posNames.IndexOf (posNames.First (s => x.Contains (s))); + _yRadioGroup.SelectedItem = posNames.IndexOf (posNames.First (s => y.Contains (s))); + } + catch (InvalidOperationException e) + { + // This is a hack to work around the fact that the Pos enum doesn't have an "Align" value yet + Debug.WriteLine ($"{e}"); + } + _xText.Text = $"{view.Frame.X}"; _yText.Text = $"{view.Frame.Y}"; var w = view.Width.ToString (); var h = view.Height.ToString (); - _wRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.Where (s => w.Contains (s)).First ()); - _hRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.Where (s => h.Contains (s)).First ()); + + _wRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.First (s => w.Contains (s))); + _hRadioGroup.SelectedItem = dimNames.IndexOf (dimNames.First (s => h.Contains (s))); + _wText.Text = $"{view.Frame.Width}"; _hText.Text = $"{view.Frame.Height}"; }