Skip to content

Commit

Permalink
Merge pull request #1171 from TestCentric/issue-1161-2
Browse files Browse the repository at this point in the history
Disable TextFilter when no project is loaded
  • Loading branch information
rowo360 authored Jan 19, 2025
2 parents 51e5c2f + 63d6aed commit 6d0ca17
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public bool HasResults
public void OnTestUnloaded()
{
ClearTree();
_view.OutcomeFilter.Enabled = false;
_view.EnableTestFilter(false);
}

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

_view.OutcomeFilter.Enabled = true;
_view.EnableTestFilter(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
2 changes: 2 additions & 0 deletions src/TestCentric/testcentric.gui/Views/ITestTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public interface ITestTreeView : IView

void SetTestFilterVisibility(bool visible);

void EnableTestFilter(bool enable);

// Tree-related Methods
void Clear();
void Add(TreeNode treeNode);
Expand Down
6 changes: 6 additions & 0 deletions src/TestCentric/testcentric.gui/Views/TestTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ public void SetTestFilterVisibility(bool isVisible)
filterTextToolStrip.Visible = isVisible;
}

public void EnableTestFilter(bool enable)
{
filterToolStrip.Enabled = enable;
filterTextToolStrip.Enabled = enable;
}

public void LoadAlternateImages(string imageSet)
{
string[] imageNames = { "Skipped", "Inconclusive", "Success", "Ignored", "Failure" };
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public void OnTestLoaded_SetupFixtureNode_ContainingTwoNamespaces_AreNotFolded()
}

[Test]
public void OnTestLoaded_OutcomeFilter_IsEnabled()
public void OnTestLoaded_TestFilters_AreEnabled()
{
// Arrange
string xml =
Expand All @@ -371,17 +371,17 @@ public void OnTestLoaded_OutcomeFilter_IsEnabled()
_strategy.OnTestLoaded(new TestNode(xml), null);

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

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

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

Expand Down

0 comments on commit 6d0ca17

Please sign in to comment.