|
1 | 1 | describe('i18nService', function () {
|
2 |
| - var i18nService; |
3 |
| - beforeEach(module('ui.grid')); |
| 2 | + var i18nConstants, i18nService; |
4 | 3 |
|
5 |
| - beforeEach(inject(function (_i18nService_) { |
6 |
| - i18nService = _i18nService_; |
7 |
| - })); |
| 4 | + beforeEach(function() { |
| 5 | + module('ui.grid'); |
| 6 | + inject(function (_i18nConstants_, _i18nService_) { |
| 7 | + i18nConstants = _i18nConstants_; |
| 8 | + i18nService = _i18nService_; |
| 9 | + }); |
| 10 | + }); |
8 | 11 |
|
9 |
| - describe('i18n service', function () { |
10 |
| - it('should default to English', function () { |
| 12 | + describe('i18n service', function() { |
| 13 | + it('should default to English', function() { |
11 | 14 | expect(i18nService.getCurrentLang()).toBe('en');
|
12 | 15 | expect(i18nService.get().search.placeholder).toBe('Search...');
|
13 | 16 | });
|
14 |
| - it('should set a new Current', function () { |
| 17 | + it('should set a new Current', function() { |
15 | 18 | i18nService.setCurrentLang('fr');
|
16 | 19 | expect(i18nService.getCurrentLang()).toBe('fr');
|
17 | 20 | expect(i18nService.get().search.placeholder).toBe('Recherche...');
|
18 | 21 | });
|
19 |
| - it('should add a language', function () { |
20 |
| - i18nService.add('tst',{test:'testlang'}); |
21 |
| - i18nService.setCurrentLang('tst'); |
22 |
| - expect(i18nService.get().test).toBe('testlang'); |
| 22 | + describe('add', function() { |
| 23 | + it('should add a language when langs is a string', function() { |
| 24 | + i18nService.add('tst',{test:'testlang'}); |
| 25 | + i18nService.setCurrentLang('tst'); |
| 26 | + expect(i18nService.get().test).toBe('testlang'); |
| 27 | + }); |
| 28 | + it('should add multiple languages when langs is an array', function() { |
| 29 | + i18nService.add(['tst1', 'tst2'], {test:'testlang'}); |
| 30 | + i18nService.setCurrentLang('tst1'); |
| 31 | + expect(i18nService.get().test).toBe('testlang'); |
| 32 | + i18nService.setCurrentLang('tst2'); |
| 33 | + expect(i18nService.get().test).toBe('testlang'); |
| 34 | + }); |
| 35 | + it('should not add null languages', function() { |
| 36 | + i18nService.add([null], {test:'testlang'}); |
| 37 | + i18nService.setCurrentLang(null); |
| 38 | + expect(i18nService.get().test).toBeUndefined(); |
| 39 | + }); |
23 | 40 | });
|
24 |
| - it('should return all langs', function () { |
| 41 | + it('should return all langs', function() { |
25 | 42 | var langs = i18nService.getAllLangs();
|
26 | 43 | expect(langs.length).toBeGreaterThan(8);
|
27 | 44 | });
|
28 |
| - it('should get safe text', function () { |
29 |
| - var text = i18nService.getSafeText('search.placeholder'); |
30 |
| - expect(text).toBe('Search...'); |
31 |
| - }); |
32 |
| - it('should get safe text for missing property', function () { |
33 |
| - var text = i18nService.getSafeText('search.bad.text'); |
34 |
| - expect(text).toBe('[MISSING]'); |
| 45 | + |
| 46 | + describe('getSafeText', function() { |
| 47 | + it('should get safe text when text is defined', function() { |
| 48 | + expect(i18nService.getSafeText('search.placeholder')).toBe('Search...'); |
| 49 | + }); |
| 50 | + it('should get safe text for missing property', function() { |
| 51 | + expect(i18nService.getSafeText('search.bad.text')).toBe('[MISSING]'); |
| 52 | + }); |
| 53 | + it('should get missing text when language is missing or nonexistent', function() { |
| 54 | + expect(i18nService.getSafeText('search.placeholder', 'valerian')).toBe(i18nConstants.MISSING); |
| 55 | + }); |
35 | 56 | });
|
36 | 57 | });
|
37 | 58 | });
|
0 commit comments