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

Revert "feat: add option to cancel Row Detail opening" #1127

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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