Denys Vuika 6b24bfb1d4 [ADF-3299] and [ADF-3300] upgrade to Angular and Material 6 (#3579)
* upgrade to HttpClient

* upgrade to Renderer2

* upgrade Document reference

* remove useless test with deprecated ReflectiveInjector

* upgrade to latest typescript

* upgrade libs

* upgrade package scripts

* remove rxjs blacklists and duplicate rules

* add rxjs compat to help with migration

* fix breaking changes

* fix breaking changes in material

* fix breaking changes (material 6)

* upgrade rxjs, ngx-translate and flex layout

* update unit tests

* restore providers

* upgrade deprecated Observable.error

* rebase
fix first configuration problems

* fix style issues commented

* fix core build

* fix lib template errors

* move lib test execution in angular.json

* ignore

* karma conf files

* fix import statement test

* single run option

* update packages reporter

* restore report

* increase timeout

* improve karma conf test configuration

* fix test issues about lint

* fix test analytics

* fix process service test

* content service fix test

* fix logout directive test

* fix core test

* fix build

* update node-sass to latest

* update angular cli dependencies

* improve build script

create directorites and move files only if previous command succeded

* upgrade individual libs to 6.0

* remove old webpack files

* revert sass change

* fix type issues
fix style issues

* fix tslint demo shell issue

* fix peerdependencies

* fix test e2e BC

* package upate

* fix style import issue

* extract-text-webpack-plugin beta

* fix test dist build command

* remove alpha js-api

* fix tslint issue
add banner tslint rule

* upload service fix

* change BC script

* fix test dist script

* increase demo shell timeout test

* verbose copy

* path absolute

* fix script bc

* fix copy part

* fix path warning
fix monaco editor

* remove duplicate header

* remove unused import

* fix align and check ago tests

* add missing import

* fix notification button selector

* [ANGULAR6] fixed core tests

* fix CS test

* fix cs test step 2

* increase travis_wait for dist

* fix attachment PS

* fix checklist test

* use pdf min
2018-08-14 15:42:43 +01:00

244 lines
9.3 KiB
TypeScript

/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AlfrescoApiServiceMock, AlfrescoApiService,
AppConfigService, StorageService, ContentService, setupTestBed, CoreModule, LogService, AppConfigServiceMock } from '@alfresco/adf-core';
import { DocumentListService } from './document-list.service';
declare let jasmine: any;
describe('DocumentListService', () => {
let service: DocumentListService;
let alfrescoApiService: AlfrescoApiService;
let fakeEntryNode = {
'entry': {
'aspectNames': ['cm:auditable'],
'createdAt': '2016-12-06T15:58:32.408+0000',
'isFolder': true,
'isFile': false,
'createdByUser': { 'id': 'admin', 'displayName': 'Administrator' },
'modifiedAt': '2016-12-06T15:58:32.408+0000',
'modifiedByUser': { 'id': 'admin', 'displayName': 'Administrator' },
'name': 'fake-name',
'id': '2214733d-a920-4dbe-af95-4230345fae82',
'nodeType': 'cm:folder',
'parentId': 'ed7ab80e-b398-4bed-b38d-139ae4cc592a'
}
};
let fakeAlreadyExist = {
'error': {
'errorKey': 'Duplicate child name not allowed: empty',
'statusCode': 409,
'briefSummary': '11060002 Duplicate child name not' +
' allowed: empty',
'stackTrace': 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
'descriptionURL': 'https://api-explorer.alfresco.com'
}
};
let fakeFolder = {
'list': {
'pagination': { 'count': 1, 'hasMoreItems': false, 'totalItems': 1, 'skipCount': 0, 'maxItems': 20 },
'entries': [{
'entry': {
'createdAt': '2016-12-06T13:03:14.880+0000',
'path': {
'name': '/Company Home/Sites/swsdp/documentLibrary/empty',
'isComplete': true,
'elements': [{
'id': 'ed7ab80e-b398-4bed-b38d-139ae4cc592a',
'name': 'Company Home'
}, { 'id': '99e1368f-e816-47fc-a8bf-3b358feaf31e', 'name': 'Sites' }, {
'id': 'b4cff62a-664d-4d45-9302-98723eac1319',
'name': 'swsdp'
}, {
'id': '8f2105b4-daaf-4874-9e8a-2152569d109b',
'name': 'documentLibrary'
}, { 'id': '17fa78d2-4d6b-4a46-876b-4b0ea07f7f32', 'name': 'empty' }]
},
'isFolder': true,
'isFile': false,
'createdByUser': { 'id': 'admin', 'displayName': 'Administrator' },
'modifiedAt': '2016-12-06T13:03:14.880+0000',
'modifiedByUser': { 'id': 'admin', 'displayName': 'Administrator' },
'name': 'fake-name',
'id': 'aac546f6-1525-46ff-bf6b-51cb85f3cda7',
'nodeType': 'cm:folder',
'parentId': '17fa78d2-4d6b-4a46-876b-4b0ea07f7f32'
}
}]
}
};
setupTestBed({
imports: [
CoreModule.forRoot()
]
});
beforeEach(() => {
let logService = new LogService(new AppConfigServiceMock(null));
let contentService = new ContentService(null, null, null, null);
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
service = new DocumentListService(null, contentService, alfrescoApiService, logService, null);
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('should create a folder in the path', () => {
service.createFolder('fake-name', 'fake-path').subscribe(
res => {
expect(res).toBeDefined();
expect(res.entry).toBeDefined();
expect(res.entry.isFolder).toBeTruthy();
expect(res.entry.name).toEqual('fake-name');
expect(res.entry.nodeType).toEqual('cm:folder');
}
);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: fakeEntryNode
});
});
it('should emit an error when the folder already exist', () => {
service.createFolder('fake-name', 'fake-path').subscribe(
res => {
},
err => {
expect(err).toBeDefined();
expect(err.status).toEqual(409);
expect(err.response).toBeDefined();
}
);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 409,
contentType: 'json',
responseText: fakeAlreadyExist
});
});
it('should return the folder info', () => {
service.getFolder('/fake-root/fake-name').subscribe(
res => {
expect(res).toBeDefined();
expect(res.list).toBeDefined();
expect(res.list.entries).toBeDefined();
expect(res.list.entries.length).toBe(1);
expect(res.list.entries[0].entry.isFolder).toBeTruthy();
expect(res.list.entries[0].entry.name).toEqual('fake-name');
}
);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: fakeFolder
});
});
it('should add the includeTypes in the request Node Children if required', () => {
let spyGetNodeInfo = spyOn(alfrescoApiService.getInstance().nodes, 'getNodeChildren').and.callThrough();
service.getFolder('/fake-root/fake-name', {}, ['isLocked']);
expect(spyGetNodeInfo).toHaveBeenCalledWith('-root-', {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions', 'isLocked'],
relativePath: '/fake-root/fake-name'
});
});
it('should not add the includeTypes in the request Node Children if is duplicated', () => {
let spyGetNodeInfo = spyOn(alfrescoApiService.getInstance().nodes, 'getNodeChildren').and.callThrough();
service.getFolder('/fake-root/fake-name', {}, ['allowableOperations']);
expect(spyGetNodeInfo).toHaveBeenCalledWith('-root-', {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions'],
relativePath: '/fake-root/fake-name'
});
});
it('should add the includeTypes in the request getFolderNode if required', () => {
let spyGetNodeInfo = spyOn(alfrescoApiService.getInstance().nodes, 'getNodeInfo').and.callThrough();
service.getFolderNode('test-id', ['isLocked']);
expect(spyGetNodeInfo).toHaveBeenCalledWith('test-id', {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions', 'isLocked']
});
});
it('should not add the includeTypes in the request getFolderNode if is duplicated', () => {
let spyGetNodeInfo = spyOn(alfrescoApiService.getInstance().nodes, 'getNodeInfo').and.callThrough();
service.getFolderNode('test-id', ['allowableOperations']);
expect(spyGetNodeInfo).toHaveBeenCalledWith('test-id', {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions']
}
);
});
it('should delete the folder', () => {
service.deleteNode('fake-id').subscribe(
res => {
expect(res).toBeNull();
}
);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 204,
contentType: 'json'
});
});
it('should copy a node', (done) => {
service.copyNode('node-id', 'parent-id').subscribe(done);
expect(jasmine.Ajax.requests.mostRecent().method).toBe('POST');
expect(jasmine.Ajax.requests.mostRecent().url).toContain('/nodes/node-id/copy');
expect(jasmine.Ajax.requests.mostRecent().params).toEqual(JSON.stringify({ targetParentId: 'parent-id' }));
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json' });
});
it('should move a node', (done) => {
service.moveNode('node-id', 'parent-id').subscribe(done);
expect(jasmine.Ajax.requests.mostRecent().method).toBe('POST');
expect(jasmine.Ajax.requests.mostRecent().url).toContain('/nodes/node-id/move');
expect(jasmine.Ajax.requests.mostRecent().params).toEqual(JSON.stringify({ targetParentId: 'parent-id' }));
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json' });
});
});