From db4d743413170c85b83388b245ce08f681ca5afa Mon Sep 17 00:00:00 2001 From: rockdrigo Date: Sat, 21 Nov 2026 04:48:43 -0600 Subject: [PATCH] Governance: spec for the risk batches panel's domains --- .../risk-batches-panel.spec.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/app/governance/components/risk-batches-panel/risk-batches-panel.spec.ts diff --git a/src/app/governance/components/risk-batches-panel/risk-batches-panel.spec.ts b/src/app/governance/components/risk-batches-panel/risk-batches-panel.spec.ts new file mode 100644 index 0000000..5fb0ca6 --- /dev/null +++ b/src/app/governance/components/risk-batches-panel/risk-batches-panel.spec.ts @@ -0,0 +1,48 @@ +// Covers the risk batches panel's domain choice: it lists the pending batches of the domain shown (CaCu first, CaMa on +// request) and decides a batch in that domain. Fixtures: a stub of `RiskBatchesApi` that records the domain of each call, +// and an account that reaches every domain. +import { TestBed } from '@angular/core/testing'; +import { of } from 'rxjs'; +import { vi } from 'vitest'; +import { AuthService } from '../../../auth/auth.service'; +import { RiskBatchesApi } from '../../api/risk-batches.api'; +import { RiskBatchesPanel } from './risk-batches-panel'; + +describe('RiskBatchesPanel domains', () => { + let api: Record>; + + beforeEach(() => { + api = { + listPending: vi.fn(() => of([{ lote_id: 5, modelo: 'cama-survival v1', evaluado_en: '2026-01-01T00:00:00Z', n_evaluaciones: 1500, motivo: null }])), + confirm: vi.fn(() => of({ lote_id: 5, evaluaciones_cambiadas: 1500 })), + void: vi.fn(() => of({ lote_id: 5, evaluaciones_cambiadas: 1500 })), + }; + TestBed.configureTestingModule({ + providers: [{ provide: RiskBatchesApi, useValue: api }, { provide: AuthService, useValue: { puedeVer: () => true } }], + }); + }); + + // Fails if the panel stops asking CaCu first, or never asks CaMa's batches when it is chosen. + it('lists CaCu first and the chosen domain after', () => { + const f = TestBed.createComponent(RiskBatchesPanel); + f.detectChanges(); + expect(api['listPending']).toHaveBeenLastCalledWith('cacu'); + + f.componentInstance.setDomain('cama'); + + expect(api['listPending']).toHaveBeenLastCalledWith('cama'); + }); + + // Fails if a decision goes to the wrong domain's batches, which would confirm another model's evaluations. + it('confirms a batch in the domain being shown', () => { + const f = TestBed.createComponent(RiskBatchesPanel); + f.detectChanges(); + f.componentInstance.setDomain('cama'); + const batch = f.componentInstance.batches()[0]; + f.componentInstance.reasonFor(batch).setValue('revisado'); + + f.componentInstance.confirm(batch); + + expect(api['confirm']).toHaveBeenCalledExactlyOnceWith('cama', 5, 'revisado'); + }); +});