@@ -299,6 +299,7 @@ describe('OCA.Files.FileActions tests', function() {
299299 clock . restore ( ) ;
300300 } ) ;
301301 it ( 'passes context to action handler' , function ( ) {
302+ var notifyUpdateListenersSpy = sinon . spy ( fileList . fileActions , '_notifyUpdateListeners' ) ;
302303 $tr . find ( '.action-test' ) . click ( ) ;
303304 expect ( actionStub . calledOnce ) . toEqual ( true ) ;
304305 expect ( actionStub . getCall ( 0 ) . args [ 0 ] ) . toEqual ( 'testName.txt' ) ;
@@ -309,6 +310,22 @@ describe('OCA.Files.FileActions tests', function() {
309310 expect ( context . dir ) . toEqual ( '/subdir' ) ;
310311 expect ( context . fileInfoModel . get ( 'name' ) ) . toEqual ( 'testName.txt' ) ;
311312
313+ expect ( notifyUpdateListenersSpy . calledTwice ) . toEqual ( true ) ;
314+ expect ( notifyUpdateListenersSpy . calledBefore ( actionStub ) ) . toEqual ( true ) ;
315+ expect ( notifyUpdateListenersSpy . calledAfter ( actionStub ) ) . toEqual ( true ) ;
316+ expect ( notifyUpdateListenersSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( 'beforeTriggerAction' ) ;
317+ expect ( notifyUpdateListenersSpy . getCall ( 0 ) . args [ 1 ] ) . toEqual ( {
318+ action : fileActions . getActions ( 'all' , OCA . Files . FileActions . TYPE_INLINE , OC . PERMISSION_READ ) [ 'Test' ] ,
319+ fileName : 'testName.txt' ,
320+ context : context
321+ } ) ;
322+ expect ( notifyUpdateListenersSpy . getCall ( 1 ) . args [ 0 ] ) . toEqual ( 'afterTriggerAction' ) ;
323+ expect ( notifyUpdateListenersSpy . getCall ( 1 ) . args [ 1 ] ) . toEqual ( {
324+ action : fileActions . getActions ( 'all' , OCA . Files . FileActions . TYPE_INLINE , OC . PERMISSION_READ ) [ 'Test' ] ,
325+ fileName : 'testName.txt' ,
326+ context : context
327+ } ) ;
328+
312329 // when data-path is defined
313330 actionStub . reset ( ) ;
314331 $tr . attr ( 'data-path' , '/somepath' ) ;
@@ -317,6 +334,7 @@ describe('OCA.Files.FileActions tests', function() {
317334 expect ( context . dir ) . toEqual ( '/somepath' ) ;
318335 } ) ;
319336 it ( 'also triggers action handler when calling triggerAction()' , function ( ) {
337+ var notifyUpdateListenersSpy = sinon . spy ( fileList . fileActions , '_notifyUpdateListeners' ) ;
320338 var model = new OCA . Files . FileInfoModel ( {
321339 id : 1 ,
322340 name : 'Test.txt' ,
@@ -331,7 +349,62 @@ describe('OCA.Files.FileActions tests', function() {
331349 expect ( actionStub . getCall ( 0 ) . args [ 1 ] . fileList ) . toEqual ( fileList ) ;
332350 expect ( actionStub . getCall ( 0 ) . args [ 1 ] . fileActions ) . toEqual ( fileActions ) ;
333351 expect ( actionStub . getCall ( 0 ) . args [ 1 ] . fileInfoModel ) . toEqual ( model ) ;
352+
353+ expect ( notifyUpdateListenersSpy . calledTwice ) . toEqual ( true ) ;
354+ expect ( notifyUpdateListenersSpy . calledBefore ( actionStub ) ) . toEqual ( true ) ;
355+ expect ( notifyUpdateListenersSpy . calledAfter ( actionStub ) ) . toEqual ( true ) ;
356+ expect ( notifyUpdateListenersSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( 'beforeTriggerAction' ) ;
357+ expect ( notifyUpdateListenersSpy . getCall ( 0 ) . args [ 1 ] ) . toEqual ( {
358+ action : fileActions . getActions ( 'all' , OCA . Files . FileActions . TYPE_INLINE , OC . PERMISSION_READ ) [ 'Test' ] ,
359+ fileName : 'Test.txt' ,
360+ context : {
361+ fileActions : fileActions ,
362+ fileInfoModel : model ,
363+ dir : '/subdir' ,
364+ fileList : fileList ,
365+ $file : fileList . findFileEl ( 'Test.txt' )
366+ }
367+ } ) ;
368+ expect ( notifyUpdateListenersSpy . getCall ( 1 ) . args [ 0 ] ) . toEqual ( 'afterTriggerAction' ) ;
369+ expect ( notifyUpdateListenersSpy . getCall ( 1 ) . args [ 1 ] ) . toEqual ( {
370+ action : fileActions . getActions ( 'all' , OCA . Files . FileActions . TYPE_INLINE , OC . PERMISSION_READ ) [ 'Test' ] ,
371+ fileName : 'Test.txt' ,
372+ context : {
373+ fileActions : fileActions ,
374+ fileInfoModel : model ,
375+ dir : '/subdir' ,
376+ fileList : fileList ,
377+ $file : fileList . findFileEl ( 'Test.txt' )
378+ }
379+ } ) ;
334380 } ) ;
381+ it ( 'triggers listener events when invoked directly' , function ( ) {
382+ var context = { fileActions : new OCA . Files . FileActions ( ) }
383+ var notifyUpdateListenersSpy = sinon . spy ( context . fileActions , '_notifyUpdateListeners' ) ;
384+ var testAction = fileActions . get ( 'all' , OCA . Files . FileActions . TYPE_INLINE , OC . PERMISSION_READ ) [ 'Test' ] ;
385+
386+ testAction ( 'Test.txt' , context ) ;
387+
388+ expect ( actionStub . calledOnce ) . toEqual ( true ) ;
389+ expect ( actionStub . getCall ( 0 ) . args [ 0 ] ) . toEqual ( 'Test.txt' ) ;
390+ expect ( actionStub . getCall ( 0 ) . args [ 1 ] ) . toBe ( context ) ;
391+
392+ expect ( notifyUpdateListenersSpy . calledTwice ) . toEqual ( true ) ;
393+ expect ( notifyUpdateListenersSpy . calledBefore ( actionStub ) ) . toEqual ( true ) ;
394+ expect ( notifyUpdateListenersSpy . calledAfter ( actionStub ) ) . toEqual ( true ) ;
395+ expect ( notifyUpdateListenersSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( 'beforeTriggerAction' ) ;
396+ expect ( notifyUpdateListenersSpy . getCall ( 0 ) . args [ 1 ] ) . toEqual ( {
397+ action : fileActions . getActions ( 'all' , OCA . Files . FileActions . TYPE_INLINE , OC . PERMISSION_READ ) [ 'Test' ] ,
398+ fileName : 'Test.txt' ,
399+ context : context
400+ } ) ;
401+ expect ( notifyUpdateListenersSpy . getCall ( 1 ) . args [ 0 ] ) . toEqual ( 'afterTriggerAction' ) ;
402+ expect ( notifyUpdateListenersSpy . getCall ( 1 ) . args [ 1 ] ) . toEqual ( {
403+ action : fileActions . getActions ( 'all' , OCA . Files . FileActions . TYPE_INLINE , OC . PERMISSION_READ ) [ 'Test' ] ,
404+ fileName : 'Test.txt' ,
405+ context : context
406+ } ) ;
407+ } ) ,
335408 describe ( 'actions menu' , function ( ) {
336409 it ( 'shows actions menu inside row when clicking the menu trigger' , function ( ) {
337410 expect ( $tr . find ( 'td.filename .fileActionsMenu' ) . length ) . toEqual ( 0 ) ;
0 commit comments