Skip to content

Commit

Permalink
[ACS-5611] Add custom metadata panels unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalKinas committed Oct 6, 2023
1 parent e4b6991 commit 8dbf010
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import { AppState, EditOfflineAction, SetInfoDrawerMetadataAspectAction } from '
import { By } from '@angular/platform-browser';
import { AppExtensionService, NodePermissionService } from '@alfresco/aca-shared';
import { Actions } from '@ngrx/effects';
import { Subject } from 'rxjs';
import { of, Subject } from 'rxjs';
import { ContentActionType } from '@alfresco/adf-extensions';

describe('MetadataTabComponent', () => {
let fixture: ComponentFixture<MetadataTabComponent>;
Expand All @@ -42,6 +43,7 @@ describe('MetadataTabComponent', () => {
let extensions: AppExtensionService;
let nodePermissionService: NodePermissionService;
let actions$: Subject<EditOfflineAction>;
let appExtensionService: AppExtensionService;

const presets = {
default: {
Expand All @@ -61,6 +63,7 @@ describe('MetadataTabComponent', () => {
]
});
nodePermissionService = TestBed.inject(NodePermissionService);
appExtensionService = TestBed.inject(AppExtensionService);
spyOn(nodePermissionService, 'check').and.callFake((source: Node, permissions: string[]) => {
return permissions.some((permission) => source.allowableOperations.includes(permission));
});
Expand Down Expand Up @@ -270,4 +273,19 @@ describe('MetadataTabComponent', () => {
expect(initialState.componentInstance.displayAspect).toBe('EXIF');
});
});

describe('Custom metadata panels', () => {
it('should get custom metadata panels', (done) => {
spyOn(appExtensionService, 'getCustomMetadataPanels').and.returnValue(
of([{ id: 'test', type: ContentActionType.custom, title: 'testTitle', component: 'test-id' }])
);
const localComponent = TestBed.createComponent(MetadataTabComponent);
localComponent.componentInstance.customPanels.subscribe((panels) => {
expect(panels.length).toBe(1);
expect(panels[0].title).toEqual('testTitle');
expect(panels[0].component).toEqual('test-id');
done();
});
});
});
});
56 changes: 56 additions & 0 deletions projects/aca-shared/src/lib/services/app.extension.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1736,4 +1736,60 @@ describe('AppExtensionService', () => {
done();
});
});

it('should get custom metadata panels from config', (done) => {
extensions.setEvaluators({
'action.enabled': () => true
});

applyConfig({
$id: 'test',
$name: 'test',
$version: '1.0.0',
$license: 'MIT',
$vendor: 'Good company',
$runtime: '1.5.0',
features: {
customMetadataPanels: [
{
id: 'panel1-id',
title: 'testTitle',
component: 'testComponent1',
rules: {
visible: 'action.enabled'
}
},
{
id: 'panel2-id',
title: 'testTitle2',
component: 'testComponent2',
rules: {
visible: 'action.enabled'
}
}
]
}
});

const node: NodeEntry = {
entry: {
id: 'testId',
name: 'testName',
nodeType: 'test',
isFile: true,
isFolder: false,
modifiedAt: undefined,
createdAt: undefined,
modifiedByUser: undefined,
createdByUser: undefined
}
};

service.getCustomMetadataPanels(node).subscribe((panels) => {
expect(panels.length).toBe(2);
expect(panels[0].id).toEqual('panel1-id');
expect(panels[1].id).toEqual('panel2-id');
done();
});
});
});

0 comments on commit 8dbf010

Please sign in to comment.