From 4e08bb8c4b4c15d6e1f4e56dec59664ae1ad434b Mon Sep 17 00:00:00 2001 From: edgar Date: Sun, 22 Nov 2026 09:35:01 -0600 Subject: [PATCH] Risk batches: one decision at a time, so a double click doesn't send it twice (cherry picked from commit 88c1eb33be973fbbedb69a820793031cd46fb7ed) --- .../risk-batches-panel.spec.ts | 21 +++++++++++++++++-- .../risk-batches-panel/risk-batches-panel.ts | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) 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 index 5fb0ca6..46297c5 100644 --- 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 @@ -1,8 +1,8 @@ // 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, +// 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 } from 'rxjs'; +import { of, Subject } from 'rxjs'; import { vi } from 'vitest'; import { AuthService } from '../../../auth/auth.service'; import { RiskBatchesApi } from '../../api/risk-batches.api'; @@ -45,4 +45,21 @@ describe('RiskBatchesPanel domains', () => { 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(); + }); }); diff --git a/src/app/governance/components/risk-batches-panel/risk-batches-panel.ts b/src/app/governance/components/risk-batches-panel/risk-batches-panel.ts index 8a0a52e..825bb24 100644 --- a/src/app/governance/components/risk-batches-panel/risk-batches-panel.ts +++ b/src/app/governance/components/risk-batches-panel/risk-batches-panel.ts @@ -111,7 +111,8 @@ export class RiskBatchesPanel implements OnInit { verb: string, ): void { const reason = this.reasonFor(batch).value.trim(); - if (!reason) return; + // a double click reaches here before the disabled button is drawn: one decision at a time + if (!reason || this.deciding() !== null) return; this.deciding.set(batch.lote_id); request(reason).subscribe({ next: () => {