Skip to content

Commit

Permalink
Merge pull request #41 from AxaFrance/feat/ReportViewerFilter
Browse files Browse the repository at this point in the history
feat: [ReportViewer] add filter on test name and failed tests
  • Loading branch information
huaxing-yuan authored Sep 8, 2023
2 parents 874bc49 + 04f7edf commit 81ab04e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/AxaFrance.WebEngine.ReportViewer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
41 changes: 25 additions & 16 deletions src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,31 @@
</TabControl>


<ListBox x:Name="lvTestcases" Grid.Row="2" Grid.Column="0" Grid.RowSpan="2" BorderThickness="0,1,0,0" SelectionChanged="lvTestcases_SelectionChanged" Background="Transparent" Margin="0,0,6,0" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Source="{Binding Result, Converter={StaticResource ResultToImageSourceConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="4,4" />
<TextBlock Text="{Binding TestName}" Grid.Column="1" Margin="4" VerticalAlignment="Center" />
<TextBlock Text="{Binding DurationText}" Grid.Column="2" Margin="4" VerticalAlignment="Center" Foreground="#CCCCCC" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Orientation="Vertical" VerticalAlignment="Top" Grid.Row="2" Grid.Column="0" Grid.RowSpan="2">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top">
<Label Content="Filter" HorizontalAlignment="Left" />
<TextBox x:Name="txFilter" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" Height="25" Width="175" TextChanged="TxFilter_OnTextChanged" />
<CheckBox x:Name="cbFailed" Content="Failed" Foreground="White" Checked="CbFailed_OnChecked" Unchecked="cbFailed_Unchecked"/>
</StackPanel>
<ListBox x:Name="lvTestcases" BorderThickness="0,1,0,0" SelectionChanged="lvTestcases_SelectionChanged" Background="Transparent" Margin="0,0,6,0" Height="693" VerticalAlignment="Top" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Source="{Binding Result, Converter={StaticResource ResultToImageSourceConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="4,4" />
<TextBlock Text="{Binding TestName}" Grid.Column="1" Margin="4" VerticalAlignment="Center" />
<TextBlock Text="{Binding DurationText}" Grid.Column="2" Margin="4" VerticalAlignment="Center" Foreground="#CCCCCC" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</StackPanel>

<GridSplitter Grid.Column="0" Grid.Row="2" Grid.RowSpan="2" Width="5" />
<GridSplitter Grid.Row="2" Grid.Column="1" Panel.ZIndex="10" Style="{DynamicResource HorizontalGridSplitter}" VerticalAlignment="Bottom" />
Expand Down
63 changes: 63 additions & 0 deletions src/AxaFrance.WebEngine.ReportViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit 81ab04e

Please sign in to comment.