b90ff252d1
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.
75 lines
2.8 KiB
TypeScript
75 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { blockMediaIds, emptyBlockData, isBlockEmpty, isBlockType, parseBlocks } from '~/domain/blocks'
|
|
|
|
const id = '11111111-1111-4111-8111-111111111111'
|
|
|
|
describe('parseBlocks', () => {
|
|
it('nimmt alle Blocktypen in Reihenfolge an', async () => {
|
|
const result = parseBlocks([
|
|
{ type: 'text', data: { text: 'Hallo' } },
|
|
{ type: 'image', data: { mediaId: id } },
|
|
{ type: 'gallery', data: { mediaIds: [id] } },
|
|
{ type: 'before_after', data: { beforeMediaId: id, afterMediaId: id } },
|
|
{ type: 'video', data: { url: 'https://nyo.de/film.mp4' } },
|
|
{ type: 'quote', data: { text: 'Kurz', source: 'Paul' } },
|
|
{ type: 'code', data: { code: 'const a = 1', language: 'ts' } },
|
|
{ type: 'link', data: { url: 'https://nyo.de', label: 'NYO' } },
|
|
{ type: 'callout', data: { text: 'Achtung', tone: 'warning' } },
|
|
])
|
|
|
|
expect(result.ok).toBe(true)
|
|
expect(result.ok && result.blocks.map(block => block.type)).toEqual([
|
|
'text',
|
|
'image',
|
|
'gallery',
|
|
'before_after',
|
|
'video',
|
|
'quote',
|
|
'code',
|
|
'link',
|
|
'callout',
|
|
])
|
|
})
|
|
|
|
it('füllt fehlende Felder mit leeren Werten', () => {
|
|
const result = parseBlocks([{ type: 'callout', data: {} }])
|
|
|
|
expect(result.ok && result.blocks[0]?.data).toEqual({ title: '', text: '', tone: 'info' })
|
|
})
|
|
|
|
it('meldet einen unbekannten Blocktyp mit Position', () => {
|
|
const result = parseBlocks([{ type: 'text', data: { text: 'Hallo' } }, { type: 'karussell', data: {} }])
|
|
|
|
expect(result).toMatchObject({ ok: false, index: 1, type: 'karussell' })
|
|
})
|
|
|
|
it('lehnt eine kaputte Adresse und eine kaputte Bildkennung ab', () => {
|
|
expect(parseBlocks([{ type: 'link', data: { url: 'kein-verweis' } }]).ok).toBe(false)
|
|
expect(parseBlocks([{ type: 'image', data: { mediaId: 'abc' } }]).ok).toBe(false)
|
|
})
|
|
|
|
it('nimmt eine leere Bildkennung an', () => {
|
|
expect(parseBlocks([{ type: 'image', data: { mediaId: '' } }]).ok).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('Blockhilfen', () => {
|
|
it('sammelt alle Bildkennungen eines Blocks', () => {
|
|
expect(blockMediaIds({ type: 'gallery', data: { mediaIds: [id, ''] } })).toEqual([id])
|
|
expect(blockMediaIds({ type: 'before_after', data: { beforeMediaId: id, afterMediaId: '' } })).toEqual([id])
|
|
})
|
|
|
|
it('erkennt leere Blöcke', () => {
|
|
expect(isBlockEmpty({ type: 'text', data: emptyBlockData('text') })).toBe(true)
|
|
expect(isBlockEmpty({ type: 'text', data: { text: ' ' } })).toBe(true)
|
|
expect(isBlockEmpty({ type: 'text', data: { text: 'Inhalt' } })).toBe(false)
|
|
expect(isBlockEmpty({ type: 'callout', data: emptyBlockData('callout') })).toBe(true)
|
|
expect(isBlockEmpty({ type: 'image', data: { mediaId: id } })).toBe(false)
|
|
})
|
|
|
|
it('kennt die erlaubten Typen', () => {
|
|
expect(isBlockType('text')).toBe(true)
|
|
expect(isBlockType('karussell')).toBe(false)
|
|
})
|
|
})
|