import { TestBed } from '@angular/core/testing' ; import { AppTestingModule } from '../../testing/app-testing.module' ; import { ContextMenuEffects } from './contextmenu.effects' ; import { EffectsModule } from '@ngrx/effects' ; import { Store } from '@ngrx/store' ; import { ContextMenu } from '@alfresco/aca-shared/store' ; import { ContextMenuService } from '../../components/context-menu/context-menu.service' ; import { OverlayRef } from '@angular/cdk/overlay' ; import { ContextMenuOverlayRef } from '../../components/context-menu/context-menu-overlay' ; describe ( 'ContextMenuEffects' , ( ) => { let store ; let contextMenuService ; const overlayRefMock = new ContextMenuOverlayRef ( { } as OverlayRef ) ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ AppTestingModule , EffectsModule . forRoot ( [ ContextMenuEffects ] ) ] , providers : [ ContextMenuService ] } ) ; store = TestBed . inject ( Store ) ; contextMenuService = TestBed . inject ( ContextMenuService ) ; spyOn ( overlayRefMock , 'close' ) . and . callFake ( ( ) => { } ) ; spyOn ( contextMenuService , 'open' ) . and . returnValue ( overlayRefMock ) ; } ) ; it ( 'should open dialog' , ( ) => { store . dispatch ( new ContextMenu ( new MouseEvent ( 'click' ) ) ) ; expect ( contextMenuService . open ) . toHaveBeenCalled ( ) ; } ) ; it ( 'should close dialog reference if previously was opened' , ( ) => { store . dispatch ( new ContextMenu ( new MouseEvent ( 'click' ) ) ) ; expect ( contextMenuService . open ) . toHaveBeenCalled ( ) ; store . dispatch ( new ContextMenu ( new MouseEvent ( 'click' ) ) ) ; expect ( overlayRefMock . close ) . toHaveBeenCalled ( ) ; } ) ; } ) ;