import { TestBed } from '@angular/core/testing' ; import { ViewNodeComponent } from './view-node.component' ; import { Store } from '@ngrx/store' ; import { CoreModule } from '@alfresco/adf-core' ; import { Router } from '@angular/router' ; import { of } from 'rxjs' ; import { TranslateModule } from '@ngx-translate/core' ; import { ViewNodeAction } from '@alfresco/aca-shared/store' ; describe ( 'ViewNodeComponent' , ( ) => { let component ; let fixture ; const mockRouter = { url : 'some-url' } ; const mockStore = { dispatch : jasmine . createSpy ( 'dispatch' ) , select : jasmine . createSpy ( 'select' ) . and . returnValue ( of ( { file : { entry : { id : 'nodeId' } } } ) ) } ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ TranslateModule . forRoot ( ) , CoreModule . forRoot ( ) ] , declarations : [ ViewNodeComponent ] , providers : [ { provide : Store , useValue : mockStore } , { provide : Router , useValue : mockRouter } ] } ) ; fixture = TestBed . createComponent ( ViewNodeComponent ) ; component = fixture . componentInstance ; } ) ; afterEach ( ( ) => { mockStore . dispatch . calls . reset ( ) ; } ) ; it ( 'should render as a menu button' , ( ) => { component . data = { menuButton : true } ; fixture . detectChanges ( ) ; expect ( fixture . nativeElement . querySelector ( '.mat-menu-item' ) ) . not . toBe ( null ) ; } ) ; it ( 'should render as a icon button' , ( ) => { component . data = { iconButton : true } ; fixture . detectChanges ( ) ; expect ( fixture . nativeElement . querySelector ( '.mat-icon-button' ) ) . not . toBe ( null ) ; } ) ; it ( 'should call ViewNodeAction onClick event' , ( ) => { component . data = { iconButton : true } ; fixture . detectChanges ( ) ; component . onClick ( ) ; expect ( mockStore . dispatch ) . toHaveBeenCalled ( ) ; } ) ; it ( 'should call ViewNodeAction for `app:filelink` node type' , ( ) => { const linkNode = { file : { entry : { id : 'nodeId' , nodeType : 'app:filelink' , properties : { 'cm:destination' : 'original-node-id' } } } } ; component . data = { iconButton : true } ; mockStore . select . and . returnValue ( of ( linkNode ) ) ; fixture . detectChanges ( ) ; component . onClick ( ) ; const id = linkNode . file . entry . properties [ 'cm:destination' ] ; expect ( mockStore . dispatch ) . toHaveBeenCalledWith ( new ViewNodeAction ( id , { location : mockRouter . url } ) ) ; } ) ; } ) ;