import { TestBed , ComponentFixture } from '@angular/core/testing' ; import { NO_ERRORS_SCHEMA } from '@angular/core' ; import { NodeFavoriteDirective , DataTableComponent , AppConfigModule } from '@alfresco/adf-core' ; import { CustomResourcesService , DocumentListComponent } from '@alfresco/adf-content-services' ; import { RecentFilesComponent } from './recent-files.component' ; import { AppTestingModule } from '../../testing/app-testing.module' ; import { Router } from '@angular/router' ; import { NodePaging , SearchApi } from '@alfresco/js-api' ; import { of } from 'rxjs' ; describe ( 'RecentFilesComponent' , ( ) => { let fixture ; let component ; beforeEach ( async ( ) => { const searchApi = jasmine . createSpyObj ( 'SearchApi' , [ 'search' ] ) ; const testBed = TestBed . configureTestingModule ( { imports : [ AppTestingModule , AppConfigModule ] , declarations : [ DataTableComponent , NodeFavoriteDirective , DocumentListComponent , RecentFilesComponent ] , providers : [ { provide : SearchApi , useValue : searchApi } , { provide : Router , useValue : { url : 'recent-files' } } ] , schemas : [ NO_ERRORS_SCHEMA ] } ) ; await testBed . compileComponents ( ) ; const customResourcesService = TestBed . inject ( CustomResourcesService ) ; const page = { list : { entries : [ { entry : { id : '1' , name : 'node1' , nodeType : 'cm:file' , isFile : true , isFolder : false , createdAt : null , modifiedAt : null , modifiedByUser : null , createdByUser : null } } , { entry : { id : '2' , name : 'node2' , nodeType : 'cm:file' , isFile : true , isFolder : false , createdAt : null , modifiedAt : null , modifiedByUser : null , createdByUser : null } } ] , pagination : { count : 2 , totalItems : 2 } } } ; spyOn ( customResourcesService , 'getRecentFiles' ) . and . returnValue ( of ( page ) ) ; fixture = TestBed . createComponent ( RecentFilesComponent ) ; component = fixture . componentInstance ; } ) ; it ( 'should call showPreview method' , ( ) => { const node = { entry : { } } ; spyOn ( component , 'showPreview' ) ; fixture . detectChanges ( ) ; component . onNodeDoubleClick ( node ) ; expect ( component . showPreview ) . toHaveBeenCalledWith ( node , { location : 'recent-files' } ) ; } ) ; } ) ;