// One post, one rendering. De Krant, Berichten and the Guardian PWA all run a // note through partials/note-body, so a quote card, a link preview, the media // and the custom emojis show up wherever the post turns up — not only in the // feed it happened to arrive in. import { test } from 'node:test'; import assert from 'node:assert/strict'; import fs from 'fs'; import path from 'path'; process.env.DATABASE_PATH = ':memory:'; process.env.PUBLIC_BASE_URL = 'https://test.example'; const dbMod = await import('../src/config/database.js'); const db = dbMod.default; dbMod.initializeDatabase(); const { renderNoteBody } = await import('../src/middleware/render.js'); const AP = (await import('../src/services/ActivityPubService.js')).default; const VIEWS = path.join(process.cwd(), 'src', 'views', 'partials'); const EMOJI = JSON.stringify({ ':party:': 'https://cdn.test/party.png' }); const MEDIA = JSON.stringify([{ url: 'https://cdn.test/capture.png', type: 'image/png' }]); const QUOTE = JSON.stringify({ url: 'https://q.test/notes/7', author: { name: 'Opie', handle: '@opie@q.test' }, content: '

het origineel

', media: [] }); const EMBED = JSON.stringify({ url: 'https://video.test/watch?v=1', title: 'Een filmpje', provider: 'video.test', media: [{ url: 'https://video.test/thumb.jpg', type: 'image/jpeg' }] }); test('the content renders with its custom emojis', () => { const html = renderNoteBody({ content: '

hoi :party:

', emoji_json: EMOJI }, 'nl'); assert.match(html, /class="tl-content"/); assert.match(html, /]+class="emoji"[^>]+party\.png/, ':party: became an image, not a shortcode'); }); test('a quoted post renders as the quote card', () => { const html = renderNoteBody({ content: '

kijk

', quote_json: QUOTE }, 'nl'); assert.match(html, /class="tl-quote"/); assert.match(html, /het origineel/); assert.match(html, /@opie@q\.test/); }); test('an external link preview renders as that same card, with the title escaped', () => { const html = renderNoteBody({ content: '

kijk

', embed_json: EMBED }, 'nl'); assert.match(html, /class="tl-quote"/, 'one card for both, only the origin differs'); assert.match(html, /Een filmpje/); assert.ok(!/