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

Fix category filtering for "No category" #1181

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/TestModel/model/Filter/CategoryFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public IEnumerable<string> Condition

public bool IsMatching(TestNode testNode)
{
if (_condition.Any() == false)
// Consider test-case nodes only: categories from fixtures are applied to test-cases
if (_condition.Any() == false || testNode.IsProject || testNode.IsSuite)
return false;

string xpathExpression = "ancestor-or-self::*/properties/property[@name='Category']";
Expand Down
32 changes: 25 additions & 7 deletions src/TestModel/tests/Filter/TestCentricTestFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ public void FilterByText_TestNodesAreVisible(string textFilter, IList<string> ex

private static object[] FilterByCategoryTestCases =
{
new object[] { new[] { "Category_1" }, new List<string>() { "3-1000", "3-1100", "3-1110", "3-1111", "3-1112", "3-1300", "3-1310", "3-1311", "3-1312" } },
new object[] { new[] { "Category_1", "Category_2" }, new List<string>() { "3-1100", "3-1000", "3-1110", "3-1111", "3-1112", "3-1200", "3-1211", "3-1300", "3-1311", "3-1312" } },
new object[] { new[] { "Category_2" }, new List<string>() { "3-1000", "3-1100", "3-1110", "3-1111", "3-1112", "3-1200", "3-1211", "3-1300", "3-1312" } },
new object[] { new[] { "Category_1" }, new List<string>() { "3-1000", "3-1100", "3-1110", "3-1111", "3-1112", "3-1300", "3-1310", "3-1311", "3-1312", "3-1330", "3-1331" } },
new object[] { new[] { "Category_1", "Category_2" }, new List<string>() { "3-1100", "3-1000", "3-1110", "3-1111", "3-1112", "3-1200", "3-1210", "3-1211", "3-1300", "3-1310", "3-1311", "3-1312", "3-1330", "3-1331", "3-1332" } },
new object[] { new[] { "Category_2" }, new List<string>() { "3-1000", "3-1100", "3-1110", "3-1111", "3-1112", "3-1200", "3-1210", "3-1211", "3-1300", "3-1310", "3-1312", "3-1330", "3-1332" } },
new object[] { new[] { "Category_3" }, new List<string>() { "3-1000", "3-1300", "3-1320", "3-1321" } },
new object[] { new[] { "Category_3", CategoryFilter.NoCategory }, new List<string>() { "3-1000", "3-1200", "3-1210", "3-1212", "3-1300", "3-1320", "3-1321", "3-1322" } },
new object[] { new[] { CategoryFilter.NoCategory }, new List<string>() { "3-1000", "3-1200", "3-1210", "3-1212", "3-1300", "3-1320", "3-1322" } },
Expand All @@ -313,7 +313,10 @@ public void FilterByCategory_TestNodesAreVisible(IList<string> categoryFilter, I
CreateTestcaseXml("3-1312", "LibraryA.NamespaceC.Fixture_1.TestB", "", new[] { "Category_2" })) +
CreateTestFixtureXml("3-1320", "LibraryA.NamespaceC.Fixture_2", "",
CreateTestcaseXml("3-1321", "LibraryA.NamespaceC.Fixture_2.TestC", "Failed", new[] { "Category_3" }),
CreateTestcaseXml("3-1322", "LibraryA.NamespaceC.Fixture_2.TestD", "")))));
CreateTestcaseXml("3-1322", "LibraryA.NamespaceC.Fixture_2.TestD", "")) +
CreateTestFixtureXml("3-1330", "LibraryA.NamespaceC.Fixture_3", "",
CreateTestcaseXml("3-1331", "LibraryA.NamespaceC.Fixture_3.TestA", "", new[] { "Category_1" }),
CreateTestcaseXml("3-1332", "LibraryA.NamespaceC.Fixture_3.TestB", "", new[] { "Category_2" })))));
_model.LoadedTests.Returns(testNode);

// Act
Expand All @@ -322,10 +325,11 @@ public void FilterByCategory_TestNodesAreVisible(IList<string> categoryFilter, I
testFilter.CategoryFilter = categoryFilter;

// Assert
foreach (string testId in expectedVisibleNodes)
IList<TestNode> nodes = GetAllTestNodes(testNode);
foreach (TestNode node in nodes)
{
TestNode node = GetTestNode(testNode, testId);
Assert.That(node.IsVisible, Is.True);
bool expectedIsVisible = expectedVisibleNodes.Contains(node.Id);
Assert.That(node.IsVisible, Is.EqualTo(expectedIsVisible));
}
}

Expand Down Expand Up @@ -489,6 +493,20 @@ private TestNode GetTestNode(TestNode testNode, string testId)
return null;
}

private IList<TestNode> GetAllTestNodes(TestNode testNode)
{
List<TestNode> testNodes = new List<TestNode>();

foreach (TestNode child in testNode.Children)
{
IList<TestNode> childNodes = GetAllTestNodes(child);
testNodes.AddRange(childNodes);
}

testNodes.AddRange(testNode.Children);
return testNodes;
}

private string CreateTestcaseXml(string testId, string testName, string outcome)
{
return CreateTestcaseXml(testId, testName, outcome, new List<string>());
Expand Down