Skip to content

Commit

Permalink
fix: unexpected change of fixedHeight (fix #269) (#274)
Browse files Browse the repository at this point in the history
* fix: unexpected change of fixedHeight

* style: arrange indentation
  • Loading branch information
김동우 authored Feb 22, 2019
1 parent 56d91d8 commit 69e8f31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 41 deletions.
5 changes: 4 additions & 1 deletion src/js/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ var Grid = View.extend(/** @lends Grid.prototype */{
* @param {number} value - The number of pixel
*/
setBodyHeight: function(value) {
this.modelManager.dimensionModel.set('bodyHeight', value);
this.modelManager.dimensionModel.set({
bodyHeight: value,
fixedHeight: value !== 'auto'
});
},

/**
Expand Down
16 changes: 0 additions & 16 deletions src/js/model/dimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ var Dimension = Model.extend(/** @lends module:model/dimension.prototype */{
this.domState = options.domState;

this.on('change:fixedHeight', this._resetSyncHeightHandler);
this.on('change:bodyHeight', this._onChangeBodyHeight);

if (options.domEventBus) {
this.listenTo(options.domEventBus, 'windowResize', this._onResizeWindow);
Expand Down Expand Up @@ -97,21 +96,6 @@ var Dimension = Model.extend(/** @lends module:model/dimension.prototype */{
this.setHeight(height);
},

/**
* Event handler for changing 'bodyHeight' value
* @param {object} model - dimension model
* @private
*/
_onChangeBodyHeight: function(model) {
var changed = model.changed;
var changedTotalRowHeight = changed.totalRowHeight;
var changedBodyHeight = changed.bodyHeight;

if (!changedTotalRowHeight && changedBodyHeight) {
this.set('fixedHeight', (changedBodyHeight !== 'auto'));
}
},

/**
* Attach/Detach event handler of change:totalRowHeight event based on the fixedHeight.
* @private
Expand Down
22 changes: 22 additions & 0 deletions test/unit/js/grid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ describe('grid', function() {
});
});

describe('setBodyHeight', function() {
it('if bodyHeight is auto, fixedHeight should be false', function() {
var grid = createGrid();
var dimensionModel = grid.modelManager.dimensionModel;

grid.setBodyHeight('auto');

expect(dimensionModel.get('fixedHeight')).toBe(false);
expect(dimensionModel.get('bodyHeight')).toBe('auto');
});

it('if bodyHeight is number, fixedHeight should be true', function() {
var grid = createGrid();
var dimensionModel = grid.modelManager.dimensionModel;

grid.setBodyHeight(100);

expect(dimensionModel.get('fixedHeight')).toBe(true);
expect(dimensionModel.get('bodyHeight')).toBe(100);
});
});

describe('setSummaryColumnContent', function() {
it('should call summaryModel.setColumnContent', function() {
var grid = createGrid(null, {
Expand Down
24 changes: 0 additions & 24 deletions test/unit/js/model/dimension.simple.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,28 +197,4 @@ describe('model.dimension', function() {
expect(dimension.getOverflowFromMousePosition(limitX + 1, limitY + 1)).toEqual(expected);
});
});

describe('fixedHeight value', function() {
var dimension;

beforeEach(function() {
dimension = create({
bodyHeight: 100,
fixedHeight: false
});
});

it('when changed from "auto" to a fixed value.', function() {
dimension.set('bodyHeight', '300');
expect(dimension.get('fixedHeight')).toEqual(true);
});

it('when not changed from "auto" to a fixed value.', function() {
dimension.set({
totalRowHeight: true,
bodyHeight: '300'
});
expect(dimension.get('fixedHeight')).toEqual(false);
});
});
});

0 comments on commit 69e8f31

Please sign in to comment.