Feature: Flujo inicial
This commit is contained in:
+161
-4
@@ -1,12 +1,15 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { provideRouter, Router } from '@angular/router';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { App } from './app';
|
||||
import { routes } from './app.routes';
|
||||
|
||||
describe('App', () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [App],
|
||||
})
|
||||
.compileComponents();
|
||||
providers: [provideRouter(routes)],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
it('should create the app', () => {
|
||||
@@ -15,11 +18,165 @@ describe('App', () => {
|
||||
expect(app).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should render the toolbar title', async () => {
|
||||
it('should render the ISSSTELEON header and home page', async () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.detectChanges();
|
||||
await TestBed.inject(Router).navigateByUrl('/');
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('mat-toolbar')?.textContent).toContain('ISSSTELEON');
|
||||
expect(compiled.querySelector('.brand img')?.getAttribute('alt')).toBe('ISSSTELEON');
|
||||
expect(compiled.querySelector('.site-header__section')?.textContent).toContain(
|
||||
'Análisis de información',
|
||||
);
|
||||
expect(compiled.querySelector('h1')?.textContent).toContain('Analiza tu información');
|
||||
});
|
||||
|
||||
it('opens one dialog and keeps it open on backdrop and Escape', async () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.detectChanges();
|
||||
await TestBed.inject(Router).navigateByUrl('/');
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.nativeElement.querySelector('.home__action').click();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const dialog = TestBed.inject(MatDialog);
|
||||
expect(dialog.openDialogs).toHaveLength(1);
|
||||
const overlay = document.querySelector('.cdk-overlay-container')!;
|
||||
expect(overlay.querySelector('#upload-title')?.textContent).toContain('Cargar información');
|
||||
overlay.querySelector<HTMLElement>('.cdk-overlay-backdrop')?.click();
|
||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
|
||||
expect(dialog.openDialogs).toHaveLength(1);
|
||||
expect(overlay.querySelector('.upload-dialog__continue')?.hasAttribute('disabled')).toBe(true);
|
||||
});
|
||||
|
||||
it('selects either source, continues, returns with selection, and closes explicitly', async () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.detectChanges();
|
||||
await TestBed.inject(Router).navigateByUrl('/');
|
||||
await fixture.whenStable();
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.nativeElement.querySelector('.home__action').click();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const overlay = document.querySelector('.cdk-overlay-container')!;
|
||||
const cards = () => overlay.querySelectorAll<HTMLButtonElement>('.source-card');
|
||||
const continueButton = overlay.querySelector<HTMLButtonElement>('.upload-dialog__continue')!;
|
||||
const detectDialogChanges = () => TestBed.inject(MatDialog).openDialogs[0].componentRef?.changeDetectorRef.detectChanges();
|
||||
expect(continueButton.disabled).toBe(true);
|
||||
overlay.querySelector<HTMLButtonElement>('.source-card')!.click();
|
||||
detectDialogChanges();
|
||||
expect(continueButton.disabled).toBe(false);
|
||||
continueButton.click();
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
expect(overlay.querySelector('.upload-dialog__description')?.textContent).toContain(
|
||||
'Selecciona los archivos que deseas procesar.',
|
||||
);
|
||||
expect(overlay.querySelector('.upload-steps__item--active')?.textContent).toContain(
|
||||
'Configuración',
|
||||
);
|
||||
expect(continueButton.disabled).toBe(true);
|
||||
const fileInput = overlay.querySelector<HTMLInputElement>('input[type="file"]')!;
|
||||
const validFile = new File(['contenido'], 'pacientes.XLSX', {
|
||||
type: 'application/octet-stream',
|
||||
});
|
||||
const csvFile = new File(['a,b'], 'consultas.csv', { type: 'text/csv' });
|
||||
const invalidFile = new File(['x'], 'documento.docx');
|
||||
const emptyFile = new File([], 'vacio.csv');
|
||||
const selectFiles = (...files: File[]) => {
|
||||
Object.defineProperty(fileInput, 'files', { configurable: true, value: files });
|
||||
fileInput.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
};
|
||||
selectFiles(validFile, csvFile, invalidFile, emptyFile);
|
||||
expect(overlay.querySelectorAll('.file-row')).toHaveLength(2);
|
||||
expect(overlay.querySelector('.file-messages')?.textContent).toContain(
|
||||
'documento.docx no fue agregado. Formato no compatible.',
|
||||
);
|
||||
expect(overlay.querySelector('.file-messages')?.textContent).toContain(
|
||||
'vacio.csv no fue agregado. El archivo está vacío.',
|
||||
);
|
||||
expect(continueButton.disabled).toBe(false);
|
||||
selectFiles(validFile);
|
||||
expect(overlay.querySelectorAll('.file-row')).toHaveLength(2);
|
||||
expect(overlay.querySelector('.file-messages')?.textContent).toContain(
|
||||
'pacientes.XLSX ya se encuentra seleccionado.',
|
||||
);
|
||||
const jsonFile = new File(['{}'], 'nuevo.json', { type: 'application/json' });
|
||||
const dialogComponent = TestBed.inject(MatDialog).openDialogs[0].componentRef!
|
||||
.instance as import('./information-upload-dialog').InformationUploadDialog;
|
||||
dialogComponent.onDrop({
|
||||
preventDefault: () => undefined,
|
||||
dataTransfer: { files: [jsonFile] },
|
||||
} as unknown as DragEvent);
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
expect(overlay.querySelectorAll('.file-row')).toHaveLength(3);
|
||||
overlay.querySelector<HTMLButtonElement>('.file-row__remove')!.click();
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
expect(overlay.querySelectorAll('.file-row')).toHaveLength(2);
|
||||
continueButton.click();
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
expect(overlay.querySelector('h3')?.textContent).toContain('Confirmación');
|
||||
expect(overlay.querySelector('.configuration-placeholder p')?.textContent).toContain(
|
||||
'La confirmación de los archivos se implementará en la siguiente fase.',
|
||||
);
|
||||
overlay.querySelector<HTMLButtonElement>('.upload-dialog__back')!.click();
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
expect(overlay.querySelectorAll('.file-row')).toHaveLength(2);
|
||||
while (overlay.querySelector('.file-row__remove')) {
|
||||
overlay.querySelector<HTMLButtonElement>('.file-row__remove')!.click();
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
}
|
||||
expect(overlay.querySelectorAll('.file-row')).toHaveLength(0);
|
||||
expect(overlay.querySelector<HTMLButtonElement>('.upload-dialog__continue')?.disabled).toBe(true);
|
||||
overlay.querySelector<HTMLButtonElement>('.upload-dialog__back')!.click();
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
expect(cards()[0].getAttribute('aria-pressed')).toBe('true');
|
||||
overlay.querySelectorAll<HTMLButtonElement>('.source-card')[1].click();
|
||||
detectDialogChanges();
|
||||
const sqlContinueButton = overlay.querySelector<HTMLButtonElement>('.upload-dialog__continue')!;
|
||||
expect(sqlContinueButton.disabled).toBe(false);
|
||||
sqlContinueButton.click();
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
expect(overlay.querySelector('h3')?.textContent).toContain('Conexión SQL');
|
||||
expect(overlay.querySelector<HTMLButtonElement>('.upload-dialog__continue')?.disabled).toBe(true);
|
||||
overlay.querySelector<HTMLButtonElement>('.upload-dialog__back')!.click();
|
||||
detectDialogChanges();
|
||||
fixture.detectChanges();
|
||||
expect(cards()[1].getAttribute('aria-pressed')).toBe('true');
|
||||
overlay.querySelector<HTMLButtonElement>('.upload-dialog__close')!.click();
|
||||
fixture.detectChanges();
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
expect(TestBed.inject(MatDialog).openDialogs).toHaveLength(0);
|
||||
|
||||
fixture.nativeElement.querySelector('.home__action').click();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const reopenedOverlay = document.querySelector('.cdk-overlay-container')!;
|
||||
reopenedOverlay.querySelector<HTMLButtonElement>('.source-card')!.click();
|
||||
const reopenedDialog = TestBed.inject(MatDialog).openDialogs[0].componentRef!;
|
||||
reopenedDialog.changeDetectorRef.detectChanges();
|
||||
reopenedOverlay.querySelector<HTMLButtonElement>('.upload-dialog__continue')!.click();
|
||||
reopenedDialog.changeDetectorRef.detectChanges();
|
||||
expect(reopenedOverlay.querySelector('.selected-files')).toBeNull();
|
||||
expect(reopenedOverlay.querySelector<HTMLButtonElement>('.upload-dialog__continue')?.disabled).toBe(true);
|
||||
reopenedOverlay.querySelector<HTMLButtonElement>('.upload-dialog__cancel')!.click();
|
||||
fixture.detectChanges();
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
expect(TestBed.inject(MatDialog).openDialogs).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user