|
4 | 4 |
|
5 | 5 | describe('ui.grid.edit GridCellDirective', function() {
|
6 | 6 | var $compile, $rootScope, $templateCache, $timeout, element, grid, gridClassFactory, gridUtil,
|
7 |
| - recompile, scope, uiGridConstants, uiGridCtrl, uiGridEditService; |
| 7 | + recompile, scope, uiGridConstants, uiGridCtrl, uiGridEditService, onNavigateCb; |
8 | 8 |
|
9 | 9 | beforeEach(function() {
|
| 10 | + module('ui.grid'); |
10 | 11 | module('ui.grid.edit');
|
11 | 12 |
|
12 | 13 | inject(function(_$compile_, _$rootScope_, _$templateCache_, _$timeout_, _gridClassFactory_,
|
|
37 | 38 | uiGridEditService.initializeGrid(grid);
|
38 | 39 | grid.buildColumns();
|
39 | 40 | grid.modifyRows(grid.options.data);
|
| 41 | + grid.options.onRegisterApi = function(gridApi) { |
| 42 | + uiGridCtrl = { |
| 43 | + grid: { |
| 44 | + api: gridApi |
| 45 | + } |
| 46 | + }; |
| 47 | + gridApi.cellNav = { |
| 48 | + on: { |
| 49 | + navigate: function(scope, callback) { |
| 50 | + uiGridCtrl.gridScope = scope; |
| 51 | + onNavigateCb = callback; |
| 52 | + |
| 53 | + return angular.noop; |
| 54 | + }, |
| 55 | + viewPortKeyDown: function() { |
| 56 | + return angular.noop; |
| 57 | + } |
| 58 | + } |
| 59 | + }; |
| 60 | + }; |
| 61 | + element = angular.element('<div ui-grid-cell/>'); |
40 | 62 |
|
41 | 63 | scope.grid = grid;
|
42 | 64 | scope.col = grid.columns[0];
|
|
89 | 111 | });
|
90 | 112 | });
|
91 | 113 |
|
| 114 | + describe('on navigate', function() { |
| 115 | + beforeEach(function() { |
| 116 | + element = angular.element('<div ui-grid="grid.options" ui-grid-edit/>'); |
| 117 | + }); |
| 118 | + describe('if enableCellEditOnFocus is set to true', function() { |
| 119 | + beforeEach(function() { |
| 120 | + recompile(); |
| 121 | + uiGridCtrl.gridScope.col.colDef.enableCellEditOnFocus = true; |
| 122 | + uiGridCtrl.gridScope.col.editableCellTemplate = ''; |
| 123 | + uiGridCtrl.gridScope.grid.api.core.scrollToIfNecessary = jasmine.createSpy('scrollToIfNecessary').and.returnValue({then: angular.noop}); |
| 124 | + scope.$apply(); |
| 125 | + }); |
| 126 | + afterEach(function() { |
| 127 | + uiGridCtrl.gridScope.grid.api.core.scrollToIfNecessary.calls.reset(); |
| 128 | + }); |
| 129 | + it('should trigger scrolling if necessary when the navigating to the current row and column via click', function(done) { |
| 130 | + var event = new jQuery.Event('click'); |
| 131 | + |
| 132 | + onNavigateCb({row: uiGridCtrl.gridScope.row, col: uiGridCtrl.gridScope.col}, {}, event); |
| 133 | + $timeout.flush(); |
| 134 | + setTimeout(function() { |
| 135 | + expect(uiGridCtrl.gridScope.grid.api.core.scrollToIfNecessary).toHaveBeenCalled(); |
| 136 | + done(); |
| 137 | + }, 1); |
| 138 | + }); |
| 139 | + it('should trigger scrolling if necessary when the navigating to the current row and column via keydown', function(done) { |
| 140 | + var event = new jQuery.Event('keydown'); |
| 141 | + |
| 142 | + onNavigateCb({row: uiGridCtrl.gridScope.row, col: uiGridCtrl.gridScope.col}, {}, event); |
| 143 | + $timeout.flush(); |
| 144 | + setTimeout(function() { |
| 145 | + expect(uiGridCtrl.gridScope.grid.api.core.scrollToIfNecessary).toHaveBeenCalled(); |
| 146 | + done(); |
| 147 | + }, 1); |
| 148 | + }); |
| 149 | + it('should trigger scrolling if necessary when the navigating to the current row and column without an event', function(done) { |
| 150 | + onNavigateCb({row: uiGridCtrl.gridScope.row, col: uiGridCtrl.gridScope.col}, {}, null); |
| 151 | + $timeout.flush(); |
| 152 | + setTimeout(function() { |
| 153 | + expect(uiGridCtrl.gridScope.grid.api.core.scrollToIfNecessary).toHaveBeenCalled(); |
| 154 | + done(); |
| 155 | + }, 1); |
| 156 | + }); |
| 157 | + it('should not trigger scrolling if necessary when the navigating to a different row and column', function(done) { |
| 158 | + onNavigateCb({row: 'DifferentRow', col: 'DifferentCol'}, {}, null); |
| 159 | + $timeout.flush(); |
| 160 | + setTimeout(function() { |
| 161 | + expect(uiGridCtrl.gridScope.grid.api.core.scrollToIfNecessary).not.toHaveBeenCalled(); |
| 162 | + done(); |
| 163 | + }, 1); |
| 164 | + }); |
| 165 | + }); |
| 166 | + describe('if enableCellEditOnFocus is set to false', function() { |
| 167 | + beforeEach(function() { |
| 168 | + recompile(); |
| 169 | + uiGridCtrl.gridScope.col.colDef.enableCellEditOnFocus = false; |
| 170 | + uiGridCtrl.gridScope.grid.api.core.scrollToIfNecessary = jasmine.createSpy('scrollToIfNecessary').and.returnValue({then: angular.noop}); |
| 171 | + onNavigateCb({row: uiGridCtrl.gridScope.row, col: uiGridCtrl.gridScope.col}, {}, null); |
| 172 | + $timeout.flush(); |
| 173 | + scope.$apply(); |
| 174 | + }); |
| 175 | + afterEach(function() { |
| 176 | + uiGridCtrl.gridScope.grid.api.core.scrollToIfNecessary.calls.reset(); |
| 177 | + }); |
| 178 | + it('should not trigger scrolling', function(done) { |
| 179 | + setTimeout(function() { |
| 180 | + expect(uiGridCtrl.gridScope.grid.api.core.scrollToIfNecessary).not.toHaveBeenCalled(); |
| 181 | + done(); |
| 182 | + }, 1); |
| 183 | + }); |
| 184 | + }); |
| 185 | + }); |
| 186 | + |
92 | 187 | describe('touchStart', function() {
|
93 | 188 | function testTouchStart(withOriginalEvent) {
|
94 | 189 | beforeEach(function() {
|
|
0 commit comments