From 76e2870c66bc79f5fa730c79e1ecf2d6e23db5c1 Mon Sep 17 00:00:00 2001 From: MichalKinas <113341662+MichalKinas@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:29:42 +0200 Subject: [PATCH] Adjust ADF to latest JS-API version (#8882) * Bump js-api version * Fix imports * Fix content-services unit tests * Fix process-services unit tests * [ci:force] Trigger CI * Fix code smells * Fix orderBy param * Fix code smells * Fix failing unit tests * Bump js-api version and align with new changes * Remove dangling coma * Fix delete return type * Add correct date format in task filters e2es * Fix typing in task filter sorting * Fix activiti content api import * Add null check for has avatar * Make User class instead of type * Fix user type in comment model * Fix sonar cloud issue * Type fixes * Update js-api version --- .../directives/node-delete.directive.md | 4 +- .../directives/node-restore.directive.md | 2 +- .../tasks/custom-tasks-filters.e2e.ts | 4 +- .../task-attachment-list-action-menu.e2e.ts | 6 +- .../tasks/task-filters-sorting.e2e.ts | 16 +- lib/cli/package.json | 2 +- lib/content-services/package.json | 2 +- .../lib/common/mocks/ecm-user.service.mock.ts | 4 +- .../common/services/content.service.spec.ts | 6 +- .../common/services/upload.service.spec.ts | 10 +- .../src/lib/common/services/upload.service.ts | 4 +- .../content-node-dialog.service.spec.ts | 4 +- ...de-selector-panel.component-search.spec.ts | 6 +- ...tent-node-selector-panel.component.spec.ts | 30 ++- .../content-node-selector.component.spec.ts | 13 +- .../library-membership.directive.spec.ts | 2 +- .../library-membership.directive.ts | 4 +- .../lib/directives/node-delete.directive.ts | 8 +- .../document-list.component.spec.ts | 10 +- .../services/custom-resources.service.spec.ts | 76 +++--- .../restore-message-model.interface.ts | 4 +- .../lib/mock/document-list.component.mock.ts | 20 +- .../src/lib/mock/search.component.mock.ts | 42 ++-- .../lib/mock/sites-dropdown.component.mock.ts | 236 +++++++++--------- .../node-comments/mocks/node-comments.mock.ts | 30 +-- .../services/node-comments.service.ts | 5 +- .../add-permission-panel.component.ts | 30 +-- .../user-icon-column.component.ts | 10 +- .../lib/search/mocks/search.service.mock.ts | 24 +- .../src/lib/search/services/search.service.ts | 4 +- ...rols-groups-marks-security.service.spec.ts | 123 +++------ ...-controls-groups-marks-security.service.ts | 16 +- .../site-dropdown/sites-dropdown.component.ts | 10 +- .../src/lib/tag/services/tag.service.spec.ts | 80 +++--- .../src/lib/tag/services/tag.service.ts | 4 +- .../services/tree-view.service.spec.ts | 37 ++- .../upload-button.component.spec.ts | 38 +-- .../version-list.component.spec.ts | 124 ++++----- .../version-manager.component.spec.ts | 29 +-- .../alfresco-viewer.component.spec.ts | 145 ++++------- lib/core/package.json | 2 +- .../comment-list/mocks/comment-list.mock.ts | 17 +- .../comments/mocks/comments.service.mock.ts | 96 +------ .../mocks/comments.service.stories.mock.ts | 77 +----- lib/core/src/lib/models/comment.model.ts | 6 +- lib/core/src/lib/models/general-user.model.ts | 21 +- lib/extensions/package.json | 2 +- lib/process-services-cloud/package.json | 2 +- .../lib/form/services/form-cloud.service.ts | 2 +- .../services/process-cloud-content.service.ts | 2 +- lib/process-services/package.json | 2 +- .../services/activiti-alfresco.service.ts | 2 +- ...ttach-file-widget-dialog.component.spec.ts | 4 +- .../form/widgets/upload/upload.widget.spec.ts | 2 +- .../lib/mock/process/process-comments.mock.ts | 8 +- .../src/lib/mock/task/task-details.mock.ts | 4 +- .../services/comment-process.service.ts | 8 +- .../models/filter-process.model.ts | 4 +- .../services/task-comments.service.ts | 4 +- .../components/task-details.component.spec.ts | 9 +- lib/testing/package.json | 2 +- .../content-services/actions/model.actions.ts | 2 +- package-lock.json | 8 +- package.json | 2 +- 64 files changed, 628 insertions(+), 884 deletions(-) diff --git a/docs/content-services/directives/node-delete.directive.md b/docs/content-services/directives/node-delete.directive.md index 3da6f3af84..187eb7e3e7 100644 --- a/docs/content-services/directives/node-delete.directive.md +++ b/docs/content-services/directives/node-delete.directive.md @@ -31,7 +31,7 @@ Deletes multiple files and folders. | Name | Type | Default value | Description | | ---- | ---- | ------------- | ----------- | | permanent | `boolean` | false | If true then the nodes are deleted immediately rather than being put in the trash | -| selection | [`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md)`[] \| DeletedNodeEntity[]` | | Array of nodes to delete. | +| selection | [`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md)`[] \| DeletedNodeEntry[]` | | Array of nodes to delete. | ### Events @@ -41,7 +41,7 @@ Deletes multiple files and folders. ## Details -Note that if a target item is already in the trashcan (and is therefore a `DeletedNodeEntity`) then +Note that if a target item is already in the trashcan (and is therefore a `DeletedNodeEntry`) then this action will delete the file permanently. ## See also diff --git a/docs/content-services/directives/node-restore.directive.md b/docs/content-services/directives/node-restore.directive.md index 5460fa448a..64d3e0b996 100644 --- a/docs/content-services/directives/node-restore.directive.md +++ b/docs/content-services/directives/node-restore.directive.md @@ -38,7 +38,7 @@ Restores deleted nodes to their original location. this.documentList.reload(); } - navigateLocation(path: PathInfoEntity) { + navigateLocation(path: PathInfo) { const parent = path.elements[path.elements.length - 1]; this.router.navigate(['files/', parent.id]); } diff --git a/e2e/process-services/tasks/custom-tasks-filters.e2e.ts b/e2e/process-services/tasks/custom-tasks-filters.e2e.ts index 1c49b10783..0ef6bfcad0 100644 --- a/e2e/process-services/tasks/custom-tasks-filters.e2e.ts +++ b/e2e/process-services/tasks/custom-tasks-filters.e2e.ts @@ -108,14 +108,14 @@ describe('Start Task - Custom App', () => { for (let i = 0; i < 3; i++) { completedTasks[i] = await tasksApi.createNewTask(new TaskRepresentation({ name: completedTasksName[i], - dueDate: DateUtil.formatDate('YYYY-MM-DDTHH:mm:ss.SSSZ', new Date(), i + 2) + dueDate: new Date(DateUtil.formatDate('YYYY-MM-DDTHH:mm:ss.SSSZ', new Date(), i + 2)) })); await taskActionsApi.completeTask(completedTasks[i].id); } taskWithDueDate = await tasksApi.createNewTask(new TaskRepresentation({ name: paginationTasksName[0], - dueDate: currentDateStandardFormat + dueDate: new Date(currentDateStandardFormat) })); await loginPage.login(processUserModel.username, processUserModel.password); diff --git a/e2e/process-services/tasks/task-attachment-list-action-menu.e2e.ts b/e2e/process-services/tasks/task-attachment-list-action-menu.e2e.ts index f9d053da53..076934202d 100644 --- a/e2e/process-services/tasks/task-attachment-list-action-menu.e2e.ts +++ b/e2e/process-services/tasks/task-attachment-list-action-menu.e2e.ts @@ -30,8 +30,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { FileModel } from '../../models/ACS/file.model'; import CONSTANTS = require('../../util/constants'); -import { Activiti, RelatedContentRepresentation } from '@alfresco/js-api'; -import ContentApi = Activiti.ContentApi; +import { ActivitiContentApi, RelatedContentRepresentation } from '@alfresco/js-api'; describe('Attachment list action menu for tasks', () => { const app = browser.params.resources.Files.SIMPLE_APP_WITH_USER_FORM; @@ -46,8 +45,7 @@ describe('Attachment list action menu for tasks', () => { const usersActions = new UsersActions(apiService); const modelsActions = new ModelsActions(apiService); const taskUtil = new TaskUtil(apiService); - const contentApi = new ContentApi(); - contentApi.init(apiService.getInstance()); + const contentApi = new ActivitiContentApi(apiService.getInstance()); const pngFile = new FileModel({ location: browser.params.resources.Files.ADF_DOCUMENTS.PNG.file_location, diff --git a/e2e/process-services/tasks/task-filters-sorting.e2e.ts b/e2e/process-services/tasks/task-filters-sorting.e2e.ts index 446240b9de..1577ed69bf 100644 --- a/e2e/process-services/tasks/task-filters-sorting.e2e.ts +++ b/e2e/process-services/tasks/task-filters-sorting.e2e.ts @@ -91,7 +91,7 @@ describe('Task Filters Sorting', () => { appId, name: 'Newest first', icon: 'glyphicon-filter', - filter: { sort: 'created-desc', state: 'completed', assignment: 'involved' } + filter: { sort: 'created-desc', state: 'completed' } }); await userFiltersUtil.createUserTaskFilter(newFilter); @@ -108,7 +108,7 @@ describe('Task Filters Sorting', () => { appId, name: 'Newest last', icon: 'glyphicon-filter', - filter: { sort: 'created-asc', state: 'completed', assignment: 'involved' } + filter: { sort: 'created-asc', state: 'completed' } }); await userFiltersUtil.createUserTaskFilter(newFilter); @@ -125,7 +125,7 @@ describe('Task Filters Sorting', () => { appId, name: 'Due first', icon: 'glyphicon-filter', - filter: { sort: 'due-desc', state: 'completed', assignment: 'involved' } + filter: { sort: 'due-desc', state: 'completed' } }); await userFiltersUtil.createUserTaskFilter(newFilter); @@ -142,7 +142,7 @@ describe('Task Filters Sorting', () => { appId, name: 'Due last', icon: 'glyphicon-filter', - filter: { sort: 'due-asc', state: 'completed', assignment: 'involved' } + filter: { sort: 'due-asc', state: 'completed' } }); await userFiltersUtil.createUserTaskFilter(newFilter); @@ -159,7 +159,7 @@ describe('Task Filters Sorting', () => { appId, name: 'Newest first Open', icon: 'glyphicon-filter', - filter: { sort: 'created-desc', state: 'open', assignment: 'involved' } + filter: { sort: 'created-desc', state: 'open' } }); await userFiltersUtil.createUserTaskFilter(newFilter); @@ -176,7 +176,7 @@ describe('Task Filters Sorting', () => { appId, name: 'Newest last Open', icon: 'glyphicon-filter', - filter: { sort: 'created-asc', state: 'open', assignment: 'involved' } + filter: { sort: 'created-asc', state: 'open' } }); await userFiltersUtil.createUserTaskFilter(newFilter); @@ -193,7 +193,7 @@ describe('Task Filters Sorting', () => { appId, name: 'Due first Open', icon: 'glyphicon-filter', - filter: { sort: 'due-desc', state: 'open', assignment: 'involved' } + filter: { sort: 'due-desc', state: 'open' } }); await userFiltersUtil.createUserTaskFilter(newFilter); @@ -210,7 +210,7 @@ describe('Task Filters Sorting', () => { appId, name: 'Due last Open', icon: 'glyphicon-filter', - filter: { sort: 'due-asc', state: 'open', assignment: 'involved' } + filter: { sort: 'due-asc', state: 'open' } }); await userFiltersUtil.createUserTaskFilter(newFilter); diff --git a/lib/cli/package.json b/lib/cli/package.json index e0f62adb2c..e2a78c973d 100644 --- a/lib/cli/package.json +++ b/lib/cli/package.json @@ -20,7 +20,7 @@ "dist": "rm -rf ../../dist/libs/cli && npm run build && cp -R ./bin ../../dist/libs/cli && cp -R ./resources ../../dist/libs/cli && cp -R ./templates ../../dist/libs/cli && cp ./package.json ../../dist/libs/cli" }, "dependencies": { - "@alfresco/js-api": ">=6.3.0-1108", + "@alfresco/js-api": ">=6.3.0-1271", "commander": "^6.2.1", "ejs": "^3.1.9", "license-checker": "^25.0.1", diff --git a/lib/content-services/package.json b/lib/content-services/package.json index 4b370dd4bc..c6b57a2b39 100644 --- a/lib/content-services/package.json +++ b/lib/content-services/package.json @@ -21,7 +21,7 @@ "@angular/platform-browser": ">=14.1.3", "@angular/platform-browser-dynamic": ">=14.1.3", "@angular/router": ">=14.1.3", - "@alfresco/js-api": ">=6.3.0-1108", + "@alfresco/js-api": ">=6.3.0-1271", "@ngx-translate/core": ">=14.0.0", "moment": ">=2.22.2", "@alfresco/adf-core": ">=6.2.0" diff --git a/lib/content-services/src/lib/common/mocks/ecm-user.service.mock.ts b/lib/content-services/src/lib/common/mocks/ecm-user.service.mock.ts index 1ce65822e4..20d21a11a2 100644 --- a/lib/content-services/src/lib/common/mocks/ecm-user.service.mock.ts +++ b/lib/content-services/src/lib/common/mocks/ecm-user.service.mock.ts @@ -17,7 +17,7 @@ import { PersonEntry, Person, PersonPaging } from '@alfresco/js-api'; -export const fakeEcmUser = { +export const fakeEcmUser: Person = { id: 'fake-id', firstName: 'fake-ecm-first-name', lastName: 'fake-ecm-last-name', @@ -32,7 +32,7 @@ export const fakeEcmUser = { location: 'fake location', mobile: '000000000', telephone: '11111111', - statusUpdatedAt: 'fake-date', + statusUpdatedAt: new Date(), userStatus: 'active', enabled: true, emailNotificationsEnabled: true diff --git a/lib/content-services/src/lib/common/services/content.service.spec.ts b/lib/content-services/src/lib/common/services/content.service.spec.ts index f73838d4ec..c2a7dadce5 100644 --- a/lib/content-services/src/lib/common/services/content.service.spec.ts +++ b/lib/content-services/src/lib/common/services/content.service.spec.ts @@ -18,7 +18,7 @@ import { TestBed } from '@angular/core/testing'; import { ContentService } from './content.service'; import { AppConfigService, AuthenticationService, StorageService, CoreTestingModule } from '@alfresco/adf-core'; -import { Node } from '@alfresco/js-api'; +import { Node, PermissionsInfo } from '@alfresco/js-api'; import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; @@ -140,12 +140,12 @@ describe('ContentService', () => { }); it('should havePermission return true if the permissions is empty and the permission to check is Consumer', () => { - const permissionNode = new Node({ permissions: [] }); + const permissionNode = new Node({ permissions: new PermissionsInfo() }); expect(contentService.hasPermissions(permissionNode, 'Consumer', 'user1')).toBeTruthy(); }); it('should havePermission return false if the permissions is empty and the permission to check is not Consumer', () => { - const permissionNode = new Node({ permissions: [] }); + const permissionNode = new Node({ permissions: new PermissionsInfo() }); expect(contentService.hasPermissions(permissionNode, '!Consumer', 'user1')).toBeFalsy(); }); diff --git a/lib/content-services/src/lib/common/services/upload.service.spec.ts b/lib/content-services/src/lib/common/services/upload.service.spec.ts index 15893ab5a8..7d10c6fada 100644 --- a/lib/content-services/src/lib/common/services/upload.service.spec.ts +++ b/lib/content-services/src/lib/common/services/upload.service.spec.ts @@ -321,7 +321,7 @@ describe('UploadService', () => { }, undefined, undefined, - { newVersion: true }, + { newVersion: true, name: 'fake-name', nodeType: undefined }, { renditions: 'doclib', include: ['allowableOperations'], @@ -376,7 +376,7 @@ describe('UploadService', () => { }, undefined, undefined, - { newVersion: false }, + { newVersion: false, name: 'file-name', nodeType: undefined }, { include: [ 'allowableOperations' ], renditions: 'doclib', @@ -402,7 +402,7 @@ describe('UploadService', () => { }, undefined, undefined, - { newVersion: false }, + { newVersion: false, name: 'file-name', nodeType: undefined }, { include: [ 'allowableOperations' ], renditions: 'doclib', @@ -434,6 +434,8 @@ describe('UploadService', () => { '123', { newVersion: false, + name: 'fake-name', + nodeType: undefined, parentId: '123', path: 'fake-dir', secondaryChildren: [ { assocType: 'assoc-1', childId: 'child-id' }], @@ -547,7 +549,7 @@ describe('UploadService', () => { }, undefined, undefined, - { newVersion: true }, + { newVersion: true, name: 'fake-name', nodeType: undefined }, { include: ['allowableOperations'], overwrite: true, diff --git a/lib/content-services/src/lib/common/services/upload.service.ts b/lib/content-services/src/lib/common/services/upload.service.ts index 864a7bb68a..4522e13935 100644 --- a/lib/content-services/src/lib/common/services/upload.service.ts +++ b/lib/content-services/src/lib/common/services/upload.service.ts @@ -28,7 +28,7 @@ import { FileModel, FileUploadProgress, FileUploadStatus } from '../models/file. import { AppConfigService, AlfrescoApiService } from '@alfresco/adf-core'; import { filter } from 'rxjs/operators'; import { DiscoveryApiService } from '../../common/services/discovery-api.service'; -import { NodesApi, UploadApi, VersionsApi } from '@alfresco/js-api'; +import { NodeBodyCreate, NodesApi, UploadApi, VersionsApi } from '@alfresco/js-api'; const MIN_CANCELLABLE_FILE_SIZE = 1000000; const MAX_CANCELLABLE_FILE_PERCENTAGE = 50; @@ -237,7 +237,7 @@ export class UploadService { if (file.id) { return this.nodesApi.updateNodeContent(file.id, file.file as any, opts); } else { - const nodeBody = {...file.options}; + const nodeBody: NodeBodyCreate = { ...file.options, name: file.name, nodeType: file.options.nodeType }; delete nodeBody['versioningEnabled']; return this.uploadApi.uploadFile( diff --git a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts index 3bedd23dec..18800954a7 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts @@ -50,11 +50,11 @@ const fakeSiteList: SitePaging = new SitePaging({ }, entries: [ { - entry: { + entry: new Site({ id: 'FAKE', guid: 'FAKE-GUID', title: 'FAKE-SITE-TITLE' - } + }) } ] } diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component-search.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component-search.spec.ts index d4f46a848c..bd8f19fda2 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component-search.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component-search.spec.ts @@ -18,7 +18,7 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { ComponentFixture, fakeAsync, flush, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { Node, NodeEntry, NodePaging, RequestScope, ResultSetPaging, SiteEntry, SitePaging } from '@alfresco/js-api'; +import { Node, NodeEntry, NodePaging, RequestScope, ResultSetPaging, SiteEntry, SitePaging, SitePagingList } from '@alfresco/js-api'; import { of } from 'rxjs'; import { ContentNodeSelectorPanelComponent } from './content-node-selector-panel.component'; import { ContentTestingModule } from '../testing/content.testing.module'; @@ -134,13 +134,13 @@ describe('ContentNodeSelectorPanelComponent', () => { list: { pagination: {}, entries: [], - source: {} + source: new Node() } }) ) ); - spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: new SitePagingList({ entries: [] }) }))); customResourcesService = TestBed.inject(CustomResourcesService); getCorrespondingNodeIdsSpy = spyOn(customResourcesService, 'getCorrespondingNodeIds').and.callFake((id) => { diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts index 30d3879b45..e4071bf8df 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts @@ -18,7 +18,7 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { Node, NodeEntry, NodePaging, ResultSetPaging, SiteEntry, SitePaging, UserInfo } from '@alfresco/js-api'; +import { Node, NodeEntry, NodePaging, PathElement, ResultSetPaging, Site, SiteEntry, SitePaging, SitePagingList, UserInfo } from '@alfresco/js-api'; import { AppConfigService, DataRow, ThumbnailService, DataColumn } from '@alfresco/adf-core'; import { ContentService } from '../common/services/content.service'; import { UploadService } from '../common/services/upload.service'; @@ -123,7 +123,7 @@ describe('ContentNodeSelectorPanelComponent', () => { describe('Site selection', () => { beforeEach(() => { - spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: new SitePagingList({ entries: [] }) }))); component.currentFolderId = 'fake-starting-folder'; }); @@ -138,7 +138,7 @@ describe('ContentNodeSelectorPanelComponent', () => { }); it('should trigger siteChange event when a site is selected in sites-dropdown', async () => { - const fakeSiteEntry = new SiteEntry({ entry: { title: 'fake-new-site', guid: 'fake-new-site' } }); + const fakeSiteEntry = new SiteEntry({ entry: new Site({ title: 'fake-new-site', guid: 'fake-new-site' }) }); fixture.detectChanges(); await fixture.whenStable(); @@ -162,9 +162,9 @@ describe('ContentNodeSelectorPanelComponent', () => { spyOn(sitesService, 'getSites').and.returnValue( of( new SitePaging({ - list: { - entries: [{ entry: { guid: 'namek', id: 'namek' } }, { entry: { guid: 'blog', id: 'blog' } }] - } + list: new SitePagingList({ + entries: [{ entry: new Site({ guid: 'namek', id: 'namek' }) }, { entry: new Site({ guid: 'blog', id: 'blog' }) }] + }) }) ) ); @@ -262,7 +262,7 @@ describe('ContentNodeSelectorPanelComponent', () => { spyOn(documentListService, 'getFolderNode').and.returnValue(of(new NodeEntry())); spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test')); - spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: new SitePagingList({ entries: [] }) }))); component.currentFolderId = 'cat-girl-nuku-nuku'; fixture.detectChanges(); @@ -303,7 +303,7 @@ describe('ContentNodeSelectorPanelComponent', () => { searchQueryBuilderService.update(); triggerSearchResults(fakeResultSetPaging); - const chosenNode = new Node({ path: { elements: ['one'] } }); + const chosenNode = new Node({ path: { elements: [new PathElement({ name: 'one' })] } }); component.onCurrentSelection([{ entry: chosenNode }]); fixture.detectChanges(); @@ -318,7 +318,7 @@ describe('ContentNodeSelectorPanelComponent', () => { searchQueryBuilderService.update(); triggerSearchResults(fakeResultSetPaging); - const chosenNode = new Node({ path: { elements: ['fake-path'] }, isFile: false, isFolder: true }); + const chosenNode = new Node({ path: { elements: [new PathElement({ name: 'fake-path' })] }, isFile: false, isFolder: true }); component.onCurrentSelection([{ entry: chosenNode }]); fixture.detectChanges(); @@ -384,7 +384,7 @@ describe('ContentNodeSelectorPanelComponent', () => { const rows = [{}, {}] as DataRow[]; component.documentList.data = new ShareDataTableAdapter(thumbnailService, contentService, schema); spyOn(component.documentList.data, 'getRows').and.returnValue(rows); - spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: new SitePagingList({ entries: [] }) }))); }); it('should the selection become the currently navigated folder when the folder loads (Acts as destination for cases like copy action)', () => { @@ -655,7 +655,10 @@ describe('ContentNodeSelectorPanelComponent', () => { it('should return only the last uploaded node to become preselected when the selection mode is single', () => { fixture.detectChanges(); - const fakeNodes = [new NodeEntry({ id: 'fakeNode1' }), new NodeEntry({ id: 'fakeNode2' })]; + const fakeNodes = [ + new NodeEntry({ entry: new Node({ id: 'fakeNode1' }) }), + new NodeEntry({ entry: new Node({ id: 'fakeNode2' }) }) + ]; component.currentUploadBatch = fakeNodes; component.selectionMode = 'single'; @@ -664,7 +667,10 @@ describe('ContentNodeSelectorPanelComponent', () => { it('should return all the uploaded nodes to become preselected when the selection mode is multiple', () => { fixture.detectChanges(); - const fakeNodes = [new NodeEntry({ id: 'fakeNode1' }), new NodeEntry({ id: 'fakeNode2' })]; + const fakeNodes = [ + new NodeEntry({ entry: new Node({ id: 'fakeNode1' }) }), + new NodeEntry({ entry: new Node({ id: 'fakeNode2' }) }) + ]; component.currentUploadBatch = fakeNodes; component.selectionMode = 'multiple'; diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts index 2f7f1ebd8c..7a4222afeb 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts @@ -19,7 +19,7 @@ import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/materia import { CUSTOM_ELEMENTS_SCHEMA, EventEmitter } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ContentNodeSelectorComponent } from './content-node-selector.component'; -import { Node, NodeEntry, SitePaging } from '@alfresco/js-api'; +import { Node, NodeEntry, SitePaging, SitePagingList } from '@alfresco/js-api'; import { By } from '@angular/platform-browser'; import { FileModel } from '../common/models/file.model'; import { FileUploadEvent } from '../common/events/file.event'; @@ -88,7 +88,7 @@ describe('ContentNodeSelectorComponent', () => { spyOn(documentListService, 'getFolder'); spyOn(documentListService, 'getFolderNode'); - spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: new SitePagingList({ entries: [] }) }))); fixture = TestBed.createComponent(ContentNodeSelectorComponent); component = fixture.componentInstance; @@ -97,15 +97,12 @@ describe('ContentNodeSelectorComponent', () => { spyOn(contentService, 'hasAllowableOperations').and.returnValue(true); const fakeFolderNodeWithPermission = new NodeEntry({ - entry: { - allowableOperations: [ - 'create', - 'update' - ], + entry: new Node({ + allowableOperations: ['create', 'update'], isFolder: true, name: 'Folder Fake Name', nodeType: 'cm:folder' - } + }) }); const nodesApiService = TestBed.inject(NodesApiService); diff --git a/lib/content-services/src/lib/directives/library-membership.directive.spec.ts b/lib/content-services/src/lib/directives/library-membership.directive.spec.ts index dae45fe18e..dc96e8092b 100644 --- a/lib/content-services/src/lib/directives/library-membership.directive.spec.ts +++ b/lib/content-services/src/lib/directives/library-membership.directive.spec.ts @@ -113,7 +113,7 @@ describe('LibraryMembershipDirective', () => { mockSupportedVersion = false; getMembershipSpy = spyOn(directive['sitesApi'], 'getSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse })); addMembershipSpy = spyOn(directive['sitesApi'], 'createSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse })); - deleteMembershipSpy = spyOn(directive['sitesApi'], 'deleteSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({})); + deleteMembershipSpy = spyOn(directive['sitesApi'], 'deleteSiteMembershipRequestForPerson').and.returnValue(Promise.resolve()); }); it('should do nothing if there is no selected library ', fakeAsync(() => { diff --git a/lib/content-services/src/lib/directives/library-membership.directive.ts b/lib/content-services/src/lib/directives/library-membership.directive.ts index 553c70d6f0..697ed42968 100644 --- a/lib/content-services/src/lib/directives/library-membership.directive.ts +++ b/lib/content-services/src/lib/directives/library-membership.directive.ts @@ -18,7 +18,7 @@ import { Directive, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { SiteEntry, - SiteMembershipRequestBody, + SiteMembershipRequestBodyCreate, SiteMemberEntry, SiteMembershipRequestEntry, SitesApi @@ -208,7 +208,7 @@ export class LibraryMembershipDirective implements OnChanges { private joinLibraryRequest(): Observable { const memberBody = { id: this.targetSite.id - } as SiteMembershipRequestBody; + } as SiteMembershipRequestBodyCreate; if (this.versionCompatibilityService.isVersionSupported('7.0.0')) { memberBody.client = 'workspace'; diff --git a/lib/content-services/src/lib/directives/node-delete.directive.ts b/lib/content-services/src/lib/directives/node-delete.directive.ts index 2c4336f978..2b8e0a23f0 100644 --- a/lib/content-services/src/lib/directives/node-delete.directive.ts +++ b/lib/content-services/src/lib/directives/node-delete.directive.ts @@ -18,7 +18,7 @@ /* eslint-disable @angular-eslint/no-input-rename */ import { Directive, ElementRef, EventEmitter, HostListener, Input, OnChanges, Output } from '@angular/core'; -import { NodeEntry, Node, DeletedNodeEntity, DeletedNode, TrashcanApi, NodesApi } from '@alfresco/js-api'; +import { NodeEntry, Node, DeletedNodeEntry, DeletedNode, TrashcanApi, NodesApi } from '@alfresco/js-api'; import { Observable, forkJoin, from, of } from 'rxjs'; import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core'; import { map, catchError, retry } from 'rxjs/operators'; @@ -51,7 +51,7 @@ interface ProcessStatus { export class NodeDeleteDirective implements OnChanges { /** Array of nodes to delete. */ @Input('adf-delete') - selection: NodeEntry[] | DeletedNodeEntity[]; + selection: NodeEntry[] | DeletedNodeEntry[]; /** If true then the nodes are deleted immediately rather than being put in the trash */ @Input() @@ -97,7 +97,7 @@ export class NodeDeleteDirective implements OnChanges { this.elementRef.nativeElement.disabled = disable; } - private process(selection: NodeEntry[] | DeletedNodeEntity[]) { + private process(selection: NodeEntry[] | DeletedNodeEntry[]) { if (selection && selection.length) { const batch = this.getDeleteNodesBatch(selection); @@ -118,7 +118,7 @@ export class NodeDeleteDirective implements OnChanges { return selection.map((node) => this.deleteNode(node)); } - private deleteNode(node: NodeEntry | DeletedNodeEntity): Observable { + private deleteNode(node: NodeEntry | DeletedNodeEntry): Observable { const id = (node.entry as any).nodeId || node.entry.id; let promise: Promise; diff --git a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts index df1b2a4ada..111a27b636 100644 --- a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts +++ b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts @@ -51,7 +51,7 @@ import { DocumentListService } from './../services/document-list.service'; import { CustomResourcesService } from './../services/custom-resources.service'; import { DocumentListComponent } from './document-list.component'; import { ContentTestingModule } from '../../testing/content.testing.module'; -import { FavoritePaging, NodeEntry, NodePaging, Node } from '@alfresco/js-api'; +import { FavoritePaging, NodeEntry, NodePaging, Node, FavoritePagingList } from '@alfresco/js-api'; import { By } from '@angular/platform-browser'; import { DocumentListModule } from '../document-list.module'; import { TranslateModule } from '@ngx-translate/core'; @@ -106,15 +106,15 @@ describe('DocumentList', () => { appConfigService = TestBed.inject(AppConfigService); spyFolder = spyOn(documentListService, 'getFolder').and.returnValue(of({ list: {} })); - spyFolderNode = spyOn(documentListService, 'getFolderNode').and.returnValue(of(new NodeEntry({ entry: {} }))); - spyOn(documentList['nodesApi'], 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ entry: {} }))); + spyFolderNode = spyOn(documentListService, 'getFolderNode').and.returnValue(of(new NodeEntry({ entry: new Node() }))); + spyOn(documentList['nodesApi'], 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ entry: new Node() }))); documentList.ngOnInit(); documentList.currentFolderId = 'no-node'; spyGetSites = spyOn(customResourcesService.sitesApi, 'listSites').and.returnValue(Promise.resolve(fakeGetSitesAnswer)); spyFavorite = spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue( - Promise.resolve(new FavoritePaging({ list: { entries: [] } })) + Promise.resolve(new FavoritePaging({ list: new FavoritePagingList({ entries: [] }) })) ); }); @@ -1208,7 +1208,7 @@ describe('DocumentList', () => { expect(folderNode.value.id).toBe('fake-node'); done(); }); - documentList.onNodeDblClick(new NodeEntry({ entry: { id: 'fake-node', isFolder: true } })); + documentList.onNodeDblClick(new NodeEntry({ entry: new Node({ id: 'fake-node', isFolder: true }) })); }); it('should set no permission when getFolderNode fails with 403', (done) => { 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 index 9015921f05..4017f6c5f6 100644 --- 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 @@ -19,7 +19,7 @@ import { CustomResourcesService } from './custom-resources.service'; import { PaginationModel } from '@alfresco/adf-core'; import { TestBed } from '@angular/core/testing'; import { ContentTestingModule } from '../../testing/content.testing.module'; -import { FavoritePaging } from '@alfresco/js-api'; +import { Favorite, FavoritePaging, FavoritePagingList } from '@alfresco/js-api'; describe('CustomResourcesService', () => { let customResourcesService: CustomResourcesService; @@ -34,22 +34,26 @@ describe('CustomResourcesService', () => { describe('loadFavorites', () => { it('should return a list of items with default properties when target properties does not exist', (done) => { - spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve(new FavoritePaging({ - list: { - entries: [ - { - entry: { - target: { - file: { - title: 'some-title', - description: 'some-description' - } + spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue( + Promise.resolve( + new FavoritePaging({ + list: new FavoritePagingList({ + entries: [ + { + entry: new Favorite({ + target: { + file: { + title: 'some-title', + description: 'some-description' + } + } + }) } - } - } - ] - } - }))); + ] + }) + }) + ) + ); const pagination: PaginationModel = { maxItems: 100, skipCount: 0 @@ -73,25 +77,29 @@ describe('CustomResourcesService', () => { }); it('should return a list of items with merged properties when target properties exist', (done) => { - spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve(new FavoritePaging({ - list: { - entries: [ - { - entry: { - properties: { - 'cm:property': 'some-property' - }, - target: { - file: { - title: 'some-title', - description: 'some-description' - } + spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue( + Promise.resolve( + new FavoritePaging({ + list: new FavoritePagingList({ + entries: [ + { + entry: new Favorite({ + properties: { + 'cm:property': 'some-property' + }, + target: { + file: { + title: 'some-title', + description: 'some-description' + } + } + }) } - } - } - ] - } - }))); + ] + }) + }) + ) + ); const pagination: PaginationModel = { maxItems: 100, skipCount: 0 diff --git a/lib/content-services/src/lib/interfaces/restore-message-model.interface.ts b/lib/content-services/src/lib/interfaces/restore-message-model.interface.ts index 6b2bd5bfa7..787e605241 100644 --- a/lib/content-services/src/lib/interfaces/restore-message-model.interface.ts +++ b/lib/content-services/src/lib/interfaces/restore-message-model.interface.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import { PathInfoEntity } from '@alfresco/js-api'; +import { PathInfo } from '@alfresco/js-api'; export class RestoreMessageModel { message: string; - path: PathInfoEntity; + path: PathInfo; action: string; } diff --git a/lib/content-services/src/lib/mock/document-list.component.mock.ts b/lib/content-services/src/lib/mock/document-list.component.mock.ts index 11efb60577..04e00daea2 100644 --- a/lib/content-services/src/lib/mock/document-list.component.mock.ts +++ b/lib/content-services/src/lib/mock/document-list.component.mock.ts @@ -20,10 +20,10 @@ import { Node, NodePaging, NodeEntry } from '@alfresco/js-api'; export const fakeNodeWithCreatePermission = new Node({ isFile: false, createdByUser: { id: 'admin', displayName: 'Administrator' }, - modifiedAt: '2017-06-08T13:53:46.495Z', + modifiedAt: new Date('2017-06-08T13:53:46.495Z'), nodeType: 'cm:folder', parentId: '55052317-7e59-4058-8e07-769f41e615e1', - createdAt: '2017-05-22T11:36:11.270Z', + createdAt: new Date('2017-05-22T11:36:11.270Z'), path: { name: '/Company Home/User Homes', isComplete: true, @@ -43,11 +43,11 @@ export const fakeNodeWithCreatePermission = new Node({ export const fakeNodeWithNoPermission = new Node({ isFile: false, createdByUser: { id: 'admin', displayName: 'Administrator' }, - modifiedAt: '2017-06-08T13:53:46.495Z', + modifiedAt: new Date('2017-06-08T13:53:46.495Z'), nodeType: 'cm:folder', parentId: '55052317-7e59-4058-8e07-769f41e615e1', aspectNames: ['cm:ownable', 'cm:auditable'], - createdAt: '2017-05-22T11:36:11.270Z', + createdAt: new Date('2017-05-22T11:36:11.270Z'), path: { name: '/Company Home/User Homes', isComplete: true, @@ -219,7 +219,7 @@ export const fakeNodePaging: NodePaging = { export const mockNode1 = new Node({ isFile: true, createdByUser: { id: 'admin', displayName: 'Administrator' }, - modifiedAt: '2017-05-24T15:08:55.640Z', + modifiedAt: new Date('2017-05-24T15:08:55.640Z'), nodeType: 'cm:content', content: { mimeType: 'application/rtf', @@ -228,7 +228,7 @@ export const mockNode1 = new Node({ encoding: 'UTF-8' }, parentId: 'd124de26-6ba0-4f40-8d98-4907da2d337a', - createdAt: '2017-05-24T15:08:55.640Z', + createdAt: new Date('2017-05-24T15:08:55.640Z'), path: { name: '/Company Home/Guest Home', isComplete: true, @@ -248,7 +248,7 @@ export const mockNode1 = new Node({ export const mockNode2 = new Node({ isFile: true, createdByUser: { id: 'admin', displayName: 'Administrator' }, - modifiedAt: '2017-05-24T15:08:55.640Z', + modifiedAt: new Date('2017-05-24T15:08:55.640Z'), nodeType: 'cm:content', content: { mimeType: 'application/rtf', @@ -257,7 +257,7 @@ export const mockNode2 = new Node({ encoding: 'UTF-8' }, parentId: 'd124de26-6ba0-4f40-8d98-4907da2d337a', - createdAt: '2017-05-24T15:08:55.640Z', + createdAt: new Date('2017-05-24T15:08:55.640Z'), path: { name: '/Company Home/Guest Home', isComplete: true, @@ -277,7 +277,7 @@ export const mockNode2 = new Node({ export const mockNode3 = new Node({ isFile: true, createdByUser: { id: 'admin', displayName: 'Administrator' }, - modifiedAt: '2017-05-24T15:08:55.640Z', + modifiedAt: new Date('2017-05-24T15:08:55.640Z'), nodeType: 'cm:content', content: { mimeType: 'application/rtf', @@ -286,7 +286,7 @@ export const mockNode3 = new Node({ encoding: 'UTF-8' }, parentId: 'd124de26-6ba0-4f40-8d98-4907da2d337a', - createdAt: '2017-05-24T15:08:55.640Z', + createdAt: new Date('2017-05-24T15:08:55.640Z'), path: { name: '/Company Home/Guest Home', isComplete: true, diff --git a/lib/content-services/src/lib/mock/search.component.mock.ts b/lib/content-services/src/lib/mock/search.component.mock.ts index 47162b3c43..c78a7b09fe 100644 --- a/lib/content-services/src/lib/mock/search.component.mock.ts +++ b/lib/content-services/src/lib/mock/search.component.mock.ts @@ -17,41 +17,41 @@ import { Component, ViewChild } from '@angular/core'; import { SearchComponent } from '../search/components/search.component'; -import { SearchRequest, ResultSetPaging } from '@alfresco/js-api'; +import { SearchRequest, ResultSetPaging, ResultSetRowEntry, ContentInfo, UserInfo, ResultNode } from '@alfresco/js-api'; -const entryItem = { - entry: { +const entryItem = new ResultSetRowEntry({ + entry: new ResultNode({ id: '123', name: 'MyDoc', isFile: true, - content: { + content: new ContentInfo({ mimeType: 'text/plain' - }, - createdByUser: { + }), + createdByUser: new UserInfo({ displayName: 'John Doe' - }, - modifiedByUser: { + }), + modifiedByUser: new UserInfo({ displayName: 'John Doe' - } - } -}; + }) + }) +}); -const entryDifferentItem = { - entry: { +const entryDifferentItem = new ResultSetRowEntry({ + entry: new ResultNode({ id: '999', name: 'TEST_DOC', isFile: true, - content: { + content: new ContentInfo({ mimeType: 'text/plain' - }, - createdByUser: { + }), + createdByUser: new UserInfo({ displayName: 'John TEST' - }, - modifiedByUser: { + }), + modifiedByUser: new UserInfo({ displayName: 'John TEST' - } - } -}; + }) + }) +}); export const result = new ResultSetPaging({ list: { diff --git a/lib/content-services/src/lib/mock/sites-dropdown.component.mock.ts b/lib/content-services/src/lib/mock/sites-dropdown.component.mock.ts index b7471da6d9..5901fedafa 100644 --- a/lib/content-services/src/lib/mock/sites-dropdown.component.mock.ts +++ b/lib/content-services/src/lib/mock/sites-dropdown.component.mock.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { SitePaging } from '@alfresco/js-api'; +import { SitePaging, SitePagingList } from '@alfresco/js-api'; /* We are using functions instead of constants here to pass a new instance of the object each time */ export const getFakeSitePaging = (): SitePaging => ({ @@ -162,122 +162,126 @@ export const getFakeSitePagingLastPage = (): SitePaging => ({ } }); -export const getFakeSitePagingWithMembers = () => new SitePaging({ - list: { - entries: [{ - entry: { - visibility: 'MODERATED', - guid: 'b4cff62a-664d-4d45-9302-98723eac1319', - description: 'This is a Sample Alfresco Team site.', - id: 'MODERATED-SITE', - preset: 'site-dashboard', - title: 'FAKE-MODERATED-SITE' - }, - relations: { - members: { - list: { - pagination: { - count: 3, - hasMoreItems: false, - skipCount: 0, - maxItems: 100 - }, - entries: [ - { - entry: { - role: 'SiteManager', - person: { - firstName: 'Administrator', - emailNotificationsEnabled: true, - company: {}, - id: 'admin', - enabled: true, - email: 'admin@alfresco.com' +export const getFakeSitePagingWithMembers = () => + new SitePaging({ + list: new SitePagingList({ + entries: [ + { + entry: { + visibility: 'MODERATED', + guid: 'b4cff62a-664d-4d45-9302-98723eac1319', + description: 'This is a Sample Alfresco Team site.', + id: 'MODERATED-SITE', + preset: 'site-dashboard', + title: 'FAKE-MODERATED-SITE' + }, + relations: { + members: { + list: { + pagination: { + count: 3, + hasMoreItems: false, + skipCount: 0, + maxItems: 100 + }, + entries: [ + { + entry: { + role: 'SiteManager', + person: { + firstName: 'Administrator', + emailNotificationsEnabled: true, + company: {}, + id: 'admin', + enabled: true, + email: 'admin@alfresco.com' + }, + id: 'admin' + } }, - id: 'admin' - } - }, - { - entry: { - role: 'SiteCollaborator', - person: { - lastName: 'Beecher', - userStatus: 'Helping to design the look and feel of the new web site', - jobTitle: 'Graphic Designer', - statusUpdatedAt: '2011-02-15T20:20:13.432+0000', - mobile: '0112211001100', - emailNotificationsEnabled: true, - description: 'Alice is a demo user for the sample Alfresco Team site.', - telephone: '0112211001100', - enabled: false, - firstName: 'Alice', - skypeId: 'abeecher', - avatarId: '198500fc-1e99-4f5f-8926-248cea433366', - location: 'Tilbury, UK', - company: { - organization: 'Moresby, Garland and Wedge', - address1: '200 Butterwick Street', - address2: 'Tilbury', - address3: 'UK', - postcode: 'ALF1 SAM1' - }, - id: 'abeecher', - email: 'abeecher@example.com' - }, - id: 'abeecher' - } + { + entry: { + role: 'SiteCollaborator', + person: { + lastName: 'Beecher', + userStatus: 'Helping to design the look and feel of the new web site', + jobTitle: 'Graphic Designer', + statusUpdatedAt: new Date('2011-02-15T20:20:13.432+0000'), + mobile: '0112211001100', + emailNotificationsEnabled: true, + description: 'Alice is a demo user for the sample Alfresco Team site.', + telephone: '0112211001100', + enabled: false, + firstName: 'Alice', + skypeId: 'abeecher', + avatarId: '198500fc-1e99-4f5f-8926-248cea433366', + location: 'Tilbury, UK', + company: { + organization: 'Moresby, Garland and Wedge', + address1: '200 Butterwick Street', + address2: 'Tilbury', + address3: 'UK', + postcode: 'ALF1 SAM1' + }, + id: 'abeecher', + email: 'abeecher@example.com' + }, + id: 'abeecher' + } + } + ] } - ] + } + } + }, + { + entry: { + visibility: 'PUBLIC', + guid: 'b4cff62a-664d-4d45-9302-98723eac1319', + description: 'This is a Sample Alfresco Team site.', + id: 'PUBLIC-SITE', + preset: 'site-dashboard', + title: 'FAKE-SITE-PUBLIC' + } + }, + { + entry: { + visibility: 'PRIVATE', + guid: 'b4cff62a-664d-4d45-9302-98723eac1319', + description: 'This is a Sample Alfresco Team site.', + id: 'MEMBER-SITE', + preset: 'site-dashboard', + title: 'FAKE-PRIVATE-SITE-MEMBER' + }, + relations: { + members: { + list: { + pagination: { + count: 3, + hasMoreItems: false, + skipCount: 0, + maxItems: 100 + }, + entries: [ + { + entry: { + role: 'SiteManager', + person: { + firstName: 'Administrator', + emailNotificationsEnabled: true, + company: {}, + id: 'admin', + enabled: true, + email: 'admin@alfresco.com' + }, + id: 'test' + } + } + ] + } + } } } - } - }, { - entry: { - visibility: 'PUBLIC', - guid: 'b4cff62a-664d-4d45-9302-98723eac1319', - description: 'This is a Sample Alfresco Team site.', - id: 'PUBLIC-SITE', - preset: 'site-dashboard', - title: 'FAKE-SITE-PUBLIC' - } - }, { - entry: { - visibility: 'PRIVATE', - guid: 'b4cff62a-664d-4d45-9302-98723eac1319', - description: 'This is a Sample Alfresco Team site.', - id: 'MEMBER-SITE', - preset: 'site-dashboard', - title: 'FAKE-PRIVATE-SITE-MEMBER' - }, - relations: { - members: { - list: { - pagination: { - count: 3, - hasMoreItems: false, - skipCount: 0, - maxItems: 100 - }, - entries: [ - { - entry: { - role: 'SiteManager', - person: { - firstName: 'Administrator', - emailNotificationsEnabled: true, - company: {}, - id: 'admin', - enabled: true, - email: 'admin@alfresco.com' - }, - id: 'test' - } - } - ] - } - } - } - } - ] - } -}); + ] + }) + }); diff --git a/lib/content-services/src/lib/node-comments/mocks/node-comments.mock.ts b/lib/content-services/src/lib/node-comments/mocks/node-comments.mock.ts index c608dee260..14a2fdfb9a 100644 --- a/lib/content-services/src/lib/node-comments/mocks/node-comments.mock.ts +++ b/lib/content-services/src/lib/node-comments/mocks/node-comments.mock.ts @@ -15,31 +15,27 @@ * limitations under the License. */ -import { CommentModel } from '@alfresco/adf-core'; +import { CommentModel, User } from '@alfresco/adf-core'; import { EcmCompanyModel } from '../../common/models/ecm-company.model'; import { EcmUserModel } from '../../common/models/ecm-user.model'; -export const fakeUser1 = { +export const fakeUser1 = new User({ enabled: true, firstName: 'firstName', lastName: 'lastName', email: 'fake-email@dom.com', - emailNotificationsEnabled: true, - company: {}, id: 'fake-email@dom.com', avatarId: '123-123-123' -}; +}); -export const fakeUser2 = { +export const fakeUser2 = new User({ enabled: true, firstName: 'some', lastName: 'one', email: 'some-one@somegroup.com', - emailNotificationsEnabled: true, - company: {}, id: 'fake-email@dom.com', avatarId: '001-001-001' -}; +}); export const fakeContentComments = { list: { @@ -153,28 +149,28 @@ export const commentsNodeData: CommentModel[] = [ id: 1, message: `I've done this component, is it cool?`, created: getDateXMinutesAgo(30), - createdBy: johnDoe, + createdBy: new User(johnDoe), isSelected: false }), new CommentModel({ id: 2, message: 'Yeah', created: getDateXMinutesAgo(15), - createdBy: janeEod, + createdBy: new User(janeEod), isSelected: false }), new CommentModel({ id: 3, message: '+1', created: getDateXMinutesAgo(12), - createdBy: robertSmith, + createdBy: new User(robertSmith), isSelected: false }), new CommentModel({ id: 4, message: 'ty', created: new Date(), - createdBy: johnDoe, + createdBy: new User(johnDoe), isSelected: false }) ]; @@ -184,28 +180,28 @@ export const commentsTaskData: CommentModel[] = [ id: 1, message: `I've done this task, what's next?`, created: getDateXMinutesAgo(30), - createdBy: johnDoe, + createdBy: new User(johnDoe), isSelected: false }), new CommentModel({ id: 2, message: `I've assigned you another one 🤠`, created: getDateXMinutesAgo(15), - createdBy: janeEod, + createdBy: new User(janeEod), isSelected: false }), new CommentModel({ id: 3, message: '+1', created: getDateXMinutesAgo(12), - createdBy: robertSmith, + createdBy: new User(robertSmith), isSelected: false }), new CommentModel({ id: 4, message: 'Cheers', created: new Date(), - createdBy: johnDoe, + createdBy: new User(johnDoe), isSelected: false }) ]; diff --git a/lib/content-services/src/lib/node-comments/services/node-comments.service.ts b/lib/content-services/src/lib/node-comments/services/node-comments.service.ts index 9ac6fae662..a4263018bb 100644 --- a/lib/content-services/src/lib/node-comments/services/node-comments.service.ts +++ b/lib/content-services/src/lib/node-comments/services/node-comments.service.ts @@ -19,7 +19,8 @@ import { AlfrescoApiService, LogService, CommentModel, - CommentsService + CommentsService, + User } from '@alfresco/adf-core'; import { CommentEntry, CommentsApi, Comment } from '@alfresco/js-api'; import { Injectable } from '@angular/core'; @@ -98,7 +99,7 @@ export class NodeCommentsService implements CommentsService { id: comment.id, message: comment.content, created: comment.createdAt, - createdBy: comment.createdBy + createdBy: new User(comment.createdBy) }); } diff --git a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.ts b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.ts index 982e302197..e98a4d73c3 100644 --- a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.ts +++ b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.ts @@ -17,7 +17,7 @@ import { SearchConfigurationService } from '../../../search/services/search-configuration.service'; import { SearchService } from '../../../search/services/search.service'; -import { NodeEntry } from '@alfresco/js-api'; +import { Node, NodeEntry } from '@alfresco/js-api'; import { Component, EventEmitter, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { UntypedFormControl } from '@angular/forms'; import { debounceTime } from 'rxjs/operators'; @@ -30,13 +30,9 @@ import { MatSelectionList } from '@angular/material/list'; templateUrl: './add-permission-panel.component.html', styleUrls: ['./add-permission-panel.component.scss'], encapsulation: ViewEncapsulation.None, - providers: [ - { provide: SearchConfigurationService, useClass: SearchPermissionConfigurationService }, - SearchService - ] + providers: [{ provide: SearchConfigurationService, useClass: SearchPermissionConfigurationService }, SearchService] }) export class AddPermissionPanelComponent { - @ViewChild('search', { static: true }) search: SearchComponent; @@ -54,15 +50,13 @@ export class AddPermissionPanelComponent { selectedItems: NodeEntry[] = []; // eslint-disable-next-line @typescript-eslint/naming-convention - EVERYONE: NodeEntry = new NodeEntry({ entry: { nodeType: 'cm:authorityContainer', properties: {'cm:authorityName': 'GROUP_EVERYONE'}}}); + EVERYONE: NodeEntry = new NodeEntry({ + entry: new Node({ nodeType: 'cm:authorityContainer', properties: { 'cm:authorityName': 'GROUP_EVERYONE' } }) + }); constructor() { - this.searchInput.valueChanges - .pipe( - debounceTime(this.debounceSearch) - ) - .subscribe((searchValue) => { - const selectionOptions = this.matSelectionList.selectedOptions.selected.map(option => option.value); + this.searchInput.valueChanges.pipe(debounceTime(this.debounceSearch)).subscribe((searchValue) => { + const selectionOptions = this.matSelectionList.selectedOptions.selected.map((option) => option.value); this.selectedItems.push(...selectionOptions); this.matSelectionList.deselectAll(); this.searchedWord = searchValue; @@ -73,15 +67,14 @@ export class AddPermissionPanelComponent { } onSelectionChange() { - const currentSelection = this.matSelectionList.selectedOptions.selected.map(option => option.value); - const uniqueSelection = [ ...currentSelection, ...this.selectedItems ] - .reduce((uniquesElements, currentElement) => { - const isExist = uniquesElements.find(uniqueElement => uniqueElement.entry.id === currentElement.entry.id); + const currentSelection = this.matSelectionList.selectedOptions.selected.map((option) => option.value); + const uniqueSelection = [...currentSelection, ...this.selectedItems].reduce((uniquesElements, currentElement) => { + const isExist = uniquesElements.find((uniqueElement) => uniqueElement.entry.id === currentElement.entry.id); if (!isExist) { uniquesElements.push(currentElement); } return uniquesElements; - }, []); + }, []); this.select.emit(uniqueSelection); } @@ -90,5 +83,4 @@ export class AddPermissionPanelComponent { this.selectedItems.splice(0, this.selectedItems.length); this.search.resetResults(); } - } diff --git a/lib/content-services/src/lib/permission-manager/components/user-icon-column/user-icon-column.component.ts b/lib/content-services/src/lib/permission-manager/components/user-icon-column/user-icon-column.component.ts index fdb8a949c4..ef605f717f 100644 --- a/lib/content-services/src/lib/permission-manager/components/user-icon-column/user-icon-column.component.ts +++ b/lib/content-services/src/lib/permission-manager/components/user-icon-column/user-icon-column.component.ts @@ -16,7 +16,7 @@ */ import { User } from '@alfresco/adf-core'; -import { NodeEntry } from '@alfresco/js-api'; +import { Group, NodeEntry } from '@alfresco/js-api'; import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; import { NodePermissionService } from '../../services/node-permission.service'; @@ -48,7 +48,7 @@ export class UserIconColumnComponent implements OnInit { @Input() selected: boolean = false; - displayText$ = new BehaviorSubject(null); + displayText$ = new BehaviorSubject(null); group = false; get isSelected(): boolean { @@ -61,13 +61,15 @@ export class UserIconColumnComponent implements OnInit { if (this.context) { const { person, group, authorityId } = this.context.row.obj?.entry ?? this.context.row.obj; this.group = this.isGroup(group, authorityId); - this.displayText$.next(person || group || { displayName: authorityId }); + const user = person ? new User(person) : undefined; + this.displayText$.next(user || group || { displayName: authorityId }); } if (this.node) { const { person, group } = this.nodePermissionService.transformNodeToUserPerson(this.node.entry); this.group = this.isGroup(group, null); - this.displayText$.next(person || group); + const user = person ? new User(person) : undefined; + this.displayText$.next(user || group); } } diff --git a/lib/content-services/src/lib/search/mocks/search.service.mock.ts b/lib/content-services/src/lib/search/mocks/search.service.mock.ts index 5f43f6398e..af57ac86a7 100644 --- a/lib/content-services/src/lib/search/mocks/search.service.mock.ts +++ b/lib/content-services/src/lib/search/mocks/search.service.mock.ts @@ -15,8 +15,10 @@ * limitations under the License. */ +import { ContentInfo, Node, NodePagingList, UserInfo } from '@alfresco/js-api'; + export const fakeSearch = { - list: { + list: new NodePagingList({ pagination: { count: 1, hasMoreItems: false, @@ -26,22 +28,20 @@ export const fakeSearch = { }, entries: [ { - entry: { + entry: new Node({ id: '123', name: 'MyDoc', - content: { - mimetype: 'text/plain' - }, - createdByUser: { + content: new ContentInfo({ mimeType: 'text/plain' }), + createdByUser: new UserInfo({ displayName: 'John Doe' - }, - modifiedByUser: { + }), + modifiedByUser: new UserInfo({ displayName: 'John Doe' - } - } + }) + }) } ] - } + }) }; export const mockError = { @@ -55,7 +55,5 @@ export const mockError = { }; export const searchMockApi: any = { - findNodes: () => Promise.resolve(fakeSearch) - }; diff --git a/lib/content-services/src/lib/search/services/search.service.ts b/lib/content-services/src/lib/search/services/search.service.ts index 792670c0fc..ac1640208a 100644 --- a/lib/content-services/src/lib/search/services/search.service.ts +++ b/lib/content-services/src/lib/search/services/search.service.ts @@ -124,13 +124,13 @@ export interface SearchOptions { include?: string[]; /** - * String to control the order of the entities returned in a list. You can use this + * String array to control the order of the entities returned in a list. You can use this * parameter to sort the list by one or more fields. Each field has a default sort order, * which is normally ascending order (but see the JS-API docs to check if any fields used * in a method have a descending default search order). To sort the entities in a specific * order, you can use the "ASC" and "DESC" keywords for any field. */ - orderBy?: string; + orderBy?: string[]; /** * List of field names. You can use this parameter to restrict the fields returned within diff --git a/lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.spec.ts b/lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.spec.ts index febad3291f..2052023d60 100644 --- a/lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.spec.ts +++ b/lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.spec.ts @@ -19,20 +19,9 @@ import { TestBed } from '@angular/core/testing'; import { CoreTestingModule } from '@alfresco/adf-core'; import { SecurityControlsService } from './security-controls-groups-marks-security.service'; import { fakeAuthorityClearanceApiResponse } from './mock/security-authorities.mock'; -import { - fakeGroupsApiResponse, - createNewSecurityGroupMock -} from './mock/security-groups.mock'; -import { - fakeMarksApiResponse, - createNewSecurityMarkMock -} from './mock/security-marks.mock'; -import { - SecurityGroupBody, - SecurityGroupEntry, - SecurityMarkBody, - SecurityMarkEntry -} from '@alfresco/js-api'; +import { fakeGroupsApiResponse, createNewSecurityGroupMock } from './mock/security-groups.mock'; +import { fakeMarksApiResponse, createNewSecurityMarkMock } from './mock/security-marks.mock'; +import { SecurityGroup, SecurityGroupBody, SecurityGroupEntry, SecurityMarkBody, SecurityMarkEntry } from '@alfresco/js-api'; describe('SecurityControlsService', () => { let service: SecurityControlsService; @@ -55,11 +44,8 @@ describe('SecurityControlsService', () => { }); it('should be able to get the list of Security groups', async () => { - const getGroupSpy = spyOn( - service.groupsApi, - 'getSecurityGroups' - ).and.returnValue(Promise.resolve(fakeGroupsApiResponse)); - const groupPromise = service.getSecurityGroup( 0, 5, 'inUse'); + const getGroupSpy = spyOn(service.groupsApi, 'getSecurityGroups').and.returnValue(Promise.resolve(fakeGroupsApiResponse)); + const groupPromise = service.getSecurityGroup(0, 5, 'inUse'); const group = await groupPromise; expect(getGroupSpy).toHaveBeenCalledWith({ skipCount: 0, @@ -73,21 +59,15 @@ describe('SecurityControlsService', () => { expect(group.entries[0].groupName).toBe('Classification'); expect(group.entries[0].groupType).toBe('HIERARCHICAL'); - expect(group.entries[1].id).toBe( - 'd2b11d9f-2707-439f-a7c6-e7872f395553' - ); + expect(group.entries[1].id).toBe('d2b11d9f-2707-439f-a7c6-e7872f395553'); expect(group.entries[1].groupName).toBe('SG1'); expect(group.entries[1].groupType).toBe('USER_REQUIRES_ALL'); - expect(group.entries[2].id).toBe( - '1b77a32d-6b8b-4a37-b195-7f2ff2fe4ed3' - ); + expect(group.entries[2].id).toBe('1b77a32d-6b8b-4a37-b195-7f2ff2fe4ed3'); expect(group.entries[2].groupName).toBe('SG2'); expect(group.entries[2].groupType).toBe('USER_REQUIRES_ALL'); - expect(group.entries[3].id).toBe( - '709791f8-22dc-428a-82dd-daf3e1aa8a60' - ); + expect(group.entries[3].id).toBe('709791f8-22dc-428a-82dd-daf3e1aa8a60'); expect(group.entries[3].groupName).toBe('SG3'); expect(group.entries[3].groupType).toBe('USER_REQUIRES_ALL'); }); @@ -96,48 +76,34 @@ describe('SecurityControlsService', () => { spyOn(service.groupsApi, 'createSecurityGroup').and.returnValue( Promise.resolve( new SecurityGroupEntry({ - entry: { + entry: new SecurityGroup({ groupName: 'TestGroup', groupType: 'HIERARCHICAL', id: 'eddf6269-ceba-42c6-b979-9ac445d29a94' - } + }) }) ) ); - const response = await service - .createSecurityGroup(createNewSecurityGroupMock) - .toPromise(); + const response = await service.createSecurityGroup(createNewSecurityGroupMock).toPromise(); securityGroupId = response.entry.id; expect(response.entry.groupName).toEqual('TestGroup'); expect(response.entry.groupType).toEqual('HIERARCHICAL'); - expect(response.entry.id).toEqual( - 'eddf6269-ceba-42c6-b979-9ac445d29a94' - ); + expect(response.entry.id).toEqual('eddf6269-ceba-42c6-b979-9ac445d29a94'); }); it('should be able to get the list of Security Marks', async () => { - const getMarkSpy = spyOn( - service.marksApi, - 'getSecurityMarks' - ).and.returnValue(Promise.resolve(fakeMarksApiResponse)); - const markPromise = service.getSecurityMark( - securityGroupId, - 0, - 'inUse' - ); + const getMarkSpy = spyOn(service.marksApi, 'getSecurityMarks').and.returnValue(Promise.resolve(fakeMarksApiResponse)); + const markPromise = service.getSecurityMark(securityGroupId, 0); const mark = await markPromise; expect(getMarkSpy).toHaveBeenCalledWith(securityGroupId, { - skipCount: 0, - include: 'inUse' + skipCount: 0 }); expect(mark.pagination.skipCount).toBe(0); expect(mark.pagination.maxItems).toBe(10); - expect(mark.entries[0].groupId).toBe( - 'eddf6269-ceba-42c6-b979-9ac445d29a94' - ); + expect(mark.entries[0].groupId).toBe('eddf6269-ceba-42c6-b979-9ac445d29a94'); expect(mark.entries[0].name).toBe('securityMark1'); expect(mark.entries[0].id).toBe('ffBOeOJJ'); }); @@ -176,12 +142,7 @@ describe('SecurityControlsService', () => { }) ) ); - const response = await service - .updateSecurityMark( - securityGroupId, - securityMarkId, - securityMarkBody - ); + const response = await service.updateSecurityMark(securityGroupId, securityMarkId, securityMarkBody); securityGroupId = response.entry.groupId; securityMarkId = response.entry.id; @@ -194,11 +155,11 @@ describe('SecurityControlsService', () => { spyOn(service.groupsApi, 'updateSecurityGroup').and.returnValue( Promise.resolve( new SecurityGroupEntry({ - entry: { + entry: new SecurityGroup({ groupName: 'TestGroup', groupType: 'HIERARCHICAL', id: 'eddf6269-ceba-42c6-b979-9ac445d29a94' - } + }) }) ) ); @@ -230,31 +191,15 @@ describe('SecurityControlsService', () => { }); it('should delete a security group', async () => { - spyOn(service.groupsApi, 'deleteSecurityGroup').and.returnValue( - Promise.resolve( - new SecurityGroupEntry({ - entry: { - groupName: 'TestGroup', - groupType: 'HIERARCHICAL', - id: 'eddf6269-ceba-42c6-b979-9ac445d29a94' - } - }) - ) - ); - const response = await service - .deleteSecurityGroup(securityGroupId) - .toPromise(); - - expect(response.entry.groupName).toEqual('TestGroup'); - expect(response.entry.groupType).toEqual('HIERARCHICAL'); - expect(response.entry.id).toEqual('eddf6269-ceba-42c6-b979-9ac445d29a94'); + spyOn(service.groupsApi, 'deleteSecurityGroup').and.returnValue(Promise.resolve()); + await service.deleteSecurityGroup(securityGroupId).toPromise(); + expect(service.groupsApi.deleteSecurityGroup).toHaveBeenCalled(); }); it('should be able to get clearances for authority', async () => { - const getClearancesForAuthoritySpy = spyOn( - service.authorityClearanceApi, - 'getAuthorityClearanceForAuthority' - ).and.returnValue(Promise.resolve(fakeAuthorityClearanceApiResponse)); + const getClearancesForAuthoritySpy = spyOn(service.authorityClearanceApi, 'getAuthorityClearanceForAuthority').and.returnValue( + Promise.resolve(fakeAuthorityClearanceApiResponse) + ); const clearancePromise = service.getClearancesForAuthority('test-id', 0, 10); const clearance = await clearancePromise.toPromise(); @@ -283,11 +228,15 @@ describe('SecurityControlsService', () => { }) ) ); - const response = await service.updateClearancesForAuthority('test-id', [{ - groupId: 'test-group-id', - op: 'test-op', - id: 'test-id' - }]).toPromise(); + const response = await service + .updateClearancesForAuthority('test-id', [ + { + groupId: 'test-group-id', + op: 'test-op', + id: 'test-id' + } + ]) + .toPromise(); if (response instanceof SecurityMarkEntry) { expect(response.entry.id).toEqual('test-id'); @@ -296,8 +245,8 @@ describe('SecurityControlsService', () => { } }); - it('should reload security groups', doneCallback => { - service.reloadSecurityControls$.subscribe(res => { + it('should reload security groups', (doneCallback) => { + service.reloadSecurityControls$.subscribe((res) => { expect(res).toBeUndefined(); doneCallback(); }); diff --git a/lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.ts b/lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.ts index 1bb1c42c9b..e4c76d30ad 100644 --- a/lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.ts +++ b/lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.ts @@ -30,7 +30,8 @@ import { SecurityGroupPaging, AuthorityClearanceApi, AuthorityClearanceGroupPaging, - NodeSecurityMarkBody + NodeSecurityMarkBody, + GsGroupInclude } from '@alfresco/js-api'; import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core'; import { finalize } from 'rxjs/operators'; @@ -125,8 +126,8 @@ export class SecurityControlsService { const payload: SecurityGroupBody = { ...input }; - const opts = { - DEFAULT_INCLUDE + const opts: GsGroupInclude = { + include: DEFAULT_INCLUDE }; const promise = this.groupsApi.createSecurityGroup(payload, opts); @@ -169,19 +170,16 @@ export class SecurityControlsService { * * @param securityGroupId The key for the security group id. * @param skipCount The number of entities that exist in the collection before those included in this list. - * @param include The key for the security mark is in use or not * @return Promise */ getSecurityMark( securityGroupId: string, - skipCount = DEFAULT_SKIP_COUNT, - include = DEFAULT_INCLUDE + skipCount = DEFAULT_SKIP_COUNT ): Promise { let securityControlsMarkResponse: SecurityControlsMarkResponse; return new Promise((resolve, reject) => { this.marksApi .getSecurityMarks(securityGroupId, { - include, skipCount }) .then((response: SecurityMarkPaging) => { @@ -276,11 +274,11 @@ export class SecurityControlsService { * Delete security group * * @param securityGroupId The key for the security group id. - * @return Observable + * @return Observable */ deleteSecurityGroup( securityGroupId: string - ): Observable { + ): Observable { this.loadingSource.next(true); const promise = this.groupsApi.deleteSecurityGroup(securityGroupId); diff --git a/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts b/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts index 4c6099b6f2..232515181b 100644 --- a/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts +++ b/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts @@ -17,7 +17,7 @@ import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; import { LogService, InfiniteSelectScrollDirective, AuthenticationService } from '@alfresco/adf-core'; -import { SitePaging, SiteEntry } from '@alfresco/js-api'; +import { SitePaging, SiteEntry, Site } from '@alfresco/js-api'; import { MatSelectChange } from '@angular/material/select'; import {LiveAnnouncer} from '@angular/cdk/a11y'; import {TranslateService} from '@ngx-translate/core'; @@ -128,11 +128,7 @@ export class DropdownSitesComponent implements OnInit { if (!this.hideMyFiles) { const siteEntry = new SiteEntry({ - entry: { - id: this.MY_FILES_VALUE, - guid: this.MY_FILES_VALUE, - title: 'DROPDOWN.MY_FILES_OPTION' - } + entry: new Site({ id: this.MY_FILES_VALUE, guid: this.MY_FILES_VALUE, title: 'DROPDOWN.MY_FILES_OPTION' }) }); this.siteList.list.entries.unshift(siteEntry); @@ -180,7 +176,7 @@ export class DropdownSitesComponent implements OnInit { return sites; } - private isCurrentUserMember(site, loggedUserName): boolean { + private isCurrentUserMember(site: SiteEntry, loggedUserName: string): boolean { return site.entry.visibility === 'PUBLIC' || !!site.relations.members.list.entries.find((member) => member.entry.id.toLowerCase() === loggedUserName.toLowerCase()); } diff --git a/lib/content-services/src/lib/tag/services/tag.service.spec.ts b/lib/content-services/src/lib/tag/services/tag.service.spec.ts index 5cc57a1ffb..be1f2a8056 100644 --- a/lib/content-services/src/lib/tag/services/tag.service.spec.ts +++ b/lib/content-services/src/lib/tag/services/tag.service.spec.ts @@ -24,7 +24,6 @@ import { throwError } from 'rxjs'; import { Pagination, Tag, TagBody, TagEntry, TagPaging, TagPagingList } from '@alfresco/js-api'; describe('TagService', () => { - let service: TagService; let logService: LogService; let userPreferencesService: UserPreferencesService; @@ -43,37 +42,32 @@ describe('TagService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ContentTestingModule - ] + imports: [TranslateModule.forRoot(), ContentTestingModule] }); service = TestBed.inject(TagService); logService = TestBed.inject(LogService); userPreferencesService = TestBed.inject(UserPreferencesService); - spyOn(service.tagsApi, 'deleteTagFromNode').and.returnValue( - Promise.resolve({}) - ); - spyOn(service.tagsApi, 'createTagForNode').and.returnValue( - Promise.resolve(new TagEntry({})) - ); + spyOn(service.tagsApi, 'deleteTagFromNode').and.returnValue(Promise.resolve()); + spyOn(service.tagsApi, 'createTagForNode').and.returnValue(Promise.resolve(new TagEntry({}))); }); describe('Content tests', () => { - it('should catch errors on getTagsByNodeId call', async () => { - spyOn(service, 'getTagsByNodeId').and.returnValue(throwError({error : 'error'})); - await service.getTagsByNodeId('fake-node-id').subscribe(() => { - throwError('This call should fail'); - }, (error) => { - expect(error.error).toBe('error'); - }); + spyOn(service, 'getTagsByNodeId').and.returnValue(throwError({ error: 'error' })); + await service.getTagsByNodeId('fake-node-id').subscribe( + () => { + throwError('This call should fail'); + }, + (error) => { + expect(error.error).toBe('error'); + } + ); }); it('should trigger a refresh event on removeTag() call', async () => { - await service.refresh.subscribe((res) => { - expect(res).toBeDefined(); + await service.refresh.subscribe(() => { + expect(service.tagsApi.deleteTagFromNode).toHaveBeenCalledWith('fake-node-id', 'fake-tag'); }); service.removeTag('fake-node-id', 'fake-tag'); @@ -108,12 +102,14 @@ describe('TagService', () => { }); it('should emit refresh when tags creation is success', fakeAsync(() => { - const tags: TagEntry[] = [{ - entry: { - id: 'Some id 1', - tag: 'Some tag 1' + const tags: TagEntry[] = [ + { + entry: { + id: 'Some id 1', + tag: 'Some tag 1' + } } - }]; + ]; spyOn(service.refresh, 'emit'); spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve(tags)); service.createTags([]); @@ -140,11 +136,14 @@ describe('TagService', () => { it('should call listTags on TagsApi with correct parameters when includedCounts is true', () => { spyOn(service.tagsApi, 'listTags').and.returnValue(Promise.resolve(result)); - const skipCount = 10; + const skipCount = 10; - service.getAllTheTags({ - skipCount - }, true); + service.getAllTheTags( + { + skipCount + }, + true + ); expect(service.tagsApi.listTags).toHaveBeenCalledWith({ include: ['count'], skipCount @@ -153,11 +152,14 @@ describe('TagService', () => { it('should call listTags on TagsApi with correct parameters when includedCounts is false', () => { spyOn(service.tagsApi, 'listTags').and.returnValue(Promise.resolve(result)); - const skipCount = 10; + const skipCount = 10; - service.getAllTheTags({ - skipCount - }, false); + service.getAllTheTags( + { + skipCount + }, + false + ); expect(service.tagsApi.listTags).toHaveBeenCalledWith({ include: undefined, skipCount @@ -264,7 +266,7 @@ describe('TagService', () => { id: 'fake-node-id' } }; - const tagBody: TagBody = {tag: 'updated-tag'}; + const tagBody: TagBody = { tag: 'updated-tag' }; const updatedTag: TagEntry = { entry: { ...tagBody, @@ -361,7 +363,9 @@ describe('TagService', () => { }); it('should call assignTagsToNode on TagsApi with correct parameters', () => { - spyOn(service.tagsApi, 'assignTagsToNode').and.returnValue(Promise.resolve(singleResult)); + spyOn(service.tagsApi, 'assignTagsToNode').and.returnValue( + Promise.resolve(new TagPaging({ list: new TagPagingList({ entries: [singleResult] }) })) + ); service.assignTagsToNode(nodeId, tags); expect(service.tagsApi.assignTagsToNode).toHaveBeenCalledWith(nodeId, tags); @@ -381,10 +385,12 @@ describe('TagService', () => { })); it('should return observable which emits single tag', fakeAsync(() => { - spyOn(service.tagsApi, 'assignTagsToNode').and.returnValue(Promise.resolve(singleResult)); + spyOn(service.tagsApi, 'assignTagsToNode').and.returnValue( + Promise.resolve(new TagPaging({ list: new TagPagingList({ entries: [singleResult] }) })) + ); service.assignTagsToNode(nodeId, tags).subscribe((tagsResult) => { - expect(tagsResult).toEqual(singleResult); + expect(tagsResult).toEqual(new TagPaging({ list: new TagPagingList({ entries: [singleResult] }) })); }); tick(); })); diff --git a/lib/content-services/src/lib/tag/services/tag.service.ts b/lib/content-services/src/lib/tag/services/tag.service.ts index 693196c040..e42a0a7f61 100644 --- a/lib/content-services/src/lib/tag/services/tag.service.ts +++ b/lib/content-services/src/lib/tag/services/tag.service.ts @@ -99,8 +99,8 @@ export class TagService { removeTag(nodeId: string, tag: string): Observable { const observableRemove = from(this.tagsApi.deleteTagFromNode(nodeId, tag)); - observableRemove.subscribe((data) => { - this.refresh.emit(data); + observableRemove.subscribe(() => { + this.refresh.emit(); }, (err) => { this.handleError(err); }); diff --git a/lib/content-services/src/lib/tree-view/services/tree-view.service.spec.ts b/lib/content-services/src/lib/tree-view/services/tree-view.service.spec.ts index ad408cbc8a..15a23edeff 100644 --- a/lib/content-services/src/lib/tree-view/services/tree-view.service.spec.ts +++ b/lib/content-services/src/lib/tree-view/services/tree-view.service.spec.ts @@ -22,28 +22,39 @@ import { ContentTestingModule } from '../../testing/content.testing.module'; import { of } from 'rxjs'; import { TreeBaseNode } from '../models/tree-view.model'; import { TranslateModule } from '@ngx-translate/core'; -import { NodePaging } from '@alfresco/js-api'; +import { Node, NodePaging } from '@alfresco/js-api'; describe('TreeViewService', () => { - let service: TreeViewService; let nodeService: NodesApiService; - const fakeNodeList = new NodePaging({ list: { entries: [ - { entry: { id: 'fake-node-id', name: 'fake-node-name', isFolder: true } } - ] } }); + const fakeNodeList = new NodePaging({ + list: { + entries: [ + { + entry: new Node({ + id: 'fake-node-id', + name: 'fake-node-name', + isFolder: true, + isFile: false, + nodeType: 'cm:folder', + createdByUser: null, + modifiedByUser: null, + createdAt: new Date(), + modifiedAt: new Date() + }) + } + ] + } + }); - const fakeMixedNodeList = new NodePaging({ list: { entries: [ - { entry: { id: 'fake-node-id', name: 'fake-node-name', isFolder: true } }, - { entry: { id: 'fake-file-id', name: 'fake-file-name', isFolder: false } } - ] } }); + const fakeMixedNodeList = new NodePaging({ + list: { entries: [fakeNodeList.list.entries[0], { entry: new Node({ id: 'fake-file-id', name: 'fake-file-name', isFolder: false }) }] } + }); beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ContentTestingModule - ] + imports: [TranslateModule.forRoot(), ContentTestingModule] }); service = TestBed.inject(TreeViewService); nodeService = TestBed.inject(NodesApiService); diff --git a/lib/content-services/src/lib/upload/components/upload-button.component.spec.ts b/lib/content-services/src/lib/upload/components/upload-button.component.spec.ts index 44542c6e83..9d042173e3 100644 --- a/lib/content-services/src/lib/upload/components/upload-button.component.spec.ts +++ b/lib/content-services/src/lib/upload/components/upload-button.component.spec.ts @@ -19,7 +19,7 @@ import { SimpleChange } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { of, throwError } from 'rxjs'; import { UploadButtonComponent } from './upload-button.component'; -import { NodeEntry } from '@alfresco/js-api'; +import { Node, NodeEntry } from '@alfresco/js-api'; import { ContentTestingModule } from '../../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { mockUploadErrorPromise } from '../../mock/upload.service.mock'; @@ -28,7 +28,6 @@ import { NodesApiService } from '../../common/services/nodes-api.service'; import { FileUploadErrorEvent } from '../../common/events/file.event'; describe('UploadButtonComponent', () => { - const file = { name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json' }; const fakeEvent = { currentTarget: { @@ -38,15 +37,7 @@ describe('UploadButtonComponent', () => { }; const fakeFolderNodeWithPermission = new NodeEntry({ - entry: { - allowableOperations: [ - 'create', - 'update' - ], - isFolder: true, - name: 'Folder Fake Name', - nodeType: 'cm:folder' - } + entry: new Node({ name: 'Folder Fake Name', nodeType: 'cm:folder', isFolder: true, allowableOperations: ['create', 'update'] }) }); let component: UploadButtonComponent; @@ -56,10 +47,7 @@ describe('UploadButtonComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ContentTestingModule - ] + imports: [TranslateModule.forRoot(), ContentTestingModule] }); fixture = TestBed.createComponent(UploadButtonComponent); uploadService = TestBed.inject(UploadService); @@ -214,11 +202,7 @@ describe('UploadButtonComponent', () => { }); describe('fileSize', () => { - - const files: File[] = [ - { name: 'bigFile.png', size: 1000 } as File, - { name: 'smallFile.png', size: 10 } as File - ]; + const files: File[] = [{ name: 'bigFile.png', size: 1000 } as File, { name: 'smallFile.png', size: 10 } as File]; let addToQueueSpy; @@ -245,9 +229,7 @@ describe('UploadButtonComponent', () => { }); it('should allow file of 0 size when the max file size is set to 0', () => { - const zeroFiles: File[] = [ - { name: 'zeroFile.png', size: 0 } as File - ]; + const zeroFiles: File[] = [{ name: 'zeroFile.png', size: 0 } as File]; component.maxFilesSize = 0; component.uploadFiles(zeroFiles); @@ -284,12 +266,7 @@ describe('UploadButtonComponent', () => { }); describe('uploadFiles', () => { - - const files: File[] = [ - { name: 'phobos.jpg' } as File, - { name: 'deimos.png' } as File, - { name: 'ganymede.bmp' } as File - ]; + const files: File[] = [{ name: 'phobos.jpg' } as File, { name: 'deimos.png' } as File, { name: 'ganymede.bmp' } as File]; let addToQueueSpy; @@ -344,8 +321,7 @@ describe('UploadButtonComponent', () => { beforeEach(() => { spyOn(uploadService, 'uploadFilesInTheQueue').and.stub(); - fakeNodeWithNoPermission = { - }; + fakeNodeWithNoPermission = {}; }); it('should not call uploadFiles for node without permission', () => { diff --git a/lib/content-services/src/lib/version-manager/version-list.component.spec.ts b/lib/content-services/src/lib/version-manager/version-list.component.spec.ts index 956d1f3164..009f928eb4 100644 --- a/lib/content-services/src/lib/version-manager/version-list.component.spec.ts +++ b/lib/content-services/src/lib/version-manager/version-list.component.spec.ts @@ -21,7 +21,7 @@ import { By } from '@angular/platform-browser'; import { VersionListComponent } from './version-list.component'; import { MatDialog } from '@angular/material/dialog'; import { of } from 'rxjs'; -import { Node, VersionPaging, VersionEntry, NodeEntry } from '@alfresco/js-api'; +import { Node, VersionPaging, NodeEntry, VersionEntry, Version } from '@alfresco/js-api'; import { ContentTestingModule } from '../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { ContentVersionService } from './content-version.service'; @@ -36,8 +36,8 @@ describe('VersionListComponent', () => { const versionId = '1.0'; const versionTest = [ - { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } } as VersionEntry, - { entry: { name: 'test-file-name-two', id: '1.0', versionComment: 'test-version-comment' } } as VersionEntry + new VersionEntry({ entry: new Version({ name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' }) }), + new VersionEntry({ entry: new Version({ name: 'test-file-name-two', id: '1.0', versionComment: 'test-version-comment' }) }) ]; afterEach(() => { @@ -47,10 +47,7 @@ describe('VersionListComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ContentTestingModule - ], + imports: [TranslateModule.forRoot(), ContentTestingModule], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(VersionListComponent); @@ -61,7 +58,7 @@ describe('VersionListComponent', () => { component.node = { id: nodeId, allowableOperations: ['update'] } as Node; spyOn(component, 'downloadContent').and.stub(); - spyOn(component.nodesApi, 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ entry: { id: 'nodeInfoId' } }))); + spyOn(component.nodesApi, 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ entry: new Node({ id: 'nodeInfoId' }) }))); }); it('should raise confirmation dialog on delete', () => { @@ -84,7 +81,7 @@ describe('VersionListComponent', () => { afterClosed: () => of(true) } as any); - spyOn(component.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true)); + spyOn(component.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve()); component.deleteVersion(versionId); @@ -99,7 +96,7 @@ describe('VersionListComponent', () => { afterClosed: () => of(false) } as any); - spyOn(component.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true)); + spyOn(component.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve()); component.deleteVersion(versionId); @@ -118,10 +115,8 @@ describe('VersionListComponent', () => { }); describe('Version history fetching', () => { - it('should use loading bar', () => { - spyOn(component.versionsApi, 'listVersionHistory').and - .callFake(() => Promise.resolve({ list: { entries: versionTest } })); + spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve({ list: { entries: versionTest } })); let loadingProgressBar = fixture.debugElement.query(By.css('[data-automation-id="version-history-loading-bar"]')); expect(loadingProgressBar).toBeNull(); @@ -134,8 +129,7 @@ describe('VersionListComponent', () => { }); it('should load the versions for a given id', () => { - spyOn(component.versionsApi, 'listVersionHistory').and - .callFake(() => Promise.resolve({ list: { entries: versionTest } })); + spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve({ list: { entries: versionTest } })); component.ngOnChanges(); fixture.detectChanges(); @@ -145,15 +139,15 @@ describe('VersionListComponent', () => { it('should show the versions after loading', (done) => { fixture.detectChanges(); - spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({ - list: { - entries: [ - { - entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } + spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => + Promise.resolve( + new VersionPaging({ + list: { + entries: [versionTest[0]] } - ] - } - }))); + }) + ) + ); component.ngOnChanges(); @@ -171,18 +165,15 @@ describe('VersionListComponent', () => { }); it('should NOT show the versions comments if input property is set not to show them', (done) => { - spyOn(component.versionsApi, 'listVersionHistory').and - .callFake(() => Promise.resolve( + spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => + Promise.resolve( new VersionPaging({ list: { - entries: [ - { - entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } - } - ] + entries: [versionTest[0]] } }) - )); + ) + ); component.showComments = false; fixture.detectChanges(); @@ -199,14 +190,9 @@ describe('VersionListComponent', () => { }); it('should be able to download a version', () => { - const versionEntry = { - entry: { - name: 'test-file-name', - id: '1.0', - versionComment: 'test-version-comment' - } - }; - spyOn(component.versionsApi, 'listVersionHistory').and.returnValue(Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } }))); + spyOn(component.versionsApi, 'listVersionHistory').and.returnValue( + Promise.resolve(new VersionPaging({ list: { entries: [versionTest[0]] } })) + ); spyOn(contentVersionService.contentApi, 'getContentUrl').and.returnValue('the/download/url'); fixture.detectChanges(); @@ -223,15 +209,9 @@ describe('VersionListComponent', () => { }); it('should NOT be able to download a version if configured so', () => { - const versionEntry = { - entry: { - name: 'test-file-name', - id: '1.0', - versionComment: 'test-version-comment' - } - }; - spyOn(component.versionsApi, 'listVersionHistory').and - .callFake(() => Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } }))); + spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => + Promise.resolve(new VersionPaging({ list: { entries: [versionTest[0]] } })) + ); const spyOnDownload = spyOn(component.contentApi, 'getContentUrl').and.stub(); component.allowDownload = false; @@ -243,7 +223,6 @@ describe('VersionListComponent', () => { }); describe('Version restoring', () => { - it('should restore version only when restore allowed', () => { component.node.allowableOperations = []; spyOn(component.versionsApi, 'revertVersion').and.stub(); @@ -255,9 +234,7 @@ describe('VersionListComponent', () => { fixture.detectChanges(); component.versions = versionTest; - const spyOnRevertVersion = spyOn(component.versionsApi, 'revertVersion').and - .callFake(() => Promise.resolve(new VersionEntry( - { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } }))); + const spyOnRevertVersion = spyOn(component.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve(versionTest[0])); component.restore(versionId); @@ -267,12 +244,9 @@ describe('VersionListComponent', () => { it('should get node info after restoring the node', fakeAsync(() => { fixture.detectChanges(); component.versions = versionTest; - spyOn(component.versionsApi, 'listVersionHistory') - .and.callFake(() => Promise.resolve({ list: { entries: versionTest } })); + spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve({ list: { entries: versionTest } })); - spyOn(component.versionsApi, 'revertVersion') - .and.callFake(() => Promise.resolve(new VersionEntry( - { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } }))); + spyOn(component.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve(versionTest[0])); component.restore(versionId); fixture.detectChanges(); @@ -284,12 +258,9 @@ describe('VersionListComponent', () => { it('should emit with node info data', fakeAsync(() => { fixture.detectChanges(); component.versions = versionTest; - spyOn(component.versionsApi, 'listVersionHistory') - .and.callFake(() => Promise.resolve({ list: { entries: versionTest } })); + spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve({ list: { entries: versionTest } })); - spyOn(component.versionsApi, 'revertVersion') - .and.callFake(() => Promise.resolve(new VersionEntry( - { entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } }))); + spyOn(component.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve(versionTest[0])); spyOn(component.restored, 'emit'); @@ -304,8 +275,9 @@ describe('VersionListComponent', () => { fixture.detectChanges(); component.versions = versionTest; - const spyOnListVersionHistory = spyOn(component.versionsApi, 'listVersionHistory').and - .callFake(() => Promise.resolve({ list: { entries: versionTest } })); + const spyOnListVersionHistory = spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => + Promise.resolve({ list: { entries: versionTest } }) + ); spyOn(component.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve(null)); component.restore(versionId); @@ -329,18 +301,16 @@ describe('VersionListComponent', () => { beforeEach(() => { fixture.detectChanges(); - spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({ - list: { - entries: [ - { - entry: { name: 'test-file-two', id: '1.1', versionComment: 'test-version-comment' } - }, - { - entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } + versionTest[1].entry.id = '1.1'; + spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => + Promise.resolve( + new VersionPaging({ + list: { + entries: versionTest } - ] - } - }))); + }) + ) + ); }); describe('showActions', () => { @@ -373,7 +343,6 @@ describe('VersionListComponent', () => { }); describe('disabled', () => { - beforeEach(() => { component.node = { id: nodeId } as Node; component.ngOnChanges(); @@ -406,7 +375,6 @@ describe('VersionListComponent', () => { }); describe('enabled', () => { - beforeEach(() => { component.node = { id: nodeId, allowableOperations: ['update', 'delete'] } as Node; component.ngOnChanges(); @@ -425,7 +393,7 @@ describe('VersionListComponent', () => { it('should enable restore action if is allowed', (done) => { fixture.whenStable().then(() => { - expect(getRestoreButton().disabled).toBeFalse(); + expect(getRestoreButton('1.1').disabled).toBeFalse(); done(); }); }); diff --git a/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts b/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts index b4964b5a08..0dd5c41991 100644 --- a/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts +++ b/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts @@ -18,7 +18,7 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { Node, VersionPaging } from '@alfresco/js-api'; +import { Node, Version, VersionEntry, VersionPaging } from '@alfresco/js-api'; import { VersionManagerComponent } from './version-manager.component'; import { ContentTestingModule } from '../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; @@ -31,25 +31,16 @@ describe('VersionManagerComponent', () => { let nodesApiService: NodesApiService; const expectedComment = 'test-version-comment'; - const node: Node = new Node({ + const node: Node = new Node({ id: '1234', name: 'TEST-NODE', isFile: true }); - const versionEntry = { - entry: { - id: '1.0', - name: node.name, - versionComment: expectedComment - } - }; + const versionEntry = new VersionEntry({ entry: new Version({ id: '1.0', name: node.name, versionComment: expectedComment }) }); beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - ContentTestingModule - ], + imports: [TranslateModule.forRoot(), ContentTestingModule], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(VersionManagerComponent); @@ -57,8 +48,9 @@ describe('VersionManagerComponent', () => { component.node = node; nodesApiService = TestBed.inject(NodesApiService); - spyOnListVersionHistory = spyOn(component.versionListComponent['versionsApi'], 'listVersionHistory').and - .callFake(() => Promise.resolve(new VersionPaging({ list: { entries: [ versionEntry ] }}))); + spyOnListVersionHistory = spyOn(component.versionListComponent['versionsApi'], 'listVersionHistory').and.callFake(() => + Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } })) + ); }); it('should load the versions for a given node', () => { @@ -92,7 +84,7 @@ describe('VersionManagerComponent', () => { it('should emit success event upon successful upload of a new version', async () => { fixture.detectChanges(); - const emittedData = { value: { entry: node }}; + const emittedData = { value: { entry: node } }; await component.uploadSuccess.subscribe((event) => { expect(event).toBe(node); }); @@ -105,12 +97,11 @@ describe('VersionManagerComponent', () => { expect(res).toEqual(node); }); - const emittedData = { value: { entry: node }}; + const emittedData = { value: { entry: node } }; component.onUploadSuccess(emittedData); }); describe('Animation', () => { - it('should upload button be hide by default', () => { fixture.detectChanges(); @@ -126,5 +117,5 @@ describe('VersionManagerComponent', () => { expect(component.uploadState).toEqual('open'); }); - }); + }); }); diff --git a/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.spec.ts b/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.spec.ts index e5dc4d355b..0654d4ddef 100644 --- a/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.spec.ts +++ b/lib/content-services/src/lib/viewer/components/alfresco-viewer.component.spec.ts @@ -24,7 +24,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { AppExtensionService, ViewerExtensionRef } from '@alfresco/adf-extensions'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; -import { NodeEntry, VersionEntry } from '@alfresco/js-api'; +import { ContentInfo, Node, NodeEntry, VersionEntry } from '@alfresco/js-api'; import { AlfrescoViewerComponent, NodeActionsService, RenditionService } from '@alfresco/adf-content-services'; import { CoreTestingModule, EventMock, ViewUtilService, ViewerComponent } from '@alfresco/adf-core'; import { NodesApiService } from '../../common/services/nodes-api.service'; @@ -45,8 +45,7 @@ import { By } from '@angular/platform-browser'; ` }) -class ViewerWithCustomToolbarComponent { -} +class ViewerWithCustomToolbarComponent {} @Component({ selector: 'adf-viewer-container-toolbar-actions', @@ -60,8 +59,7 @@ class ViewerWithCustomToolbarComponent { ` }) -class ViewerWithCustomToolbarActionsComponent { -} +class ViewerWithCustomToolbarActionsComponent {} @Component({ selector: 'adf-viewer-container-sidebar', @@ -73,15 +71,13 @@ class ViewerWithCustomToolbarActionsComponent { ` }) -class ViewerWithCustomSidebarComponent { -} +class ViewerWithCustomSidebarComponent {} @Component({ selector: 'adf-dialog-dummy', template: `` }) -class DummyDialogComponent { -} +class DummyDialogComponent {} @Component({ selector: 'adf-viewer-container-open-with', @@ -104,8 +100,7 @@ class DummyDialogComponent { ` }) -class ViewerWithCustomOpenWithComponent { -} +class ViewerWithCustomOpenWithComponent {} @Component({ selector: 'adf-viewer-container-more-actions', @@ -128,12 +123,9 @@ class ViewerWithCustomOpenWithComponent { ` }) -class ViewerWithCustomMoreActionsComponent { -} - +class ViewerWithCustomMoreActionsComponent {} describe('AlfrescoViewerComponent', () => { - let component: AlfrescoViewerComponent; let fixture: ComponentFixture; let element: HTMLElement; @@ -148,13 +140,7 @@ describe('AlfrescoViewerComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - NoopAnimationsModule, - TranslateModule.forRoot(), - CoreTestingModule, - MatButtonModule, - MatIconModule - ], + imports: [NoopAnimationsModule, TranslateModule.forRoot(), CoreTestingModule, MatButtonModule, MatIconModule], declarations: [ ViewerWithCustomToolbarComponent, ViewerWithCustomSidebarComponent, @@ -164,12 +150,13 @@ describe('AlfrescoViewerComponent', () => { ], providers: [ { - provide: RenditionService, useValue: { + provide: RenditionService, + useValue: { getNodeRendition: () => throwError('thrown'), generateMediaTracksRendition: () => {} } }, - {provide: Location, useClass: SpyLocation}, + { provide: Location, useClass: SpyLocation }, MatDialog ], schemas: [CUSTOM_ELEMENTS_SCHEMA] @@ -191,11 +178,8 @@ describe('AlfrescoViewerComponent', () => { fixture.destroy(); }); - describe('Extension Type Test', () => { - - - it('should use external viewer to display node by id', fakeAsync(() => { + it('should use external viewer to display node by id', fakeAsync(() => { const extension: ViewerExtensionRef = { component: 'custom.component', id: 'custom.component.id', @@ -210,7 +194,7 @@ describe('AlfrescoViewerComponent', () => { element = fixture.nativeElement; component = fixture.componentInstance; - spyOn(component.nodesApi, 'getNode').and.callFake(() => Promise.resolve(new NodeEntry({entry: {}}))); + spyOn(component.nodesApi, 'getNode').and.callFake(() => Promise.resolve(new NodeEntry({ entry: new Node() }))); component.nodeId = '37f7f34d-4e64-4db6-bb3f-5c89f7844251'; component.ngOnChanges(); @@ -223,20 +207,17 @@ describe('AlfrescoViewerComponent', () => { expect(renditionService.generateMediaTracksRendition).not.toHaveBeenCalled(); expect(element.querySelector('[data-automation-id="custom.component"]')).not.toBeNull(); })); - - }); describe('MimeType handling', () => { - it('should node without content show unkonwn', (done) => { const displayName = 'the-name'; const contentUrl = '/content/url/path'; component.nodeId = '12'; - spyOn(component['nodesApi'], 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ - entry: {content: {name: displayName, id: '12'}} - }))); + spyOn(component['nodesApi'], 'getNode').and.returnValue( + Promise.resolve(new NodeEntry({ entry: new Node({ name: displayName, id: '12', content: new ContentInfo() }) })) + ); spyOn(component['contentApi'], 'getContentUrl').and.returnValue(contentUrl); @@ -251,8 +232,8 @@ describe('AlfrescoViewerComponent', () => { it('should change display name every time node changes', fakeAsync(() => { spyOn(component['nodesApi'], 'getNode').and.returnValues( - Promise.resolve(new NodeEntry({entry: {name: 'file1', content: {}}})), - Promise.resolve(new NodeEntry({entry: {name: 'file2', content: {}}})) + Promise.resolve(new NodeEntry({ entry: new Node({ name: 'file1', content: new ContentInfo() }) })), + Promise.resolve(new NodeEntry({ entry: new Node({ name: 'file2', content: new ContentInfo() }) })) ); component.showViewer = true; @@ -272,13 +253,15 @@ describe('AlfrescoViewerComponent', () => { it('should append version of the file to the file content URL', fakeAsync(() => { spyOn(component['nodesApi'], 'getNode').and.returnValue( - Promise.resolve(new NodeEntry({ - entry: { - name: 'file1.pdf', - content: {}, - properties: {'cm:versionLabel': '10'} - } - })) + Promise.resolve( + new NodeEntry({ + entry: new Node({ + name: 'file1.pdf', + content: new ContentInfo(), + properties: { 'cm:versionLabel': '10' } + }) + }) + ) ); spyOn(component['versionsApi'], 'getVersion').and.returnValue(Promise.resolve(undefined)); @@ -293,14 +276,14 @@ describe('AlfrescoViewerComponent', () => { expect(component.urlFileContent).toContain('/public/alfresco/versions/1/nodes/id1/content?attachment=false&10'); })); - it('should change display name every time node\`s version changes', fakeAsync(() => { + it('should change display name every time node`s version changes', fakeAsync(() => { spyOn(component['nodesApi'], 'getNode').and.returnValue( - Promise.resolve(new NodeEntry({entry: {name: 'node1', content: {}}})) + Promise.resolve(new NodeEntry({ entry: new Node({ name: 'node1', content: new ContentInfo() }) })) ); spyOn(component['versionsApi'], 'getVersion').and.returnValues( - Promise.resolve(new VersionEntry({entry: {name: 'file1', content: {}}})), - Promise.resolve(new VersionEntry({entry: {name: 'file2', content: {}}})) + Promise.resolve(new VersionEntry({ entry: new Node({ name: 'file1', content: new ContentInfo() }) })), + Promise.resolve(new VersionEntry({ entry: new Node({ name: 'file2', content: new ContentInfo() }) })) ); component.nodeId = 'id1'; @@ -321,7 +304,7 @@ describe('AlfrescoViewerComponent', () => { it('should update node only if node name changed', fakeAsync(() => { spyOn(component['nodesApi'], 'getNode').and.returnValues( - Promise.resolve(new NodeEntry({entry: {name: 'file1', content: {}}})) + Promise.resolve(new NodeEntry({ entry: new Node({ name: 'file1', content: new ContentInfo() }) })) ); component.showViewer = true; @@ -333,15 +316,15 @@ describe('AlfrescoViewerComponent', () => { expect(component.fileName).toBe('file1'); - nodesApiService.nodeUpdated.next({id: 'id1', name: 'file2'} as any); + nodesApiService.nodeUpdated.next({ id: 'id1', name: 'file2' } as any); fixture.detectChanges(); expect(component.fileName).toBe('file2'); - nodesApiService.nodeUpdated.next({id: 'id1', name: 'file3'} as any); + nodesApiService.nodeUpdated.next({ id: 'id1', name: 'file3' } as any); fixture.detectChanges(); expect(component.fileName).toBe('file3'); - nodesApiService.nodeUpdated.next({id: 'id2', name: 'file4'} as any); + nodesApiService.nodeUpdated.next({ id: 'id2', name: 'file4' } as any); fixture.detectChanges(); expect(component.fileName).toBe('file3'); expect(component.nodeId).toBe('id1'); @@ -357,7 +340,6 @@ describe('AlfrescoViewerComponent', () => { }); describe('Viewer Example Component Rendering', () => { - it('should use custom toolbar', (done) => { const customFixture = TestBed.createComponent(ViewerWithCustomToolbarComponent); const customElement: HTMLElement = customFixture.nativeElement; @@ -414,7 +396,6 @@ describe('AlfrescoViewerComponent', () => { expect(customElement.querySelector('.adf-viewer-container-more-actions')).toBeDefined(); done(); }); - }); it('should stop propagation on sidebar keydown event [keydown]', fakeAsync(() => { @@ -447,10 +428,8 @@ describe('AlfrescoViewerComponent', () => { }); describe('error handling', () => { - it('should show unknown view when node file not found', (done) => { - spyOn(component['nodesApi'], 'getNode') - .and.returnValue(Promise.reject({})); + spyOn(component['nodesApi'], 'getNode').and.returnValue(Promise.reject(new Error('error'))); component.nodeId = 'the-node-id-of-the-file-to-preview'; component.mimeType = null; @@ -464,8 +443,7 @@ describe('AlfrescoViewerComponent', () => { }); it('should show unknown view when sharedLink file not found', (done) => { - spyOn(component['sharedLinksApi'], 'getSharedLink') - .and.returnValue(Promise.reject({})); + spyOn(component['sharedLinksApi'], 'getSharedLink').and.returnValue(Promise.reject(new Error('error'))); component.sharedLinkId = 'the-Shared-Link-id'; component.mimeType = null; @@ -477,12 +455,10 @@ describe('AlfrescoViewerComponent', () => { expect(element.querySelector('adf-viewer-unknown-format')).not.toBeNull(); done(); }); - }); it('should raise an event when the shared link is invalid', fakeAsync(() => { - spyOn(component['sharedLinksApi'], 'getSharedLink') - .and.returnValue(Promise.reject({})); + spyOn(component['sharedLinksApi'], 'getSharedLink').and.returnValue(Promise.reject(new Error('error'))); component.sharedLinkId = 'the-Shared-Link-id'; component.mimeType = null; @@ -494,11 +470,10 @@ describe('AlfrescoViewerComponent', () => { component.ngOnChanges(); })); -// + // }); describe('Toolbar', () => { - it('should show only next file button', async () => { component.allowNavigate = true; component.canNavigateBefore = false; @@ -658,7 +633,7 @@ describe('AlfrescoViewerComponent', () => { component.nodeId = '12'; const displayName = 'the-name'; const nodeDetails = { - entry: {name: displayName, id: '12', content: {mimeType: 'txt'}} + entry: new Node({ name: displayName, id: '12', content: new ContentInfo({ mimeType: 'txt' }) }) }; const contentUrl = '/content/url/path'; @@ -687,8 +662,7 @@ describe('AlfrescoViewerComponent', () => { }); it('should not render close viewer button if it is a shared link', (done) => { - spyOn(component['sharedLinksApi'], 'getSharedLink') - .and.returnValue(Promise.reject({})); + spyOn(component['sharedLinksApi'], 'getSharedLink').and.returnValue(Promise.reject(new Error('error'))); component.sharedLinkId = 'the-Shared-Link-id'; component.mimeType = null; @@ -700,11 +674,9 @@ describe('AlfrescoViewerComponent', () => { done(); }); }); - }); describe('Base component', () => { - beforeEach(() => { component.mimeType = 'application/pdf'; component.nodeId = 'id1'; @@ -713,7 +685,6 @@ describe('AlfrescoViewerComponent', () => { }); describe('SideBar Test', () => { - it('should NOT display sidebar if is not allowed', (done) => { component.showRightSidebar = true; component.allowRightSidebar = false; @@ -748,7 +719,6 @@ describe('AlfrescoViewerComponent', () => { expect(sidebar).toBeNull(); done(); }); - }); it('should display sidebar on the left side', (done) => { @@ -765,9 +735,7 @@ describe('AlfrescoViewerComponent', () => { }); describe('View', () => { - describe('Overlay mode true', () => { - beforeEach(() => { component.overlayMode = true; component.fileName = 'fake-test-file.pdf'; @@ -843,7 +811,6 @@ describe('AlfrescoViewerComponent', () => { }); describe('Overlay mode false', () => { - beforeEach(() => { component.overlayMode = false; fixture.detectChanges(); @@ -863,7 +830,6 @@ describe('AlfrescoViewerComponent', () => { }); describe('Attribute', () => { - it('should FileNodeId present not thrown any error ', () => { component.showViewer = true; component.nodeId = 'file-node-id'; @@ -873,7 +839,6 @@ describe('AlfrescoViewerComponent', () => { }).not.toThrow(); }); - it('should showViewer default value be true', () => { expect(component.showViewer).toBe(true); }); @@ -887,22 +852,18 @@ describe('AlfrescoViewerComponent', () => { }); describe('Events', () => { - it('should update version when emitted by image-viewer and user has update permissions', () => { - spyOn(uploadService, 'uploadFilesInTheQueue').and.callFake(() => { - }); + spyOn(uploadService, 'uploadFilesInTheQueue').and.callFake(() => {}); spyOn(uploadService, 'addToQueue'); component.readOnly = false; component.nodeEntry = new NodeEntry({ - entry: { - name: 'fakeImage.png', - id: '12', - content: {mimeType: 'img/png'} - } + entry: new Node({ name: 'fakeImage.png', id: '12', content: new ContentInfo({ mimeType: 'img/png' }) }) }); const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='); - const fakeBlob = new Blob([data], {type: 'image/png'}); - const newImageFile: File = new File([fakeBlob], component?.nodeEntry?.entry?.name, {type: component?.nodeEntry?.entry?.content?.mimeType}); + const fakeBlob = new Blob([data], { type: 'image/png' }); + const newImageFile: File = new File([fakeBlob], component?.nodeEntry?.entry?.name, { + type: component?.nodeEntry?.entry?.content?.mimeType + }); const newFile = new FileModel( newImageFile, { @@ -921,24 +882,18 @@ describe('AlfrescoViewerComponent', () => { }); it('should not update version when emitted by image-viewer and user doesn`t have update permissions', () => { - spyOn(uploadService, 'uploadFilesInTheQueue').and.callFake(() => { - }); + spyOn(uploadService, 'uploadFilesInTheQueue').and.callFake(() => {}); component.readOnly = true; component.nodeEntry = new NodeEntry({ - entry: { - name: 'fakeImage.png', - id: '12', - content: {mimeType: 'img/png'} - } + entry: new Node({ name: 'fakeImage.png', id: '12', content: new ContentInfo({ mimeType: 'img/png' }) }) }); const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='); - const fakeBlob = new Blob([data], {type: 'image/png'}); + const fakeBlob = new Blob([data], { type: 'image/png' }); component.onSubmitFile(fakeBlob); fixture.detectChanges(); expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled(); }); }); - }); }); diff --git a/lib/core/package.json b/lib/core/package.json index b3612f3a96..eff427ad94 100644 --- a/lib/core/package.json +++ b/lib/core/package.json @@ -35,7 +35,7 @@ "@angular/router": ">=14.1.3", "@mat-datetimepicker/core": "^10.1.1", "@mat-datetimepicker/moment": "^10.1.1", - "@alfresco/js-api": ">=6.3.0-1108", + "@alfresco/js-api": ">=6.3.0-1271", "@alfresco/adf-extensions": ">=6.2.0", "@ngx-translate/core": ">=14.0.0", "minimatch-browser": ">=1.0.0", diff --git a/lib/core/src/lib/comments/comment-list/mocks/comment-list.mock.ts b/lib/core/src/lib/comments/comment-list/mocks/comment-list.mock.ts index 2482fa6148..07baf64216 100644 --- a/lib/core/src/lib/comments/comment-list/mocks/comment-list.mock.ts +++ b/lib/core/src/lib/comments/comment-list/mocks/comment-list.mock.ts @@ -15,14 +15,15 @@ * limitations under the License. */ +import { User } from '../../../../..'; import { CommentModel } from '../../../models/comment.model'; -export const testUser = { +export const testUser = new User({ id: '1', firstName: 'Test', lastName: 'User', email: 'tu@domain.com' -}; +}); export const mockCommentOne = new CommentModel({ id: 1, @@ -42,29 +43,25 @@ export const commentUserPictureDefined = new CommentModel({ id: 2, message: '2nd Test Comment', created: new Date(), - createdBy: { + createdBy: new User({ enabled: true, firstName: 'some', lastName: 'one', email: 'some-one@somegroup.com', - emailNotificationsEnabled: true, - company: {}, id: 'fake-email@dom.com', avatarId: '001-001-001' - } + }) }); export const commentUserNoPictureDefined = new CommentModel({ id: 2, message: '2nd Test Comment', created: new Date(), - createdBy: { + createdBy: new User({ enabled: true, firstName: 'some', lastName: 'one', email: 'some-one@somegroup.com', - emailNotificationsEnabled: true, - company: {}, id: 'fake-email@dom.com' - } + }) }); diff --git a/lib/core/src/lib/comments/mocks/comments.service.mock.ts b/lib/core/src/lib/comments/mocks/comments.service.mock.ts index 4775c0d5ee..91acee71ac 100644 --- a/lib/core/src/lib/comments/mocks/comments.service.mock.ts +++ b/lib/core/src/lib/comments/mocks/comments.service.mock.ts @@ -31,87 +31,35 @@ export class CommentsServiceMock implements Partial { } } +const commentUser = new User({ + enabled: true, + firstName: 'hruser', + displayName: 'hruser', + id: 'hruser', + email: 'test' +}); + export const commentsResponseMock = { getComments: () => of([ new CommentModel({ id: 1, message: 'Test Comment', created: new Date(), - createdBy: { - enabled: true, - firstName: 'hruser', - displayName: 'hruser', - quota: -1, - quotaUsed: 12, - emailNotificationsEnabled: true, - company: { - organization: 'test', - address1: 'test', - address2: 'test', - address3: 'test', - postcode: 'test', - telephone: 'test', - fax: 'test', - email: 'test' - }, - id: 'hruser', - email: 'test', - isAdmin: () => false - } as User, + createdBy: commentUser, isSelected: false }), new CommentModel({ id: 2, message: 'Test Comment', created: new Date(), - createdBy: { - enabled: true, - firstName: 'hruser', - displayName: 'hruser', - quota: -1, - quotaUsed: 12, - emailNotificationsEnabled: true, - company: { - organization: 'test', - address1: 'test', - address2: 'test', - address3: 'test', - postcode: 'test', - telephone: 'test', - fax: 'test', - email: 'test' - }, - id: 'hruser', - email: 'test', - isAdmin: () => false - } as User, + createdBy: commentUser, isSelected: false }), new CommentModel({ id: 3, message: 'Test Comment', created: new Date(), - createdBy: { - enabled: true, - firstName: 'hruser', - displayName: 'hruser', - quota: -1, - quotaUsed: 12, - emailNotificationsEnabled: true, - company: { - organization: 'test', - address1: 'test', - address2: 'test', - address3: 'test', - postcode: 'test', - telephone: 'test', - fax: 'test', - email: 'test' - }, - id: 'hruser', - email: 'test', - isAdmin: () => false - } as User, + createdBy: commentUser, isSelected: false }) ]), @@ -120,27 +68,7 @@ export const commentsResponseMock = { id: 1, message, created: new Date(), - createdBy: { - enabled: true, - firstName: 'hruser', - displayName: 'hruser', - quota: -1, - quotaUsed: 12, - emailNotificationsEnabled: true, - company: { - organization: 'test', - address1: 'test', - address2: 'test', - address3: 'test', - postcode: 'test', - telephone: 'test', - fax: 'test', - email: 'test' - }, - id: 'hruser', - email: 'test', - isAdmin: () => false - } as User, + createdBy: commentUser, isSelected: false }) ) diff --git a/lib/core/src/lib/comments/mocks/comments.service.stories.mock.ts b/lib/core/src/lib/comments/mocks/comments.service.stories.mock.ts index 549ee649a2..e5c95568ae 100644 --- a/lib/core/src/lib/comments/mocks/comments.service.stories.mock.ts +++ b/lib/core/src/lib/comments/mocks/comments.service.stories.mock.ts @@ -15,11 +15,10 @@ * limitations under the License. */ -import { CommentModel } from '../../models'; +import { CommentModel, User } from '../../models'; import { Observable, of } from 'rxjs'; import { CommentsService } from '../interfaces/comments-service.interface'; import { testUser } from './comments.stories.mock'; -import { UserLike } from '../../pipes/user-like.interface'; export class CommentsServiceStoriesMock implements Partial { @@ -33,87 +32,35 @@ export class CommentsServiceStoriesMock implements Partial { } } +const commentUser = new User({ + enabled: true, + firstName: 'hruser', + displayName: 'hruser', + id: 'hruser', + email: 'test' +}); + export const commentsResponseMock = { getComments: () => of([ new CommentModel({ id: 1, message: 'Test Comment', created: new Date(), - createdBy: { - enabled: true, - firstName: 'hruser', - displayName: 'hruser', - quota: -1, - quotaUsed: 12, - emailNotificationsEnabled: true, - company: { - organization: 'test', - address1: 'test', - address2: 'test', - address3: 'test', - postcode: 'test', - telephone: 'test', - fax: 'test', - email: 'test' - }, - id: 'hruser', - email: 'test', - isAdmin: () => false - } as UserLike, + createdBy: commentUser, isSelected: false }), new CommentModel({ id: 2, message: 'Test Comment', created: new Date(), - createdBy: { - enabled: true, - firstName: 'hruser', - displayName: 'hruser', - quota: -1, - quotaUsed: 12, - emailNotificationsEnabled: true, - company: { - organization: 'test', - address1: 'test', - address2: 'test', - address3: 'test', - postcode: 'test', - telephone: 'test', - fax: 'test', - email: 'test' - }, - id: 'hruser', - email: 'test', - isAdmin: () => false - } as UserLike, + createdBy: commentUser, isSelected: false }), new CommentModel({ id: 3, message: 'Test Comment', created: new Date(), - createdBy: { - enabled: true, - firstName: 'hruser', - displayName: 'hruser', - quota: -1, - quotaUsed: 12, - emailNotificationsEnabled: true, - company: { - organization: 'test', - address1: 'test', - address2: 'test', - address3: 'test', - postcode: 'test', - telephone: 'test', - fax: 'test', - email: 'test' - }, - id: 'hruser', - email: 'test', - isAdmin: () => false - } as UserLike, + createdBy: commentUser, isSelected: false }) ]), diff --git a/lib/core/src/lib/models/comment.model.ts b/lib/core/src/lib/models/comment.model.ts index 72e1b7dcdc..b2763b76d2 100644 --- a/lib/core/src/lib/models/comment.model.ts +++ b/lib/core/src/lib/models/comment.model.ts @@ -18,14 +18,14 @@ import { User } from './general-user.model'; export class CommentModel { - id: number; + id: string | number; message: string; created: Date; createdBy: User; isSelected: boolean; get hasAvatarPicture(): boolean { - return !!(this.createdBy['pictureId'] || this.createdBy['avatarId']); + return !!this.createdBy && !!(this.createdBy['pictureId'] || this.createdBy['avatarId']); } get userDisplayName(): string { @@ -51,7 +51,7 @@ export class CommentModel { return result.toUpperCase(); } - constructor(obj?: any) { + constructor(obj?: Partial) { if (obj) { this.id = obj.id; this.message = obj.message; diff --git a/lib/core/src/lib/models/general-user.model.ts b/lib/core/src/lib/models/general-user.model.ts index 40a27e9975..05eff49d28 100644 --- a/lib/core/src/lib/models/general-user.model.ts +++ b/lib/core/src/lib/models/general-user.model.ts @@ -15,6 +15,23 @@ * limitations under the License. */ -import { IdentityUserModel } from '../auth/models/identity-user.model'; +export class User { + displayName?: string; + username?: string; + id?: string | number; + firstName?: string; + lastName?: string; + email?: string; + createdTimestamp?: any; + emailVerified?: boolean; + enabled?: boolean; + readonly?: boolean; + pictureId?: number; + avatarId: string; -export type User = (IdentityUserModel) & { displayName?: string } & { username?: string }; + constructor(user?: Partial) { + if (user) { + Object.assign(this, user); + } + } +}; diff --git a/lib/extensions/package.json b/lib/extensions/package.json index 22b661bc59..fb0e1e4f75 100644 --- a/lib/extensions/package.json +++ b/lib/extensions/package.json @@ -14,7 +14,7 @@ "peerDependencies": { "@angular/common": ">=14.1.3", "@angular/core": ">=14.1.3", - "@alfresco/js-api": ">=6.3.0-1108" + "@alfresco/js-api": ">=6.3.0-1271" }, "keywords": [ "extensions", diff --git a/lib/process-services-cloud/package.json b/lib/process-services-cloud/package.json index e8c5623bc7..610cd289ae 100644 --- a/lib/process-services-cloud/package.json +++ b/lib/process-services-cloud/package.json @@ -35,7 +35,7 @@ "@angular/platform-browser": ">=14.1.3", "@angular/platform-browser-dynamic": ">=14.1.3", "@angular/router": ">=14.1.3", - "@alfresco/js-api": ">=6.3.0-1108", + "@alfresco/js-api": ">=6.3.0-1271", "@alfresco/adf-core": ">=6.2.0", "@alfresco/adf-content-services": ">=6.2.0", "@apollo/client": "^3.7.2", diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts index b9fe37c1dd..8679464252 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts @@ -104,7 +104,7 @@ export class FormCloudService extends BaseCloudService implements FormCloudServi file, '', nodeId, - '', + null, { overwrite: true } )).pipe( map((res: any) => res.entry) diff --git a/lib/process-services-cloud/src/lib/form/services/process-cloud-content.service.ts b/lib/process-services-cloud/src/lib/form/services/process-cloud-content.service.ts index 2f86830853..43a3f3a05e 100644 --- a/lib/process-services-cloud/src/lib/form/services/process-cloud-content.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/process-cloud-content.service.ts @@ -58,7 +58,7 @@ export class ProcessCloudContentService { ): Observable { return from( - this.uploadApi.uploadFile(file, '', nodeId, '', {overwrite: true}) + this.uploadApi.uploadFile(file, '', nodeId, null, {overwrite: true}) ).pipe( map((res: any) => ({ ...res.entry, diff --git a/lib/process-services/package.json b/lib/process-services/package.json index 83f0729aa5..6017c71dba 100644 --- a/lib/process-services/package.json +++ b/lib/process-services/package.json @@ -21,7 +21,7 @@ "@angular/platform-browser": ">=14.1.3", "@angular/platform-browser-dynamic": ">=14.1.3", "@angular/router": ">=14.1.3", - "@alfresco/js-api": ">=6.3.0-1108", + "@alfresco/js-api": ">=6.3.0-1271", "@alfresco/adf-core": ">=6.2.0", "@alfresco/adf-content-services": ">=6.2.0", "@ngx-translate/core": ">=14.0.0", diff --git a/lib/process-services/src/lib/form/services/activiti-alfresco.service.ts b/lib/process-services/src/lib/form/services/activiti-alfresco.service.ts index 2c6196aaf1..49d84cc09b 100644 --- a/lib/process-services/src/lib/form/services/activiti-alfresco.service.ts +++ b/lib/process-services/src/lib/form/services/activiti-alfresco.service.ts @@ -64,7 +64,7 @@ export class ActivitiContentService { * @param tenantId * @param includeAccount */ - getAlfrescoRepositories(tenantId?: number, includeAccount?: boolean): Observable { + getAlfrescoRepositories(tenantId?: string, includeAccount?: boolean): Observable { const opts = { tenantId, includeAccounts: includeAccount ? includeAccount : true diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts index 988be084c0..664148ac19 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts @@ -25,7 +25,7 @@ import { AuthenticationService, AlfrescoApiService } from '@alfresco/adf-core'; import { AttachFileWidgetDialogComponentData } from './attach-file-widget-dialog-component.interface'; import { of, throwError } from 'rxjs'; import { By } from '@angular/platform-browser'; -import { Node, SiteEntry, NodeEntry, SitePaging } from '@alfresco/js-api'; +import { Node, SiteEntry, NodeEntry, SitePaging, SitePagingList } from '@alfresco/js-api'; import { TranslateModule } from '@ngx-translate/core'; describe('AttachFileWidgetDialogComponent', () => { @@ -78,7 +78,7 @@ describe('AttachFileWidgetDialogComponent', () => { spyOn(nodeService, 'getNode').and.returnValue(of(new Node({ id: 'fake-node', path: { elements: [{ nodeType: 'st:site', name: 'fake-site'}] } }))); spyOn(siteService, 'getSite').and.returnValue(of(fakeSite)); - spyOn(siteService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); + spyOn(siteService, 'getSites').and.returnValue(of(new SitePaging({ list: new SitePagingList({ entries: [] }) }))); spyOn(widget, 'isLoggedIn').and.callFake(() => isLogged); }); diff --git a/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts b/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts index 1525eeef48..971cf54ead 100644 --- a/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts @@ -34,7 +34,7 @@ import { ProcessContentService } from '../../services/process-content.service'; const fakePngAnswer = new RelatedContentRepresentation({ id: 1155, name: 'a_png_file.png', - created: '2017-07-25T17:17:37.099Z', + created: new Date('2017-07-25T17:17:37.099Z'), createdBy: {id: 1001, firstName: 'Admin', lastName: 'admin', email: 'admin'}, relatedContent: false, contentAvailable: true, diff --git a/lib/process-services/src/lib/mock/process/process-comments.mock.ts b/lib/process-services/src/lib/mock/process/process-comments.mock.ts index 62c2dd0e19..e74571a767 100644 --- a/lib/process-services/src/lib/mock/process/process-comments.mock.ts +++ b/lib/process-services/src/lib/mock/process/process-comments.mock.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import { CommentModel } from '@alfresco/adf-core'; +import { CommentModel, User } from '@alfresco/adf-core'; export const mockProcessInstanceComments = [ - new CommentModel({ message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }), - new CommentModel({ message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }), - new CommentModel({ message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }) + new CommentModel({ message: 'Test1', created: new Date(), createdBy: new User({firstName: 'Admin', lastName: 'User'}) }), + new CommentModel({ message: 'Test2', created: new Date(), createdBy: new User({firstName: 'Admin', lastName: 'User'}) }), + new CommentModel({ message: 'Test3', created: new Date(), createdBy: new User({firstName: 'Admin', lastName: 'User'}) }) ]; diff --git a/lib/process-services/src/lib/mock/task/task-details.mock.ts b/lib/process-services/src/lib/mock/task/task-details.mock.ts index f0373aedb4..c6eafb8385 100644 --- a/lib/process-services/src/lib/mock/task/task-details.mock.ts +++ b/lib/process-services/src/lib/mock/task/task-details.mock.ts @@ -911,8 +911,8 @@ export const fakeUser = new UserRepresentation({ password: null, type: 'enterprise', status: 'active', - created: '2020-08-14T09:21:52.306Z', - lastUpdate: '2020-08-14T09:22:48.147Z', + created: new Date('2020-08-14T09:21:52.306Z'), + lastUpdate: new Date('2020-08-14T09:22:48.147Z'), tenantId: 310, groups: [ { diff --git a/lib/process-services/src/lib/process-comments/services/comment-process.service.ts b/lib/process-services/src/lib/process-comments/services/comment-process.service.ts index a155d2e9b8..1dbec8bdda 100644 --- a/lib/process-services/src/lib/process-comments/services/comment-process.service.ts +++ b/lib/process-services/src/lib/process-comments/services/comment-process.service.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { Observable, from, throwError } from 'rxjs'; -import { CommentModel, AlfrescoApiService, LogService, CommentsService } from '@alfresco/adf-core'; +import { CommentModel, AlfrescoApiService, LogService, CommentsService, User } from '@alfresco/adf-core'; import { map, catchError } from 'rxjs/operators'; import { ActivitiCommentsApi } from '@alfresco/js-api'; import { PeopleProcessService } from '../../common/services/people-process.service'; @@ -57,7 +57,7 @@ export class CommentProcessService implements CommentsService { id: comment.id, message: comment.message, created: comment.created, - createdBy: user + createdBy: new User(user) })); }); return comments; @@ -81,7 +81,7 @@ export class CommentProcessService implements CommentsService { id: response.id, message: response.message, created: response.created, - createdBy: response.createdBy + createdBy: new User(response.createdBy) })), catchError((err: any) => this.handleError(err)) ); @@ -92,7 +92,7 @@ export class CommentProcessService implements CommentsService { return throwError(error || 'Server error'); } - getUserImage(user: any): string { + getUserImage(user: UserProcessModel): string { return this.peopleProcessService.getUserImage(user); } } diff --git a/lib/process-services/src/lib/process-list/models/filter-process.model.ts b/lib/process-services/src/lib/process-list/models/filter-process.model.ts index 96f32df63b..2b5a3737b6 100644 --- a/lib/process-services/src/lib/process-list/models/filter-process.model.ts +++ b/lib/process-services/src/lib/process-list/models/filter-process.model.ts @@ -16,7 +16,7 @@ */ import { - ProcessFilterRequestRepresentation, + ProcessInstanceQueryRepresentation, ProcessInstanceFilterRepresentation, UserProcessInstanceFilterRepresentation } from '@alfresco/js-api'; @@ -50,7 +50,7 @@ export class FilterProcessRepresentationModel implements UserProcessInstanceFilt /** * This object represent the parameters of a process filter. */ -export class ProcessFilterParamRepresentationModel implements ProcessFilterRequestRepresentation { +export class ProcessFilterParamRepresentationModel implements ProcessInstanceQueryRepresentation { processDefinitionId?: string; processInstanceId?: string; diff --git a/lib/process-services/src/lib/task-comments/services/task-comments.service.ts b/lib/process-services/src/lib/task-comments/services/task-comments.service.ts index 4d2c16f4de..12b9c5f87a 100644 --- a/lib/process-services/src/lib/task-comments/services/task-comments.service.ts +++ b/lib/process-services/src/lib/task-comments/services/task-comments.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AlfrescoApiService, CommentModel, CommentsService } from '@alfresco/adf-core'; +import { AlfrescoApiService, CommentModel, CommentsService, User } from '@alfresco/adf-core'; import { ActivitiCommentsApi, CommentRepresentation } from '@alfresco/js-api'; import { Injectable } from '@angular/core'; import { from, Observable, throwError } from 'rxjs'; @@ -100,7 +100,7 @@ export class TaskCommentsService implements CommentsService { id: representation.id, message: representation.message, created: representation.created, - createdBy: representation.createdBy + createdBy: new User(representation.createdBy) }); } diff --git a/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts index fda4a5b997..b2697659fa 100644 --- a/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts @@ -24,7 +24,8 @@ import { FormOutcomeEvent, FormOutcomeModel, LogService, - CommentModel + CommentModel, + User } from '@alfresco/adf-core'; import { TaskDetailsModel } from '../models/task-details.model'; import { @@ -101,9 +102,9 @@ describe('TaskDetailsComponent', () => { taskCommentsService = TestBed.inject(TaskCommentsService); spyOn(taskCommentsService, 'get').and.returnValue(of([ - new CommentModel({ message: 'Test1', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }), - new CommentModel({ message: 'Test2', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }), - new CommentModel({ message: 'Test3', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }) + new CommentModel({ message: 'Test1', created: new Date(), createdBy: new User({ firstName: 'Admin', lastName: 'User' }) }), + new CommentModel({ message: 'Test2', created: new Date(), createdBy: new User({ firstName: 'Admin', lastName: 'User' }) }), + new CommentModel({ message: 'Test3', created: new Date(), createdBy: new User({ firstName: 'Admin', lastName: 'User' }) }) ])); fixture = TestBed.createComponent(TaskDetailsComponent); diff --git a/lib/testing/package.json b/lib/testing/package.json index 52202677c8..0c1bafa6ab 100644 --- a/lib/testing/package.json +++ b/lib/testing/package.json @@ -11,7 +11,7 @@ "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, "peerDependencies": { - "@alfresco/js-api": ">=6.3.0-1108" + "@alfresco/js-api": ">=6.3.0-1271" }, "keywords": [ "testing", diff --git a/lib/testing/src/lib/protractor/content-services/actions/model.actions.ts b/lib/testing/src/lib/protractor/content-services/actions/model.actions.ts index b2077c3fdb..bc1567ab53 100644 --- a/lib/testing/src/lib/protractor/content-services/actions/model.actions.ts +++ b/lib/testing/src/lib/protractor/content-services/actions/model.actions.ts @@ -49,7 +49,7 @@ export class ModelActions { return this.customModelApi.deactivateCustomModel(modelName); } - async deleteCustomModel(modelName: string): Promise<{ entry: CustomModel }> { + async deleteCustomModel(modelName: string): Promise { return this.customModelApi.deleteCustomModel(modelName); } diff --git a/package-lock.json b/package-lock.json index c219df37f1..e48aa2e83b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { - "@alfresco/js-api": "6.3.0-1108", + "@alfresco/js-api": "6.3.0-1271", "@angular/animations": "14.1.3", "@angular/cdk": "14.1.2", "@angular/common": "14.1.3", @@ -158,9 +158,9 @@ } }, "node_modules/@alfresco/js-api": { - "version": "6.3.0-1108", - "resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-6.3.0-1108.tgz", - "integrity": "sha512-U7YlT6HVsO14OdTi4g0l4MckgugioSfHCUnoAk0KVDQWk/j5CKl+GGIq71mf2ram2L3o9XB/oNhbFSo2cfilTA==", + "version": "6.3.0-1271", + "resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-6.3.0-1271.tgz", + "integrity": "sha512-Q/zZeZt9V5di8acKeSEPXGmTf5gNyj7PQgPvVFq3Fgvsqjj4P2v5WcRQJbumeMK/Snk8bsWwYQk5Lh/Aau3cyA==", "dependencies": { "event-emitter": "^0.3.5", "superagent": "^8.0.9", diff --git a/package.json b/package.json index 4b1aa31f2a..77963f9c05 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "process services-cloud" ], "dependencies": { - "@alfresco/js-api": "6.3.0-1108", + "@alfresco/js-api": "6.3.0-1271", "@angular/animations": "14.1.3", "@angular/cdk": "14.1.2", "@angular/common": "14.1.3",