-
Notifications
You must be signed in to change notification settings - Fork 31
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
NUnit tree: add option to show/hide namespace nodes; add folding of namespace nodes #1153
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
|
||
namespace TestCentric.Gui.Presenters | ||
{ | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Model; | ||
using Views; | ||
|
||
|
@@ -18,6 +19,8 @@ namespace TestCentric.Gui.Presenters | |
/// </summary> | ||
public class NUnitTreeDisplayStrategy : DisplayStrategy | ||
{ | ||
private IDictionary<TestNode, string> _foldedNodeNames = new Dictionary<TestNode, string>(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you examine whether the base class dictionary, |
||
public NUnitTreeDisplayStrategy(ITestTreeView view, ITestModel model) | ||
: base(view, model) { } | ||
|
||
|
@@ -32,17 +35,98 @@ public override string Description | |
public override void OnTestLoaded(TestNode testNode, VisualState visualState) | ||
{ | ||
ClearTree(); | ||
_foldedNodeNames.Clear(); | ||
|
||
foreach (var topLevelNode in testNode.Children) | ||
_view.Add(MakeTreeNode(topLevelNode, true)); | ||
_view.Add(CreateNUnitTreeNode(null, topLevelNode)); | ||
|
||
if (visualState != null) | ||
visualState.ApplyTo(_view.TreeView); | ||
else | ||
SetDefaultInitialExpansion(); | ||
} | ||
|
||
protected override VisualState CreateVisualState() => new VisualState("NUNIT_TREE").LoadFrom(_view.TreeView); | ||
protected override VisualState CreateVisualState() => new VisualState("NUNIT_TREE", _settings.Gui.TestTree.ShowNamespace).LoadFrom(_view.TreeView); | ||
|
||
protected override string GetTreeNodeName(TestNode testNode) | ||
{ | ||
// For folded namespace nodes use the combined name of all folded nodes ("Library.Test.Folder") | ||
if (_foldedNodeNames.TryGetValue(testNode, out var name)) | ||
return name; | ||
|
||
return base.GetTreeNodeName(testNode); | ||
} | ||
|
||
private TreeNode CreateNUnitTreeNode(TreeNode parentNode, TestNode testNode) | ||
{ | ||
TreeNode treeNode = null; | ||
|
||
if (ShowTreeNodeType(testNode)) | ||
{ | ||
if (IsNamespaceNode(testNode)) | ||
{ | ||
// Get list of all namespace nodes which can be folded | ||
// And get name of folded namespaces and store in dictionary for later usage | ||
IList<TestNode> foldedNodes = FoldNamespaceNodes(testNode); | ||
_foldedNodeNames[foldedNodes.First()] = GetFoldedNamespaceName(foldedNodes); | ||
|
||
treeNode = MakeTreeNode(foldedNodes.First(), false); // Create TreeNode representing the first node | ||
testNode = foldedNodes.Last(); // But proceed building up tree with last node | ||
} | ||
else | ||
treeNode = MakeTreeNode(testNode, false); | ||
|
||
parentNode?.Nodes.Add(treeNode); | ||
parentNode = treeNode; | ||
} | ||
|
||
foreach (TestNode child in testNode.Children) | ||
{ | ||
CreateNUnitTreeNode(parentNode, child); | ||
} | ||
|
||
return treeNode; | ||
} | ||
|
||
/// <summary> | ||
/// Check if a tree node type should be shown or omitted | ||
/// Currently we support only omitting the namespace nodes | ||
/// </summary> | ||
private bool ShowTreeNodeType(TestNode testNode) | ||
{ | ||
if (IsNamespaceNode(testNode)) | ||
return _settings.Gui.TestTree.ShowNamespace; | ||
|
||
return true; | ||
} | ||
|
||
private string GetFoldedNamespaceName(IList<TestNode> foldedNamespaces) | ||
{ | ||
var namespaceNames = foldedNamespaces.Select(x => x.Name); | ||
return String.Join(".", namespaceNames); | ||
} | ||
|
||
private IList<TestNode> FoldNamespaceNodes(TestNode testNode) | ||
{ | ||
if (!IsNamespaceNode(testNode)) | ||
{ | ||
return new List<TestNode>(); | ||
} | ||
|
||
// If a namespace node only contains one child item which is also a namespace node, we can fold them. | ||
List<TestNode> namespaceNodes = new List<TestNode>() { testNode }; | ||
if (testNode.Children.Count == 1 && IsNamespaceNode(testNode.Children[0])) | ||
{ | ||
namespaceNodes.AddRange(FoldNamespaceNodes(testNode.Children[0])); | ||
} | ||
|
||
return namespaceNodes; | ||
} | ||
|
||
private bool IsNamespaceNode(TestNode testNode) | ||
{ | ||
return testNode.IsSuite && (testNode.Type == "TestSuite" || testNode.Type == "SetUpFixture"); | ||
} | ||
|
||
private void SetDefaultInitialExpansion() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,8 @@ public class TestCentricMainView : TestCentricFormBase, IMainView | |
private ToolStripMenuItem nunitTreeMenuItem; | ||
private ToolStripMenuItem fixtureListMenuItem; | ||
private ToolStripMenuItem testListMenuItem; | ||
private ToolStripMenuItem nunitTreeShowNamespaceMenuItem; | ||
private ToolStripMenuItem nunitTreeHideNamespaceMenuItem; | ||
private ToolStripSeparator toolStripSeparator13; | ||
private ToolStripMenuItem byAssemblyMenuItem; | ||
private ToolStripMenuItem byFixtureMenuItem; | ||
|
@@ -175,6 +177,7 @@ public TestCentricMainView() : base("TestCentric") | |
GroupBy = new CheckedToolStripMenuGroup( | ||
"testGrouping", | ||
byAssemblyMenuItem, byFixtureMenuItem, byCategoryMenuItem, byOutcomeMenuItem, byDurationMenuItem); | ||
ShowNamespace = new CheckedToolStripMenuGroup("showNamespace", nunitTreeShowNamespaceMenuItem, nunitTreeHideNamespaceMenuItem); | ||
RunParametersButton = new ToolStripButtonElement(runParametersButton); | ||
RunSummaryButton = new CheckBoxElement(runSummaryButton); | ||
|
||
|
@@ -217,6 +220,8 @@ private void InitializeComponent() | |
this.nunitTreeMenuItem = new System.Windows.Forms.ToolStripMenuItem(); | ||
this.fixtureListMenuItem = new System.Windows.Forms.ToolStripMenuItem(); | ||
this.testListMenuItem = new System.Windows.Forms.ToolStripMenuItem(); | ||
this.nunitTreeShowNamespaceMenuItem = new System.Windows.Forms.ToolStripMenuItem(); | ||
this.nunitTreeHideNamespaceMenuItem = new System.Windows.Forms.ToolStripMenuItem(); | ||
this.toolStripSeparator13 = new System.Windows.Forms.ToolStripSeparator(); | ||
this.byAssemblyMenuItem = new System.Windows.Forms.ToolStripMenuItem(); | ||
this.byFixtureMenuItem = new System.Windows.Forms.ToolStripMenuItem(); | ||
|
@@ -405,13 +410,32 @@ private void InitializeComponent() | |
this.displayFormatButton.Size = new System.Drawing.Size(29, 21); | ||
this.displayFormatButton.Text = "Display"; | ||
this.displayFormatButton.ToolTipText = "Tree Display Format"; | ||
|
||
// | ||
// nunitTreeShowNamespaceMenuItem | ||
// | ||
this.nunitTreeShowNamespaceMenuItem.Name = "NUNIT_TREE_SHOW_NAMESPACE"; | ||
this.nunitTreeShowNamespaceMenuItem.Size = new System.Drawing.Size(198, 22); | ||
this.nunitTreeShowNamespaceMenuItem.Tag = "NUNIT_TREE_SHOW_NAMESPACE"; | ||
this.nunitTreeShowNamespaceMenuItem.Text = "Show Namespace"; | ||
|
||
// | ||
// nunitTreeHideNamespaceMenuItem | ||
// | ||
this.nunitTreeHideNamespaceMenuItem.Name = "NUNIT_TREE_HIDE_NAMESPACE"; | ||
this.nunitTreeHideNamespaceMenuItem.Size = new System.Drawing.Size(198, 22); | ||
this.nunitTreeHideNamespaceMenuItem.Tag = "NUNIT_TREE_HIDE_NAMESPACE"; | ||
this.nunitTreeHideNamespaceMenuItem.Text = "Hide Namespace"; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make the text "Show Namespace" so it's clear what it does. I'd actually prefer to see both Show Namespace and Hide Namespace exclusive radio buttons to make it completely clear, but I think we will redo this whole menu thing at least one more time so it could wait. |
||
// | ||
// nunitTreeMenuItem | ||
// | ||
this.nunitTreeMenuItem.Name = "nunitTreeMenuItem"; | ||
this.nunitTreeMenuItem.Size = new System.Drawing.Size(198, 22); | ||
this.nunitTreeMenuItem.Tag = "NUNIT_TREE"; | ||
this.nunitTreeMenuItem.Text = "NUnit Tree"; | ||
nunitTreeMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { nunitTreeShowNamespaceMenuItem, nunitTreeHideNamespaceMenuItem }); | ||
|
||
// | ||
// fixtureListMenuItem | ||
// | ||
|
@@ -1124,6 +1148,7 @@ public int SplitterPosition | |
public IViewElement DisplayFormatButton { get; private set; } | ||
public ISelection DisplayFormat { get; private set; } | ||
public ISelection GroupBy { get; private set; } | ||
public ISelection ShowNamespace { get; private set; } | ||
public ICommand RunParametersButton { get; private set; } | ||
|
||
public IChecked RunSummaryButton { get; private set; } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this method is slightly confusing. Up till now, each tree node representeed only one test node. But now, with folding, it can map to multiple namespaces. So... each test node has a name and the tree node may have a combined name. It would be great if this method and the next one could reflect that in some way. GetTreeNodeName and GetTreeNodeDisplayName?