From 5773b88ab4d690b1de827b04b13b5e4344436dd1 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 24 Aug 2016 15:17:39 +0100 Subject: [PATCH 1/8] #543 dedicated AlfrescoApi service --- demo-shell-ng2/systemjs.config.js | 6 ++- ng2-components/ng2-alfresco-core/index.ts | 2 + .../src/services/AlfrescoApi.service.ts | 34 +++++++++++++++++ .../AlfrescoAuthentication.service.ts | 37 +++++++++++-------- .../ng2-alfresco-core/src/services/index.ts | 1 + 5 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 ng2-components/ng2-alfresco-core/src/services/AlfrescoApi.service.ts diff --git a/demo-shell-ng2/systemjs.config.js b/demo-shell-ng2/systemjs.config.js index 70c4466d67..726992d104 100644 --- a/demo-shell-ng2/systemjs.config.js +++ b/demo-shell-ng2/systemjs.config.js @@ -20,7 +20,8 @@ 'ng2-activiti-form': 'node_modules/ng2-activiti-form/dist', 'ng2-alfresco-viewer': 'node_modules/ng2-alfresco-viewer/dist', 'ng2-alfresco-webscript': 'node_modules/ng2-alfresco-webscript/dist', - 'ng2-activiti-tasklist': 'node_modules/ng2-activiti-tasklist/dist' + 'ng2-activiti-tasklist': 'node_modules/ng2-activiti-tasklist/dist', + 'alfresco-js-api': 'node_modules/alfresco-js-api/dist' }; // packages tells the System loader how to load when no filename and/or no extension var packages = { @@ -39,7 +40,8 @@ 'ng2-alfresco-viewer': { main: 'index.js', defaultExtension: 'js'}, 'ng2-activiti-form': { main: 'index.js', defaultExtension: 'js'}, 'ng2-activiti-tasklist': { main: 'index.js', defaultExtension: 'js'}, - 'ng2-alfresco-webscript': { main: 'index.js', defaultExtension: 'js'} + 'ng2-alfresco-webscript': { main: 'index.js', defaultExtension: 'js'}, + 'alfresco-js-api': { main: 'alfresco-js-api.js', defaultExtension: 'js'} }; var ngPackageNames = [ 'common', diff --git a/ng2-components/ng2-alfresco-core/index.ts b/ng2-components/ng2-alfresco-core/index.ts index 231df2fe5b..be1f41d742 100644 --- a/ng2-components/ng2-alfresco-core/index.ts +++ b/ng2-components/ng2-alfresco-core/index.ts @@ -16,6 +16,7 @@ */ import { + AlfrescoApiService, AlfrescoSettingsService, AlfrescoTranslationLoader, AlfrescoTranslationService, @@ -31,6 +32,7 @@ export * from './src/components/index'; export * from './src/utils/index'; export const ALFRESCO_CORE_PROVIDERS: [any] = [ + AlfrescoApiService, AlfrescoAuthenticationService, AlfrescoContentService, AlfrescoSettingsService, diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoApi.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoApi.service.ts new file mode 100644 index 0000000000..f71d5f5df5 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoApi.service.ts @@ -0,0 +1,34 @@ +/*! + * @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 { Injectable } from '@angular/core'; +import { AlfrescoJsApi } from 'alfresco-js-api'; + +@Injectable() +export class AlfrescoApiService { + + private _instance: AlfrescoJsApi; + + public getInstance(): AlfrescoJsApi { + return this._instance; + } + + public setInstance(value: AlfrescoJsApi) { + this._instance = value; + } + +} diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts index ba92bff800..9a22bdbde2 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -15,11 +15,13 @@ * limitations under the License. */ -import {Injectable} from '@angular/core'; -import {Observable} from 'rxjs/Rx'; -import {AlfrescoSettingsService} from './AlfrescoSettings.service'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Rx'; +import { AlfrescoSettingsService } from './AlfrescoSettings.service'; +import { AlfrescoApiService } from './AlfrescoApi.service'; +import { AlfrescoJsApi } from 'alfresco-js-api'; -declare let AlfrescoApi: any; +declare var AlfrescoApi: AlfrescoJsApi; /** * The AlfrescoAuthenticationService provide the login service and store the ticket in the localStorage @@ -27,32 +29,37 @@ declare let AlfrescoApi: any; @Injectable() export class AlfrescoAuthenticationService { - alfrescoApi: any; + alfrescoApi: AlfrescoJsApi; - /**A + /** * Constructor - * @param alfrescoSetting + * @param settingsService + * @param apiService */ - constructor(public alfrescoSetting: AlfrescoSettingsService) { + constructor(private settingsService: AlfrescoSettingsService, + private apiService: AlfrescoApiService) { this.alfrescoApi = new AlfrescoApi({ - provider: this.alfrescoSetting.getProviders(), + provider: this.settingsService.getProviders(), ticketEcm: this.getTicketEcm(), ticketBpm: this.getTicketBpm(), - hostEcm: this.alfrescoSetting.ecmHost, - hostBpm: this.alfrescoSetting.bpmHost + hostEcm: this.settingsService.ecmHost, + hostBpm: this.settingsService.bpmHost, + contextRoot: 'alfresco' }); - alfrescoSetting.bpmHostSubject.subscribe((bpmHost) => { + settingsService.bpmHostSubject.subscribe((bpmHost) => { this.alfrescoApi.changeBpmHost(bpmHost); }); - alfrescoSetting.ecmHostSubject.subscribe((ecmHost) => { + settingsService.ecmHostSubject.subscribe((ecmHost) => { this.alfrescoApi.changeEcmHost(ecmHost); }); - alfrescoSetting.providerSubject.subscribe((value) => { + settingsService.providerSubject.subscribe((value) => { this.alfrescoApi.config.provider = value; }); + + this.apiService.setInstance(this.alfrescoApi); } /** @@ -73,7 +80,7 @@ export class AlfrescoAuthenticationService { return Observable.fromPromise(this.callApiLogin(username, password)) .map((response: any) => { this.saveTickets(); - return {type: this.alfrescoSetting.getProviders(), ticket: response}; + return {type: this.settingsService.getProviders(), ticket: response}; }) .catch(this.handleError); } diff --git a/ng2-components/ng2-alfresco-core/src/services/index.ts b/ng2-components/ng2-alfresco-core/src/services/index.ts index 7c013a4b4c..b4d963d6e1 100644 --- a/ng2-components/ng2-alfresco-core/src/services/index.ts +++ b/ng2-components/ng2-alfresco-core/src/services/index.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +export * from './AlfrescoApi.service'; export * from './AlfrescoSettings.service'; export * from './AlfrescoTranslationLoader.service'; export * from './AlfrescoTranslation.service'; From f08796a3d2af70fa1000629bc752331c04f8511f Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 24 Aug 2016 17:46:55 +0100 Subject: [PATCH 2/8] Improved type safety --- .../AlfrescoAuthentication.service.spec.ts | 29 ++++++++++--------- .../AlfrescoAuthentication.service.ts | 4 +-- .../src/services/AlfrescoContent.spec.ts | 2 ++ .../src/components/document-list.ts | 2 +- .../services/document-list.service.spec.ts | 4 ++- .../src/services/document-list.service.ts | 14 ++++----- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts index 34e9ccf2f6..18273cbe1d 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts @@ -19,19 +19,26 @@ import {it, describe, beforeEach, afterEach} from '@angular/core/testing'; import {ReflectiveInjector, provide} from '@angular/core'; import {AlfrescoSettingsService} from './AlfrescoSettings.service'; import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service'; +import { AlfrescoApiService } from './AlfrescoApi.service'; declare var AlfrescoApi: any; declare let jasmine: any; describe('AlfrescoAuthentication', () => { - let injector, authService; + let injector; + let authService: AlfrescoAuthenticationService; + let settingsService: AlfrescoSettingsService; beforeEach(() => { injector = ReflectiveInjector.resolveAndCreate([ - provide(AlfrescoSettingsService, {useClass: AlfrescoSettingsService}), + AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService ]); + authService = injector.get(AlfrescoAuthenticationService); + settingsService = injector.get(AlfrescoSettingsService); + let store = {}; spyOn(localStorage, 'getItem').and.callFake(function (key) { @@ -61,8 +68,7 @@ describe('AlfrescoAuthentication', () => { describe('when the setting is ECM', () => { beforeEach(() => { - authService = injector.get(AlfrescoAuthenticationService); - authService.alfrescoSetting.setProviders('ECM'); + settingsService.setProviders('ECM'); }); it('should return an ECM ticket after the login done', (done) => { @@ -144,8 +150,7 @@ describe('AlfrescoAuthentication', () => { describe('when the setting is BPM', () => { beforeEach(() => { - authService = injector.get(AlfrescoAuthenticationService); - authService.alfrescoSetting.setProviders('BPM'); + settingsService.setProviders('BPM'); }); it('should return an BPM ticket after the login done', (done) => { @@ -212,24 +217,23 @@ describe('AlfrescoAuthentication', () => { describe('Setting service change should reflect in the api', () => { beforeEach(() => { - authService = injector.get(AlfrescoAuthenticationService); - authService.alfrescoSetting.setProviders('ALL'); + settingsService.setProviders('ALL'); }); it('should host ecm url change be reflected in the api configuration', () => { - authService.alfrescoSetting.ecmHost = '127.99.99.99'; + settingsService.ecmHost = '127.99.99.99'; expect(authService.getAlfrescoApi().config.hostEcm).toBe('127.99.99.99'); }); it('should host bpm url change be reflected in the api configuration', () => { - authService.alfrescoSetting.bpmHost = '127.99.99.99'; + settingsService.bpmHost = '127.99.99.99'; expect(authService.getAlfrescoApi().config.hostBpm).toBe('127.99.99.99'); }); it('should host bpm provider change be reflected in the api configuration', () => { - authService.alfrescoSetting.setProviders('ECM'); + settingsService.setProviders('ECM'); expect(authService.getAlfrescoApi().config.provider).toBe('ECM'); }); @@ -239,8 +243,7 @@ describe('AlfrescoAuthentication', () => { describe('when the setting is both ECM and BPM ', () => { beforeEach(() => { - authService = injector.get(AlfrescoAuthenticationService); - authService.providers = 'ALL'; + settingsService.setProviders('ALL'); }); it('should return both ECM and BPM tickets after the login done', (done) => { diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts index 9a22bdbde2..174c626ae2 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -76,7 +76,7 @@ export class AlfrescoAuthenticationService { * @param password * @returns {Observable|Observable} */ - login(username: string, password: string) { + login(username: string, password: string): Observable<{ type: string, ticket: any }> { return Observable.fromPromise(this.callApiLogin(username, password)) .map((response: any) => { this.saveTickets(); @@ -196,7 +196,7 @@ export class AlfrescoAuthenticationService { return Observable.throw(error || 'Server error'); } - getAlfrescoApi(): any { + getAlfrescoApi(): AlfrescoJsApi { return this.alfrescoApi; } } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts index 922f976d63..064fb7f0b2 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts @@ -20,6 +20,7 @@ import {ReflectiveInjector} from '@angular/core'; import {AlfrescoSettingsService} from './AlfrescoSettings.service'; import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service'; import {AlfrescoContentService} from './AlfrescoContent.service'; +import { AlfrescoApiService } from './AlfrescoApi.service'; describe('AlfrescoContentService', () => { @@ -29,6 +30,7 @@ describe('AlfrescoContentService', () => { beforeEach(() => { injector = ReflectiveInjector.resolveAndCreate([ + AlfrescoApiService, AlfrescoContentService, AlfrescoAuthenticationService, AlfrescoSettingsService diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts index 54394d654c..36e2f87ada 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts @@ -30,6 +30,7 @@ import { HostListener } from '@angular/core'; import { Subject } from 'rxjs/Rx'; +import { MinimalNodeEntity } from 'alfresco-js-api'; import { CONTEXT_MENU_DIRECTIVES, AlfrescoTranslationService @@ -43,7 +44,6 @@ import { } from 'ng2-alfresco-datatable'; import { DocumentListService } from './../services/document-list.service'; -import { MinimalNodeEntity } from './../models/document-library.model'; import { ContentActionModel } from './../models/content-action.model'; import { ShareDataTableAdapter, diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.spec.ts b/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.spec.ts index 21bb90e4c5..036d9eacde 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.spec.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.spec.ts @@ -24,7 +24,8 @@ import { import { AlfrescoSettingsService, AlfrescoAuthenticationService, - AlfrescoContentService + AlfrescoContentService, + AlfrescoApiService } from 'ng2-alfresco-core'; import { FileNode } from '../assets/document-library.model.mock'; import { ReflectiveInjector } from '@angular/core'; @@ -42,6 +43,7 @@ describe('DocumentListService', () => { beforeEach(() => { injector = ReflectiveInjector.resolveAndCreate([ HTTP_PROVIDERS, + AlfrescoApiService, AlfrescoAuthenticationService, AlfrescoSettingsService ]); diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.ts b/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.ts index dced40e264..c73b96182c 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.ts @@ -18,14 +18,12 @@ import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { Observable } from 'rxjs/Rx'; -import { NodePaging, MinimalNodeEntity } from './../models/document-library.model'; +import { AlfrescoJsApi, NodePaging, MinimalNodeEntity } from 'alfresco-js-api'; import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core'; -declare let AlfrescoApi: any; - @Injectable() export class DocumentListService { @@ -66,11 +64,11 @@ export class DocumentListService { ) { } - private getAlfrescoApi() { + private getAlfrescoApi(): AlfrescoJsApi { return this.authService.getAlfrescoApi(); } - private getNodesPromise(folder: string, opts?: any) { + private getNodesPromise(folder: string, opts?: any): Promise { let nodeId = '-root-'; let params: any = { relativePath: folder, @@ -86,11 +84,11 @@ export class DocumentListService { } } - return this.getAlfrescoApi().node.getNodeChildren(nodeId, params); + return this.getAlfrescoApi().nodes.getNodeChildren(nodeId, params); } - deleteNode(nodeId: string) { - return Observable.fromPromise(this.getAlfrescoApi().node.deleteNode(nodeId)); + deleteNode(nodeId: string): Observable { + return Observable.fromPromise(this.getAlfrescoApi().nodes.deleteNode(nodeId)); } /** From dee7166a262a3b1a00761f4f97b8db5f0ac06fb2 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 24 Aug 2016 18:12:41 +0100 Subject: [PATCH 3/8] Improved type safety --- .../services/AlfrescoAuthentication.service.spec.ts | 8 ++++---- .../ng2-alfresco-viewer/src/viewer.component.spec.ts | 3 ++- .../ng2-alfresco-viewer/src/viewer.component.ts | 12 ++++++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts index 18273cbe1d..97a14e3c9a 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import {it, describe, beforeEach, afterEach} from '@angular/core/testing'; -import {ReflectiveInjector, provide} from '@angular/core'; -import {AlfrescoSettingsService} from './AlfrescoSettings.service'; -import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service'; +import { it, describe, beforeEach, afterEach } from '@angular/core/testing'; +import { ReflectiveInjector } from '@angular/core'; +import { AlfrescoSettingsService } from './AlfrescoSettings.service'; +import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service'; import { AlfrescoApiService } from './AlfrescoApi.service'; declare var AlfrescoApi: any; diff --git a/ng2-components/ng2-alfresco-viewer/src/viewer.component.spec.ts b/ng2-components/ng2-alfresco-viewer/src/viewer.component.spec.ts index a54433b541..f5a2fe863d 100644 --- a/ng2-components/ng2-alfresco-viewer/src/viewer.component.spec.ts +++ b/ng2-components/ng2-alfresco-viewer/src/viewer.component.spec.ts @@ -19,7 +19,7 @@ import {describe, expect, it, inject, beforeEachProviders, beforeEach} from '@an import {TestComponentBuilder} from '@angular/compiler/testing'; import {ViewerComponent} from './viewer.component'; import {EventMock} from './assets/event.mock'; -import {AlfrescoAuthenticationService, AlfrescoSettingsService} from 'ng2-alfresco-core'; +import { AlfrescoApiService, AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; describe('ViewerComponent', () => { @@ -27,6 +27,7 @@ describe('ViewerComponent', () => { beforeEachProviders(() => { return [ + AlfrescoApiService, AlfrescoSettingsService, AlfrescoAuthenticationService ]; diff --git a/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts b/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts index 4fb0dfc7f3..de03a029ac 100644 --- a/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts +++ b/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts @@ -20,7 +20,8 @@ import { PdfViewerComponent } from './pdfViewer.component'; import { ImgViewerComponent } from './imgViewer.component'; import { NotSupportedFormat } from './notSupportedFormat.component'; import { DOCUMENT } from '@angular/platform-browser'; -import { AlfrescoAuthenticationService} from 'ng2-alfresco-core'; +import { MinimalNodeEntryEntity } from 'alfresco-js-api'; +import { AlfrescoApiService } from 'ng2-alfresco-core'; declare let __moduleName: string; @@ -61,7 +62,9 @@ export class ViewerComponent { loaded: boolean = false; - constructor(private authService: AlfrescoAuthenticationService, private element: ElementRef, @Inject(DOCUMENT) private document) { + constructor(private apiService: AlfrescoApiService, + private element: ElementRef, + @Inject(DOCUMENT) private document) { } ngOnChanges(changes) { @@ -72,15 +75,16 @@ export class ViewerComponent { throw new Error('Attribute urlFile or fileNodeId is required'); } return new Promise((resolve) => { + let alfrescoApi = this.apiService.getInstance(); if (this.urlFile) { let filenameFromUrl = this.getFilenameFromUrl(this.urlFile); this.displayName = filenameFromUrl ? filenameFromUrl : ''; this.extension = this.getFileExtension(filenameFromUrl); } else if (this.fileNodeId) { - this.authService.getAlfrescoApi().nodes.getNodeInfo(this.fileNodeId).then((data) => { + alfrescoApi.nodes.getNodeInfo(this.fileNodeId).then((data: MinimalNodeEntryEntity) => { this.mimeType = data.content.mimeType; this.displayName = data.name; - this.urlFile = this.authService.getAlfrescoApi().content.getContentUrl(data.id); + this.urlFile = alfrescoApi.content.getContentUrl(data.id); this.loaded = true; }, function (error) { console.log('This node does not exist'); From 3c662de36ded1f06c5a33e082e9d6b0cc042c6a8 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 30 Aug 2016 14:38:28 +0100 Subject: [PATCH 4/8] Update upload service with Api service --- .../file-uploading-dialog.component.spec.ts | 18 +++++++++++++----- .../components/upload-button.component.spec.ts | 12 ++++++++++-- .../upload-drag-area.component.spec.ts | 3 ++- .../src/services/upload.service.spec.ts | 10 ++++++---- .../src/services/upload.service.ts | 8 ++++---- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts index e72f85c22c..5323da124d 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts @@ -17,14 +17,21 @@ import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; import { TestComponentBuilder } from '@angular/compiler/testing'; -import { FileUploadingDialogComponent } from './file-uploading-dialog.component'; -import { FileModel } from '../models/file.model'; -import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; -import { TranslationMock } from '../assets/translation.service.mock'; -import { UploadService } from '../services/upload.service'; import { Observable } from 'rxjs/Observable'; import { HTTP_PROVIDERS } from '@angular/http'; +import { + AlfrescoTranslationService, + AlfrescoSettingsService, + AlfrescoAuthenticationService, + AlfrescoApiService +} from 'ng2-alfresco-core'; + +import { FileUploadingDialogComponent } from './file-uploading-dialog.component'; +import { FileModel } from '../models/file.model'; +import { TranslationMock } from '../assets/translation.service.mock'; +import { UploadService } from '../services/upload.service'; + describe('FileUploadDialog', () => { let componentFixture; @@ -33,6 +40,7 @@ describe('FileUploadDialog', () => { beforeEachProviders(() => { return [ HTTP_PROVIDERS, + AlfrescoApiService, AlfrescoSettingsService, AlfrescoAuthenticationService, { provide: AlfrescoTranslationService, useClass: TranslationMock }, diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts index 25081c240b..ad311a00ba 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts @@ -17,11 +17,18 @@ import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; import { TestComponentBuilder } from '@angular/compiler/testing'; +import { HTTP_PROVIDERS } from '@angular/http'; + +import { + AlfrescoTranslationService, + AlfrescoSettingsService, + AlfrescoAuthenticationService, + AlfrescoApiService +} from 'ng2-alfresco-core'; + import { UploadButtonComponent } from './upload-button.component'; -import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { TranslationMock } from '../assets/translation.service.mock'; import { UploadService } from '../services/upload.service'; -import { HTTP_PROVIDERS } from '@angular/http'; declare var AlfrescoApi: any; @@ -71,6 +78,7 @@ describe('AlfrescoUploadButton', () => { HTTP_PROVIDERS, AlfrescoSettingsService, AlfrescoAuthenticationService, + AlfrescoApiService, { provide: AlfrescoTranslationService, useClass: TranslationMock }, UploadService ]; diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts index d90e49f0f9..c4c79ae0ec 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts @@ -18,7 +18,7 @@ import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; import { TestComponentBuilder } from '@angular/compiler/testing'; import { UploadDragAreaComponent } from './upload-drag-area.component'; -import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoApiService } from 'ng2-alfresco-core'; import { TranslationMock } from '../assets/translation.service.mock'; import { UploadService } from '../services/upload.service'; import { HTTP_PROVIDERS } from '@angular/http'; @@ -39,6 +39,7 @@ describe('AlfrescoUploadDragArea', () => { HTTP_PROVIDERS, AlfrescoSettingsService, AlfrescoAuthenticationService, + AlfrescoApiService, { provide: AlfrescoTranslationService, useClass: TranslationMock }, UploadService ]; diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts index b0b220c4e5..289b92cb40 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts @@ -18,7 +18,7 @@ import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; import { EventEmitter } from '@angular/core'; import { UploadService } from './upload.service'; -import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { AlfrescoSettingsService, AlfrescoApiService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; declare let AlfrescoApi: any; declare let jasmine: any; @@ -39,14 +39,16 @@ describe('AlfrescoUploadService', () => { beforeEachProviders(() => { return [ AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService, UploadService ]; }); - beforeEach( inject([UploadService], (uploadService: UploadService) => { + beforeEach( inject([UploadService, AlfrescoApiService], (uploadService: UploadService, apiService: AlfrescoApiService) => { jasmine.Ajax.install(); service = uploadService; + apiService.setInstance(new AlfrescoApi({})); })); afterEach(() => { @@ -85,7 +87,7 @@ describe('AlfrescoUploadService', () => { service.uploadFilesInTheQueue('fake-dir', emitter); let request = jasmine.Ajax.requests.mostRecent(); - expect(request.url).toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children'); + expect(request.url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children'); expect(request.method).toBe('POST'); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -107,7 +109,7 @@ describe('AlfrescoUploadService', () => { service.addToQueue(filesFake); service.uploadFilesInTheQueue('', emitter); expect(jasmine.Ajax.requests.mostRecent().url) - .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children'); + .toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children'); jasmine.Ajax.requests.mostRecent().respondWith({ 'status': 404, contentType: 'text/plain', diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts index 897787dbe9..edb55caac0 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -19,7 +19,7 @@ import { EventEmitter, Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import { Observer } from 'rxjs/Observer'; -import { AlfrescoAuthenticationService} from 'ng2-alfresco-core'; +import { AlfrescoApiService } from 'ng2-alfresco-core'; import { FileModel } from '../models/file.model'; /** @@ -42,7 +42,7 @@ export class UploadService { filesUpload$: Observable; totalCompleted$: Observable; - constructor(private authService: AlfrescoAuthenticationService) { + constructor(private apiService: AlfrescoApiService) { this.filesUpload$ = new Observable(observer => this.filesUploadObserverProgressBar = observer).share(); this.totalCompleted$ = new Observable(observer => this.totalCompletedObserver = observer).share(); } @@ -91,7 +91,7 @@ export class UploadService { filesToUpload.forEach((uploadingFileModel: FileModel) => { uploadingFileModel.setUploading(); - let promiseUpload = this.authService.getAlfrescoApi(). + let promiseUpload = this.apiService.getInstance(). upload.uploadFile(uploadingFileModel.file, directory, null, null, {renditions: 'doclib'}) .on('progress', (progress: any) => { uploadingFileModel.setProgres(progress); @@ -161,7 +161,7 @@ export class UploadService { } private callApiCreateFolder(relativePath: string, name: string) { - return this.authService.getAlfrescoApi().node.createFolder(name, relativePath); + return this.apiService.getInstance().nodes.createFolder(name, relativePath); } /** From 8159cc1dd95758d8d627f583610674567eaa4718 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 5 Sep 2016 09:33:42 +0100 Subject: [PATCH 5/8] Code fixes after merge --- ng2-components/ng2-activiti-form/package.json | 3 +-- .../ng2-activiti-form/src/services/node.service.ts | 4 +++- .../ng2-alfresco-upload/src/services/upload.service.ts | 5 ++--- .../ng2-alfresco-viewer/src/componets/viewer.component.ts | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ng2-components/ng2-activiti-form/package.json b/ng2-components/ng2-activiti-form/package.json index d0594e8c52..151a5d824c 100644 --- a/ng2-components/ng2-activiti-form/package.json +++ b/ng2-components/ng2-activiti-form/package.json @@ -65,7 +65,7 @@ "rxjs": "5.0.0-beta.6", "zone.js": "0.6.12", "ng2-translate": "2.2.2", - "ng2-alfresco-core": "0.3.0" + "ng2-alfresco-core": "^0.3.0" }, "peerDependencies": { "material-design-icons": "^2.2.3", @@ -83,7 +83,6 @@ "karma-jasmine": "1.0.2", "karma-jasmine-ajax": "0.1.13", "karma-jasmine-html-reporter": "0.2.0", - "karma-jasmine-ajax": "0.1.13", "karma-mocha-reporter": "2.0.3", "license-check": "1.1.5", "remap-istanbul": "0.6.3", diff --git a/ng2-components/ng2-activiti-form/src/services/node.service.ts b/ng2-components/ng2-activiti-form/src/services/node.service.ts index 10a9c39815..7c52f703a0 100644 --- a/ng2-components/ng2-activiti-form/src/services/node.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/node.service.ts @@ -70,7 +70,9 @@ export class NodeService { relativePath: path }; - return Observable.fromPromise(this.authService.getAlfrescoApi().nodes.addNode('-root-', body, {})); + // TODO: requires update to alfresco-js-api typings + let apiService: any = this.authService.getAlfrescoApi(); + return Observable.fromPromise(apiService.nodes.addNode('-root-', body, {})); } private generateUuid() { diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts index f98b147505..e4c661cae2 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -20,7 +20,6 @@ import { Response } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import { Observer } from 'rxjs/Observer'; import { AlfrescoApiService } from 'ng2-alfresco-core'; -import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { FileModel } from '../models/file.model'; /** @@ -45,7 +44,7 @@ export class UploadService { filesUpload$: Observable; totalCompleted$: Observable; - constructor(private authService: AlfrescoAuthenticationService) { + constructor(private apiService: AlfrescoApiService) { this.filesUpload$ = new Observable(observer => this.filesUploadObserverProgressBar = observer).share(); this.totalCompleted$ = new Observable(observer => this.totalCompletedObserver = observer).share(); } @@ -106,7 +105,7 @@ export class UploadService { filesToUpload.forEach((uploadingFileModel: FileModel) => { uploadingFileModel.setUploading(); - let promiseUpload = this.authService.getAlfrescoApi().upload.uploadFile(uploadingFileModel.file, directory, null, null, opts) + let promiseUpload = this.apiService.getInstance().upload.uploadFile(uploadingFileModel.file, directory, null, null, opts) .on('progress', (progress: any) => { uploadingFileModel.setProgres(progress); this.updateFileListStream(this.queue); diff --git a/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts b/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts index edc1c16db5..4df9c01460 100644 --- a/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts +++ b/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts @@ -23,7 +23,6 @@ import { NotSupportedFormat } from './notSupportedFormat.component'; import { DOCUMENT } from '@angular/platform-browser'; import { MinimalNodeEntryEntity } from 'alfresco-js-api'; import { AlfrescoApiService } from 'ng2-alfresco-core'; -import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; declare let __moduleName: string; From c4a593f9a2933efb7d070e83dacd1e986bc7752a Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 5 Sep 2016 10:23:27 +0100 Subject: [PATCH 6/8] Fix unit tests --- .../ng2-activiti-form/src/services/form.service.spec.ts | 3 ++- .../src/services/activiti-process.service.spec.ts | 3 ++- .../src/services/activiti-tasklist.service.spec.ts | 3 ++- .../alfresco-search-autocomplete.component.spec.ts | 2 ++ .../components/alfresco-search-control.component.spec.ts | 8 +++++++- .../src/components/alfresco-search.component.spec.ts | 2 ++ .../src/services/alfresco-search.service.spec.ts | 3 ++- .../src/services/upload.service.spec.ts | 4 ++-- .../src/webscript.component.spec.ts | 3 ++- 9 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts b/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts index a93a0abe25..577963736e 100644 --- a/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts +++ b/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts @@ -16,7 +16,7 @@ */ import { it, inject, describe, expect, beforeEach, beforeEachProviders, afterEach } from '@angular/core/testing'; -import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core'; import { HTTP_PROVIDERS, Response, ResponseOptions } from '@angular/http'; import { FormService } from './form.service'; import { EcmModelService } from './ecm-model.service'; @@ -32,6 +32,7 @@ describe('FormService', () => { return [ FormService, AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService, EcmModelService, HTTP_PROVIDERS, diff --git a/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.spec.ts b/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.spec.ts index ddfe2d0ab9..a5695d4a21 100644 --- a/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.spec.ts +++ b/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.spec.ts @@ -16,7 +16,7 @@ */ import { it, describe, expect, beforeEachProviders, beforeEach, inject } from '@angular/core/testing'; -import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core'; import { ActivitiProcessService } from './activiti-process.service'; // import { ProcessInstance } from '../models/process-instance'; @@ -28,6 +28,7 @@ describe('ActivitiProcessService', () => { return [ ActivitiProcessService, AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService ]; }); diff --git a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts index 8684988f3a..982d9642f6 100644 --- a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts @@ -17,7 +17,7 @@ import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; import { ActivitiTaskListService } from './activiti-tasklist.service'; -import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoApiService } from 'ng2-alfresco-core'; import { TaskDetailsModel } from '../models/task-details.model'; import { Comment } from '../models/comment.model'; @@ -97,6 +97,7 @@ describe('ActivitiTaskListService', () => { return [ ActivitiTaskListService, AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService ]; }); diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts index dd1474c155..a2a6f261d2 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts @@ -22,6 +22,7 @@ import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.servi import { TranslationMock } from './../assets/translation.service.mock'; import { AlfrescoSearchService } from '../services/alfresco-search.service'; import { + AlfrescoApiService, AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoContentService, @@ -68,6 +69,7 @@ describe('AlfrescoSearchAutocompleteComponent', () => { {provide: AlfrescoTranslationService, useClass: TranslationMock}, AlfrescoThumbnailService, AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService, AlfrescoContentService, AlfrescoSearchService diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts index daaa56deee..f06af22be2 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts @@ -21,7 +21,12 @@ import { TestComponentBuilder } from '@angular/compiler/testing'; import { AlfrescoSearchControlComponent } from './alfresco-search-control.component'; import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service'; import { TranslationMock } from './../assets/translation.service.mock'; -import { AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoContentService, AlfrescoTranslationService +import { + AlfrescoSettingsService, + AlfrescoApiService, + AlfrescoAuthenticationService, + AlfrescoContentService, + AlfrescoTranslationService } from 'ng2-alfresco-core'; import { AlfrescoSearchService } from '../services/alfresco-search.service'; @@ -36,6 +41,7 @@ describe('AlfrescoSearchControlComponent', () => { provide(AlfrescoTranslationService, {useClass: TranslationMock}), AlfrescoThumbnailService, AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService, AlfrescoContentService ]; diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts index d1ac7b7fa7..055a6f043a 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts @@ -24,6 +24,7 @@ import { TranslationMock } from './../assets/translation.service.mock'; import { AlfrescoSearchService } from '../services/alfresco-search.service'; import { AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService, AlfrescoContentService, AlfrescoTranslationService @@ -70,6 +71,7 @@ describe('AlfrescoSearchComponent', () => { {provide: AlfrescoTranslationService, useClass: TranslationMock}, AlfrescoThumbnailService, AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService, AlfrescoContentService ]; diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts index e72f0c8509..64e4062759 100644 --- a/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts @@ -17,7 +17,7 @@ import { it, describe, beforeEach, inject, beforeEachProviders } from '@angular/core/testing'; import { AlfrescoSearchService } from './alfresco-search.service'; -import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core'; declare let jasmine: any; @@ -58,6 +58,7 @@ describe('AlfrescoSearchService', () => { return [ AlfrescoSearchService, AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService ]; }); diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts index 71edad5b85..395aa9ae04 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts @@ -87,7 +87,7 @@ describe('AlfrescoUploadService', () => { service.uploadFilesInTheQueue('fake-dir', emitter); let request = jasmine.Ajax.requests.mostRecent(); - expect(request.url).toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true'); + expect(request.url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true'); expect(request.method).toBe('POST'); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -109,7 +109,7 @@ describe('AlfrescoUploadService', () => { service.addToQueue(filesFake); service.uploadFilesInTheQueue('', emitter); expect(jasmine.Ajax.requests.mostRecent().url) - .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true'); + .toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true'); jasmine.Ajax.requests.mostRecent().respondWith({ 'status': 404, diff --git a/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts b/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts index bdade46782..fd11aa8534 100644 --- a/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts +++ b/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts @@ -19,7 +19,7 @@ import { describe, expect, it, inject, beforeEachProviders, beforeEach, afterEac import { TestComponentBuilder } from '@angular/compiler/testing'; import { WebscriptComponent } from '../src/webscript.component'; -import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core'; declare let jasmine: any; @@ -30,6 +30,7 @@ describe('Test ng2-alfresco-webscript', () => { beforeEachProviders(() => { return [ AlfrescoSettingsService, + AlfrescoApiService, AlfrescoAuthenticationService ]; }); From f5b16468bed9764c6839d209d8eee9b025240254 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 5 Sep 2016 10:59:26 +0100 Subject: [PATCH 7/8] Fix unit tests --- .../src/componets/viewer.component.spec.ts | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.spec.ts b/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.spec.ts index ee7aebff67..d115065589 100644 --- a/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.spec.ts +++ b/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.spec.ts @@ -23,10 +23,12 @@ import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiServ import { RenderingQueueServices } from '../services/rendering-queue.services'; declare let jasmine: any; +declare let AlfrescoApi: any; describe('ViewerComponent', () => { let viewerComponentFixture, element, component; + let apiService: AlfrescoApiService; beforeEachProviders(() => { return [ @@ -37,7 +39,10 @@ describe('ViewerComponent', () => { ]; }); - beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { + beforeEach(inject([TestComponentBuilder, AlfrescoApiService], (tcb: TestComponentBuilder, api: AlfrescoApiService) => { + apiService = api; + apiService.setInstance(new AlfrescoApi({})); + return tcb .createAsync(ViewerComponent) .then(fixture => { @@ -161,27 +166,16 @@ describe('ViewerComponent', () => { }).not.toThrow(); }); - it('If FileNodeId is present the node api should be called', (done) => { + it('If FileNodeId is present the node api should be called', (/*done*/) => { component.showViewer = true; component.fileNodeId = 'file-node-id'; component.urlFile = undefined; - jasmine.Ajax.stubRequest( - 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/file-node-id' - ).andReturn({ - status: 200, - responseText: '{"entry":{"isFile":true,"createdByUser":{"id":"admin","displayName":"Administrator"},' + - '"modifiedAt":"2016-08-05T23:08:22.730+0000","nodeType":"cm:content","content":' + - '{"mimeType":"application/pdf","mimeTypeName":"Adobe PDF Document","sizeInBytes":' + - '381778,"encoding":"UTF-8"},"parentId":"8f2105b4-daaf-4874-9e8a-2152569d109b","createdAt":"2016-08-05T23:08:22.730+0000","isFolder":false,' + - '"modifiedByUser":{"id":"admin","displayName":"Administrator"},"name":"content.pdf","id":' + - '"b8bd4c81-6f2e-4ec2-9c4d-30c97cf42bc8"}}' - }); + let alfrescoApi = apiService.getInstance(); + spyOn(alfrescoApi.nodes, 'getNodeInfo').and.stub(); - component.ngOnChanges().then(() => { - expect(jasmine.Ajax.requests.mostRecent().url.endsWith('nodes/file-node-id')).toBe(true); - done(); - }); + component.ngOnChanges(); + expect(alfrescoApi.nodes.getNodeInfo).toHaveBeenCalledWith(component.fileNodeId); }); it('showViewer default value should be true', () => { From f7f4f65f81f64edc24b7471ff48debb5c1ee90a9 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 5 Sep 2016 12:29:10 +0100 Subject: [PATCH 8/8] Fix missing coma --- demo-shell-ng2/systemjs.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo-shell-ng2/systemjs.config.js b/demo-shell-ng2/systemjs.config.js index 2b0b1daf97..f8375ae5cc 100644 --- a/demo-shell-ng2/systemjs.config.js +++ b/demo-shell-ng2/systemjs.config.js @@ -21,7 +21,7 @@ 'ng2-alfresco-viewer': 'node_modules/ng2-alfresco-viewer/dist', 'ng2-alfresco-webscript': 'node_modules/ng2-alfresco-webscript/dist', 'ng2-activiti-tasklist': 'node_modules/ng2-activiti-tasklist/dist', - 'alfresco-js-api': 'node_modules/alfresco-js-api/dist' + 'alfresco-js-api': 'node_modules/alfresco-js-api/dist', 'ng2-activiti-processlist': 'node_modules/ng2-activiti-processlist/dist' }; // packages tells the System loader how to load when no filename and/or no extension