From 61db395e74495c081cebd875079d54effee99406 Mon Sep 17 00:00:00 2001 From: rowo360 <59574371+rowo360@users.noreply.github.com> Date: Sun, 9 Feb 2025 16:27:13 +0100 Subject: [PATCH] Fix category filtering for "No category" --- src/TestModel/model/Filter/CategoryFilter.cs | 3 +- .../Filter/TestCentricTestFilterTests.cs | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/TestModel/model/Filter/CategoryFilter.cs b/src/TestModel/model/Filter/CategoryFilter.cs index d0e18ae5..085f60b3 100644 --- a/src/TestModel/model/Filter/CategoryFilter.cs +++ b/src/TestModel/model/Filter/CategoryFilter.cs @@ -39,7 +39,8 @@ public IEnumerable 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']"; diff --git a/src/TestModel/tests/Filter/TestCentricTestFilterTests.cs b/src/TestModel/tests/Filter/TestCentricTestFilterTests.cs index fbdd526c..ea6f8899 100644 --- a/src/TestModel/tests/Filter/TestCentricTestFilterTests.cs +++ b/src/TestModel/tests/Filter/TestCentricTestFilterTests.cs @@ -284,9 +284,9 @@ public void FilterByText_TestNodesAreVisible(string textFilter, IList ex private static object[] FilterByCategoryTestCases = { - new object[] { new[] { "Category_1" }, new List() { "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() { "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() { "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() { "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() { "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() { "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() { "3-1000", "3-1300", "3-1320", "3-1321" } }, new object[] { new[] { "Category_3", CategoryFilter.NoCategory }, new List() { "3-1000", "3-1200", "3-1210", "3-1212", "3-1300", "3-1320", "3-1321", "3-1322" } }, new object[] { new[] { CategoryFilter.NoCategory }, new List() { "3-1000", "3-1200", "3-1210", "3-1212", "3-1300", "3-1320", "3-1322" } }, @@ -313,7 +313,10 @@ public void FilterByCategory_TestNodesAreVisible(IList 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 @@ -322,10 +325,11 @@ public void FilterByCategory_TestNodesAreVisible(IList categoryFilter, I testFilter.CategoryFilter = categoryFilter; // Assert - foreach (string testId in expectedVisibleNodes) + IList 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)); } } @@ -489,6 +493,20 @@ private TestNode GetTestNode(TestNode testNode, string testId) return null; } + private IList GetAllTestNodes(TestNode testNode) + { + List testNodes = new List(); + + foreach (TestNode child in testNode.Children) + { + IList 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());