Files
Siteforge/test/note-format.test.js

33 lines
1.5 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { parseNoteEntries, serializeNoteEntries, noteEntriesToText } from '../shared/note-format.js'
test('legacy anchor map upgrades to entries and round-trips as v2', () => {
const entries = parseNoteEntries(JSON.stringify({ scripture: '<p>a</p>', general: '', commentary: '<p>b</p>' }))
assert.deepEqual(entries.map(e => e.anchor), ['scripture', 'commentary'])
const again = parseNoteEntries(serializeNoteEntries(entries))
assert.equal(again.length, 2)
assert.equal(JSON.parse(serializeNoteEntries(entries)).v, 2)
})
test('plain-text legacy notes become a general entry', () => {
const entries = parseNoteEntries('just some text')
assert.equal(entries.length, 1)
assert.equal(entries[0].anchor, 'general')
})
test('multiple entries per anchor are kept and empty ones dropped', () => {
const raw = serializeNoteEntries([
{ id: '1', anchor: 'general', html: '<p>one</p>', updatedAt: '2026-01-01T00:00:00.000Z' },
{ id: '2', anchor: 'general', html: '<p>two</p>', updatedAt: null },
{ id: '3', anchor: 'general', html: ' ', updatedAt: null },
])
assert.equal(parseNoteEntries(raw).length, 2)
assert.equal(serializeNoteEntries([]), '')
})
test('plain-text export strips markup', () => {
const text = noteEntriesToText(serializeNoteEntries([{ id: '1', anchor: 'scripture', html: '<p>Hi &amp; bye</p>', updatedAt: null }]))
assert.equal(text, 'Scripture Text\nHi & bye')
})