Skip to content

Commit

Permalink
Keep expand/collapse state of tree nodes when changing the tree filter
Browse files Browse the repository at this point in the history
  • Loading branch information
rowo360 committed Jan 15, 2025
1 parent 8d60a2c commit 55ebb46
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/TestCentric/testcentric.gui/Presenters/DisplayStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ public virtual void OnTestRunFinished()

// Called when either the display strategy or the grouping
// changes. May need to distinguish these cases.
public void Reload()
public void Reload(bool applyVisualState = false)
{
TestNode testNode = _model.LoadedTests;
if (testNode != null)
{
OnTestLoaded(testNode, null);
VisualState visualState = applyVisualState ? CreateVisualState() : null;
OnTestLoaded(testNode, visualState);

if (_view.Nodes != null) // TODO: Null when mocked
foreach (TreeNode treeNode in _view.Nodes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface ITreeDisplayStrategy
/// <summary>
/// Reload tree: clear all tree nodes first and rebuild all nodes afterwards
/// </summary>
void Reload();
void Reload(bool applyVisualState=false);

/// <summary>
/// Save the visual state of the tree display strategy into a file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void WireUpEvents()

_model.Events.TestFilterChanged += (ea) =>
{
Strategy?.Reload();
Strategy?.Reload(true);
};

_model.Events.TestFinished += OnTestFinished;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,21 @@ public void TextFilterChanged_ApplyFilter()
_model.TestCentricTestFilter.Received().TextFilter = "TestA";
}

[Test]
public void FilterChanged_ReloadTree_IsInvoked()
{
// 1. Arrange
ITreeDisplayStrategy strategy = Substitute.For<ITreeDisplayStrategy>();
_treeDisplayStrategyFactory.Create(null, null, null).ReturnsForAnyArgs(strategy);
_model.Settings.Gui.TestTree.DisplayFormat = "NUNIT_TREE";

// 2. Act
_model.Events.TestFilterChanged += Raise.Event<TestEventHandler>(new TestEventArgs());

// 3. Assert
strategy.Received().Reload(true);
}

// TODO: Version 1 Test - Make it work if needed.
//[Test]
//public void WhenContextNodeIsNotNull_RunCommandExecutesThatTest()
Expand Down

0 comments on commit 55ebb46

Please sign in to comment.