Unit testing improvements and config fixes

refs #9
This commit is contained in:
Denys Vuika
2016-05-06 10:37:23 +01:00
parent cb14007788
commit 807b3338dc
7 changed files with 82 additions and 33 deletions

View File

@@ -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 () {

View File

@@ -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,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,O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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"}

View File

@@ -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';

View File

@@ -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();
});
}
}

View File

@@ -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);

View File

@@ -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 ...

View File

@@ -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": [
]
}