1import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
2import { MatListModule, MatSelectionListChange } from '@angular/material/list';
3
4import { Golden } from '../golden';
5import { MotionGoldenComponent } from '../motion-golden/motion-golden.component';
6import { ScreenshotGoldenComponent } from '../screenshot-golden/screenshot-golden.component';
7
8@Component({
9  selector: 'app-test-overview',
10  standalone: true,
11  imports: [MatListModule, MotionGoldenComponent, ScreenshotGoldenComponent],
12  templateUrl: './test-overview.component.html',
13  styleUrl: './test-overview.component.scss',
14})
15export class TestOverviewComponent implements OnChanges {
16  @Input() goldens: Golden[] = [];
17
18  totalTestCount = 0;
19  passingTestCount = 0;
20  failingTestCount = 0;
21
22  ngOnChanges(changes: SimpleChanges): void {
23    if (changes['goldens']) {
24      this.totalTestCount = this.goldens.length;
25      this.failingTestCount = this.goldens.filter(
26        (golden) => golden.result !== 'PASSED',
27      ).length;
28      this.passingTestCount = this.totalTestCount - this.failingTestCount;
29    }
30  }
31
32  get selectedGolden() {
33    return this.goldens.find((it) => it.id == this.selectedGoldenId);
34  }
35
36  selectedGoldenId: String | null = null;
37
38  goldenSelected(ev: MatSelectionListChange) {
39    const selection = ev.source.selectedOptions;
40    this.selectedGoldenId = selection.hasValue()
41      ? selection.selected[0].value
42      : null;
43  }
44}
45