import { describe, it, expect } from 'vitest' import { resolveWishName } from './wishName' import { translate } from '@/i18n' const t = (key: Parameters[1]) => translate('sv', key) describe('resolveWishName', () => { it('translates through nameMessageKey when present, ignoring the stored name', () => { // The core bug fix: the persisted `name` can be stale (saved while the // UI was a different language) — the key, when present, is the source // of truth for display. const wish = { name: 'STALE_ENGLISH_NAME', nameMessageKey: 'wishEditor.seasonJul' } expect(resolveWishName(wish, t)).toBe('Jul') }) it('returns the literal name verbatim when nameMessageKey is null', () => { const wish = { name: 'Resa till mormor', nameMessageKey: null } expect(resolveWishName(wish, t)).toBe('Resa till mormor') }) it('falls back to the literal name for a key this build does not recognise', () => { // A stale key from an older/newer server build must never crash or // render a raw, untranslated key string to the user. const wish = { name: 'Sommar', nameMessageKey: 'wishEditor.thisKeyDoesNotExist' } expect(resolveWishName(wish, t)).toBe('Sommar') }) it('falls back to the literal name for an empty-string key', () => { const wish = { name: 'Custom trip', nameMessageKey: '' } expect(resolveWishName(wish, t)).toBe('Custom trip') }) })