From 1e782c9f10ca1421282b0e4e769d8a15602c358c Mon Sep 17 00:00:00 2001 From: rowo360 <59574371+rowo360@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:05:11 +0100 Subject: [PATCH] Fix TreeView flickering --- .../Presenters/DisplayStrategy.cs | 8 ++++++-- .../Presenters/NUnitTreeDisplayStrategyTests.cs | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/TestCentric/testcentric.gui/Presenters/DisplayStrategy.cs b/src/TestCentric/testcentric.gui/Presenters/DisplayStrategy.cs index b4ec7dd0..ea67aa9a 100644 --- a/src/TestCentric/testcentric.gui/Presenters/DisplayStrategy.cs +++ b/src/TestCentric/testcentric.gui/Presenters/DisplayStrategy.cs @@ -84,18 +84,20 @@ public virtual void OnTestFinished(ResultNode result) foreach (TreeNode treeNode in GetTreeNodesForTest(result)) { _view.SetImageIndex(treeNode, imageIndex); - UpdateTreeNodeName(treeNode); } } public virtual void OnTestRunStarting() { _view.ResetAllTreeNodeImages(); - UpdateTreeNodeNames(); + if (_settings.Gui.TestTree.ShowTestDuration) + _view.InvokeIfRequired(() => UpdateTreeNodeNames()); } public virtual void OnTestRunFinished() { + if (_settings.Gui.TestTree.ShowTestDuration) + _view.InvokeIfRequired(() => UpdateTreeNodeNames()); } // Called when either the display strategy or the grouping @@ -205,11 +207,13 @@ public void UpdateTreeNodeNames() private void UpdateTreeNodeNames(TreeNodeCollection nodes) { + _view.TreeView.BeginUpdate(); foreach (TreeNode treeNode in nodes) { UpdateTreeNodeName(treeNode); UpdateTreeNodeNames(treeNode.Nodes); } + _view.TreeView.EndUpdate(); } private void UpdateTreeNodeName(TreeNode treeNode) diff --git a/src/TestCentric/tests/Presenters/NUnitTreeDisplayStrategyTests.cs b/src/TestCentric/tests/Presenters/NUnitTreeDisplayStrategyTests.cs index e9eb9809..8a81d69d 100644 --- a/src/TestCentric/tests/Presenters/NUnitTreeDisplayStrategyTests.cs +++ b/src/TestCentric/tests/Presenters/NUnitTreeDisplayStrategyTests.cs @@ -133,7 +133,7 @@ public void OnTestFinished_TreeNodeImage_IsUpdated(string testResult, int expect } [Test] - public void OnTestFinished_ShowDurationIsInactive_TreeNodeName_IsUpdated() + public void OnTestRunFinished_ShowDurationIsInactive_TreeNodeName_IsUpdated() { // Arrange TestNode testNode = new TestNode(""); @@ -142,8 +142,13 @@ public void OnTestFinished_ShowDurationIsInactive_TreeNodeName_IsUpdated() _model.GetResultForTest(testNode.Id).Returns(result); _view.InvokeIfRequired(Arg.Do(x => x.Invoke())); + var nodes = new TreeNode().Nodes; + nodes.Add(treeNode); + _view.Nodes.Returns(nodes); + _view.TreeView.Returns(new TreeView()); + // Act - _strategy.OnTestFinished(result); + _strategy.OnTestRunFinished(); // Assert Assert.That(treeNode.Text, Is.EqualTo("Test1")); @@ -160,8 +165,13 @@ public void OnTestFinished_ShowDurationIsActive_TreeNodeName_IsUpdated() _model.GetResultForTest(testNode.Id).Returns(result); _view.InvokeIfRequired(Arg.Do(x => x.Invoke())); + var nodes = new TreeNode().Nodes; + nodes.Add(treeNode); + _view.Nodes.Returns(nodes); + _view.TreeView.Returns(new TreeView()); + // Act - _strategy.OnTestFinished(result); + _strategy.OnTestRunFinished(); // Assert Assert.That(treeNode.Text, Does.Match(@"Test1 \[1[,.]500s\]"));