import { ContextActionsDirective } from './contextmenu.directive' ; import { ContextMenu } from '@alfresco/aca-shared/store' ; import { fakeAsync , tick } from '@angular/core/testing' ; describe ( 'ContextActionsDirective' , ( ) => { let directive ; const storeMock = { dispatch : jasmine . createSpy ( 'dispatch' ) } ; beforeEach ( ( ) => { directive = new ContextActionsDirective ( storeMock ) ; } ) ; it ( 'should not render context menu when `enabled` property is false' , ( ) => { spyOn ( directive , 'execute' ) . and . stub ( ) ; directive . enabled = false ; directive . onContextMenuEvent ( new MouseEvent ( 'contextmenu' ) ) ; expect ( directive . execute ) . not . toHaveBeenCalled ( ) ; } ) ; it ( 'should call service to render context menu' , fakeAsync ( ( ) => { const el = document . createElement ( 'div' ) ; el . className = 'adf-datatable-cell adf-datatable-cell--text adf-datatable-row' ; const fragment = document . createDocumentFragment ( ) ; fragment . appendChild ( el ) ; const target = fragment . querySelector ( 'div' ) ; const mouseEventMock = { preventDefault : ( ) => { } , target } ; directive . ngOnInit ( ) ; directive . onContextMenuEvent ( mouseEventMock ) ; tick ( 500 ) ; expect ( storeMock . dispatch ) . toHaveBeenCalledWith ( new ContextMenu ( mouseEventMock ) ) ; } ) ) ; } ) ;