From 04f7edfcd6a6e06fb630dee45a7adfd297d93ad1 Mon Sep 17 00:00:00 2001 From: Etienne DIVINA Date: Fri, 8 Sep 2023 15:29:59 +0200 Subject: [PATCH] feat: [ReportViewer] add filter on test name and failed tests --- .../App.xaml.cs | 3 + .../MainWindow.xaml | 41 +++++++----- .../MainWindow.xaml.cs | 63 +++++++++++++++++++ 3 files changed, 91 insertions(+), 16 deletions(-) diff --git a/src/AxaFrance.WebEngine.ReportViewer/App.xaml.cs b/src/AxaFrance.WebEngine.ReportViewer/App.xaml.cs index 040907a..96ed549 100644 --- a/src/AxaFrance.WebEngine.ReportViewer/App.xaml.cs +++ b/src/AxaFrance.WebEngine.ReportViewer/App.xaml.cs @@ -20,6 +20,9 @@ public partial class App : Application { public static string LogFile { get; set; } + public static string Filter { get; set; } + public static bool FilterFailed { get; set; } + private void Application_Startup(object sender, StartupEventArgs e) { this.StartupUri = new Uri("MainWindow.xaml", UriKind.RelativeOrAbsolute); diff --git a/src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml b/src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml index daee20a..41b3ceb 100644 --- a/src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml +++ b/src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml @@ -136,22 +136,31 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml.cs b/src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml.cs index 7c4bf6b..93391a8 100644 --- a/src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml.cs +++ b/src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml.cs @@ -37,6 +37,20 @@ private void Window_Loaded(object sender, RoutedEventArgs e) } string xmlReport; + private bool ShouldSkip(TestCaseReport tc) + { + if (!string.IsNullOrEmpty(App.Filter) && !(tc.TestName.IndexOf(App.Filter, StringComparison.OrdinalIgnoreCase) >= 0)) + { + return true; + } + + if (App.FilterFailed && tc.Result != Result.Failed && tc.Result != Result.CriticalError) + { + return true; + } + + return false; + } private void Load() { @@ -57,6 +71,10 @@ private void Load() double totalSeconds = ts.Duration.TotalSeconds; foreach (var tc in ts.TestResult) { + if (this.ShouldSkip(tc)) + { + continue; + } lvTestcases.Items.Add(tc); switch (tc.Result) { @@ -295,6 +313,7 @@ private void ShowXmlReport_Click(object sender, RoutedEventArgs e) WindowViewXML xml = new WindowViewXML(xmlReport); xml.ShowDialog(); } + private bool Reseting = false; private void OpenReport_Click(object sender, RoutedEventArgs e) { @@ -309,6 +328,12 @@ private void OpenReport_Click(object sender, RoutedEventArgs e) if (result.HasValue && result.Value) { App.LogFile = ofd.FileName; + + this.Reseting = true; + txFilter.Text = string.Empty; + cbFailed.IsChecked = false; + this.Reseting = false; + Load(); } } @@ -347,5 +372,43 @@ private void BtnAbout_Click(object sender, RoutedEventArgs e) wa.ShowDialog(); wa.Close(); } + + private void TxFilter_OnTextChanged(object sender, TextChangedEventArgs e) + { + if (!this.IsInitialized) + { + return; + } + App.Filter = txFilter.Text; + if (this.Reseting) + { + return; + } + Load(); + } + + private void CheckedChanged() + { + if (!this.IsInitialized) + { + return; + } + App.FilterFailed = cbFailed.IsChecked.HasValue && cbFailed.IsChecked.Value; + if (this.Reseting) + { + return; + } + Load(); + } + + private void CbFailed_OnChecked(object sender, RoutedEventArgs e) + { + this.CheckedChanged(); + } + + private void cbFailed_Unchecked(object sender, RoutedEventArgs e) + { + this.CheckedChanged(); + } } }