4e08bb8c4b
(cherry picked from commit 88c1eb33be)
66 lines
2.9 KiB
TypeScript
66 lines
2.9 KiB
TypeScript
// 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, one decision at a time. 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, Subject } 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<string, ReturnType<typeof vi.fn>>;
|
|
|
|
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');
|
|
});
|
|
|
|
// Fails if a double click sends the decision twice: the second one finds nothing to decide or collides with the first.
|
|
it('sends one decision while another is on its way', () => {
|
|
const answer = new Subject<{ lote_id: number; evaluaciones_cambiadas: number }>();
|
|
api['confirm'].mockReturnValue(answer);
|
|
const f = TestBed.createComponent(RiskBatchesPanel);
|
|
f.detectChanges();
|
|
const batch = f.componentInstance.batches()[0];
|
|
f.componentInstance.reasonFor(batch).setValue('revisado');
|
|
|
|
f.componentInstance.confirm(batch);
|
|
f.componentInstance.confirm(batch);
|
|
f.componentInstance.void(batch);
|
|
|
|
expect(api['confirm']).toHaveBeenCalledTimes(1);
|
|
expect(api['void']).not.toHaveBeenCalled();
|
|
});
|
|
});
|