Risk batches: one decision at a time, so a double click doesn't send it twice
(cherry picked from commit 88c1eb33be)
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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: () => {
|
||||
|
||||
Reference in New Issue
Block a user