import { describe, expect, it } from 'vitest'; import { db } from './db'; import { translations } from './db/schema'; import { saveSettings } from './settings'; import { applyTranslation, hashOf } from './translate'; const post = { id: 1, title: 'Sommerfest', teaser: 'Danke!', content: '
Es war schön.
', contentEasy: 'Leicht
', contentEasyAuto: '', easyAutoPending: false }; describe('Übersetzungen für Leser', () => { it('bleibt deutsch, solange die Sprache nicht eingeschaltet ist', () => { expect(applyTranslation('post', post, 'tr')).toEqual({ item: post, translation: null }); saveSettings({ aiEnabled: true, aiProvider: 'ollama', aiModel: 'llama3.2', aiLanguages: ['tr'] }); expect(applyTranslation('post', post, 'de').translation).toBeNull(); expect(applyTranslation('post', post, 'ar').translation).toBeNull(); }); it('meldet „wird übersetzt“ und zeigt danach die gespeicherte Übersetzung', () => { saveSettings({ aiEnabled: true, aiProvider: 'ollama', aiModel: 'llama3.2', aiLanguages: ['tr'] }); expect(applyTranslation('post', post, 'tr').translation).toEqual({ lang: 'tr', status: 'pending' }); // so speichert translate() das Ergebnis der KI const hash = hashOf(post, 'tr'); db.insert(translations).values({ kind: 'post', refId: 1, lang: 'tr', hash, title: 'Yaz şenliği', teaser: '', html: 'Güzeldi.
' }).run(); const { item, translation } = applyTranslation('post', post, 'tr'); expect(translation).toEqual({ lang: 'tr', status: 'ready' }); expect(item).toMatchObject({ title: 'Yaz şenliği', teaser: 'Danke!', content: 'Güzeldi.
', contentEasy: '' }); }); it('übersetzt neu, wenn sich der deutsche Text ändert', () => { const changed = { ...post, content: 'Es war sehr schön.
' }; expect(applyTranslation('post', changed, 'tr').translation?.status).toBe('pending'); }); });