Files
Nitro-V3/src/api/utils/localizeWithFallback.test.ts
T
simoleo89 58fe56175f fix(purse): don't show raw localization keys for unnamed seasonal currencies
A seasonal currency with no purse.seasonal.currency.<type> text rendered the raw key (e.g. 'purse.seasonal.currency.11') in the purse. Share PurseView's existing localizeWithFallback helper (extracted to api/utils with a pure resolveLocalized core + tests) and use it in SeasonalView with an empty fallback, so an unnamed currency shows just its icon + amount. Verified in-app.
2026-06-17 20:15:48 +02:00

30 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { resolveLocalized } from './localizeWithFallback';
/**
* The localization manager returns the KEY itself when a translation is missing
* (LocalizationManager.getValue → `value || key`). `resolveLocalized` turns that
* "missing" signal into a caller-supplied fallback so raw keys like
* `purse.seasonal.currency.11` never reach the UI.
*/
describe('resolveLocalized', () =>
{
it('returns the localized text when it differs from the key', () =>
{
expect(resolveLocalized('Pixels', 'purse.seasonal.currency.5', 'fallback')).toBe('Pixels');
});
it('returns the fallback when the text equals the key (missing translation)', () =>
{
expect(resolveLocalized('purse.seasonal.currency.11', 'purse.seasonal.currency.11', '')).toBe('');
expect(resolveLocalized('purse.seasonal.currency.11', 'purse.seasonal.currency.11', 'Currency')).toBe('Currency');
});
it('returns the fallback for empty / null text', () =>
{
expect(resolveLocalized('', 'some.key', 'FB')).toBe('FB');
expect(resolveLocalized(null as unknown as string, 'some.key', 'FB')).toBe('FB');
});
});