Skip to content

Commit

Permalink
Add UI elements for test outcome filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
rowo360 committed Dec 7, 2024
1 parent 18b8a35 commit 46c7f0c
Show file tree
Hide file tree
Showing 17 changed files with 404 additions and 10 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// ***********************************************************************
// 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.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace TestCentric.Gui.Elements
{
/// <summary>
/// This class is a specialized class of class MultiCheckedToolStripButtonGroup
/// Therefore this class supports also the selection of multiple buttons.
/// But additionally there is one special default button that resets all other buttons when it is clicked.
/// </summary>
internal class MultiCheckedToolStripButtonGroupWithDefaultButton : MultiCheckedToolStripButtonGroup
{
public MultiCheckedToolStripButtonGroupWithDefaultButton(params ToolStripButton[] buttons) : base(buttons)
{
// By convention the default button is the first one in the list
DefaultButton = buttons.First();
IndividualButtons = buttons.Skip(1);

foreach (ToolStripButton button in ToolStripButtons)
button.CheckedChanged += OnButtonCheckedChanged;

DefaultButton.Checked = true;
}

private ToolStripButton DefaultButton { get; }

private IEnumerable<ToolStripButton> IndividualButtons { get; }

protected override void OnButtonClicked(object sender, EventArgs e)
{
ToolStripButton clickedButton = sender as ToolStripButton;
if (clickedButton == DefaultButton)
DefaultButtonClicked(sender, e);
else
IndividualButtonClicked(sender, e);

base.OnButtonClicked(sender, e);
}

private void DefaultButtonClicked(object sender, EventArgs e)
{
foreach (ToolStripButton button in IndividualButtons)
button.Checked = false;
}

private void IndividualButtonClicked(object sender, EventArgs e)
{
DefaultButton.Checked = false;
}

private void OnButtonCheckedChanged(object sender, EventArgs e)
{
ToolStripButton button = sender as ToolStripButton;
var style = button.Checked ? FontStyle.Bold : FontStyle.Regular;
button.Font = new Font(button.Font, style);
}
}
}
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(true);
}


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 @@ -248,6 +248,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
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
71 changes: 71 additions & 0 deletions src/TestCentric/testcentric.gui/Views/TestTreeView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 46c7f0c

Please sign in to comment.