Skip to content

Commit

Permalink
Merge pull request #489 from jr01/bugfix/only-bind-autoresize-when-en…
Browse files Browse the repository at this point in the history
…abled

fix(resizer): only bind autoresize when enabled
  • Loading branch information
ghiscoding authored Sep 21, 2021
2 parents 9efb278 + d4864d3 commit 09d5d96
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
42 changes: 39 additions & 3 deletions packages/common/src/services/__tests__/resizer.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,45 @@ describe('Resizer Service', () => {
expect(service).toBeTruthy();
});

it('should throw an error when there is no grid object defined', () => {
service = new ResizerService(eventPubSubService);
expect(() => service.init(null as any, divContainer)).toThrowError('[Slickgrid-Universal] Resizer Service requires a valid Grid object and DOM Element Container to be provided.');
describe('init method', () => {
it('should throw an error when there is no grid object defined', () => {
expect(() => service.init(null as any, divContainer)).toThrowError('[Slickgrid-Universal] Resizer Service requires a valid Grid object and DOM Element Container to be provided.');
});

it('should call "bindAutoResizeDataGrid" when autoResize is enabled', () => {
mockGridOptions.enableAutoResize = true;
jest.spyOn(gridStub, 'getContainerNode').mockReturnValue(null);
const bindAutoResizeDataGridSpy = jest.spyOn(service, 'bindAutoResizeDataGrid').mockImplementation();

service.init(gridStub, divContainer);

expect(bindAutoResizeDataGridSpy).toHaveBeenCalled();
});

it('should not call "bindAutoResizeDataGrid" when autoResize is not enabled', () => {
mockGridOptions.enableAutoResize = false;
jest.spyOn(gridStub, 'getContainerNode').mockReturnValue(null);
const bindAutoResizeDataGridSpy = jest.spyOn(service, 'bindAutoResizeDataGrid').mockImplementation();

service.init(gridStub, divContainer);

expect(bindAutoResizeDataGridSpy).not.toHaveBeenCalled();
});
});

describe('dispose method', () => {
it('should clear resizeGrid timeout', (done) => {
service.init(gridStub, divContainer);

const resizeGridWithDimensionsSpy = jest.spyOn(service, 'resizeGridWithDimensions');
service.resizeGrid(1);
service.dispose();

setTimeout(() => {
expect(resizeGridWithDimensionsSpy).not.toHaveBeenCalled();
done();
}, 2);
});
});

describe('resizeGrid method', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/services/resizer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class ResizerService {
if (this._intervalId) {
clearInterval(this._intervalId);
}
clearTimeout(this._timer);

$(window).off(`resize.grid${this.gridUidSelector}`);
}
Expand Down Expand Up @@ -117,7 +118,7 @@ export class ResizerService {
this._fixedWidth = fixedGridSizes.width;
}

if (this.gridOptions) {
if (this.gridOptions && this.gridOptions.enableAutoResize) {
this.bindAutoResizeDataGrid();
}

Expand Down

0 comments on commit 09d5d96

Please sign in to comment.