Files
WebApp/src/app/governance/components/eeg-picker/eeg-picker.spec.ts
T

40 lines
2.1 KiB
TypeScript

/** Pins paging and retained EEG choices with mocked catalog pages and a failed request. */
import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { EegPicker } from './eeg-picker';
describe('EegPicker', () => {
/** Fails if a page exceeds 50 rows, a new page loses selections, or a failed page cannot be retried. */
it('keeps checked EEGs through paging and offers retry on failure', async () => {
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting()] });
const http = TestBed.inject(HttpTestingController);
const fixture = TestBed.createComponent(EegPicker);
fixture.detectChanges();
const first = http.expectOne('/governance/tea/eeg?limit=50&offset=0');
// A full first page permits forward navigation.
first.flush(Array.from({ length: 50 }, (_, id) => ({
id, lab_id: 'LAB-' + id, study_date: null, patient_id: null, valid: null, analysed: false,
})));
await fixture.whenStable();
fixture.detectChanges();
fixture.nativeElement.querySelector('input').click();
const next = Array.from(fixture.nativeElement.querySelectorAll('button') as NodeListOf<HTMLButtonElement>)
.find((button) => button.textContent?.includes('Siguiente'))!;
next.click();
fixture.detectChanges();
http.expectOne('/governance/tea/eeg?limit=50&offset=50').flush(null, { status: 500, statusText: 'Server Error' });
await fixture.whenStable();
fixture.detectChanges();
expect(fixture.componentInstance.selected()).toEqual([0]);
expect(fixture.nativeElement.querySelector('[role=alert]').textContent).toContain('No se pudieron cargar los EEGs.');
fixture.nativeElement.querySelector('button').click();
fixture.detectChanges();
http.expectOne('/governance/tea/eeg?limit=50&offset=50').flush([]);
await fixture.whenStable();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toContain('No hay EEGs en esta página.');
http.verify();
});
});