Skip to content

Commit 55ebb46

Browse files
committed
Keep expand/collapse state of tree nodes when changing the tree filter
1 parent 8d60a2c commit 55ebb46

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/TestCentric/testcentric.gui/Presenters/DisplayStrategy.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ public virtual void OnTestRunFinished()
102102

103103
// Called when either the display strategy or the grouping
104104
// changes. May need to distinguish these cases.
105-
public void Reload()
105+
public void Reload(bool applyVisualState = false)
106106
{
107107
TestNode testNode = _model.LoadedTests;
108108
if (testNode != null)
109109
{
110-
OnTestLoaded(testNode, null);
110+
VisualState visualState = applyVisualState ? CreateVisualState() : null;
111+
OnTestLoaded(testNode, visualState);
111112

112113
if (_view.Nodes != null) // TODO: Null when mocked
113114
foreach (TreeNode treeNode in _view.Nodes)

src/TestCentric/testcentric.gui/Presenters/ITreeDisplayStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface ITreeDisplayStrategy
2323
/// <summary>
2424
/// Reload tree: clear all tree nodes first and rebuild all nodes afterwards
2525
/// </summary>
26-
void Reload();
26+
void Reload(bool applyVisualState=false);
2727

2828
/// <summary>
2929
/// Save the visual state of the tree display strategy into a file

src/TestCentric/testcentric.gui/Presenters/TreeViewPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private void WireUpEvents()
112112

113113
_model.Events.TestFilterChanged += (ea) =>
114114
{
115-
Strategy?.Reload();
115+
Strategy?.Reload(true);
116116
};
117117

118118
_model.Events.TestFinished += OnTestFinished;

src/TestCentric/tests/Presenters/TestTree/TreeViewPresenterTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@ public void TextFilterChanged_ApplyFilter()
262262
_model.TestCentricTestFilter.Received().TextFilter = "TestA";
263263
}
264264

265+
[Test]
266+
public void FilterChanged_ReloadTree_IsInvoked()
267+
{
268+
// 1. Arrange
269+
ITreeDisplayStrategy strategy = Substitute.For<ITreeDisplayStrategy>();
270+
_treeDisplayStrategyFactory.Create(null, null, null).ReturnsForAnyArgs(strategy);
271+
_model.Settings.Gui.TestTree.DisplayFormat = "NUNIT_TREE";
272+
273+
// 2. Act
274+
_model.Events.TestFilterChanged += Raise.Event<TestEventHandler>(new TestEventArgs());
275+
276+
// 3. Assert
277+
strategy.Received().Reload(true);
278+
}
279+
265280
// TODO: Version 1 Test - Make it work if needed.
266281
//[Test]
267282
//public void WhenContextNodeIsNotNull_RunCommandExecutesThatTest()

0 commit comments

Comments
 (0)