@@ -306,10 +306,40 @@ describe('SlickRowDetailView plugin', () => {
306306 expect ( stopPropagationSpy ) . not . toHaveBeenCalled ( ) ;
307307 } ) ;
308308
309- it ( 'should trigger onClick and ' , ( ) => {
309+ it ( 'should trigger onClick and NOT expect Row Detail to be toggled when onBeforeRowDetailToggle returns false' , ( ) => {
310+ const mockProcess = jest . fn ( ) ;
311+ const expandDetailViewSpy = jest . spyOn ( plugin , 'expandDetailView' ) ;
312+ const onBeforeSlickEventData = new Slick . EventData ( ) ;
313+ jest . spyOn ( onBeforeSlickEventData , 'getReturnValue' ) . mockReturnValue ( false ) ;
314+ const beforeRowDetailToggleSpy = jest . spyOn ( plugin . onBeforeRowDetailToggle , 'notify' ) . mockReturnValueOnce ( onBeforeSlickEventData ) ;
315+ const afterRowDetailToggleSpy = jest . spyOn ( plugin . onAfterRowDetailToggle , 'notify' ) ;
316+ const itemMock = { id : 123 , firstName : 'John' , lastName : 'Doe' , _collapsed : true } ;
317+ const detailView = `<span>loading...</span>` ;
318+ jest . spyOn ( gridStub . getEditorLock ( ) , 'isActive' ) . mockReturnValue ( false ) ;
319+ jest . spyOn ( gridStub . getEditorLock ( ) , 'commitCurrentEdit' ) . mockReturnValue ( true ) ;
320+ jest . spyOn ( gridStub , 'getDataItem' ) . mockReturnValue ( itemMock ) ;
321+ jest . spyOn ( gridStub , 'getColumns' ) . mockReturnValue ( mockColumns ) ;
322+ jest . spyOn ( gridStub , 'getOptions' ) . mockReturnValue ( { ...gridOptionsMock , rowDetailView : { process : mockProcess , columnIndexPosition : 0 , useRowClick : true , maxRows : 2 , panelRows : 2 } as any } ) ;
323+
324+ plugin . init ( gridStub ) ;
325+ plugin . onAsyncResponse . notify ( { item : itemMock , itemDetail : itemMock , detailView, } , new Slick . EventData ( ) ) ;
326+
327+ const clickEvent = new Event ( 'click' ) ;
328+ Object . defineProperty ( clickEvent , 'target' , { writable : true , configurable : true , value : document . createElement ( 'div' ) } ) ;
329+ Object . defineProperty ( clickEvent , 'isPropagationStopped' , { writable : true , configurable : true , value : jest . fn ( ) } ) ;
330+ Object . defineProperty ( clickEvent , 'isImmediatePropagationStopped' , { writable : true , configurable : true , value : jest . fn ( ) } ) ;
331+ gridStub . onClick . notify ( { row : 0 , cell : 1 , grid : gridStub } , clickEvent ) ;
332+
333+ expect ( beforeRowDetailToggleSpy ) . toHaveBeenCalled ( ) ;
334+ expect ( afterRowDetailToggleSpy ) . not . toHaveBeenCalled ( ) ;
335+ expect ( expandDetailViewSpy ) . not . toHaveBeenCalled ( ) ;
336+ } ) ;
337+
338+ it ( 'should trigger onClick and expect Row Detail to be toggled' , ( ) => {
310339 const mockProcess = jest . fn ( ) ;
311340 const expandDetailViewSpy = jest . spyOn ( plugin , 'expandDetailView' ) ;
312341 const beforeRowDetailToggleSpy = jest . spyOn ( plugin . onBeforeRowDetailToggle , 'notify' ) ;
342+ const afterRowDetailToggleSpy = jest . spyOn ( plugin . onAfterRowDetailToggle , 'notify' ) ;
313343 const itemMock = { id : 123 , firstName : 'John' , lastName : 'Doe' , _collapsed : true } ;
314344 const detailView = `<span>loading...</span>` ;
315345 jest . spyOn ( gridStub . getEditorLock ( ) , 'isActive' ) . mockReturnValue ( false ) ;
@@ -328,6 +358,7 @@ describe('SlickRowDetailView plugin', () => {
328358 gridStub . onClick . notify ( { row : 0 , cell : 1 , grid : gridStub } , clickEvent ) ;
329359
330360 expect ( beforeRowDetailToggleSpy ) . toHaveBeenCalled ( ) ;
361+ expect ( afterRowDetailToggleSpy ) . toHaveBeenCalled ( ) ;
331362 expect ( expandDetailViewSpy ) . toHaveBeenCalledWith ( {
332363 _collapsed : false , _detailContent : undefined , _detailViewLoaded : true ,
333364 _height : 75 , _sizePadding : 3 , firstName : 'John' , id : 123 , lastName : 'Doe'
@@ -410,7 +441,7 @@ describe('SlickRowDetailView plugin', () => {
410441 _collapsed : true , _detailViewLoaded : true , _sizePadding : 0 , _height : 150 , _detailContent : '<span>loading...</span>' ,
411442 id : 123 , firstName : 'John' , lastName : 'Doe' ,
412443 }
413- } ) ;
444+ } , expect . anything ( ) , expect . anything ( ) ) ;
414445 expect ( afterRowDetailToggleSpy ) . toHaveBeenCalledWith ( {
415446 grid : gridStub ,
416447 item : {
0 commit comments