Skip to content

Commit

Permalink
Merge pull request #5097 from JLLeitschuh/chore/updateJasmine
Browse files Browse the repository at this point in the history
test: Updates tests to Jasmine 2
  • Loading branch information
swalters committed Feb 16, 2016
2 parents 7274632 + ee02583 commit cbeae2c
Show file tree
Hide file tree
Showing 43 changed files with 979 additions and 923 deletions.
9 changes: 5 additions & 4 deletions grunt/jshint.js
Expand Up @@ -17,7 +17,7 @@ module.exports = {
debug: true, // debugger statements allowed
globals: {
angular: false,

/* Protractor */
browser: false,

Expand All @@ -39,14 +39,15 @@ module.exports = {
afterEach: false,
before: false,
beforeEach: false,
afterAll: false,
console: false,
dump: false,
dump: false,
describe: false,
ddescribe: false,
fdescribe: false,
expect: false,
inject: false,
it: false,
iit: false,
fit: false,
module: false,
debugger: false,
DocumentTouch: false,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -44,7 +44,7 @@
"grunt-contrib-concat": "~0.3",
"grunt-contrib-connect": "~0.5",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-jasmine": "~0.5",
"grunt-contrib-jasmine": "^1.0.0",
"grunt-contrib-jshint": "~0.7",
"grunt-contrib-less": "~1.0",
"grunt-contrib-uglify": "~0.2",
Expand All @@ -65,7 +65,7 @@
"karma-coverage": "^0.2.5",
"karma-firefox-launcher": "~0.1",
"karma-ie-launcher": "^0.1.5",
"karma-jasmine": "~0.1",
"karma-jasmine": "^0.3.7",
"karma-phantomjs-launcher": "~0.1",
"karma-requirejs": "~0.2",
"karma-sauce-launcher": "~0.2.10",
Expand Down
58 changes: 26 additions & 32 deletions src/features/auto-resize-grid/test/auto-resize-grid.spec.js
@@ -1,5 +1,5 @@
describe('ui.grid.autoResizeGrid', function () {
var gridScope, gridElm, viewportElm, $scope, $compile, recompile, uiGridConstants;
var gridScope, gridElm, viewportElm, $scope, $compile, recompile, uiGridConstants, $timeout;

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

beforeEach(inject(function (_$compile_, $rootScope, _uiGridConstants_) {
beforeEach(inject(function (_$compile_, _$timeout_, $rootScope, _uiGridConstants_) {
$scope = $rootScope;
$timeout = _$timeout_;
$compile = _$compile_;
uiGridConstants = _uiGridConstants_;

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

describe('on grid element dimension change', function () {

it('adjusts the grid viewport size', inject(function ($timeout) {
var w = $(viewportElm).width();
var w;
beforeEach(function (done) {
w = $(viewportElm).width();
var h = $(viewportElm).height();

runs(function () {
$(gridElm).width(600);
});

waits(300);

runs(function () {
var newW = $(viewportElm).width();

expect(newW).toBeGreaterThan(w);
});
}));
$(gridElm).width(600);
$scope.$digest();
setTimeout(done, 300);
});
it('adjusts the grid viewport size', function () {
var newW = $(viewportElm).width();
expect(newW).toBeGreaterThan(w);
});
});

// 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
describe('on grid container dimension change', function () {
var gridContainerElm;
var w;

beforeEach(function () {
beforeEach(function (done) {
angular.element(gridElm).remove();

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

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

it('adjusts the grid viewport size', inject(function ($timeout) {
var w = $(viewportElm).width();
w = $(viewportElm).width();
var h = $(viewportElm).height();

runs(function () {
$(gridContainerElm).width(500);
});

waits(300);
$(gridContainerElm).width(500);
$scope.$digest();
setTimeout(done, 300);
});

runs(function () {
var newW = $(viewportElm).width();
it('adjusts the grid viewport size', function() {
var newW = $(viewportElm).width();

expect(newW).toBeGreaterThan(w);
});
}));
expect(newW).toBeGreaterThan(w);
});
});

});
});
10 changes: 5 additions & 5 deletions src/features/cellnav/test/uiGridCellNavDirective.spec.js
Expand Up @@ -53,22 +53,22 @@ describe('ui.grid.cellNav directive', function () {
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[1], col: $scope.grid.columns[0] }, true);
expect($scope.gridApi.cellNav.getCurrentSelection().length).toEqual(2);
});


it('handleKeyDown should clear the focused cells list when clearing focus', function () {
// first ensure that a cell is selected
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true);
var rowColToTest = { row: $scope.grid.rows[0], col: $scope.grid.columns[0] };
var evt = jQuery.Event("keydown");
evt.keyCode = uiGridConstants.keymap.TAB;
$scope.grid.cellNav.lastRowCol = rowColToTest;

// simulate tabbing out of grid
elm.controller('uiGrid').cellNav.handleKeyDown(evt);
expect($scope.grid.cellNav.focusedCells.length).toEqual(0);

// simulate restoring focus
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true);
expect($scope.grid.cellNav.focusedCells.length).toEqual(1);
});
});
});
2 changes: 1 addition & 1 deletion src/features/cellnav/test/uiGridCellNavFactory.spec.js
Expand Up @@ -218,4 +218,4 @@ describe('ui.grid.edit uiGridCellNavService', function () {

});

});
});
2 changes: 1 addition & 1 deletion src/features/edit/test/uiGridEditService.spec.js
Expand Up @@ -187,4 +187,4 @@ describe('ui.grid.edit uiGridEditService', function () {

});

});
});
2 changes: 1 addition & 1 deletion src/features/edit/test/uiGridInputDirective.spec.js
Expand Up @@ -57,4 +57,4 @@ describe('inputDirective', function () {
// expect(scope.inputForm.$valid).toBe(true);
// });

});
});
2 changes: 1 addition & 1 deletion src/features/expandable/test/expandable.spec.js
Expand Up @@ -81,4 +81,4 @@ describe('ui.grid.expandable', function () {
expect(element.find('.test').length).toBe(1);
});
});
});
});
93 changes: 52 additions & 41 deletions src/features/grouping/test/grouping.spec.js
Expand Up @@ -102,8 +102,12 @@ describe('ui.grid.grouping uiGridGroupingService', function () {


describe( 'groupRows', function() {
beforeEach(function() {
spyOn(gridClassFactory, 'rowTemplateAssigner').and.callFake( function() {});
});

it( 'group by col0 then col1', function() {
spyOn(gridClassFactory, 'rowTemplateAssigner').andCallFake( function() {});

grid.columns[0].grouping = { groupPriority: 1 };
grid.columns[1].grouping = { groupPriority: 2 };

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

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

uiGridGroupingService.tidyPriorities(grid);
Expand Down Expand Up @@ -482,49 +485,55 @@ describe('ui.grid.grouping uiGridGroupingService', function () {
});
});

it('sorts', function(){
grid.grouping.groupingHeaderCache = {
male: {
row: { treeNode: { state: 'collapsed' } },
children: {
22: { row: { treeNode: { state: 'expanded' } }, children: {} },
39: { row: { treeNode: { state: 'collapsed' } }, children: {} }

describe('sorts', function(){
beforeEach(function() {
spyOn(grid.api.core.raise, 'sortChanged').and.callThrough();
});

it('', function() {
grid.grouping.groupingHeaderCache = {
male: {
row: { treeNode: { state: 'collapsed' } },
children: {
22: { row: { treeNode: { state: 'expanded' } }, children: {} },
39: { row: { treeNode: { state: 'collapsed' } }, children: {} }
}
},
female: {
row: { treeNode: { state: 'expanded' } },
children: {
23: { row: { treeNode: { state: 'collapsed' } }, children: {} },
38: { row: { treeNode: { state: 'expanded' } }, children: {} }
}
}
},
female: {
row: { treeNode: { state: 'expanded' } },
children: {
23: { row: { treeNode: { state: 'collapsed' } }, children: {} },
38: { row: { treeNode: { state: 'expanded' } }, children: {} }
};


grid.api.grouping.setGrouping({
grouping: [
{ field: 'col3', colName: 'col3', groupPriority: 0 },
{ field: 'col2', colName: 'col2', groupPriority: 1 }
],
aggregations: [
{ field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } }
],
rowExpandedStates: {
male: { state: 'expanded', children: {
22: { state: 'collapsed' },
38: { state: 'expanded' }
} },
female: { state: 'expanded', children: {
23: { state: 'expanded' },
39: { state: 'collapsed' }
} }
}
}
};
});

spyOn(grid.api.core.raise, 'sortChanged').andCallThrough();

grid.api.grouping.setGrouping({
grouping: [
{ field: 'col3', colName: 'col3', groupPriority: 0 },
{ field: 'col2', colName: 'col2', groupPriority: 1 }
],
aggregations: [
{ field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } }
],
rowExpandedStates: {
male: { state: 'expanded', children: {
22: { state: 'collapsed' },
38: { state: 'expanded' }
} },
female: { state: 'expanded', children: {
23: { state: 'expanded' },
39: { state: 'collapsed' }
} }
}
// Should call sort change twice because we are grouping by two columns
expect(grid.api.core.raise.sortChanged.calls.count()).toEqual(2);
});

// Should call sort change twice because we are grouping by two columns
expect(grid.api.core.raise.sortChanged.calls.length).toEqual(2);

});

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

describe('insertGroupHeader', function() {
it('inserts a header in the middle', function() {
spyOn(gridClassFactory, 'rowTemplateAssigner').andCallFake( function() {});
var rowTemplateSpy = jasmine.createSpy('rowTemplateSpy');
rowTemplateSpy.and.callFake( function() {});
rowTemplateSpy(gridClassFactory, 'rowTemplateAssigner');
var headerRow1 = new GridRow( {}, null, grid );
var headerRow2 = new GridRow( {}, null, grid );
var headerRow3 = new GridRow( {}, null, grid );
Expand Down

0 comments on commit cbeae2c

Please sign in to comment.