Skip to content

Commit

Permalink
fix(resizer): only bind autoresize when enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jr01 committed Sep 20, 2021
1 parent 7f3eb81 commit ca894c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 24 additions & 3 deletions packages/common/src/services/__tests__/resizer.service.spec.ts
Expand Up @@ -101,9 +101,30 @@ 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('resizeGrid method', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/services/resizer.service.ts
Expand Up @@ -117,7 +117,7 @@ export class ResizerService {
this._fixedWidth = fixedGridSizes.width;
}

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

Expand Down Expand Up @@ -251,7 +251,7 @@ export class ResizerService {

/**
* Provide the possibility to pause the resizer for some time, until user decides to re-enabled it later if he wish to.
* @param {boolean} isResizePaused are we pausing the resizer?
* @param {boolean} isResizePaused are we pausing the resizer?@C
*/
pauseResizer(isResizePaused: boolean) {
this._resizePaused = isResizePaused;
Expand Down

0 comments on commit ca894c0

Please sign in to comment.