import { describe, expect, it } from '@jest/globals'; import { createXamlFiles } from './procon-xaml-export'; import type { ProConViewElement } from '../../_schemas/anlagen/procon-view-aggregate'; describe('XAML-Dateiexport', () => { const element: ProConViewElement = { key: 'main', name: '', darstellung: 'xaml', typ: 'main', width: 40, height: 40, posX: 0, posY: 0, zIndex: 0, show: true, varianten: [ { zustand: 'active', xaml: 'ä', xamlBase64: '' }, { zustand: 'inactive', xamlBase64: Buffer.from('').toString('base64') }, { zustand: 'error', xamlBase64: '' }, ], }; const aggregates = [{ componentId: 'c1', viewName: 'SF1_Band', elemente: [element] }]; const dto = { anlageId: 'a1', auswahl: [{ componentId: 'c1', elementKeys: ['main'] }] }; it('erstellt Dateien für die Auswahl und dekodiert ältere Base64-Daten', () => { expect(createXamlFiles(aggregates, dto)).toEqual({ files: [ { name: 'SF1_Band_main_active.xaml', data: 'ä' }, { name: 'SF1_Band_main_inactive.xaml', data: '' }, ], skipped: 1, }); expect(createXamlFiles(aggregates, { ...dto, auswahl: [{ componentId: 'c1', elementKeys: [] }] }).files).toEqual([]); }); it('verhindert Pfade außerhalb des Exportordners und leere View-Namen', () => { for (const viewName of ['../fremd', 'C:\\fremd', '', 'Datei.']) { expect(() => createXamlFiles([{ ...aggregates[0], viewName }], dto)).toThrow('Dateinamenbestandteile'); } }); it('verhindert doppelte Dateinamen und unbekannte Auswahlen', () => { expect(() => createXamlFiles(aggregates, { ...dto, auswahl: [...dto.auswahl, ...dto.auswahl] })).toThrow('Doppelter'); expect(() => createXamlFiles(aggregates, { ...dto, auswahl: [{ componentId: 'fremd', elementKeys: ['main'] }] })).toThrow('dieser Anlage'); }); it('verwendet den festen Bibliotheksnamen und exportiert Mehrfachverwendungen nur einmal', () => { const fixed: ProConViewElement = { ...element, varianten: [{ zustand: 'inactive', libraryId: 'library1', libraryName: 'Punkt_gruen', xaml: '', xamlBase64: '' }] }; const result = createXamlFiles([{ ...aggregates[0], elemente: [fixed] }], { ...dto, auswahl: [...dto.auswahl, ...dto.auswahl] }); expect(result.files).toEqual([{ name: 'Punkt_gruen.xaml', data: '' }]); }); });