Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resizer): only bind autoresize when enabled #489

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions 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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but isn't this make the grid to not resize even with static sizes?
Have you tried running the code in this lib project?
We need to make sure that even if enableAutoResize is disabled, this won't break grids with static sizes like the Example 1 in this webpack demo.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked out the branch on my side and it seems to work as expected so I guess we're good

this.bindAutoResizeDataGrid();
}

Expand Down Expand Up @@ -251,7 +252,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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that @C a typo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. No idea how that got there...but I'll fix it.

*/
pauseResizer(isResizePaused: boolean) {
this._resizePaused = isResizePaused;
Expand Down