diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.js b/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.js index d6e36bc464..797e2d3581 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.js +++ b/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.js @@ -49,7 +49,9 @@ System.register(['angular2/core', 'angular2/http', 'rxjs/Observable', '../../../ this.settings = settings; this._host = 'http://127.0.0.1:8080'; this._baseUrlPath = '/alfresco/service/slingshot/doclib/doclist/all/site/'; - this._host = settings.host; + if (settings) { + this._host = settings.host; + } } Object.defineProperty(AlfrescoService.prototype, "host", { get: function () { diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.js.map b/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.js.map index 2c1d113d33..48027f259e 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.js.map +++ b/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.js.map @@ -1 +1 @@ -{"version":3,"file":"alfresco.service.js","sourceRoot":"","sources":["alfresco.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YASH;gBACI,yBACY,IAAU,EACV,QAAiC;oBADjC,SAAI,GAAJ,IAAI,CAAM;oBACV,aAAQ,GAAR,QAAQ,CAAyB;oBAKrC,UAAK,GAAW,uBAAuB,CAAC;oBACxC,iBAAY,GAAW,sDAAsD,CAAC;oBAJlF,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC;gBAC/B,CAAC;gBAKD,sBAAW,iCAAI;yBAAf;wBACI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;oBACtB,CAAC;yBAED,UAAgB,KAAY;wBACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;oBACvB,CAAC;;;mBAJA;gBAMO,oCAAU,GAAlB;oBACI,MAAM,CAAC,IAAI,CAAC,IAAI,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CAAC;gBApDL;oBAAC,iBAAU,EAAE;;mCAAA;gBAqDb,sBAAC;YAAD,CAAC,AApDD,IAoDC;YApDD,6CAoDC,CAAA"} \ No newline at end of file +{"version":3,"file":"alfresco.service.js","sourceRoot":"","sources":["alfresco.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YASH;gBACI,yBACY,IAAU,EACV,QAAiC;oBADjC,SAAI,GAAJ,IAAI,CAAM;oBACV,aAAQ,GAAR,QAAQ,CAAyB;oBAOrC,UAAK,GAAW,uBAAuB,CAAC;oBACxC,iBAAY,GAAW,sDAAsD,CAAC;oBANlF,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACX,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC;oBAC/B,CAAC;gBACL,CAAC;gBAKD,sBAAW,iCAAI;yBAAf;wBACI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;oBACtB,CAAC;yBAED,UAAgB,KAAY;wBACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;oBACvB,CAAC;;;mBAJA;gBAMO,oCAAU,GAAlB;oBACI,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC;gBACzC,CAAC;gBAED,mCAAS,GAAT,UAAU,MAAc;oBACpB,IAAI,OAAO,GAAG,IAAI,cAAO,CAAC;wBACtB,cAAc,EAAE,kBAAkB;wBAClC,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;qBAChD,CAAC,CAAC;oBACH,IAAI,OAAO,GAAG,IAAI,qBAAc,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;oBACvD,MAAM,CAAC,IAAI,CAAC,IAAI;yBACX,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,MAAM,EAAE,OAAO,CAAC;yBACxC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAe,GAAG,CAAC,IAAI,EAAE,EAAzB,CAAyB,CAAC;yBACrC,EAAE,CAAC,UAAA,IAAI,IAAI,OAAA,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAjB,CAAiB,CAAC,CAAC,iCAAiC;yBAC/D,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBACjC,CAAC;gBAED,iDAAuB,GAAvB,UAAwB,QAAwB;oBAC5C,MAAM,CAAC,IAAI,CAAC,KAAK;wBACb,6BAA6B;wBAC7B,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,mEAAmE,CAAC;gBACnH,CAAC;gBAED,uCAAa,GAAb,UAAc,QAAwB;oBAClC,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,oBAAoB,GAAG,QAAQ,CAAC,UAAU,CAAC;gBACnE,CAAC;gBAEO,qCAAW,GAAnB,UAAqB,KAAe;oBAChC,mFAAmF;oBACnF,4CAA4C;oBAC5C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACrB,MAAM,CAAC,uBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC;gBAClE,CAAC;gBAtDL;oBAAC,iBAAU,EAAE;;mCAAA;gBAuDb,sBAAC;YAAD,CAAC,AAtDD,IAsDC;YAtDD,6CAsDC,CAAA"} \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.ts b/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.ts index 61ef1390ca..5639e3a5ba 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.ts @@ -27,7 +27,9 @@ export class AlfrescoService { private http: Http, private settings: AlfrescoSettingsService ) { - this._host = settings.host; + if (settings) { + this._host = settings.host; + } } private _host: string = 'http://127.0.0.1:8080'; diff --git a/ng2-components/ng2-alfresco-documentlist/test/assets/alfresco.service.mock.ts b/ng2-components/ng2-alfresco-documentlist/test/assets/alfresco.service.mock.ts new file mode 100644 index 0000000000..0254984937 --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/test/assets/alfresco.service.mock.ts @@ -0,0 +1,40 @@ +/** + * @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 {Http} from 'angular2/http'; +import {Observable} from 'rxjs/Observable'; +import {AlfrescoService} from '../../src/services/alfresco.service'; +import {AlfrescoSettingsService} from '../../../ng2-alfresco-core/services'; + +export class AlfrescoServiceMock extends AlfrescoService { + + _folderToReturn: any = {}; + + constructor( + http: Http = null, + settings: AlfrescoSettingsService = null + ) { + super(http, settings); + } + + getFolder(folder: string) { + return Observable.create(observer => { + observer.next(this._folderToReturn); + observer.complete(); + }); + } +} diff --git a/ng2-components/ng2-alfresco-documentlist/test/components/document-list.spec.ts b/ng2-components/ng2-alfresco-documentlist/test/components/document-list.spec.ts index 5a6ba9011b..c7e5fce4dd 100644 --- a/ng2-components/ng2-alfresco-documentlist/test/components/document-list.spec.ts +++ b/ng2-components/ng2-alfresco-documentlist/test/components/document-list.spec.ts @@ -15,9 +15,14 @@ * limitations under the License. */ -import {Observable} from 'rxjs/Observable'; +import { + it, + describe, + expect +} from 'angular2/testing'; import {DocumentList} from '../../src/components/document-list'; import {ContentColumnModel} from '../../src/models/content-column.model'; +import {AlfrescoServiceMock} from '../assets/alfresco.service.mock'; describe('document-list', () => { @@ -42,16 +47,17 @@ describe('document-list', () => { }); it('should setup default root for breadcrumb', () => { - let service = { - getFolder: function() { - return Observable.create(observer => { - var value = {}; - observer.next(value); - observer.complete(); - }); - } - }; + let service = new AlfrescoServiceMock(); + /* + spyOn(service, 'getFolder').and.returnValue( + Observable.create(observer => { + var value = {}; + observer.next(value); + observer.complete(); + }) + ); + */ let list: DocumentList = new DocumentList(service); list.ngOnInit(); @@ -60,15 +66,12 @@ describe('document-list', () => { }); it('should fetch folder', () => { - let folder = {}; - let service = { - getFolder: function() { - return Observable.create(observer => { - observer.next(folder); - observer.complete(); - }); - } + let folder = { + 'nodeRef': 'workspace://SpacesStore/8bb36efb-c26d-4d2b-9199-ab6922f53c28' }; + let service = new AlfrescoServiceMock(); + service._folderToReturn = folder; + let list: DocumentList = new DocumentList(service); list.ngOnInit(); @@ -77,12 +80,10 @@ describe('document-list', () => { it('should get content url', () => { let url = 'URL'; - let service = { - getContentUrl(content:any) { return url; } - }; - let list: DocumentList = new DocumentList(service); + let service = new AlfrescoServiceMock(); + spyOn(service, 'getContentUrl').and.returnValue(url); - spyOn(service, 'getContentUrl').and.callThrough(); + let list: DocumentList = new DocumentList(service); let result = list.getContentUrl(null); expect(result).toBe(url); @@ -91,12 +92,10 @@ describe('document-list', () => { it('should get thumbnail url', () => { let url = 'URL'; - let service = { - getDocumentThumbnailUrl(content:any) { return url; } - }; - let list: DocumentList = new DocumentList(service); + let service = new AlfrescoServiceMock(); + spyOn(service, 'getDocumentThumbnailUrl').and.returnValue(url); - spyOn(service, 'getDocumentThumbnailUrl').and.callThrough(); + let list: DocumentList = new DocumentList(service); let result = list.getDocumentThumbnailUrl(null); expect(result).toBe(url); diff --git a/ng2-components/ng2-alfresco-documentlist/test/index.html b/ng2-components/ng2-alfresco-documentlist/test/index.html index 1253de03ff..4eb214ae28 100644 --- a/ng2-components/ng2-alfresco-documentlist/test/index.html +++ b/ng2-components/ng2-alfresco-documentlist/test/index.html @@ -29,7 +29,7 @@ // for imports from the app folder System.config({ packages: { - 'app': {defaultExtension: 'js'}, + 'test': {defaultExtension: 'js'}, 'src': {defaultExtension: 'js'}, 'ng2-alfresco-core': {defaultExtension: 'js'} } @@ -37,7 +37,7 @@ // #3. Import the spec file explicitly Promise.all([ - System.import('test/components/document-list.spec.js')/*, + System.import('test/components/document-list.spec')/*, System.import('app/my-uppercase.pipe.spec')*/ ]) // #4. wait for all imports to load ... diff --git a/ng2-components/ng2-alfresco-documentlist/test/tsconfig.json b/ng2-components/ng2-alfresco-documentlist/test/tsconfig.json index 9f1af2fc60..9f01d6c97c 100644 --- a/ng2-components/ng2-alfresco-documentlist/test/tsconfig.json +++ b/ng2-components/ng2-alfresco-documentlist/test/tsconfig.json @@ -10,6 +10,12 @@ "noImplicitAny": false, "declaration": false }, + "files": [ + "../node_modules/angular2/typings/browser.d.ts", + "../typings/main/ambient/jasmine/index.d.ts", + "assets/alfresco.service.mock.ts", + "components/document-list.spec.ts" + ], "exclude": [ ] }