Skip to content

Commit cbeae2c

Browse files
committed
Merge pull request #5097 from JLLeitschuh/chore/updateJasmine
test: Updates tests to Jasmine 2
2 parents 7274632 + ee02583 commit cbeae2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+979
-923
lines changed

grunt/jshint.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
debug: true, // debugger statements allowed
1818
globals: {
1919
angular: false,
20-
20+
2121
/* Protractor */
2222
browser: false,
2323

@@ -39,14 +39,15 @@ module.exports = {
3939
afterEach: false,
4040
before: false,
4141
beforeEach: false,
42+
afterAll: false,
4243
console: false,
43-
dump: false,
44+
dump: false,
4445
describe: false,
45-
ddescribe: false,
46+
fdescribe: false,
4647
expect: false,
4748
inject: false,
4849
it: false,
49-
iit: false,
50+
fit: false,
5051
module: false,
5152
debugger: false,
5253
DocumentTouch: false,

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"grunt-contrib-concat": "~0.3",
4545
"grunt-contrib-connect": "~0.5",
4646
"grunt-contrib-copy": "~0.4.1",
47-
"grunt-contrib-jasmine": "~0.5",
47+
"grunt-contrib-jasmine": "^1.0.0",
4848
"grunt-contrib-jshint": "~0.7",
4949
"grunt-contrib-less": "~1.0",
5050
"grunt-contrib-uglify": "~0.2",
@@ -65,7 +65,7 @@
6565
"karma-coverage": "^0.2.5",
6666
"karma-firefox-launcher": "~0.1",
6767
"karma-ie-launcher": "^0.1.5",
68-
"karma-jasmine": "~0.1",
68+
"karma-jasmine": "^0.3.7",
6969
"karma-phantomjs-launcher": "~0.1",
7070
"karma-requirejs": "~0.2",
7171
"karma-sauce-launcher": "~0.2.10",
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe('ui.grid.autoResizeGrid', function () {
2-
var gridScope, gridElm, viewportElm, $scope, $compile, recompile, uiGridConstants;
2+
var gridScope, gridElm, viewportElm, $scope, $compile, recompile, uiGridConstants, $timeout;
33

44
var data = [
55
{ "name": "Ethel Price", "gender": "female", "company": "Enersol" },
@@ -11,8 +11,9 @@ describe('ui.grid.autoResizeGrid', function () {
1111
beforeEach(module('ui.grid'));
1212
beforeEach(module('ui.grid.autoResize'));
1313

14-
beforeEach(inject(function (_$compile_, $rootScope, _uiGridConstants_) {
14+
beforeEach(inject(function (_$compile_, _$timeout_, $rootScope, _uiGridConstants_) {
1515
$scope = $rootScope;
16+
$timeout = _$timeout_;
1617
$compile = _$compile_;
1718
uiGridConstants = _uiGridConstants_;
1819

@@ -39,30 +40,27 @@ describe('ui.grid.autoResizeGrid', function () {
3940
});
4041

4142
describe('on grid element dimension change', function () {
42-
43-
it('adjusts the grid viewport size', inject(function ($timeout) {
44-
var w = $(viewportElm).width();
43+
var w;
44+
beforeEach(function (done) {
45+
w = $(viewportElm).width();
4546
var h = $(viewportElm).height();
4647

47-
runs(function () {
48-
$(gridElm).width(600);
49-
});
50-
51-
waits(300);
52-
53-
runs(function () {
54-
var newW = $(viewportElm).width();
55-
56-
expect(newW).toBeGreaterThan(w);
57-
});
58-
}));
48+
$(gridElm).width(600);
49+
$scope.$digest();
50+
setTimeout(done, 300);
51+
});
52+
it('adjusts the grid viewport size', function () {
53+
var newW = $(viewportElm).width();
54+
expect(newW).toBeGreaterThan(w);
55+
});
5956
});
6057

6158
// Rebuild the grid as having 100% width and being in a 400px wide container, then change the container width to 500px and make sure it adjusts
6259
describe('on grid container dimension change', function () {
6360
var gridContainerElm;
61+
var w;
6462

65-
beforeEach(function () {
63+
beforeEach(function (done) {
6664
angular.element(gridElm).remove();
6765

6866
gridContainerElm = angular.element('<div style="width: 400px"><div style="width: 100%; height: 300px" ui-grid="gridOpts" ui-grid-auto-resize></div></div>');
@@ -73,24 +71,20 @@ describe('ui.grid.autoResizeGrid', function () {
7371
gridElm = gridContainerElm.find('[ui-grid]');
7472

7573
viewportElm = $(gridElm).find('.ui-grid-viewport');
76-
});
7774

78-
it('adjusts the grid viewport size', inject(function ($timeout) {
79-
var w = $(viewportElm).width();
75+
w = $(viewportElm).width();
8076
var h = $(viewportElm).height();
8177

82-
runs(function () {
83-
$(gridContainerElm).width(500);
84-
});
85-
86-
waits(300);
78+
$(gridContainerElm).width(500);
79+
$scope.$digest();
80+
setTimeout(done, 300);
81+
});
8782

88-
runs(function () {
89-
var newW = $(viewportElm).width();
83+
it('adjusts the grid viewport size', function() {
84+
var newW = $(viewportElm).width();
9085

91-
expect(newW).toBeGreaterThan(w);
92-
});
93-
}));
86+
expect(newW).toBeGreaterThan(w);
87+
});
9488
});
9589

96-
});
90+
});

src/features/cellnav/test/uiGridCellNavDirective.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ describe('ui.grid.cellNav directive', function () {
5353
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[1], col: $scope.grid.columns[0] }, true);
5454
expect($scope.gridApi.cellNav.getCurrentSelection().length).toEqual(2);
5555
});
56-
57-
56+
57+
5858
it('handleKeyDown should clear the focused cells list when clearing focus', function () {
5959
// first ensure that a cell is selected
6060
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true);
6161
var rowColToTest = { row: $scope.grid.rows[0], col: $scope.grid.columns[0] };
6262
var evt = jQuery.Event("keydown");
6363
evt.keyCode = uiGridConstants.keymap.TAB;
6464
$scope.grid.cellNav.lastRowCol = rowColToTest;
65-
65+
6666
// simulate tabbing out of grid
6767
elm.controller('uiGrid').cellNav.handleKeyDown(evt);
6868
expect($scope.grid.cellNav.focusedCells.length).toEqual(0);
69-
69+
7070
// simulate restoring focus
7171
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true);
7272
expect($scope.grid.cellNav.focusedCells.length).toEqual(1);
7373
});
74-
});
74+
});

src/features/cellnav/test/uiGridCellNavFactory.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,4 @@ describe('ui.grid.edit uiGridCellNavService', function () {
218218

219219
});
220220

221-
});
221+
});

