clone

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

refresh bundled example metadata in stale drafts

Dami committed 1f6e7cf
commit
1f6e7cfd6820a324dd612e2634c1fe589de06525
parent
f917348013be86f57c8ad212f2a6093e18bf9270
author
Dami <dami.etoile@gmail.com>
3 files changed, +57 -2
Mdiagramzip/src/example-variants.js15++++++++++++
Mdiagramzip/src/main.js7+++++-
Mdiagramzip/test/example-variants.test.js37+++++++++++++++++++++++++++++-
M diagramzip/src/example-variants.js +15 -0
M diagramzip/src/main.js +6 -1
M diagramzip/test/example-variants.test.js +36 -1
@@ -1,6 +1,10 @@
11 import assert from 'node:assert/strict'22 import test from 'node:test'3-import { exampleVariant, grayCode } from '../src/example-variants.js'3+import {4+ exampleVariant,5+ grayCode,6+ refreshMatchingExampleMetadata,7+} from '../src/example-variants.js'48 59 test('changes one example axis at a time across the catalog', () => {610 for (let index = 1; index < 30; index++) {
@@ -19,3 +23,34 @@ test('names every example while varying descriptions and padding', () => {
1923 assert.ok(variants.every(variant => variant.presentation.background === ''))2024 assert.ok(variants.every(variant => variant.presentation.frame === false))2125 })26+27+test('refreshes metadata for an untitled draft matching its bundled example', () => {28+ const state = {29+ type: 'd2',30+ source: 'a -> b',31+ meta: { title: '', description: '' },32+ presentation: { padding: 24 },33+ }34+ const example = {35+ type: 'd2',36+ source: 'a -> b',37+ meta: { title: 'Connection styles', description: 'D2 syntax.' },38+ }39+40+ assert.deepEqual(refreshMatchingExampleMetadata(state, example), {41+ ...state,42+ meta: { title: 'Connection styles', description: 'D2 syntax.' },43+ })44+})45+46+test('preserves named and edited drafts', () => {47+ const example = {48+ source: 'a -> b',49+ meta: { title: 'Connection styles', description: 'D2 syntax.' },50+ }51+ const named = { source: example.source, meta: { title: 'Mine', description: '' } }52+ const edited = { source: 'a -> b: edited', meta: { title: '', description: '' } }53+54+ assert.equal(refreshMatchingExampleMetadata(named, example), named)55+ assert.equal(refreshMatchingExampleMetadata(edited, example), edited)56+})