Files
logbuch/tests/lib/post-content.test.ts
T
Matthias Giesselmann b90ff252d1 Add Logbuch: project update blog with admin, media and API
Public archive with sidebar navigation, project pages, month archive,
search and entry pages with image blocks. Admin area for brands,
projects, post types, users, api clients, media and the entry editor
with drag and drop images, preview per audience, scheduling and
publish checks. Read and write API with bearer tokens, audience
scoping, idempotent creation, OpenAPI document and editorial guide.
Magic link login with configurable allowed domains, whole app behind
the session gate. 456 tests including design rule checks.
2026-07-31 21:33:42 +02:00

68 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { contentBlocks, readingMinutes } from '~/lib/post-content'
import type { Block } from '~/data/schema'
function block(id: string, type: string, data: Record<string, unknown>): Block {
return { id, postId: 'post', sort: 0, type, data } as Block
}
describe('contentBlocks', () => {
it('lässt Blöcke unangetastet, wenn nichts doppelt ist', () => {
const blocks = [block('a', 'text', { text: 'Ein eigener Absatz.' })]
expect(contentBlocks(blocks, 'Anderer Anreißer', null)).toHaveLength(1)
})
it('überspringt den ersten Textblock, wenn er den Anreißer wiederholt', () => {
const blocks = [
block('a', 'text', { text: ' Tickets reagieren jetzt selbst. ' }),
block('b', 'text', { text: 'Und noch etwas.' }),
]
const result = contentBlocks(blocks, 'Tickets reagieren jetzt selbst.', null)
expect(result.map(entry => entry.id)).toEqual(['b'])
})
it('überspringt einen Bildblock, der das Aufmacherbild wiederholt', () => {
const blocks = [
block('a', 'image', { mediaId: 'cover-1' }),
block('b', 'image', { mediaId: 'andere-2' }),
]
const result = contentBlocks(blocks, null, 'cover-1')
expect(result.map(entry => entry.id)).toEqual(['b'])
})
it('entfernt beide Wiederholungen zusammen', () => {
const blocks = [
block('a', 'image', { mediaId: 'cover-1' }),
block('b', 'text', { text: 'Der Anreißer.' }),
block('c', 'text', { text: 'Der eigentliche Inhalt.' }),
]
const result = contentBlocks(blocks, 'Der Anreißer.', 'cover-1')
expect(result.map(entry => entry.id)).toEqual(['c'])
})
it('behält den Bildblock, wenn es kein Aufmacherbild gibt', () => {
const blocks = [block('a', 'image', { mediaId: 'irgendwas' })]
expect(contentBlocks(blocks, null, null)).toHaveLength(1)
})
})
describe('readingMinutes', () => {
it('meldet mindestens eine Minute', () => {
expect(readingMinutes([], null)).toBe(1)
})
it('rechnet Anreißer und Blöcke zusammen', () => {
const words = Array.from({ length: 400 }, () => 'Wort').join(' ')
expect(readingMinutes([block('a', 'text', { text: words })], null)).toBe(2)
})
})