|
5 | 5 | import { TestBed } from '@angular/core/testing'; |
6 | 6 |
|
7 | 7 | import { injectSiTranslateService } from './si-translate.inject'; |
8 | | -import { SiTranslateService } from './si-translate.service'; |
| 8 | +import { getBrowserLanguage, SiTranslateService } from './si-translate.service'; |
9 | 9 |
|
10 | 10 | describe('SiNoTranslate', () => { |
11 | 11 | let service: SiTranslateService; |
@@ -36,4 +36,29 @@ describe('SiNoTranslate', () => { |
36 | 36 | it('should translate sync', () => { |
37 | 37 | expect(service.translateSync('VALUE-3')).toBe('VALUE-3'); |
38 | 38 | }); |
| 39 | + |
| 40 | + it('should return language code from different browser locales', () => { |
| 41 | + // Mock different browser languages |
| 42 | + const originalNavigator = window.navigator; |
| 43 | + |
| 44 | + // Test German |
| 45 | + Object.defineProperty(window, 'navigator', { |
| 46 | + value: { ...originalNavigator, language: 'de-DE' }, |
| 47 | + writable: true |
| 48 | + }); |
| 49 | + expect(getBrowserLanguage()).toBe('de'); |
| 50 | + |
| 51 | + // Test French |
| 52 | + Object.defineProperty(window, 'navigator', { |
| 53 | + value: { ...originalNavigator, language: 'fr-FR' }, |
| 54 | + writable: true |
| 55 | + }); |
| 56 | + expect(getBrowserLanguage()).toBe('fr'); |
| 57 | + |
| 58 | + // Restore original navigator |
| 59 | + Object.defineProperty(window, 'navigator', { |
| 60 | + value: originalNavigator, |
| 61 | + writable: true |
| 62 | + }); |
| 63 | + }); |
39 | 64 | }); |
0 commit comments