1import assert from 'node:assert/strict'2import test from 'node:test'3import { diagramTypes } from '../src/diagram-types.js'4import {5 exampleStateForTheme,6 namedExample,7 refreshMatchingExampleMetadata,8} from '../src/example-defaults.js'910test('names every example without adding description or presentation styling', () => {11 for (const { id } of diagramTypes) {12 const example = namedExample(id)13 assert.ok(example.meta.title)14 assert.equal(example.meta.title, example.meta.title.trim())15 assert.equal(example.meta.description, '')16 assert.deepEqual(example.presentation, {17 background: '',18 padding: 0,19 frame: false,20 appearance: 'raw',21 })22 }23})2425test('applies the app theme as transparent presentation without changing template source', () => {26 const template = {27 type: 'ditaa',28 source: '+---+',29 meta: { title: 'ASCII', description: '' },30 presentation: { appearance: 'raw', background: '#ffffff', padding: 24, frame: true },31 }3233 const dark = exampleStateForTheme(template, 'dark')34 assert.equal(dark.source, template.source)35 assert.equal(dark.meta, template.meta)36 assert.deepEqual(dark.presentation, {37 appearance: 'dark-transparent',38 background: '',39 padding: 0,40 frame: false,41 })42 assert.equal(exampleStateForTheme(template, 'light').presentation.appearance, 'light-transparent')43 assert.throws(() => exampleStateForTheme(template, 'auto'), /light or dark/)44})4546test('names an untitled draft matching its bundled example', () => {47 const state = {48 type: 'd2',49 source: 'a -> b',50 meta: { title: '', description: '' },51 presentation: { padding: 24 },52 }53 const example = {54 type: 'd2',55 source: 'a -> b',56 meta: { title: 'Connection styles', description: '' },57 }5859 assert.deepEqual(refreshMatchingExampleMetadata(state, example), {60 ...state,61 meta: { title: 'Connection styles', description: '' },62 })63})6465test('preserves named and edited drafts', () => {66 const example = {67 source: 'a -> b',68 meta: { title: 'Connection styles', description: '' },69 }70 const named = { source: example.source, meta: { title: 'Mine', description: '' } }71 const edited = { source: 'a -> b: edited', meta: { title: '', description: '' } }7273 assert.equal(refreshMatchingExampleMetadata(named, example), named)74 assert.equal(refreshMatchingExampleMetadata(edited, example), edited)75})