From c4232e9a3a26a2004cd4f6b981232ee1cb1b29fe Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 27 Jun 2021 19:12:29 +0100 Subject: [PATCH 1/2] More unit test for issue #1344, testing IsVertical as False. --- UnitTests/ScrollBarViewTests.cs | 77 ++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/UnitTests/ScrollBarViewTests.cs b/UnitTests/ScrollBarViewTests.cs index 36fccd7c8..21a168e6c 100644 --- a/UnitTests/ScrollBarViewTests.cs +++ b/UnitTests/ScrollBarViewTests.cs @@ -447,7 +447,7 @@ namespace Terminal.Gui.Views { } [Fact] - public void Constructor_ShowBothScrollIndicator_False_Refresh_Does_Not_Throws_An_Object_Null_Exception () + public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_True_Refresh_Does_Not_Throws_An_Object_Null_Exception () { var exception = Record.Exception (() => { Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true))); @@ -515,5 +515,80 @@ namespace Terminal.Gui.Views { }); Assert.Null (exception); } + + [Fact] + public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_False_Refresh_Does_Not_Throws_An_Object_Null_Exception () + { + var exception = Record.Exception (() => { + Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true))); + + var top = Application.Top; + + var win = new Window () { + X = 0, + Y = 0, + Width = Dim.Fill (), + Height = Dim.Fill () + }; + + List source = new List (); + + for (int i = 0; i < 50; i++) { + var text = $"item {i} - "; + for (int j = 0; j < 160; j++) { + var col = j.ToString (); + text += col.Length == 1 ? col [0] : col [1]; + } + source.Add (text); + } + + var listView = new ListView (source) { + X = 0, + Y = 0, + Width = Dim.Fill (), + Height = Dim.Fill () + }; + win.Add (listView); + + var newScrollBarView = new ScrollBarView (listView, false, false) { + KeepContentAlwaysInViewport = true + }; + win.Add (newScrollBarView); + + newScrollBarView.ChangedPosition += () => { + listView.LeftItem = newScrollBarView.Position; + if (listView.LeftItem != newScrollBarView.Position) { + newScrollBarView.Position = listView.LeftItem; + } + Assert.Equal (newScrollBarView.Position, listView.LeftItem); + listView.SetNeedsDisplay (); + }; + + listView.DrawContent += (e) => { + newScrollBarView.Size = listView.Maxlength - 1; + Assert.Equal (newScrollBarView.Size, listView.Maxlength); + newScrollBarView.Position = listView.LeftItem; + Assert.Equal (newScrollBarView.Position, listView.LeftItem); + newScrollBarView.Refresh (); + }; + + top.Ready += () => { + newScrollBarView.Position = 100; + Assert.Equal (newScrollBarView.Position, newScrollBarView.Size - listView.LeftItem + (listView.LeftItem - listView.Bounds.Width)); + Assert.Equal (newScrollBarView.Position, listView.LeftItem); + Assert.Equal (92, newScrollBarView.Position); + Assert.Equal (92, listView.LeftItem); + Application.RequestStop (); + }; + + top.Add (win); + + Application.Run (); + + Application.Shutdown (); + + }); + Assert.Null (exception); + } } } From d092fc694d9c5a8b6842bd02b6a3c0a7a07576a4 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Jul 2021 12:23:03 +0100 Subject: [PATCH 2/2] Small change to re-run the test in Github. --- UnitTests/ScrollBarViewTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitTests/ScrollBarViewTests.cs b/UnitTests/ScrollBarViewTests.cs index 21a168e6c..382847a04 100644 --- a/UnitTests/ScrollBarViewTests.cs +++ b/UnitTests/ScrollBarViewTests.cs @@ -511,8 +511,8 @@ namespace Terminal.Gui.Views { Application.Run (); Application.Shutdown (); - }); + Assert.Null (exception); } @@ -586,8 +586,8 @@ namespace Terminal.Gui.Views { Application.Run (); Application.Shutdown (); - }); + Assert.Null (exception); } }