Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TreeView flickering #1167

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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