mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-5015] DocumentList - favorites properties (#5278)
* merge entry properties to target * fix default properties undefined value * tests
This commit is contained in:
committed by
Eugenio Romano
parent
0fb954dd11
commit
90402ac43d
@@ -0,0 +1,115 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2019 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CustomResourcesService } from './custom-resources.service';
|
||||||
|
import { PaginationModel, AlfrescoApiServiceMock, AppConfigService, LogService, AppConfigServiceMock, StorageService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
|
describe('CustomResourcesService', () => {
|
||||||
|
let customActionService: CustomResourcesService;
|
||||||
|
let alfrescoApiService: AlfrescoApiServiceMock;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
const logService = new LogService(new AppConfigServiceMock(null));
|
||||||
|
|
||||||
|
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
|
||||||
|
customActionService = new CustomResourcesService(alfrescoApiService, logService);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('loadFavorites', () => {
|
||||||
|
it('should return a list of items with default properties when target properties does not exist', (done) => {
|
||||||
|
spyOn(alfrescoApiService.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve({
|
||||||
|
list: {
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
entry: {
|
||||||
|
target: {
|
||||||
|
file: {
|
||||||
|
title: 'some-title',
|
||||||
|
description: 'some-description'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
const pagination: PaginationModel = {
|
||||||
|
maxItems: 100,
|
||||||
|
skipCount: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
customActionService.loadFavorites(pagination).subscribe((result) => {
|
||||||
|
expect(result.list.entries).toEqual([
|
||||||
|
{
|
||||||
|
entry: {
|
||||||
|
title: 'some-title',
|
||||||
|
description: 'some-description',
|
||||||
|
properties: {
|
||||||
|
'cm:title': 'some-title',
|
||||||
|
'cm:description': 'some-description'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as any
|
||||||
|
]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a list of items with merged properties when target properties exist', (done) => {
|
||||||
|
spyOn(alfrescoApiService.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve({
|
||||||
|
list: {
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
entry: {
|
||||||
|
properties: {
|
||||||
|
'cm:property': 'some-property'
|
||||||
|
},
|
||||||
|
target: {
|
||||||
|
file: {
|
||||||
|
title: 'some-title',
|
||||||
|
description: 'some-description'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
const pagination: PaginationModel = {
|
||||||
|
maxItems: 100,
|
||||||
|
skipCount: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
customActionService.loadFavorites(pagination).subscribe((result) => {
|
||||||
|
expect(result.list.entries).toEqual([
|
||||||
|
{
|
||||||
|
entry: {
|
||||||
|
title: 'some-title',
|
||||||
|
description: 'some-description',
|
||||||
|
properties: {
|
||||||
|
'cm:title': 'some-title',
|
||||||
|
'cm:description': 'some-description',
|
||||||
|
'cm:property': 'some-property'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as any
|
||||||
|
]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -150,15 +150,19 @@ export class CustomResourcesService {
|
|||||||
const page: FavoritePaging = {
|
const page: FavoritePaging = {
|
||||||
list: {
|
list: {
|
||||||
entries: result.list.entries
|
entries: result.list.entries
|
||||||
.map(({ entry: { target } }: any) => ({
|
|
||||||
entry: target.file || target.folder
|
|
||||||
}))
|
|
||||||
.map(({ entry }: any) => {
|
.map(({ entry }: any) => {
|
||||||
entry.properties = {
|
const target = entry.target.file || entry.target.folder;
|
||||||
'cm:title': entry.title,
|
target.properties = {
|
||||||
'cm:description': entry.description
|
...(target.properties || {
|
||||||
};
|
'cm:title': entry.title || target.title,
|
||||||
return { entry };
|
'cm:description': entry.description || target.description
|
||||||
|
}),
|
||||||
|
...(entry.properties || {})
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
entry: target
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
pagination: result.list.pagination
|
pagination: result.list.pagination
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user