import { MetadataTabComponent } from './metadata-tab.component' ; import { Node } from '@alfresco/js-api' ; import { ComponentFixture , TestBed } from '@angular/core/testing' ; import { AppTestingModule } from '../../../testing/app-testing.module' ; import { AppConfigService , setupTestBed , CoreModule } from '@alfresco/adf-core' ; import { ContentMetadataModule } from '@alfresco/adf-content-services' ; import { Store } from '@ngrx/store' ; import { SetInfoDrawerMetadataAspectAction , AppState } from '@alfresco/aca-shared/store' ; import { By } from '@angular/platform-browser' ; import { AppExtensionService } from '@alfresco/aca-shared' ; describe ( 'MetadataTabComponent' , ( ) => { let fixture ; let component ; let store ; let appConfig ; let extensions ; const presets = { default : { includeAll : true } , custom : [ ] } ; setupTestBed ( { imports : [ CoreModule , AppTestingModule , ContentMetadataModule ] , declarations : [ MetadataTabComponent ] } ) ; afterEach ( ( ) => { fixture . destroy ( ) ; } ) ; describe ( 'content-metadata configuration' , ( ) => { beforeEach ( ( ) => { appConfig = TestBed . inject ( AppConfigService ) ; extensions = TestBed . inject ( AppExtensionService ) ; appConfig . config [ 'content-metadata' ] = { presets } ; } ) ; it ( 'should remain unchanged when metadata extension is missing' , ( ) => { extensions . contentMetadata = null ; fixture = TestBed . createComponent ( MetadataTabComponent ) ; expect ( appConfig . config [ 'content-metadata' ] . presets ) . toEqual ( presets ) ; } ) ; it ( 'should be overwritten by the one from extension' , ( ) => { extensions . contentMetadata = { presets : [ { 'new config' : true } ] } ; fixture = TestBed . createComponent ( MetadataTabComponent ) ; expect ( appConfig . config [ 'content-metadata' ] . presets ) . not . toEqual ( presets ) ; expect ( appConfig . config [ 'content-metadata' ] . presets ) . toEqual ( extensions . contentMetadata . presets ) ; } ) ; } ) ; describe ( 'canUpdateNode()' , ( ) => { beforeEach ( ( ) => { fixture = TestBed . createComponent ( MetadataTabComponent ) ; component = fixture . componentInstance ; } ) ; it ( 'should return true if node is not locked and has update permission' , ( ) => { const node = { isLocked : false , allowableOperations : [ 'update' ] } as Node ; component . node = node ; expect ( component . canUpdateNode ) . toBe ( true ) ; } ) ; it ( 'should return false if node is locked' , ( ) => { const node = { isLocked : true , allowableOperations : [ 'update' ] } as Node ; component . node = node ; expect ( component . canUpdateNode ) . toBe ( false ) ; } ) ; it ( 'should return false if node has no update permission' , ( ) => { const node = { isLocked : false , allowableOperations : [ 'other' ] } as Node ; component . node = node ; expect ( component . canUpdateNode ) . toBe ( false ) ; } ) ; it ( 'should return false if node has read only property' , ( ) => { const node = { isLocked : false , allowableOperations : [ 'update' ] , properties : { 'cm:lockType' : 'WRITE_LOCK' } } as Node ; component . node = node ; expect ( component . canUpdateNode ) . toBe ( false ) ; } ) ; } ) ; describe ( 'displayAspect' , ( ) => { beforeEach ( ( ) => { fixture = TestBed . createComponent ( MetadataTabComponent ) ; store = TestBed . inject ( Store ) ; component = fixture . componentInstance ; } ) ; it ( 'show pass empty when store is in initial state' , ( ) => { const initialState = fixture . debugElement . query ( By . css ( 'adf-content-metadata-card' ) ) ; expect ( initialState . componentInstance . displayAspect ) . toBeFalsy ( ) ; } ) ; it ( 'should update the exif if store got updated' , ( ) => { store . dispatch ( new SetInfoDrawerMetadataAspectAction ( 'EXIF' ) ) ; component . displayAspect$ . subscribe ( ( aspect ) => { expect ( aspect ) . toBe ( 'EXIF' ) ; } ) ; fixture . detectChanges ( ) ; const initialState = fixture . debugElement . query ( By . css ( 'adf-content-metadata-card' ) ) ; expect ( initialState . componentInstance . displayAspect ) . toBe ( 'EXIF' ) ; } ) ; } ) ; } ) ;