mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 10:45:44 +00:00
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { I18nService } from './i18n.service';
|
|
|
|
describe('I18nService', () => {
|
|
let service: I18nService;
|
|
|
|
beforeEach(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
providers: [I18nService],
|
|
}).compile();
|
|
|
|
service = module.get<I18nService>(I18nService);
|
|
});
|
|
|
|
it('should translate English keys', () => {
|
|
expect(service.translate('common.welcome', 'en')).toBe('Welcome');
|
|
expect(service.translate('booking.created', 'en')).toBe('Booking created successfully');
|
|
});
|
|
|
|
it('should translate Amharic keys', () => {
|
|
expect(service.translate('common.welcome', 'am')).toBe('እንኳን ደህና መጡ');
|
|
});
|
|
|
|
it('should translate French keys', () => {
|
|
expect(service.translate('common.welcome', 'fr')).toBe('Bienvenue');
|
|
});
|
|
|
|
it('should translate Oromo keys', () => {
|
|
expect(service.translate('common.welcome', 'om')).toBe('Baga nagaan dhuftan');
|
|
});
|
|
|
|
it('should fallback to English for unsupported locale', () => {
|
|
expect(service.translate('common.welcome', 'de')).toBe('Welcome');
|
|
});
|
|
|
|
it('should return key if translation not found', () => {
|
|
expect(service.translate('nonexistent.key', 'en')).toBe('nonexistent.key');
|
|
});
|
|
|
|
it('should interpolate parameters', () => {
|
|
const result = service.translate('common.welcome', 'en', { name: 'John' });
|
|
expect(result).toBeDefined();
|
|
});
|
|
|
|
it('should return supported locales', () => {
|
|
const locales = service.getSupportedLocales();
|
|
expect(locales).toEqual(['en', 'am', 'fr', 'om']);
|
|
});
|
|
});
|