Skip to content

Commit

Permalink
Disable TextFilter when no project is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
rowo360 committed Jan 12, 2025
1 parent 8d60a2c commit b740ef8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void OnTestUnloaded()
{
ClearTree();
_view.OutcomeFilter.Enabled = false;
_view.TextFilter.Enabled = false;
}

public virtual void OnTestFinished(ResultNode result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public override void OnTestLoaded(TestNode testNode, VisualState visualState)
SetDefaultInitialExpansion();

_view.OutcomeFilter.Enabled = true;
_view.TextFilter.Enabled = true;
}

protected override VisualState CreateVisualState() => new VisualState("NUNIT_TREE", _settings.Gui.TestTree.ShowNamespace).LoadFrom(_view.TreeView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ void OnRunFinished(ResultNode result)
case "TestCentric.Gui.TestTree.DisplayFormat":
_view.DisplayFormat.SelectedItem = _settings.Gui.TestTree.DisplayFormat;
UpdateTreeDisplayMenuItem();
UpdateViewCommands();
break;
case "TestCentric.Gui.TestTree.TestList.GroupBy":
_view.GroupBy.SelectedItem = _settings.Gui.TestTree.TestList.GroupBy;
Expand Down
25 changes: 21 additions & 4 deletions src/TestCentric/tests/Presenters/Main/WhenSettingsChanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License. See LICENSE file in root directory.
// ***********************************************************************

using NSubstitute;
using NUnit.Framework;

namespace TestCentric.Gui.Presenters.Main
Expand All @@ -18,7 +19,7 @@ public void DisplayFormat_SettingChanged_MenuItemIsUpdated(string displayFormat)
_settings.Gui.TestTree.DisplayFormat = displayFormat;

// 2. Assert
_view.DisplayFormat.SelectedItem = displayFormat;
Assert.That(_view.DisplayFormat.SelectedItem, Is.EqualTo(displayFormat));
}

[TestCase("ASSEMBLY")]
Expand All @@ -30,7 +31,7 @@ public void FixtureListGroupBy_SettingChanged_MenuItemIsUpdated(string groupBy)
_settings.Gui.TestTree.FixtureList.GroupBy = groupBy;

// 2. Assert
_view.GroupBy.SelectedItem = groupBy;
Assert.That(_view.GroupBy.SelectedItem, Is.EqualTo(groupBy));
}

[TestCase("ASSEMBLY")]
Expand All @@ -42,7 +43,7 @@ public void TestListGroupBy_SettingChanged_MenuItemIsUpdated(string groupBy)
_settings.Gui.TestTree.TestList.GroupBy = groupBy;

// 2. Assert
_view.GroupBy.SelectedItem = groupBy;
Assert.That(_view.GroupBy.SelectedItem, Is.EqualTo(groupBy));
}

[TestCase(true, 0)]
Expand All @@ -53,7 +54,23 @@ public void ShowNamespace_SettingChanged_MenuItemIsUpdated(bool showNamespace, i
_settings.Gui.TestTree.ShowNamespace = showNamespace;

// 2. Assert
_view.ShowNamespace.SelectedIndex = expectedMenuIndex;
Assert.That(_view.ShowNamespace.SelectedIndex, Is.EqualTo(expectedMenuIndex));
}

[TestCase("NUNIT_TREE", true)]
[TestCase("FIXTURE_LIST", false)]
[TestCase("TEST_LIST", false)]
public void DisplayFormat_SettingChanged_ShowHideFilterButton_IsUpdated(string displayFormat, bool expectedState)
{
// 1. Arrange
_model.HasTests.Returns(true);

// 2. Act
_settings.Gui.TestTree.DisplayFormat = displayFormat;

// 3. Assert
Assert.That(_view.ShowHideFilterButton.Visible, Is.EqualTo(expectedState));
Assert.That(_view.ShowHideFilterButton.Enabled, Is.EqualTo(expectedState));
}
}
}
25 changes: 25 additions & 0 deletions src/TestCentric/tests/Presenters/NUnitTreeDisplayStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,31 @@ public void OnTestUnloaded_OutcomeFilter_IsDisabled()
// Assert
_view.OutcomeFilter.Received().Enabled = false;
}

[Test]
public void OnTestLoaded_TextFilter_IsEnabled()
{
// Arrange
string xml =
"<test-suite type='Assembly' id='1-1030' name='Library.Test.dll'>" +
"</test-suite>";

// Act
_strategy.OnTestLoaded(new TestNode(xml), null);

// Assert
_view.TextFilter.Received().Enabled = true;
}

[Test]
public void OnTestUnloaded_TextFilter_IsDisabled()
{
// Arrange + Act
_strategy.OnTestUnloaded();

// Assert
_view.TextFilter.Received().Enabled = false;
}
}


Expand Down

0 comments on commit b740ef8

Please sign in to comment.