import { CustomNameColumnComponent } from './name-column.component' ; import { DocumentListCustomComponentsModule } from '../document-list-custom-components.module' ; import { Actions } from '@ngrx/effects' ; import { StoreModule } from '@ngrx/store' ; import { TestBed } from '@angular/core/testing' ; import { CoreModule } from '@alfresco/adf-core' ; import { TranslateModule } from '@ngx-translate/core' ; describe ( 'CustomNameColumnComponent' , ( ) => { let fixture ; let component ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ TranslateModule . forRoot ( ) , CoreModule . forRoot ( ) , DocumentListCustomComponentsModule , StoreModule . forRoot ( { app : ( ) => { } } , { initialState : { } } ) ] , providers : [ Actions ] } ) ; fixture = TestBed . createComponent ( CustomNameColumnComponent ) ; component = fixture . componentInstance ; } ) ; it ( 'should not render lock element if file is not locked' , ( ) => { component . context = { row : { node : { entry : { isFile : true , id : 'nodeId' } } , getValue ( key ) { return key ; } } } ; fixture . detectChanges ( ) ; expect ( fixture . debugElement . nativeElement . querySelector ( 'aca-locked-by' ) ) . toBe ( null ) ; } ) ; it ( 'should not render lock element if node is not a file' , ( ) => { component . context = { row : { node : { entry : { isFile : false , id : 'nodeId' } } , getValue ( key ) { return key ; } } } ; fixture . detectChanges ( ) ; expect ( fixture . debugElement . nativeElement . querySelector ( 'aca-locked-by' ) ) . toBe ( null ) ; } ) ; it ( 'should render lock element if file is locked' , ( ) => { component . context = { row : { node : { entry : { isFile : true , id : 'nodeId' , properties : { 'cm:lockType' : 'WRITE_LOCK' } } } , getValue ( key ) { return key ; } } } ; fixture . detectChanges ( ) ; expect ( fixture . debugElement . nativeElement . querySelector ( 'aca-locked-by' ) ) . not . toBe ( null ) ; } ) ; it ( 'should call parent component onClick method' , ( ) => { const event = new MouseEvent ( 'click' ) ; spyOn ( component , 'onClick' ) ; component . onLinkClick ( event ) ; expect ( component . onClick ) . toHaveBeenCalled ( ) ; } ) ; it ( 'should prevent event propagation' , ( ) => { const event = new MouseEvent ( 'click' ) ; spyOn ( event , 'stopPropagation' ) ; component . onLinkClick ( event ) ; expect ( event . stopPropagation ) . toHaveBeenCalled ( ) ; } ) ; } ) ;