import { Component, inject } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { ApiService } from '../../services/api.service'; interface TestResult { name: string; status: 'PASS' | 'FAIL' | 'RUNNING'; duration_ms?: number; error?: string; } interface TestRun { test_type: string; start_time: string; tests: TestResult[]; summary: { total: number; passed: number; failed: number; duration_ms: number; }; } @Component({ selector: 'app-test', standalone: true, imports: [CommonModule, FormsModule], template: `

System Tests

@if (currentRun) {

Test Results:

@for (test of currentRun.tests; track test.name) {
@if (test.status === 'PASS') { } @else if (test.status === 'FAIL') { } @else { } {{ test.name }} @if (test.duration_ms) { {{ test.duration_ms }}ms } @if (test.error) {
{{ test.error }}
}
}
@if (!running && currentRun.summary) {
Progress: {{ currentRun.summary.passed + currentRun.summary.failed }}/{{ currentRun.summary.total }} ({{ ((currentRun.summary.passed / currentRun.summary.total) * 100).toFixed(0) }}%)
Passed: {{ currentRun.summary.passed }} | Failed: {{ currentRun.summary.failed }} | Total time: {{ (currentRun.summary.duration_ms / 1000).toFixed(1) }}s
}
} @if (!currentRun && !running) {

No test results yet. Click "Run All Tests" to start.

}
`, styles: [` .test-container { h2 { margin-bottom: 1.5rem; } } .test-controls { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; } .test-categories { background: white; border: 1px solid #dee2e6; border-radius: 0.25rem; padding: 1rem; margin-bottom: 1.5rem; .category { margin-bottom: 0.5rem; label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; input[type="checkbox"] { cursor: pointer; } } } .sub-tests { margin-left: 1.5rem; margin-top: 0.5rem; label { display: block; margin-bottom: 0.25rem; font-weight: normal; color: #6c757d; } } } .test-results { background: white; border: 1px solid #dee2e6; border-radius: 0.25rem; padding: 1rem; h3 { margin-top: 0; margin-bottom: 1rem; } .results-list { max-height: 400px; overflow-y: auto; margin-bottom: 1rem; } .test-result { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem; border-bottom: 1px solid #f0f0f0; &.pass .status { color: #28a745; } &.fail .status { color: #dc3545; } .status { width: 20px; text-align: center; } .name { flex: 1; } .duration { color: #6c757d; font-size: 0.875rem; } .error { width: 100%; margin-top: 0.5rem; padding: 0.5rem; background-color: #f8d7da; color: #721c24; border-radius: 0.25rem; font-size: 0.875rem; } } } .test-summary { border-top: 1px solid #dee2e6; padding-top: 1rem; .progress-bar { height: 20px; background-color: #e9ecef; border-radius: 0.25rem; overflow: hidden; margin-bottom: 0.5rem; .progress-fill { height: 100%; transition: width 0.3s ease; &.success { background-color: #28a745; } &.warning { background-color: #ffc107; } } } .summary-text, .summary-stats { text-align: center; color: #6c757d; margin-bottom: 0.5rem; } } .empty-state { text-align: center; padding: 3rem; background-color: white; border-radius: 0.25rem; p { color: #6c757d; } } `] }) export class TestComponent { private apiService = inject(ApiService); running = false; allSelected = false; categories = { ui: false, backend: false, integration: false, spark: false }; selectedTests: string[] = []; currentRun: TestRun | null = null; toggleAll() { this.categories.ui = this.allSelected; this.categories.backend = this.allSelected; this.categories.integration = this.allSelected; this.categories.spark = this.allSelected; this.updateSelection(); } updateSelection() { this.selectedTests = []; if (this.categories.ui) this.selectedTests.push('ui'); if (this.categories.backend) this.selectedTests.push('backend'); if (this.categories.integration) this.selectedTests.push('integration'); if (this.categories.spark) this.selectedTests.push('spark'); this.allSelected = this.selectedTests.length === 4; } runAllTests() { this.running = true; this.apiService.runTests('all').subscribe({ next: (result) => { this.currentRun = result; this.running = false; }, error: (err) => { console.error('Test run failed:', err); this.running = false; } }); } runSelectedTests() { // TODO: Implement selected tests console.log('Running selected tests:', this.selectedTests); this.runAllTests(); // For now, just run all } stopTests() { this.running = false; // TODO: Implement stop functionality } }