Skip to content

Commit

Permalink
Merge pull request #1167 from TestCentric/issue-1165
Browse files Browse the repository at this point in the history
Fix TreeView flickering
  • Loading branch information
CharliePoole authored Jan 9, 2025
2 parents 6344094 + 1e782c9 commit 76d6528
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/TestCentric/testcentric.gui/Presenters/DisplayStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions src/TestCentric/tests/Presenters/NUnitTreeDisplayStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<test-case id='1' name='Test1'/>");
Expand All @@ -142,8 +142,13 @@ public void OnTestFinished_ShowDurationIsInactive_TreeNodeName_IsUpdated()
_model.GetResultForTest(testNode.Id).Returns(result);
_view.InvokeIfRequired(Arg.Do<MethodInvoker>(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"));
Expand All @@ -160,8 +165,13 @@ public void OnTestFinished_ShowDurationIsActive_TreeNodeName_IsUpdated()
_model.GetResultForTest(testNode.Id).Returns(result);
_view.InvokeIfRequired(Arg.Do<MethodInvoker>(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\]"));
Expand Down

0 comments on commit 76d6528

Please sign in to comment.