import {VirtualDocument, textSizerFactory} from '../../spec/stubs/TestDOM.mjs'; import Exporter from './exporter/Exporter.mjs'; import Generator from './generator/Generator.mjs'; import Parser from './parser/Parser.mjs'; import Renderer from './renderer/Renderer.mjs'; import SequenceDiagram from './SequenceDiagram.mjs'; function getSimplifiedContent(d) { return (d.dom().outerHTML .replace(/<\/g>/g, '') .replace(/<\/defs>/g, '') .replace(' xmlns="http://www.w3.org/2000/svg" version="1.1"', '') ); } function makeDiagram(code) { return new SequenceDiagram(code, { document: new VirtualDocument(), namespace: '', textSizerFactory, }); } describe('SequenceDiagram', () => { it('contains references to core objects', () => { expect(SequenceDiagram.Parser).toBe(Parser); expect(SequenceDiagram.Generator).toBe(Generator); expect(SequenceDiagram.Renderer).toBe(Renderer); expect(SequenceDiagram.Exporter).toBe(Exporter); }); it('provides default themes', () => { expect(SequenceDiagram.themes.length).toBeGreaterThan(1); }); it('renders empty diagrams without error', () => { const diagram = makeDiagram(''); expect(getSimplifiedContent(diagram)).toEqual( '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' ); }); it('renders simple metadata', () => { const diagram = makeDiagram('title My title here'); expect(getSimplifiedContent(diagram)).toEqual( '' + 'title My title here' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + 'My title here' + '' + '' + '' + '' + '' ); }); it('re-renders when changed', () => { const diagram = makeDiagram('title My title here'); diagram.set('title Another title'); expect(getSimplifiedContent(diagram)).toContain('Another title'); }); it('renders simple components', () => { const diagram = makeDiagram('A -> B'); const content = getSimplifiedContent(diagram); expect(content).toContain( '' ); // Agent 1 expect(content).toContain( ' { const diagram = makeDiagram('if\nA -> B\nend'); diagram.setCollapsed(0, true); const content = getSimplifiedContent(diagram); expect(content).toContain(''); expect(content).toContain( '