clone

a browser-first diagram editor with live svg previews, local drafts and encrypted, accountless sharing

main
diagramzip / renderers / edge / test / ditaa.test.ts
ditaa.test.ts 4.1K
1import { describe, expect, it } from 'vitest'2import { ditaaAdapter } from '../src/adapters/ditaa'3import type { RenderRequest } from '../src/runtime/types'45const request = (source: string, options: Record<string, string> = {}): RenderRequest => ({6 engine: 'ditaa', source, format: 'svg', options,7 metadata: { title: '', description: '' },8 presentation: { background: '', padding: 0, frame: false },9})1011describe('Ditaa edge adapter', () => {12 it('renders the documented ASCII fixture without Java', async () => {13 const result = await ditaaAdapter.render(request('+--------+ +-------------+\n| User |------>| diagram.zip |\n+--------+ +-------------+'), new AbortController().signal)14 expect(result.runtime).toBe('edge-wasm')15 expect(result.body).toContain('<svg')16 expect(result.body).toContain('User')17 expect(result.body).toContain('diagram.zip')18 })1920 it('renders the repository components fixture with its connector labels', async () => {21 const source = ` +--------+22 | |23 | User |24 | |25 +--------+26 ^27 request |28 v29 +-------------+30 | |31 | Kroki |32 | |---+33 +-------------+ |34 ^ ^ | inflate35 | | |36 v +---------+37 +-------------+38 | |39 | Ditaa |40 | |----+41 +-------------+ |42 ^ | process43 | |44 +-------+`45 const result = await ditaaAdapter.render(request(source), new AbortController().signal)46 expect(result.body).toContain('User')47 expect(result.body).toContain('Kroki')48 expect(result.body).toContain('Ditaa')49 expect(result.body).toContain('inflate')50 expect(result.body).toContain('process')51 })5253 it('removes Ditaa shape/color directives while retaining labels', async () => {54 const result = await ditaaAdapter.render(request('+-------+\n| API {cBLU} {d} |\n+-------+'), new AbortController().signal)55 expect(result.body).toContain('API')56 expect(result.body).not.toContain('cBLU')57 expect(result.body).not.toContain('{d}')58 })5960 it('supports bounded scale, tabs, and transparent/background options', async () => {61 const result = await ditaaAdapter.render(request('\t+---+\n\t| A |\n\t+---+', { tabs: '4', scale: '2', background: 'F0F0F0' }), new AbortController().signal)62 expect(result.body).toContain('#F0F0F0')63 expect(result.body).toContain('width="')64 })6566 it('accepts legacy appearance flags as documented no-ops', async () => {67 const result = await ditaaAdapter.render(request('+---+\n| A |\n+---+', {68 'no-antialias': '',69 'no-separation': 'true',70 'round-corners': '1',71 'no-shadows': 'yes',72 }), new AbortController().signal)73 expect(result.body).toContain('<svg')74 expect(result.body).toContain('A')75 })7677 it('rejects unsupported and oversized inputs', async () => {78 await expect(ditaaAdapter.render(request('A', { foo: 'bar' }), new AbortController().signal)).rejects.toMatchObject({ status: 400, code: 'unsupported_options' })79 await expect(ditaaAdapter.render(request('A', { scale: 'NaN' }), new AbortController().signal)).rejects.toMatchObject({ status: 400, code: 'invalid_options' })80 await expect(ditaaAdapter.render(request('A', { scale: '16.1' }), new AbortController().signal)).rejects.toMatchObject({ status: 400, code: 'invalid_options' })81 await expect(ditaaAdapter.render(request('\tA', { tabs: '32.1' }), new AbortController().signal)).rejects.toMatchObject({ status: 400, code: 'invalid_options' })82 await expect(ditaaAdapter.render(request('\tA', { tabs: '1.5' }), new AbortController().signal)).rejects.toMatchObject({ status: 400, code: 'invalid_options' })83 await expect(ditaaAdapter.render(request('x'.repeat(270_000)), new AbortController().signal)).rejects.toMatchObject({ status: 413, code: 'source_too_large' })84 })8586 it('accepts named CSS backgrounds without corrupting the color', async () => {87 const result = await ditaaAdapter.render(request('A', { background: 'white' }), new AbortController().signal)88 expect(result.body).toContain('white')89 expect(result.body).not.toContain('#white')90 })91})