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

Disable TextFilter when no project is loaded #1171

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be cleaner for the view to have a single property to enable filters?

}

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

}

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