mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
[MNT-22298] - Added check for ACS version (#6845)
* [MNT-22298] - Added check for ACS version * [MNT-22298] - fixed lint problem
This commit is contained in:
parent
6c295b9f1c
commit
b4fa19358c
@ -15,19 +15,64 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Node } from '@alfresco/js-api';
|
|
||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { ContentMetadataService } from './content-metadata.service';
|
|
||||||
import { of } from 'rxjs';
|
|
||||||
import { ContentTypePropertiesService } from './content-type-property.service';
|
import { ContentTypePropertiesService } from './content-type-property.service';
|
||||||
import { setupTestBed } from 'core';
|
import { CardViewItem, CardViewSelectItemModel, CardViewTextItemModel, setupTestBed, VersionCompatibilityService } from 'core';
|
||||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { ContentTypeService } from '../../content-type';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
|
||||||
describe('ContentMetaDataService', () => {
|
describe('ContentTypePropertyService', () => {
|
||||||
|
|
||||||
let service: ContentMetadataService;
|
let service: ContentTypePropertiesService;
|
||||||
let contentPropertyService: ContentTypePropertiesService;
|
let versionCompatibilityService: VersionCompatibilityService;
|
||||||
|
let contentTypeService: ContentTypeService;
|
||||||
|
|
||||||
|
const mockContent: any = { 'entry':
|
||||||
|
{ 'associations': [],
|
||||||
|
'isArchive': true,
|
||||||
|
'includedInSupertypeQuery': true,
|
||||||
|
'description': 'Base Content Object',
|
||||||
|
'isContainer': false,
|
||||||
|
'id': 'fk:nodeType',
|
||||||
|
'title': 'Content',
|
||||||
|
'properties': [{ 'id': 'cm:name', 'title': 'Name', 'description': 'Name', 'dataType': 'd:text', 'isMultiValued': false, 'isMandatory': true, 'isMandatoryEnforced': true, 'isProtected': false}],
|
||||||
|
'parentId': 'cm:cmobject' } };
|
||||||
|
const mockSelectOptions = {
|
||||||
|
'list':
|
||||||
|
{
|
||||||
|
'pagination': { 'count': 1, 'hasMoreItems': false, 'totalItems': 1, 'skipCount': 0, 'maxItems': 100 },
|
||||||
|
'entries': [
|
||||||
|
{
|
||||||
|
'entry': {
|
||||||
|
'isArchive': true,
|
||||||
|
'includedInSupertypeQuery': true,
|
||||||
|
'isContainer': false,
|
||||||
|
'model': {
|
||||||
|
'id': 'e2e:test',
|
||||||
|
'author': 'E2e Automation User',
|
||||||
|
'description': 'Custom type e2e model',
|
||||||
|
'namespaceUri': 'http://www.customModel.com/whatever',
|
||||||
|
'namespacePrefix': 'e2e'
|
||||||
|
},
|
||||||
|
'id': 'e2e:test',
|
||||||
|
'title': 'Test type',
|
||||||
|
'properties': [{
|
||||||
|
'id': 'cm:name',
|
||||||
|
'title': 'Name',
|
||||||
|
'description': 'Name',
|
||||||
|
'dataType': 'd:text',
|
||||||
|
'isMultiValued': false,
|
||||||
|
'isMandatory': true,
|
||||||
|
'isMandatoryEnforced': true,
|
||||||
|
'isProtected': false
|
||||||
|
}],
|
||||||
|
'parentId': 'cm:content'
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [
|
imports: [
|
||||||
@ -37,50 +82,37 @@ describe('ContentMetaDataService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service = TestBed.inject(ContentMetadataService);
|
service = TestBed.inject(ContentTypePropertiesService);
|
||||||
contentPropertyService = TestBed.inject(ContentTypePropertiesService);
|
versionCompatibilityService = TestBed.inject(VersionCompatibilityService);
|
||||||
|
contentTypeService = TestBed.inject(ContentTypeService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return all the properties of the node', () => {
|
it('should return a card text item for ACS version below 7', (done) => {
|
||||||
const fakeNode: Node = <Node> {
|
spyOn(versionCompatibilityService, 'isVersionSupported').and.returnValue(false);
|
||||||
name: 'Node',
|
service.getContentTypeCardItem('fk:nodeType').subscribe((items: CardViewItem[]) => {
|
||||||
id: 'fake-id',
|
expect(items.length).toBe(1);
|
||||||
isFile: true,
|
expect(items[0] instanceof CardViewTextItemModel).toBeTruthy();
|
||||||
aspectNames: ['exif:exif'],
|
expect(items[0].label).toBe('CORE.METADATA.BASIC.CONTENT_TYPE');
|
||||||
createdByUser: {displayName: 'test-user'},
|
expect(items[0].value).toBe('fk:nodeType');
|
||||||
modifiedByUser: {displayName: 'test-user-modified'}
|
expect(items[0].key).toBe('nodeType');
|
||||||
};
|
expect(items[0].editable).toBeFalsy();
|
||||||
|
done();
|
||||||
service.getBasicProperties(fakeNode).subscribe(
|
});
|
||||||
(res) => {
|
|
||||||
expect(res.length).toEqual(10);
|
|
||||||
expect(res[0].value).toEqual('Node');
|
|
||||||
expect(res[1].value).toBeFalsy();
|
|
||||||
expect(res[2].value).toBe('test-user');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the content type property', () => {
|
it('should return a card select item for ACS version 7 and above', (done) => {
|
||||||
spyOn(contentPropertyService, 'getContentTypeCardItem').and.returnValue(of({ label: 'hello i am a weird content type'}));
|
spyOn(versionCompatibilityService, 'isVersionSupported').and.returnValue(true);
|
||||||
|
spyOn(contentTypeService, 'getContentTypeByPrefix').and.returnValue(of(mockContent));
|
||||||
service.getContentTypeProperty('fn:fakenode').subscribe(
|
spyOn(contentTypeService, 'getContentTypeChildren').and.returnValue(of(mockSelectOptions));
|
||||||
(res: any) => {
|
service.getContentTypeCardItem('fk:nodeType').subscribe((items: CardViewItem[]) => {
|
||||||
expect(res).toBeDefined();
|
expect(items.length).toBe(1);
|
||||||
expect(res).not.toBeNull();
|
expect(items[0] instanceof CardViewSelectItemModel).toBeTruthy();
|
||||||
expect(res.label).toBe('hello i am a weird content type');
|
expect(items[0].label).toBe('CORE.METADATA.BASIC.CONTENT_TYPE');
|
||||||
}
|
expect(items[0].value).toBe('fk:nodeType');
|
||||||
);
|
expect(items[0].key).toBe('nodeType');
|
||||||
|
expect(items[0].editable).toBeTruthy();
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should trigger the opening of the content type dialog', () => {
|
|
||||||
spyOn(contentPropertyService, 'openContentTypeDialogConfirm').and.returnValue(of());
|
|
||||||
|
|
||||||
service.openConfirmDialog('fn:fakenode').subscribe(
|
|
||||||
() => {
|
|
||||||
expect(contentPropertyService.openContentTypeDialogConfirm).toHaveBeenCalledWith('fn:fakenode');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { CardViewItem, CardViewSelectItemModel, CardViewSelectItemOption } from '@alfresco/adf-core';
|
import { CardViewItem, CardViewSelectItemModel, CardViewSelectItemOption, CardViewTextItemModel, VersionCompatibilityService } from '@alfresco/adf-core';
|
||||||
import { Observable, of, Subject, zip } from 'rxjs';
|
import { Observable, of, Subject, zip } from 'rxjs';
|
||||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||||
import { ContentTypeDialogComponent } from '../../content-type/content-type-dialog.component';
|
import { ContentTypeDialogComponent } from '../../content-type/content-type-dialog.component';
|
||||||
@ -30,10 +30,13 @@ import { TypeEntry } from '@alfresco/js-api';
|
|||||||
})
|
})
|
||||||
export class ContentTypePropertiesService {
|
export class ContentTypePropertiesService {
|
||||||
|
|
||||||
constructor(private contentTypeService: ContentTypeService, private dialog: MatDialog) {
|
constructor(private contentTypeService: ContentTypeService,
|
||||||
|
private dialog: MatDialog,
|
||||||
|
private versionCompatibilityService: VersionCompatibilityService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
getContentTypeCardItem(nodeType: string): Observable<CardViewItem[]> {
|
getContentTypeCardItem(nodeType: string): Observable<CardViewItem[]> {
|
||||||
|
if (this.versionCompatibilityService.isVersionSupported('7')) {
|
||||||
return this.contentTypeService.getContentTypeByPrefix(nodeType).
|
return this.contentTypeService.getContentTypeByPrefix(nodeType).
|
||||||
pipe(
|
pipe(
|
||||||
map((contentType) => {
|
map((contentType) => {
|
||||||
@ -41,6 +44,20 @@ export class ContentTypePropertiesService {
|
|||||||
const contentTypeCard = this.buildContentTypeSelectCardModel(contentType.entry.id, contentTypesOptions$);
|
const contentTypeCard = this.buildContentTypeSelectCardModel(contentType.entry.id, contentTypesOptions$);
|
||||||
return [contentTypeCard];
|
return [contentTypeCard];
|
||||||
}));
|
}));
|
||||||
|
} else {
|
||||||
|
return of([this.buildContentTypeTextCardModel(nodeType)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildContentTypeTextCardModel(currentValue: string): CardViewTextItemModel {
|
||||||
|
const contentTypeCard = new CardViewTextItemModel({
|
||||||
|
label: 'CORE.METADATA.BASIC.CONTENT_TYPE',
|
||||||
|
value: currentValue,
|
||||||
|
key: 'nodeType',
|
||||||
|
editable: false
|
||||||
|
});
|
||||||
|
|
||||||
|
return contentTypeCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildContentTypeSelectCardModel(currentValue: string, options$: Observable<CardViewSelectItemOption<string>[]>): CardViewSelectItemModel<string> {
|
private buildContentTypeSelectCardModel(currentValue: string, options$: Observable<CardViewSelectItemOption<string>[]>): CardViewSelectItemModel<string> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user