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

Don't refresh the filtered tests if the filter hasn't actually changed #13236

Merged
merged 1 commit into from
Feb 10, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public TFilterArg FilterArgument
get { return filterArgument; }
set
{
if (filterArgument.Equals(value))
{
return;
}

filterArgument = value;
RefreshFilter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Layouts;

namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.VisualRunner
{
public class TestAssemblyViewModel : ViewModelBase
{
readonly ObservableCollection<TestCaseViewModel> _allTests;
readonly FilteredCollectionView<TestCaseViewModel, (string, TestState)> _filteredTests;
readonly FilteredCollectionView<TestCaseViewModel, FilterArgs> _filteredTests;
readonly ITestNavigation _navigation;
readonly ITestRunner _runner;
readonly List<TestCaseViewModel> _results;
Expand Down Expand Up @@ -70,10 +72,10 @@ internal TestAssemblyViewModel(AssemblyRunInfo runInfo, ITestNavigation navigati
}
};

_filteredTests = new FilteredCollectionView<TestCaseViewModel, (string, TestState)>(
_filteredTests = new FilteredCollectionView<TestCaseViewModel, FilterArgs>(
_allTests,
IsTestFilterMatch,
(SearchQuery, ResultFilter),
new FilterArgs(SearchQuery, ResultFilter),
new TestComparer());

_filteredTests.ItemChanged += (sender, args) => UpdateCaption();
Expand Down Expand Up @@ -177,18 +179,19 @@ void FilterAfterDelay()

Task.Delay(500, token)
.ContinueWith(
x => { _filteredTests.FilterArgument = (SearchQuery, ResultFilter); },
x => { _filteredTests.FilterArgument = new FilterArgs(SearchQuery, ResultFilter); },
token,
TaskContinuationOptions.None,
TaskScheduler.FromCurrentSynchronizationContext());
}

static bool IsTestFilterMatch(TestCaseViewModel test, (string SearchQuery, TestState ResultFilter) query)
static bool IsTestFilterMatch(TestCaseViewModel test, FilterArgs query)
{
if (test == null)
throw new ArgumentNullException(nameof(test));

var (pattern, state) = query;
var state = query.State;
var pattern = query.Query;

TestState? requiredTestState = state switch
{
Expand Down Expand Up @@ -334,4 +337,31 @@ class TestComparer : IComparer<TestCaseViewModel>
string.Compare(x?.DisplayName, y?.DisplayName, StringComparison.OrdinalIgnoreCase);
}
}

struct FilterArgs
{
public string Query { get; set; }
public TestState State { get; set; }

public FilterArgs(string query, TestState state)
{
Query = query;
State = state;
}

public override bool Equals([NotNullWhen(true)] object? obj)
{
if (obj is FilterArgs args)
{
return args.State == State && args.Query == Query;
}

return base.Equals(obj);
}

public override int GetHashCode()
{
return Query.GetHashCode(StringComparison.InvariantCulture) ^ State.GetHashCode();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
}