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

feat: Add filter for failed tests + search #448

Draft
wants to merge 1 commit into
base: staging
Choose a base branch
from
Draft
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 @@ -31,11 +31,37 @@ <h3 class="text-lg">Test Results</h3>
</button>

@if (!isTestResultsCollapsed) {
@if (testSuites(); as testSuites) {
<div class="flex items-center gap-2 w-full max-w-sm mb-2">
<p-button type="button" outlined (onClick)="toggleFilterMenu($event)" size="small">
@if (showOnlyFailed()) {
<i-tabler name="filter" />
} @else {
<i-tabler name="filter-plus" />
}
</p-button>
<input pInputText [(ngModel)]="searchValue" type="text" pSize="small" placeholder="Search" class="w-full" />
</div>

<p-popover #op>
<div class="flex flex-col gap-4">
<div>
<ul class="list-none p-0 m-0 flex flex-col gap-1">
@if (showOnlyFailed()) {
<li class="flex items-center gap-2 p-2 hover:bg-gray-300 cursor-pointer rounded-border" (click)="toggleShowOnlyFailed()">All tests</li>
<li class="flex items-center gap-2 p-2 bg-gray-700 text-gray-200 cursor-pointer rounded-border">Only failed tests</li>
} @else {
<li class="flex items-center gap-2 p-2 bg-gray-700 text-gray-200 cursor-pointer rounded-border">All tests</li>
<li class="flex items-center gap-2 p-2 hover:bg-gray-300 cursor-pointer rounded-border" (click)="toggleShowOnlyFailed()">Only failed tests</li>
}
</ul>
</div>
</div>
</p-popover>

@if (filteredTestSuites(); as testSuites) {
@if (testSuites.length === 0) {
<!-- No Results State -->
<div class="flex flex-col items-center p-4 border rounded-lg">
<i-tabler name="microscope" class="!size-12 text-primary mb-2"></i-tabler>
<span class="text-sm text-gray-500">No test results available</span>
</div>
} @else {
Expand All @@ -44,20 +70,20 @@ <h3 class="text-lg">Test Results</h3>
@for (suite of testSuites.slice(testSuiteFirst(), testSuiteFirst() + testSuiteRows()); track suite.id) {
<p-panel [toggleable]="true" [collapsed]="true">
<ng-template pTemplate="header">
<div class="flex items-center gap-2">
<div class="flex items-center gap-2 overflow-hidden">
@switch (overallSuiteState(suite)) {
@case ('SUCCESS') {
<i-tabler name="circle-check" class="text-green-500"></i-tabler>
<i-tabler name="circle-check" class="text-green-500 flex-shrink-0"></i-tabler>
}
@case ('FAILURE') {
<i-tabler name="circle-x" class="text-red-500"></i-tabler>
<i-tabler name="circle-x" class="text-red-500 flex-shrink-0"></i-tabler>
}
@case ('SKIPPED') {
<i-tabler name="circle-chevrons-right" class="text-yellow-500"></i-tabler>
<i-tabler name="circle-chevrons-right" class="text-yellow-500 flex-shrink-0"></i-tabler>
}
}
<span class="font-medium">{{ suite.name }}</span>
<span class="text-sm text-gray-500 ml-2"> ({{ suite.tests }} tests, {{ suite.failures + suite.errors }} failed, {{ suite.skipped }} skipped) </span>
<span class="font-medium truncate">{{ suite.name }}</span>
<span class="text-sm text-gray-500 ml-2 flex-shrink-0"> ({{ suite.tests }} tests, {{ suite.failures + suite.errors }} failed, {{ suite.skipped }} skipped) </span>
</div>
</ng-template>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, computed, input, signal } from '@angular/core';
import { Component, computed, input, signal, viewChild } from '@angular/core';
import { TableModule } from 'primeng/table';
import { ProgressSpinnerModule } from 'primeng/progressspinner';
import { PanelModule } from 'primeng/panel';
Expand All @@ -10,10 +10,29 @@ import { TagModule } from 'primeng/tag';
import { PaginatorModule, PaginatorState } from 'primeng/paginator';
import { CommonModule, DatePipe } from '@angular/common';
import { TestSuiteDto } from '@app/core/modules/openapi';
import { Popover, PopoverModule } from 'primeng/popover';
import { ButtonModule } from 'primeng/button';
import { InputTextModule } from 'primeng/inputtext';
import { FormsModule } from '@angular/forms';

@Component({
selector: 'app-pipeline-test-results',
imports: [TableModule, ProgressSpinnerModule, PanelModule, IconsModule, TooltipModule, SkeletonModule, TagModule, PaginatorModule, DatePipe, CommonModule],
imports: [
TableModule,
ProgressSpinnerModule,
PanelModule,
IconsModule,
TooltipModule,
SkeletonModule,
TagModule,
PaginatorModule,
DatePipe,
CommonModule,
PopoverModule,
ButtonModule,
InputTextModule,
FormsModule,
],
templateUrl: './pipeline-test-results.component.html',
})
export class PipelineTestResultsComponent {
Expand All @@ -24,6 +43,18 @@ export class PipelineTestResultsComponent {

isTestResultsCollapsed = true;

op = viewChild.required<Popover>('op');
searchValue = signal<string>('');
showOnlyFailed = signal<boolean>(false);

toggleFilterMenu(event: Event) {
this.op().toggle(event);
}

toggleShowOnlyFailed() {
this.showOnlyFailed.set(!this.showOnlyFailed());
}

testSuites = computed(() => {
const testSuites = this.pipeline()
.groups.flatMap(group => group.workflows.flatMap(workflow => workflow.testSuites))
Expand All @@ -32,6 +63,24 @@ export class PipelineTestResultsComponent {
return testSuites;
});

filteredTestSuites = computed(() => {
const testSuites = this.testSuites();
const searchValue = this.searchValue().toLowerCase();
const showOnlyFailed = this.showOnlyFailed();

return testSuites.filter(suite => {
if (showOnlyFailed && suite.failures + suite.errors === 0) {
return false;
}

if (searchValue) {
return suite.name.toLowerCase().includes(searchValue) || suite.testCases.some(testCase => testCase.name.toLowerCase().includes(searchValue));
}

return true;
});
});

sortTestCases(cases: TestSuiteDto['testCases']) {
// We want to show the failed/error test cases first
return cases.sort(a => (a.status === 'ERROR' || a.status === 'FAILED' ? -1 : 1));
Expand Down
Loading