@@ -47,7 +47,7 @@ const gridOptionsMock = {
4747 useSimpleViewportCalc : true ,
4848 saveDetailViewOnScroll : false ,
4949 process : ( ) => new Promise ( ( resolve ) => resolve ( 'process resolved' ) ) ,
50- viewComponent : null ,
50+ viewComponent : null as any ,
5151 onExtensionRegistered : jest . fn ( ) ,
5252 onAsyncResponse : ( ) => { } ,
5353 onAsyncEndUpdate : ( ) => { } ,
@@ -309,11 +309,6 @@ describe('SlickRowDetailView', () => {
309309 plugin . register ( ) ;
310310 plugin . onBeforeRowDetailToggle . notify ( { item : columnsMock [ 0 ] , grid : gridStub } , new SlickEventData ( ) , gridStub ) ;
311311
312- // expect(handlerSpy).toHaveBeenCalledTimes(8); // there are an extra 2x on the grid itself
313- // expect(handlerSpy).toHaveBeenCalledWith(
314- // { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), },
315- // expect.anything()
316- // );
317312 expect ( onAsyncRespSpy ) . not . toHaveBeenCalled ( ) ;
318313 expect ( onAsyncEndSpy ) . not . toHaveBeenCalled ( ) ;
319314 expect ( onAfterRowSpy ) . not . toHaveBeenCalled ( ) ;
@@ -656,6 +651,28 @@ describe('SlickRowDetailView', () => {
656651 expect ( disposeSpy ) . toHaveBeenCalled ( ) ;
657652 expect ( disposeAllSpy ) . toHaveBeenCalled ( ) ;
658653 } ) ;
654+
655+ it ( 'should call internal event handler subscribe and expect the "onBeforeRowDetailToggle" option to be called and return true when addon notify is called' , ( ) => {
656+ gridOptionsMock . rowDetailView ! . onBeforeRowDetailToggle = undefined ;
657+ const onAsyncRespSpy = jest . spyOn ( gridOptionsMock . rowDetailView as RowDetailView , 'onAsyncResponse' ) ;
658+ const onAsyncEndSpy = jest . spyOn ( gridOptionsMock . rowDetailView as RowDetailView , 'onAsyncEndUpdate' ) ;
659+ const onAfterRowSpy = jest . spyOn ( gridOptionsMock . rowDetailView as RowDetailView , 'onAfterRowDetailToggle' ) ;
660+ // const onBeforeRowSpy = jest.spyOn(gridOptionsMock.rowDetailView as RowDetailView, 'onBeforeRowDetailToggle');
661+ const onRowOutViewSpy = jest . spyOn ( gridOptionsMock . rowDetailView as RowDetailView , 'onRowOutOfViewportRange' ) ;
662+ const onRowBackViewSpy = jest . spyOn ( gridOptionsMock . rowDetailView as RowDetailView , 'onRowBackToViewportRange' ) ;
663+
664+ plugin . init ( gridStub ) ;
665+ plugin . onBeforeRowDetailToggle = new SlickEvent ( ) ;
666+ plugin . register ( ) ;
667+ const result = plugin . onBeforeRowDetailToggle . notify ( { item : columnsMock [ 0 ] , grid : gridStub } , new SlickEventData ( ) , gridStub ) ;
668+
669+ expect ( result . getReturnValue ( ) ) . toEqual ( true ) ;
670+ expect ( onAsyncRespSpy ) . not . toHaveBeenCalled ( ) ;
671+ expect ( onAsyncEndSpy ) . not . toHaveBeenCalled ( ) ;
672+ expect ( onAfterRowSpy ) . not . toHaveBeenCalled ( ) ;
673+ expect ( onRowOutViewSpy ) . not . toHaveBeenCalled ( ) ;
674+ expect ( onRowBackViewSpy ) . not . toHaveBeenCalled ( ) ;
675+ } ) ;
659676 } ) ;
660677
661678 describe ( 'possible error thrown' , ( ) => {
0 commit comments