import { describe, expect, it, vi } from 'vitest'; import { ELEMENT_DEFAULTS, type Slide } from '@openmaic/dsl'; import { normalizeImportedSlides, parsedToSlides } from '../src/import-pipeline'; const baseSlide = (elements: unknown[]): Slide => ({ id: 's1', elements, background: { type: 'solid', color: '#ffffff' }, viewportSize: 1280, viewportRatio: 0.5625, }) as unknown as Slide; const box = { id: 'e1', left: 10, top: 10, width: 100, height: 50, rotate: 0 }; describe('normalizeImportedSlides', () => { it('fills required content fields the transform left off', () => { const [slide] = normalizeImportedSlides([ baseSlide([{ ...box, type: 'text', content: '
hi
' }]), ]); const [text] = slide.elements; expect(text.type).toBe('text'); expect(text).toMatchObject({ defaultFontName: ELEMENT_DEFAULTS.text.defaultFontName, defaultColor: ELEMENT_DEFAULTS.text.defaultColor, }); }); it("preserves a shape's explicit empty fill โ the transform emits '' for gradient / image-filled / unfilled shapes", () => { const el = { ...box, type: 'shape', viewBox: [200, 200], path: 'M 0 0 L 200 0 L 200 200 L 0 200 Z', fill: '', gradient: { type: 'linear', colors: [], rotate: 90 }, fixedRatio: false, }; const [slide] = normalizeImportedSlides([baseSlide([el])]); expect(slide.elements[0]).toMatchObject({ type: 'shape', fill: '' }); }); it('drops an element normalization cannot repair, keeps the rest, and warns', () => { const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); const [slide] = normalizeImportedSlides([ baseSlide([ { ...box, type: 'text', content: 'ok
' }, { ...box, id: 'e2', type: 'text', defaultColor: 123 }, ]), ]); expect(slide.elements).toHaveLength(1); expect(slide.elements[0].id).toBe('e1'); expect(warn).toHaveBeenCalledWith(expect.stringContaining('dropping element')); warn.mockRestore(); }); it('does not mutate its input', () => { const el = { ...box, type: 'text', content: 'hi
' }; const input = [baseSlide([el])]; normalizeImportedSlides(input); expect(input[0].elements[0]).toBe(el); expect('defaultFontName' in (el as Record