mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
58fe56175f
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.
30 lines
1.2 KiB
TypeScript
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');
|
|
});
|
|
});
|