55 lines
2.6 KiB
TypeScript
55 lines
2.6 KiB
TypeScript
import { TestBed } from '@angular/core/testing';
|
|
import { CdkDragDrop } from '@angular/cdk/drag-drop';
|
|
import { ImportFlow } from '../../domain/import-flow';
|
|
import { FakeConnection, FakeTable, NO_GATEWAY, PACIENTE } from '../../testing/fakes';
|
|
import { ColumnMapper } from './column-mapper';
|
|
|
|
describe('ColumnMapper', () => {
|
|
function setup() {
|
|
const flow = new ImportFlow(new FakeTable(new FakeConnection()), PACIENTE);
|
|
flow.load(NO_GATEWAY).subscribe();
|
|
const fixture = TestBed.createComponent(ColumnMapper);
|
|
fixture.componentRef.setInput('flow', flow);
|
|
fixture.detectChanges();
|
|
return { flow, fixture, mapper: fixture.componentInstance };
|
|
}
|
|
|
|
const drop = (column: string, target: string) =>
|
|
({ item: { data: column }, container: { data: target }, previousContainer: { data: 'tray' } }) as unknown as CdkDragDrop<string>;
|
|
|
|
it('renders a slot per destination field, required first, with the missing one flagged', () => {
|
|
const { fixture } = setup();
|
|
const rows = Array.from(fixture.nativeElement.querySelectorAll('.field')) as HTMLElement[];
|
|
expect(rows.map((row) => row.querySelector('.field__name')?.textContent?.trim())).toEqual(['pac_id_hospital', 'pac_sexo', 'pac_parentesco']);
|
|
expect(rows[0].classList).toContain('field--missing');
|
|
});
|
|
|
|
it('dropping a column on a field maps it; dropping it back on the tray unmaps it', () => {
|
|
const { flow, mapper } = setup();
|
|
mapper.onDropOnField(drop('Clave', 'pac_id_hospital'));
|
|
expect(flow.mapping.toRecord()).toEqual({ Sexo: 'pac_sexo', Clave: 'pac_id_hospital' });
|
|
expect(flow.status()).toBe('ready');
|
|
|
|
mapper.onDropOnTray({ item: { data: 'Clave' }, container: {}, previousContainer: { other: true } } as unknown as CdkDragDrop<string>);
|
|
expect(flow.mapping.toRecord()).toEqual({ Sexo: 'pac_sexo' });
|
|
});
|
|
|
|
it('the select is an alternative to dragging, and a default value covers a required field', () => {
|
|
const { flow, mapper } = setup();
|
|
mapper.pick('pac_sexo', null);
|
|
expect(flow.mapping.size()).toBe(0);
|
|
mapper.saveDefault('pac_id_hospital', ' H-DEFAULT ');
|
|
expect(flow.defaults()).toEqual({ pac_id_hospital: 'H-DEFAULT' });
|
|
expect(flow.missingRequired()).toEqual([]);
|
|
});
|
|
|
|
it('filters fields and columns', () => {
|
|
const { mapper } = setup();
|
|
mapper.fieldFilter.set('unassigned');
|
|
expect(mapper.fields().map((f) => f.name)).toEqual(['pac_id_hospital', 'pac_parentesco']);
|
|
mapper.onlyUnusedColumns.set(true);
|
|
expect(mapper.columns().map((c) => c.name)).toEqual(['Clave']);
|
|
expect(mapper.samples().get('Sexo')).toBe('F · X');
|
|
});
|
|
});
|