From 90402ac43d5160b1d6b79d2cf114235f85eb2137 Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Tue, 26 Nov 2019 11:53:35 +0200 Subject: [PATCH] [ADF-5015] DocumentList - favorites properties (#5278) * merge entry properties to target * fix default properties undefined value * tests --- .../services/custom-resources.service.spec.ts | 115 ++++++++++++++++++ .../services/custom-resources.service.ts | 20 +-- 2 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 lib/content-services/src/lib/document-list/services/custom-resources.service.spec.ts diff --git a/lib/content-services/src/lib/document-list/services/custom-resources.service.spec.ts b/lib/content-services/src/lib/document-list/services/custom-resources.service.spec.ts new file mode 100644 index 0000000000..5532b5e78d --- /dev/null +++ b/lib/content-services/src/lib/document-list/services/custom-resources.service.spec.ts @@ -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(); + }); + }); + }); +}); diff --git a/lib/content-services/src/lib/document-list/services/custom-resources.service.ts b/lib/content-services/src/lib/document-list/services/custom-resources.service.ts index 0f90e7b754..ad9ae9c73e 100644 --- a/lib/content-services/src/lib/document-list/services/custom-resources.service.ts +++ b/lib/content-services/src/lib/document-list/services/custom-resources.service.ts @@ -150,15 +150,19 @@ export class CustomResourcesService { const page: FavoritePaging = { list: { entries: result.list.entries - .map(({ entry: { target } }: any) => ({ - entry: target.file || target.folder - })) .map(({ entry }: any) => { - entry.properties = { - 'cm:title': entry.title, - 'cm:description': entry.description - }; - return { entry }; + const target = entry.target.file || entry.target.folder; + target.properties = { + ...(target.properties || { + 'cm:title': entry.title || target.title, + 'cm:description': entry.description || target.description + }), + ...(entry.properties || {}) + }; + + return { + entry: target + }; }), pagination: result.list.pagination }