File size: 1,588 Bytes
cdfb5de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { describe, expect, it } from 'vitest';
import type { Schemas } from '../api/client';
import { effortSavedHours, regressionToDate, updateCycles } from './homeStats';

const run = (id: string, status: string, created_at: string, counts: Record<string, number>, patch_id: string | null = '26D') =>
  ({ run_id: id, status, created_at, counts, patch_id, modules: ['AP'], decisions: {} }) as unknown as Schemas['RunSummary'];

describe('home numbers', () => {
  const runs = [
    run('a', 'completed', '2026-11-18T10:00:00Z', { passed: 7, failed: 1, skipped: 2 }),
    run('b', 'waiting_review', '2026-11-19T10:00:00Z', { passed: 5, failed: 2 }),
    run('c', 'cancelled', '2026-11-10T10:00:00Z', { passed: 0, failed: 0 }, '26C'),
    run('d', 'completed', '2026-11-01T10:00:00Z', { passed: 3, failed: 0 }, null),
  ];

  it('counts only runs that executed scenarios as test cycles', () => {
    expect(regressionToDate(runs)).toEqual({ passed: 15, failed: 3, skipped: 2, executed: 18, cycles: 3, passRate: 83 });
    expect(regressionToDate([]).passRate).toBeNull();
  });

  it('states effort saved from the scenarios executed', () => {
    expect(effortSavedHours(18)).toBe(6);
    expect(effortSavedHours(0)).toBe(0);
  });

  it('gives each update its stage from its newest run, newest update first', () => {
    expect(updateCycles(runs)).toEqual([
      { patch: '26D', stage: 'in_progress', runs: 2, passed: 12, failed: 3, last: '2026-11-19T10:00:00Z' },
      { patch: '26C', stage: 'stopped', runs: 1, passed: 0, failed: 0, last: '2026-11-10T10:00:00Z' },
    ]);
  });
});