import { describe, expect, it } from 'vitest'; import { buildPrompt, cleanTranslation } from './provider'; describe('buildPrompt', () => { const prompt = buildPrompt('Fermeture exceptionnelle jeudi après-midi'); it('carries the message to translate', () => { expect(prompt).toContain('Fermeture exceptionnelle jeudi après-midi'); }); it('states the constraints that matter on a shop window', () => { expect(prompt).toMatch(/UNIQUEMENT avec la traduction/); expect(prompt).toMatch(/sans guillemets ajoutés/); expect(prompt).toMatch(/horaires, les dates et les nombres/); }); it('caps the length at the source plus a fifth', () => { // 40 characters in, 48 allowed out. expect(buildPrompt('a'.repeat(40))).toContain('48 caractères'); }); }); describe('cleanTranslation', () => { it('returns a plain answer untouched', () => { expect(cleanTranslation('Exceptionally closed on Thursday afternoon')).toBe( 'Exceptionally closed on Thursday afternoon', ); }); it('trims surrounding whitespace', () => { expect(cleanTranslation(' Closed today \n')).toBe('Closed today'); }); it('strips the quotes models like to add', () => { // A stray quotation mark on the shop window reads as a mistake. expect(cleanTranslation('"Closed today"')).toBe('Closed today'); expect(cleanTranslation('« Closed today »')).toBe('Closed today'); expect(cleanTranslation('“Closed today”')).toBe('Closed today'); }); it('keeps an apostrophe inside the text', () => { expect(cleanTranslation("Today's opening hours")).toBe("Today's opening hours"); }); it('strips a label the model prefixed', () => { expect(cleanTranslation('Translation: Closed today')).toBe('Closed today'); expect(cleanTranslation('traduction : Closed today')).toBe('Closed today'); }); it('keeps only the first line when the model explains itself', () => { expect(cleanTranslation('Closed today\n\nNote: I kept the time unchanged.')).toBe( 'Closed today', ); }); it('does not strip an unmatched quote', () => { expect(cleanTranslation('"Closed today')).toBe('"Closed today'); }); it('survives an empty answer', () => { expect(cleanTranslation(' ')).toBe(''); }); });