src/features/edit/test/uiGridEditService.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@ describe('ui.grid.edit uiGridEditService', function () {
187187

188188
});
189189

190-
});
190+
});

src/features/edit/test/uiGridInputDirective.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ describe('inputDirective', function () {
5757
// expect(scope.inputForm.$valid).toBe(true);
5858
// });
5959

60-
});
60+
});

src/features/expandable/test/expandable.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ describe('ui.grid.expandable', function () {
8181
expect(element.find('.test').length).toBe(1);
8282
});
8383
});
84-
});
84+
});

src/features/grouping/test/grouping.spec.js

+52-41
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ describe('ui.grid.grouping uiGridGroupingService', function () {
102102

103103

104104
describe( 'groupRows', function() {
105+
beforeEach(function() {
106+
spyOn(gridClassFactory, 'rowTemplateAssigner').and.callFake( function() {});
107+
});
108+
105109
it( 'group by col0 then col1', function() {
106-
spyOn(gridClassFactory, 'rowTemplateAssigner').andCallFake( function() {});
110+
107111
grid.columns[0].grouping = { groupPriority: 1 };
108112
grid.columns[1].grouping = { groupPriority: 2 };
109113

@@ -112,7 +116,6 @@ describe('ui.grid.grouping uiGridGroupingService', function () {
112116
});
113117

114118
it( 'group by col4 (type date with nulls)', function() {
115-
spyOn(gridClassFactory, 'rowTemplateAssigner').andCallFake( function() {});
116119
grid.columns[4].grouping = { groupPriority: 1 };
117120

118121
uiGridGroupingService.tidyPriorities(grid);
@@ -482,49 +485,55 @@ describe('ui.grid.grouping uiGridGroupingService', function () {
482485
});
483486
});
484487

485-
it('sorts', function(){
486-
grid.grouping.groupingHeaderCache = {
487-
male: {
488-
row: { treeNode: { state: 'collapsed' } },
489-
children: {
490-
22: { row: { treeNode: { state: 'expanded' } }, children: {} },
491-
39: { row: { treeNode: { state: 'collapsed' } }, children: {} }
488+
489+
describe('sorts', function(){
490+
beforeEach(function() {
491+
spyOn(grid.api.core.raise, 'sortChanged').and.callThrough();
492+
});
493+
494+
it('', function() {
495+
grid.grouping.groupingHeaderCache = {
496+
male: {
497+
row: { treeNode: { state: 'collapsed' } },
498+
children: {
499+
22: { row: { treeNode: { state: 'expanded' } }, children: {} },
500+
39: { row: { treeNode: { state: 'collapsed' } }, children: {} }
501+
}
502+
},
503+
female: {
504+
row: { treeNode: { state: 'expanded' } },
505+
children: {
506+
23: { row: { treeNode: { state: 'collapsed' } }, children: {} },
507+
38: { row: { treeNode: { state: 'expanded' } }, children: {} }
508+
}
492509
}
493-
},
494-
female: {
495-
row: { treeNode: { state: 'expanded' } },
496-
children: {
497-
23: { row: { treeNode: { state: 'collapsed' } }, children: {} },
498-
38: { row: { treeNode: { state: 'expanded' } }, children: {} }
510+
};
511+
512+
513+
grid.api.grouping.setGrouping({
514+
grouping: [
515+
{ field: 'col3', colName: 'col3', groupPriority: 0 },
516+
{ field: 'col2', colName: 'col2', groupPriority: 1 }
517+
],
518+
aggregations: [
519+
{ field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } }
520+
],
521+
rowExpandedStates: {
522+
male: { state: 'expanded', children: {
523+
22: { state: 'collapsed' },
524+
38: { state: 'expanded' }
525+
} },
526+
female: { state: 'expanded', children: {
527+
23: { state: 'expanded' },
528+
39: { state: 'collapsed' }
529+
} }
499530
}
500-
}
501-
};
531+
});
502532

503-
spyOn(grid.api.core.raise, 'sortChanged').andCallThrough();
504-
505-
grid.api.grouping.setGrouping({
506-
grouping: [
507-
{ field: 'col3', colName: 'col3', groupPriority: 0 },
508-
{ field: 'col2', colName: 'col2', groupPriority: 1 }
509-
],
510-
aggregations: [
511-
{ field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } }
512-
],
513-
rowExpandedStates: {
514-
male: { state: 'expanded', children: {
515-
22: { state: 'collapsed' },
516-
38: { state: 'expanded' }
517-
} },
518-
female: { state: 'expanded', children: {
519-
23: { state: 'expanded' },
520-
39: { state: 'collapsed' }
521-
} }
522-
}
533+
// Should call sort change twice because we are grouping by two columns
534+
expect(grid.api.core.raise.sortChanged.calls.count()).toEqual(2);
523535
});
524536

525-
// Should call sort change twice because we are grouping by two columns
526-
expect(grid.api.core.raise.sortChanged.calls.length).toEqual(2);
527-
528537
});
529538

530539
});
@@ -572,7 +581,9 @@ describe('ui.grid.grouping uiGridGroupingService', function () {
572581

573582
describe('insertGroupHeader', function() {
574583
it('inserts a header in the middle', function() {
575-
spyOn(gridClassFactory, 'rowTemplateAssigner').andCallFake( function() {});
584+
var rowTemplateSpy = jasmine.createSpy('rowTemplateSpy');
585+
rowTemplateSpy.and.callFake( function() {});
586+
rowTemplateSpy(gridClassFactory, 'rowTemplateAssigner');
576587
var headerRow1 = new GridRow( {}, null, grid );
577588
var headerRow2 = new GridRow( {}, null, grid );
578589
var headerRow3 = new GridRow( {}, null, grid );

0 commit comments

Comments
 (0)