Skip to content

Commit

Permalink
fix(selections): selected rows doesn't update when hidden column shown
Browse files Browse the repository at this point in the history
- related to core SlickGrid issue [#661](6pac/SlickGrid#661)
  • Loading branch information
ghiscoding committed Jan 24, 2022
1 parent 8b30f87 commit 0d1cf29
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
Expand Up @@ -139,6 +139,28 @@ describe('CellSelectionModel Plugin', () => {
expect(registerSpy).toHaveBeenCalledWith(plugin.cellRangeSelector);
});

it('should expect that "setSelectedRanges" is being triggered when "refreshSelections" is called', () => {
const registerSpy = jest.spyOn(gridStub, 'registerPlugin');

plugin = new SlickCellSelectionModel({ selectActiveCell: false, cellRangeSelector: undefined });
plugin.init(gridStub);

jest.spyOn(plugin, 'getSelectedRanges').mockReturnValue([
{ fromCell: 1, fromRow: 2, toCell: 3, toRow: 4 },
{ fromCell: 2, fromRow: 3, toCell: 3, toRow: 4 }
]);
const setSelectedRangesSpy = jest.spyOn(plugin, 'setSelectedRanges');
plugin.refreshSelections();

expect(plugin.cellRangeSelector).toBeTruthy();
expect(plugin.canvas).toBeTruthy();
expect(registerSpy).toHaveBeenCalledWith(plugin.cellRangeSelector);
expect(setSelectedRangesSpy).toHaveBeenCalledWith([
{ fromCell: 1, fromRow: 2, toCell: 3, toRow: 4 },
{ fromCell: 2, fromRow: 3, toCell: 3, toRow: 4 }
]);
});

it('should return False when onBeforeCellRangeSelected is called and getEditorLock returns False', () => {
const mouseEvent = addJQueryEventPropagation(new Event('mouseenter'));
jest.spyOn(gridStub.getEditorLock(), 'isActive').mockReturnValue(true);
Expand Down
Expand Up @@ -148,6 +148,18 @@ describe('SlickRowSelectionModel Plugin', () => {
});
});

it('should expect that "setSelectedRows" is being triggered when "refreshSelections" is called', () => {
jest.spyOn(gridStub, 'getColumns').mockReturnValueOnce(mockColumns);
plugin = new SlickRowSelectionModel({ selectActiveRow: false, });
plugin.init(gridStub);

jest.spyOn(plugin, 'getSelectedRows').mockReturnValue([0, 1]);
const setSelectedRowsSpy = jest.spyOn(plugin, 'setSelectedRows');
plugin.refreshSelections();

expect(setSelectedRowsSpy).toHaveBeenCalledWith([0, 1]);
});

it('should call "setSelectedRanges" when "setSelectedRows" is called', () => {
jest.spyOn(gridStub, 'getColumns').mockReturnValueOnce(mockColumns);
const setSelectedRangeSpy = jest.spyOn(plugin, 'setSelectedRanges');
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/extensions/slickCellSelectionModel.ts
Expand Up @@ -100,6 +100,10 @@ export class SlickCellSelectionModel {
return !areDifferent;
}

refreshSelections() {
this.setSelectedRanges(this.getSelectedRanges());
}

removeInvalidRanges(ranges: CellRange[]) {
const result = [];
for (let i = 0; i < ranges.length; i++) {
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/extensions/slickRowSelectionModel.ts
Expand Up @@ -106,6 +106,10 @@ export class SlickRowSelectionModel {
return this.rangesToRows(this._ranges);
}

refreshSelections() {
this.setSelectedRows(this.getSelectedRows());
}

setSelectedRows(rows: number[]) {
this.setSelectedRanges(this.rowsToRanges(rows), 'SlickRowSelectionModel.setSelectedRows');
}
Expand Down

0 comments on commit 0d1cf29

Please sign in to comment.