Skip to content

Commit

Permalink
Merge pull request #1163 from TestCentric/Issue-1148-2
Browse files Browse the repository at this point in the history
Add UI elements for test outcome filtering
  • Loading branch information
CharliePoole authored Dec 18, 2024
2 parents 18b8a35 + 7a82b87 commit 6344094
Show file tree
Hide file tree
Showing 25 changed files with 539 additions and 93 deletions.
26 changes: 26 additions & 0 deletions src/TestCentric/testcentric.gui/Elements/IMultiSelection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ***********************************************************************
// Copyright (c) Charlie Poole and TestCentric contributors.
// Licensed under the MIT License. See LICENSE file in root directory.
// ***********************************************************************

using System.Collections.Generic;

namespace TestCentric.Gui.Elements
{
/// <summary>
/// The IMultiSelection interface represents a group of UI elements
/// that allow the user to select a set of items.
/// </summary>
public interface IMultiSelection : IViewElement
{
/// <summary>
/// Gets or sets the string values of the currently selected items
/// </summary>
IEnumerable<string> SelectedItems { get; set; }

/// <summary>
/// Event raised when the selection is changed by the user
/// </summary>
event CommandHandler SelectionChanged;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// ***********************************************************************
// Copyright (c) Charlie Poole and TestCentric contributors.
// Licensed under the MIT License. See LICENSE file in root directory.
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace TestCentric.Gui.Elements
{
/// <summary>
/// MultiCheckedToolStripButtonGroup wraps a set of ToolStrip button items as an IMultiSelection.
/// </summary>
internal class MultiCheckedToolStripButtonGroup : IMultiSelection
{
public event CommandHandler SelectionChanged;

public MultiCheckedToolStripButtonGroup(params ToolStripButton[] buttons)
{
ToolStripButtons = new List<ToolStripButton>();

foreach (var button in buttons)
{
ToolStripButtons.Add(button);
button.Click += OnButtonClicked;
}
}

protected IList<ToolStripButton> ToolStripButtons { get; }

public IEnumerable<string> SelectedItems
{
get
{
IList<string> result = new List<string>();
foreach (ToolStripButton button in ToolStripButtons)
if (button.Checked)
result.Add(button.Tag as string);

return result;
}

set
{
foreach (ToolStripButton button in ToolStripButtons)
{
bool checkStatus = value.Contains(button.Tag as string);
button.Checked = checkStatus;
}
}
}

private bool _enabled;
public bool Enabled
{
get { return _enabled; }
set
{
_enabled = value;

foreach (ToolStripButton button in ToolStripButtons)
button.Enabled = value;
}
}

private bool _visible;
public bool Visible
{
get { return _visible; }
set
{
_visible = value;

foreach (ToolStripButton button in ToolStripButtons)
button.Visible = value;
}
}

public string Text { get; set; }


public void InvokeIfRequired(MethodInvoker _delegate)
{
throw new System.NotImplementedException();
}

protected virtual void OnButtonClicked(object sender, EventArgs e)
{
if (SelectionChanged != null)
SelectionChanged();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public bool HasResults
public void OnTestUnloaded()
{
ClearTree();
_view.OutcomeFilter.Enabled = false;
}

public virtual void OnTestFinished(ResultNode result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public abstract class GroupDisplayStrategy : DisplayStrategy
public GroupDisplayStrategy(ITestTreeView view, ITestModel model)
: base(view, model)
{
_view.SetTestFilterVisibility(false);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public class NUnitTreeDisplayStrategy : DisplayStrategy
private IDictionary<TestNode, string> _foldedNodeNames = new Dictionary<TestNode, string>();

public NUnitTreeDisplayStrategy(ITestTreeView view, ITestModel model)
: base(view, model) { }
: base(view, model)
{
_view.SetTestFilterVisibility(model.Settings.Gui.TestTree.ShowFilter);
}


public override string StrategyID => "NUNIT_TREE";
Expand All @@ -45,6 +48,8 @@ public override void OnTestLoaded(TestNode testNode, VisualState visualState)
visualState.ApplyTo(_view.TreeView);
else
SetDefaultInitialExpansion();

_view.OutcomeFilter.Enabled = 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 @@ -87,6 +87,7 @@ public TestCentricPresenter(IMainView view, ITestModel model, CommandLineOptions
_resultFormats.Add(format);

WireUpEvents();
_view.ShowHideFilterButton.Checked = _settings.Gui.TestTree.ShowFilter;
}

#endregion
Expand Down Expand Up @@ -497,6 +498,11 @@ void OnRunFinished(ResultNode result)
_settings.Gui.TestTree.ShowNamespace = _view.ShowNamespace.SelectedIndex == 0;
};

_view.ShowHideFilterButton.CheckedChanged += () =>
{
_settings.Gui.TestTree.ShowFilter = _view.ShowHideFilterButton.Checked;
};

_view.GroupBy.SelectionChanged += () =>
{
switch(_view.DisplayFormat.SelectedItem)
Expand Down Expand Up @@ -766,6 +772,8 @@ private void UpdateViewCommands(bool testLoading = false)
_view.RunAllButton.Enabled =
_view.DisplayFormatButton.Enabled =
_view.RunParametersButton.Enabled = testLoaded && !testRunning;
_view.ShowHideFilterButton.Enabled = testLoaded && _view.DisplayFormat.SelectedItem == "NUNIT_TREE";
_view.ShowHideFilterButton.Visible = testLoaded && _view.DisplayFormat.SelectedItem == "NUNIT_TREE";

_view.RunSelectedButton.Enabled = testLoaded && !testRunning && _model.SelectedTests != null && _model.SelectedTests.Any();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ private void WireUpEvents()
if (_model.Settings.Gui.GuiLayout == "Full")
ClosePropertiesDisplay();
break;
case "TestCentric.Gui.TestTree.ShowFilter":
_view.SetTestFilterVisibility(_model.Settings.Gui.TestTree.ShowFilter);
break;
}
};

Expand Down Expand Up @@ -248,6 +251,12 @@ private void WireUpEvents()
_model.SelectedTests = selection;
};

_view.OutcomeFilter.SelectionChanged += () =>
{
var filter = _view.OutcomeFilter.SelectedItems;
_model.TestCentricTestFilter.OutcomeFilter = filter;
};

// Node selected in tree
//_treeView.SelectedNodesChanged += (nodes) =>
//{
Expand Down
1 change: 1 addition & 0 deletions src/TestCentric/testcentric.gui/Views/IMainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public interface IMainView
ISelection DisplayFormat { get; }
ISelection GroupBy { get; }
ISelection ShowNamespace { get; }
IChecked ShowHideFilterButton { get; }
ICommand RunParametersButton { get; }

IChecked RunSummaryButton { get; }
Expand Down
5 changes: 5 additions & 0 deletions src/TestCentric/testcentric.gui/Views/ITestTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public interface ITestTreeView : IView
TreeNode SelectedNode { get; set; }
IList<TreeNode> CheckedNodes { get; }

// Test Filter related properties / methods
IMultiSelection OutcomeFilter { get; }

void SetTestFilterVisibility(bool visible);

// Tree-related Methods
void Clear();
void Add(TreeNode treeNode);
Expand Down
16 changes: 16 additions & 0 deletions src/TestCentric/testcentric.gui/Views/TestCentricMainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class TestCentricMainView : TestCentricFormBase, IMainView
private ToolStripButton forceStopButton;
private ProgressBarView progressBar;
private ToolStripButton runAllButton;
private ToolStripButton showFilterButton;
private ToolStripButton runParametersButton;
private ToolStripButton runFailedButton;
private ToolStripSeparator toolStripSeparator5;
Expand Down Expand Up @@ -178,6 +179,7 @@ public TestCentricMainView() : base("TestCentric")
"testGrouping",
byAssemblyMenuItem, byFixtureMenuItem, byCategoryMenuItem, byOutcomeMenuItem, byDurationMenuItem);
ShowNamespace = new CheckedToolStripMenuGroup("showNamespace", nunitTreeShowNamespaceMenuItem, nunitTreeHideNamespaceMenuItem);
ShowHideFilterButton = new ToolStripButtonElement(showFilterButton);
RunParametersButton = new ToolStripButtonElement(runParametersButton);
RunSummaryButton = new CheckBoxElement(runSummaryButton);

Expand Down Expand Up @@ -228,6 +230,7 @@ private void InitializeComponent()
this.byCategoryMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.byOutcomeMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.byDurationMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showFilterButton = new System.Windows.Forms.ToolStripButton();
this.runParametersButton = new System.Windows.Forms.ToolStripButton();
this.mainMenu = new System.Windows.Forms.MenuStrip();
this.fileMenu = new System.Windows.Forms.ToolStripMenuItem();
Expand Down Expand Up @@ -324,6 +327,7 @@ private void InitializeComponent()
this.forceStopButton,
this.toolStripSeparator5,
this.displayFormatButton,
this.showFilterButton,
this.runParametersButton});
this.toolStrip.Location = new System.Drawing.Point(0, 24);
this.toolStrip.MinimumSize = new System.Drawing.Size(0, 24);
Expand Down Expand Up @@ -491,6 +495,16 @@ private void InitializeComponent()
this.byDurationMenuItem.Tag = "DURATION";
this.byDurationMenuItem.Text = "By Duration";
//
// showFilterButton
//
this.showFilterButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.showFilterButton.Image = ((System.Drawing.Image)(resources.GetObject("TestFilterButton.Image")));
this.showFilterButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.showFilterButton.Name = "showFilterButton";
this.showFilterButton.CheckOnClick = true;
this.showFilterButton.Size = new System.Drawing.Size(23, 21);
this.showFilterButton.ToolTipText = "Show/Hide filter";
//
// runParametersButton
//
this.runParametersButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
Expand Down Expand Up @@ -1149,6 +1163,8 @@ public int SplitterPosition
public ISelection DisplayFormat { get; private set; }
public ISelection GroupBy { get; private set; }
public ISelection ShowNamespace { get; private set; }

public IChecked ShowHideFilterButton { get; private set; }
public ICommand RunParametersButton { get; private set; }

public IChecked RunSummaryButton { get; private set; }
Expand Down
Loading

0 comments on commit 6344094

Please sign in to comment.