Skip to content

Commit

Permalink
Revert "feat: add option to cancel Row Detail opening (#1125)" (#1127)
Browse files Browse the repository at this point in the history
This reverts commit 82ba377.
  • Loading branch information
ghiscoding authored Oct 5, 2023
1 parent 85a52d2 commit 5e4b14a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
35 changes: 2 additions & 33 deletions packages/row-detail-view-plugin/src/slickRowDetailView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,40 +306,10 @@ describe('SlickRowDetailView plugin', () => {
expect(stopPropagationSpy).not.toHaveBeenCalled();
});

it('should trigger onClick and NOT expect Row Detail to be toggled when onBeforeRowDetailToggle returns false', () => {
const mockProcess = jest.fn();
const expandDetailViewSpy = jest.spyOn(plugin, 'expandDetailView');
const onBeforeSlickEventData = new Slick.EventData();
jest.spyOn(onBeforeSlickEventData, 'getReturnValue').mockReturnValue(false);
const beforeRowDetailToggleSpy = jest.spyOn(plugin.onBeforeRowDetailToggle, 'notify').mockReturnValueOnce(onBeforeSlickEventData);
const afterRowDetailToggleSpy = jest.spyOn(plugin.onAfterRowDetailToggle, 'notify');
const itemMock = { id: 123, firstName: 'John', lastName: 'Doe', _collapsed: true };
const detailView = `<span>loading...</span>`;
jest.spyOn(gridStub.getEditorLock(), 'isActive').mockReturnValue(false);
jest.spyOn(gridStub.getEditorLock(), 'commitCurrentEdit').mockReturnValue(true);
jest.spyOn(gridStub, 'getDataItem').mockReturnValue(itemMock);
jest.spyOn(gridStub, 'getColumns').mockReturnValue(mockColumns);
jest.spyOn(gridStub, 'getOptions').mockReturnValue({ ...gridOptionsMock, rowDetailView: { process: mockProcess, columnIndexPosition: 0, useRowClick: true, maxRows: 2, panelRows: 2 } as any });

plugin.init(gridStub);
plugin.onAsyncResponse.notify({ item: itemMock, itemDetail: itemMock, detailView, }, new Slick.EventData());

const clickEvent = new Event('click');
Object.defineProperty(clickEvent, 'target', { writable: true, configurable: true, value: document.createElement('div') });
Object.defineProperty(clickEvent, 'isPropagationStopped', { writable: true, configurable: true, value: jest.fn() });
Object.defineProperty(clickEvent, 'isImmediatePropagationStopped', { writable: true, configurable: true, value: jest.fn() });
gridStub.onClick.notify({ row: 0, cell: 1, grid: gridStub }, clickEvent);

expect(beforeRowDetailToggleSpy).toHaveBeenCalled();
expect(afterRowDetailToggleSpy).not.toHaveBeenCalled();
expect(expandDetailViewSpy).not.toHaveBeenCalled();
});

it('should trigger onClick and expect Row Detail to be toggled', () => {
it('should trigger onClick and ', () => {
const mockProcess = jest.fn();
const expandDetailViewSpy = jest.spyOn(plugin, 'expandDetailView');
const beforeRowDetailToggleSpy = jest.spyOn(plugin.onBeforeRowDetailToggle, 'notify');
const afterRowDetailToggleSpy = jest.spyOn(plugin.onAfterRowDetailToggle, 'notify');
const itemMock = { id: 123, firstName: 'John', lastName: 'Doe', _collapsed: true };
const detailView = `<span>loading...</span>`;
jest.spyOn(gridStub.getEditorLock(), 'isActive').mockReturnValue(false);
Expand All @@ -358,7 +328,6 @@ describe('SlickRowDetailView plugin', () => {
gridStub.onClick.notify({ row: 0, cell: 1, grid: gridStub }, clickEvent);

expect(beforeRowDetailToggleSpy).toHaveBeenCalled();
expect(afterRowDetailToggleSpy).toHaveBeenCalled();
expect(expandDetailViewSpy).toHaveBeenCalledWith({
_collapsed: false, _detailContent: undefined, _detailViewLoaded: true,
_height: 75, _sizePadding: 3, firstName: 'John', id: 123, lastName: 'Doe'
Expand Down Expand Up @@ -441,7 +410,7 @@ describe('SlickRowDetailView plugin', () => {
_collapsed: true, _detailViewLoaded: true, _sizePadding: 0, _height: 150, _detailContent: '<span>loading...</span>',
id: 123, firstName: 'John', lastName: 'Doe',
}
}, expect.anything(), expect.anything());
});
expect(afterRowDetailToggleSpy).toHaveBeenCalledWith({
grid: gridStub,
item: {
Expand Down
8 changes: 4 additions & 4 deletions packages/row-detail-view-plugin/src/slickRowDetailView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,10 @@ export class SlickRowDetailView implements ExternalResource, UniversalRowDetailV
}

// trigger an event before toggling
// user could cancel the Row Detail opening when event is returning false
if (this.onBeforeRowDetailToggle.notify({ grid: this._grid, item: dataContext }, e, this).getReturnValue() === false) {
return;
}
this.onBeforeRowDetailToggle.notify({
grid: this._grid,
item: dataContext
});

this.toggleRowSelection(args.row, dataContext);

Expand Down

0 comments on commit 5e4b14a

Please sign in to comment.