Skip to content

Commit 115e790

Browse files
Portugal, Marcelomportuga
Portugal, Marcelo
authored andcommitted
chore(tests): Fix tests and improve coverage.
1 parent 27ffd24 commit 115e790

File tree

3 files changed

+65
-44
lines changed

3 files changed

+65
-44
lines changed

src/features/selection/js/selection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
* @description Selects all visible rows. Does nothing if multiSelect = false
255255
* @param {Event} event object if raised from an event
256256
*/
257-
selectAllVisibleRows: function (evt) {
257+
selectAllVisibleRows: function (event) {
258258
if (grid.options.multiSelect !== false) {
259259
var changedRows = [];
260260
var rowCache = [];

test/unit/i18n/directives.spec.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
describe('i18n Directives', function () {
2-
var gridUtil;
3-
var scope;
4-
var element;
5-
var uiGridController;
6-
var recompile;
1+
describe('i18n Directives', function() {
2+
var $compile, $rootScope, gridUtil, element, recompile, scope;
73

8-
beforeEach(module('ui.grid'));
4+
beforeEach(function() {
5+
module('ui.grid');
96

10-
beforeEach(inject(function ($rootScope, $compile, $controller, _gridUtil_, $templateCache, $timeout) {
11-
gridUtil = _gridUtil_;
7+
inject(function (_$rootScope_, _$compile_, _gridUtil_) {
8+
$compile = _$compile_;
9+
$rootScope = _$rootScope_;
10+
gridUtil = _gridUtil_;
11+
});
1212

1313
scope = $rootScope.$new();
1414
scope.options = {};
@@ -24,45 +24,45 @@ describe('i18n Directives', function () {
2424

2525
recompile = function () {
2626
$compile(element)(scope);
27-
$rootScope.$digest();
27+
$rootScope.$apply();
2828
};
29-
}));
30-
29+
});
3130

32-
describe('ui-translate directive', function () {
33-
it('should translate', function () {
34-
element = angular.element('<div ui-i18n="en"><p ui-translate="search.placeholder"></p></div>');
31+
describe('ui-translate directive', function() {
32+
beforeEach(function() {
33+
scope.lang = 'en';
34+
element = angular.element('<div ui-i18n="lang"><p ui-translate="search.placeholder"></p></div>');
3535
recompile();
36-
36+
});
37+
it('should translate', function() {
3738
expect(element.find('p').text()).toBe('Search...');
3839
});
3940
});
4041

41-
describe('ui-t directive', function () {
42-
it('should translate', function () {
42+
describe('ui-t directive', function() {
43+
it('should translate', function() {
4344
element = angular.element('<div ui-i18n="en"><p ui-t="search.placeholder"></p></div>');
4445
recompile();
4546

4647
expect(element.find('p').text()).toBe('Search...');
4748
});
4849
});
4950

50-
describe('t filter', function () {
51-
it('should translate', function () {
51+
describe('t filter', function() {
52+
it('should translate', function() {
5253
element = angular.element('<div ui-i18n="en"><p>{{"search.placeholder" | t}}</p></div>');
5354
recompile();
5455

5556
expect(element.find('p').text()).toBe('Search...');
5657
});
5758
});
5859

59-
describe('uiTranslate filter', function () {
60-
it('should translate', function () {
60+
describe('uiTranslate filter', function() {
61+
it('should translate', function() {
6162
element = angular.element('<div ui-i18n="en"><p>{{"search.placeholder" | uiTranslate}}</p></div>');
6263
recompile();
6364

6465
expect(element.find('p').text()).toBe('Search...');
6566
});
6667
});
67-
6868
});

test/unit/i18n/i18nService.spec.js

+41-20
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,58 @@
11
describe('i18nService', function () {
2-
var i18nService;
3-
beforeEach(module('ui.grid'));
2+
var i18nConstants, i18nService;
43

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+
});
811

9-
describe('i18n service', function () {
10-
it('should default to English', function () {
12+
describe('i18n service', function() {
13+
it('should default to English', function() {
1114
expect(i18nService.getCurrentLang()).toBe('en');
1215
expect(i18nService.get().search.placeholder).toBe('Search...');
1316
});
14-
it('should set a new Current', function () {
17+
it('should set a new Current', function() {
1518
i18nService.setCurrentLang('fr');
1619
expect(i18nService.getCurrentLang()).toBe('fr');
1720
expect(i18nService.get().search.placeholder).toBe('Recherche...');
1821
});
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+
});
2340
});
24-
it('should return all langs', function () {
41+
it('should return all langs', function() {
2542
var langs = i18nService.getAllLangs();
2643
expect(langs.length).toBeGreaterThan(8);
2744
});
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+
});
3556
});
3657
});
3758
});

0 commit comments

Comments
 (0)