#17 Moved test files in test folder

This commit is contained in:
mauriziovitale84
2016-05-09 15:33:46 +01:00
parent e1b28e255a
commit 93f8a12541
16 changed files with 185 additions and 529 deletions

View File

@@ -4,12 +4,13 @@
"version": "0.1.0",
"author": "Alfresco Software, Ltd.",
"scripts": {
"build": "typings install && tsc",
"build": "tslint -c tslint.json **/*.ts && typings install && tsc && license-check",
"licensecheck": "license-check",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings",
"format": "xo",
"test": "live-server --open=tests-runner.html"
"test": "live-server --open=index.html --entry-file=test/ --mount=/ng2-alfresco-core:../ng2-alfresco-core",
"test:w": "concurrently \"npm run tsc:w\" \"npm run test\" "
},
"repository": {
"type": "git",
@@ -42,9 +43,7 @@
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"zone.js": "0.6.10",
"ng2-translate": "^1.11.2",
"angular2": "2.0.0-beta.15",
"ng2-alfresco-core": "0.1.0"
"ng2-translate": "^1.11.2"
},
"peerDependencies": {
"angular2": "2.0.0-beta.15",
@@ -55,28 +54,20 @@
"live-server": "^0.9.2",
"typescript": "^1.8.10",
"typings": "^0.7.12",
"xo": "^0.14.0"
"license-check": "^1.0.4",
"tslint": "^3.8.1",
"concurrently": "^2.0.0"
},
"xo": {
"overrides": [
{
"files": "test/*.js",
"rules": {
"max-nested-callbacks": 0,
"handle-callback-err": 0
}
}
"license-check-config": {
"src": [
"**/*.ts",
"!/**/*.d.ts",
"!/**/node_modules/**/*",
"!/**/typings/**/*"
],
"rules": {
"no-lonely-if" : 0,
"one-var": 0,
"padded-blocks": 0,
"no-mixed-requires": 0,
"quotes": [
2,
"single",
"avoid-escape"
]
}
"path": "assets/license_header.txt",
"blocking": false,
"logInfo": false,
"logError": true
}
}

View File

@@ -1,294 +0,0 @@
System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angular2/core', './alfresco-login', 'rxjs/Rx', '../services/alfresco-authentication', 'angular2/src/router/router', 'angular2/router', 'angular2/src/mock/location_mock', 'ng2-translate/ng2-translate'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var browser_1, testing_1, core_1, alfresco_login_1, Rx_1, alfresco_authentication_1, router_1, router_2, location_mock_1, ng2_translate_1;
var AuthenticationMock, TranslationMock;
return {
setters:[
function (browser_1_1) {
browser_1 = browser_1_1;
},
function (testing_1_1) {
testing_1 = testing_1_1;
},
function (core_1_1) {
core_1 = core_1_1;
},
function (alfresco_login_1_1) {
alfresco_login_1 = alfresco_login_1_1;
},
function (Rx_1_1) {
Rx_1 = Rx_1_1;
},
function (alfresco_authentication_1_1) {
alfresco_authentication_1 = alfresco_authentication_1_1;
},
function (router_1_1) {
router_1 = router_1_1;
},
function (router_2_1) {
router_2 = router_2_1;
},
function (location_mock_1_1) {
location_mock_1 = location_mock_1_1;
},
function (ng2_translate_1_1) {
ng2_translate_1 = ng2_translate_1_1;
}],
execute: function() {
AuthenticationMock = (function () {
function AuthenticationMock() {
this.mockName = 'Mocked Service';
}
AuthenticationMock.prototype.login = function (method, username, password) {
if (username === 'fake-username' && password === 'fake-password') {
return Rx_1.Observable.of(true);
}
else {
return Rx_1.Observable.throw('Fake server error');
}
};
AuthenticationMock.prototype.getProviders = function () {
return [core_1.provide(alfresco_authentication_1.AlfrescoAuthenticationService, { useValue: this })];
};
return AuthenticationMock;
}());
TranslationMock = (function () {
function TranslationMock() {
this.onLangChange = new core_1.EventEmitter();
}
TranslationMock.prototype.setDefaultLang = function () {
};
TranslationMock.prototype.use = function () {
};
TranslationMock.prototype.get = function (key, interpolateParams) {
if (!key) {
throw new Error('Parameter "key" required');
}
return Rx_1.Observable.of(key);
};
return TranslationMock;
}());
testing_1.describe('AlfrescoLogin', function () {
var authService, location, router;
testing_1.setBaseTestProviders(browser_1.TEST_BROWSER_PLATFORM_PROVIDERS, browser_1.TEST_BROWSER_APPLICATION_PROVIDERS);
testing_1.beforeEachProviders(function () {
authService = new AuthenticationMock();
return [
authService.getProviders(),
router_2.RouteRegistry,
core_1.provide(router_2.Location, { useClass: location_mock_1.SpyLocation }),
core_1.provide(router_2.ROUTER_PRIMARY_COMPONENT, { useValue: alfresco_login_1.AlfrescoLoginComponent }),
core_1.provide(router_2.Router, { useClass: router_1.RootRouter }),
core_1.provide(ng2_translate_1.TranslateService, { useClass: TranslationMock })
];
});
testing_1.beforeEach(testing_1.inject([router_2.Router, router_2.Location], function (r, l) {
router = r;
location = l;
}));
testing_1.it('should render `Login` form with all the keys to be translated', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
fixture.detectChanges();
var element = fixture.nativeElement;
testing_1.expect(element.querySelector('h2').innerText).toEqual('login');
testing_1.expect(element.querySelector('[for="username"]')).toBeDefined();
testing_1.expect(element.querySelector('[for="username"]').innerText).toEqual('username');
testing_1.expect(element.querySelector('#username-error').innerText).toEqual('input-required-message');
testing_1.expect(element.querySelector('[for="password"]')).toBeDefined();
testing_1.expect(element.querySelector('[for="password"]').innerText).toEqual('password');
testing_1.expect(element.querySelector('#password-required').innerText).toEqual('input-required-message');
});
}));
testing_1.it('should render user and password input fields with default values', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
var element = fixture.nativeElement;
testing_1.expect(element.querySelector('form')).toBeDefined();
testing_1.expect(element.querySelector('input[type="password"]')).toBeDefined();
testing_1.expect(element.querySelector('input[type="text"]')).toBeDefined();
testing_1.expect(element.querySelector('input[type="password"]').value).toEqual('');
testing_1.expect(element.querySelector('input[type="text"]').value).toEqual('');
});
}));
testing_1.it('should render min-length error when the username is lower than 4 characters', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
var compiled = fixture.debugElement.nativeElement;
component.form.controls.username._value = 'us';
fixture.detectChanges();
component.onValueChanged();
fixture.detectChanges();
testing_1.expect(component.formError).toBeDefined(true);
testing_1.expect(component.formError.username).toBeDefined(true);
testing_1.expect(component.formError.username).toEqual('input-min-message');
testing_1.expect(compiled.querySelector('#username-error').innerText).toEqual('input-min-message');
});
}));
testing_1.it('should render no errors when the username and password are correct', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
var compiled = fixture.debugElement.nativeElement;
component.form.controls.username._value = 'fake-user';
component.form.controls.password._value = 'fake-password';
fixture.detectChanges();
component.onValueChanged();
fixture.detectChanges();
testing_1.expect(component.formError).toBeDefined(true);
testing_1.expect(component.formError.username).toEqual('');
testing_1.expect(component.formError.password).toEqual('');
testing_1.expect(compiled.querySelector('#login-error')).toBeNull();
});
}));
testing_1.it('should render the new values after user and password values are changed', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
var compiled = fixture.debugElement.nativeElement;
component.form.controls.username._value = 'my username';
component.form.controls.password._value = 'my password';
fixture.detectChanges();
testing_1.expect(compiled.querySelector('input[type="password"]').value).toEqual('my password');
testing_1.expect(compiled.querySelector('input[type="text"]').value).toEqual('my username');
});
}));
testing_1.it('should navigate to Home route after the login have succeeded ', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
router.config([new router_2.Route({ path: '/home', name: 'Home', component: alfresco_login_1.AlfrescoLoginComponent })]);
spyOn(router, 'navigate').and.callThrough();
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
var compiled = fixture.debugElement.nativeElement;
component.form.controls.username._value = 'fake-username';
component.form.controls.password._value = 'fake-password';
fixture.detectChanges();
compiled.querySelector('button').click();
fixture.detectChanges();
testing_1.expect(component.error).toBe(false);
testing_1.expect(router.navigate).toHaveBeenCalledWith(['Home']);
});
}));
testing_1.it('should return error with a wrong username ', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
spyOn(router, 'navigate').and.callThrough();
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
var compiled = fixture.debugElement.nativeElement;
component.form.controls.username._value = 'fake-wrong-username';
component.form.controls.password._value = 'fake-password';
fixture.detectChanges();
compiled.querySelector('button').click();
fixture.detectChanges();
testing_1.expect(fixture.componentInstance.error).toBe(true);
testing_1.expect(compiled.querySelector('#login-error').innerText).toEqual('login-error-message');
});
}));
testing_1.it('should return error with a wrong password ', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
spyOn(router, 'navigate').and.callThrough();
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
var compiled = fixture.debugElement.nativeElement;
component.form.controls.username._value = 'fake-username';
component.form.controls.password._value = 'fake-wrong-password';
fixture.detectChanges();
compiled.querySelector('button').click();
fixture.detectChanges();
testing_1.expect(fixture.componentInstance.error).toBe(true);
testing_1.expect(compiled.querySelector('#login-error').innerText).toEqual('login-error-message');
});
}));
testing_1.it('should return error with a wrong username and password ', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
spyOn(router, 'navigate').and.callThrough();
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
var compiled = fixture.debugElement.nativeElement;
component.form.controls.username._value = 'fake-wrong-username';
component.form.controls.password._value = 'fake-wrong-password';
fixture.detectChanges();
compiled.querySelector('button').click();
fixture.detectChanges();
testing_1.expect(fixture.componentInstance.error).toBe(true);
testing_1.expect(compiled.querySelector('#login-error').innerText).toEqual('login-error-message');
});
}));
testing_1.it('should emit onSuccess event after the login has succeeded', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
spyOn(component.onSuccess, 'emit');
var compiled = fixture.debugElement.nativeElement;
component.form.controls.username._value = 'fake-username';
component.form.controls.password._value = 'fake-password';
fixture.detectChanges();
component.onValueChanged();
var nativeElement = fixture.nativeElement;
var button = nativeElement.querySelector('button');
button.dispatchEvent(new Event('click'));
fixture.detectChanges();
testing_1.expect(fixture.componentInstance.error).toBe(false);
testing_1.expect(compiled.querySelector('#login-success').innerHTML).toEqual('login-success-message');
testing_1.expect(component.onSuccess.emit).toHaveBeenCalledWith({ value: 'Login OK' });
});
}));
testing_1.it('should emit onError event after the login has failed', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb
.createAsync(alfresco_login_1.AlfrescoLoginComponent)
.then(function (fixture) {
var component = fixture.componentInstance;
component.isErrorStyle = function () {
};
spyOn(component.onError, 'emit');
var compiled = fixture.debugElement.nativeElement;
component.form.controls.username._value = 'fake-wrong-username';
component.form.controls.password._value = 'fake-password';
fixture.detectChanges();
component.onValueChanged();
// trigger the click
var nativeElement = fixture.nativeElement;
var button = nativeElement.querySelector('button');
button.dispatchEvent(new Event('click'));
fixture.detectChanges();
testing_1.expect(fixture.componentInstance.error).toBe(true);
testing_1.expect(compiled.querySelector('#login-error').innerText).toEqual('login-error-message');
testing_1.expect(component.onError.emit).toHaveBeenCalledWith({ value: 'Login KO' });
});
}));
});
}
}
});
//# sourceMappingURL=alfresco-login.spec.js.map

File diff suppressed because one or more lines are too long

View File

@@ -1,100 +0,0 @@
System.register(['angular2/testing', 'angular2/core', 'angular2/http', 'angular2/http/testing', './alfresco-authentication'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var testing_1, core_1, http_1, testing_2, alfresco_authentication_1;
return {
setters:[
function (testing_1_1) {
testing_1 = testing_1_1;
},
function (core_1_1) {
core_1 = core_1_1;
},
function (http_1_1) {
http_1 = http_1_1;
},
function (testing_2_1) {
testing_2 = testing_2_1;
},
function (alfresco_authentication_1_1) {
alfresco_authentication_1 = alfresco_authentication_1_1;
}],
execute: function() {
testing_1.describe('AlfrescoAuthentication', function () {
var injector, backend, mockBackend, httpService, service;
beforeEach(function () {
injector = core_1.Injector.resolveAndCreate([
http_1.HTTP_PROVIDERS,
testing_2.MockBackend,
core_1.provide(http_1.XHRBackend, { useClass: testing_2.MockBackend }),
alfresco_authentication_1.AlfrescoAuthenticationService
]);
var store = {};
spyOn(localStorage, 'getItem').and.callFake(function (key) {
return store[key];
});
spyOn(localStorage, 'setItem').and.callFake(function (key, value) {
return store[key] = value + '';
});
spyOn(localStorage, 'clear').and.callFake(function () {
store = {};
});
spyOn(localStorage, 'removeItem').and.callFake(function (key) {
delete store[key];
});
spyOn(localStorage, 'key').and.callFake(function (i) {
var keys = Object.keys(store);
return keys[i] || null;
});
mockBackend = injector.get(testing_2.MockBackend);
backend = injector.get(http_1.XHRBackend);
httpService = injector.get(http_1.Http);
service = injector.get(alfresco_authentication_1.AlfrescoAuthenticationService);
});
testing_1.it('should return true and token if the user is logged in', function () {
service.saveJwt('fake-local-token');
expect(service.isLoggedIn()).toBe(true);
expect(localStorage.getItem('token')).toBeDefined();
expect(localStorage.getItem('token')).toEqual('fake-local-token');
});
testing_1.it('should return false and token undefined if the user is not logged in', function () {
expect(service.isLoggedIn()).toEqual(false);
expect(localStorage.getItem('token')).not.toBeDefined();
});
testing_1.it('should return true and token on sign in', function () {
backend.connections.subscribe(function (connection) {
connection.mockRespond(new http_1.Response(new http_1.ResponseOptions({ body: { data: { ticket: 'fake-post-token' } } })));
});
service.token = '';
service.login('POST', 'fakeUser', 'fakePassword')
.subscribe(function () {
expect(service.isLoggedIn()).toBe(true);
expect(service.token).toEqual('fake-post-token');
expect(localStorage.getItem('token')).toBeDefined();
expect(localStorage.getItem('token')).toEqual('fake-post-token');
});
});
testing_1.it('should return false and token undefined on log out', function () {
service.token = 'fake-token';
localStorage.setItem('token', 'fake-token');
service.logout()
.subscribe(function () {
expect(service.isLoggedIn()).toBe(false);
expect(service.token).not.toBeDefined();
expect(localStorage.getItem('token')).not.toBeDefined();
});
});
testing_1.it('should return no error if method value is GET', function () {
expect(service.login('GET', 'fakeUser', 'fakePassword').hasErrored).toBe(false);
});
testing_1.it('should return no error if method value is POST', function () {
expect(service.login('POST', 'fakeUser', 'fakePassword').hasErrored).toBe(false);
});
testing_1.it('should throw an exception if method value is different from GET or POST', function () {
expect(service.login('PUT', 'fakeUser', 'fakePassword').error).toEqual('Invalid method name the value should be GET or POST');
});
});
}
}
});
//# sourceMappingURL=alfresco-authentication.spec.js.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"alfresco-authentication.spec.js","sourceRoot":"","sources":["alfresco-authentication.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;YAuBA,kBAAQ,CAAC,wBAAwB,EAAE;gBAC/B,IAAI,QAAQ,EACR,OAAO,EACP,WAAW,EACX,WAAW,EACX,OAAO,CAAC;gBAEZ,UAAU,CAAC;oBACP,QAAQ,GAAG,eAAQ,CAAC,gBAAgB,CAAC;wBACjC,qBAAc;wBACd,qBAAW;wBACX,cAAO,CAAC,iBAAU,EAAE,EAAC,QAAQ,EAAE,qBAAW,EAAC,CAAC;wBAC5C,uDAA6B;qBAChC,CAAC,CAAC;oBAEH,IAAI,KAAK,GAAG,EAAE,CAAC;oBAEf,KAAK,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,GAAG;wBACrD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACtB,CAAC,CAAC,CAAC;oBACH,KAAK,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,C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C7B,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;oBAC5C,OAAO,CAAC,MAAM,EAAE;yBACX,SAAS,CAAC;wBACP,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBACzC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;wBACxC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;oBAC5D,CAAC,CACJ,CAAC;gBACN,CAAC,CAAC,CAAC;gBAEH,YAAE,CAAC,+CAA+C,EAAE;oBAChD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACpF,CAAC,CAAC,CAAC;gBAEH,YAAE,CAAC,gDAAgD,EAAE;oBACjD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACrF,CAAC,CAAC,CAAC;gBAEH,YAAE,CAAC,yEAAyE,EAAE;oBAC1E,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,qDAAqD,CAAC,CAAC;gBAClI,CAAC,CAAC,CAAC;YAEP,CAAC,CAAC,CAAC"}

View File

@@ -0,0 +1,3 @@
*.js
*.js.map
*.d.ts

View File

@@ -0,0 +1,35 @@
/**
* @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 {Observable} from 'rxjs/Observable';
import {provide} from 'angular2/core';
import {AlfrescoAuthenticationService} from '../../src/services/alfresco-authentication';
export class AuthenticationMock {
login(method: string, username: string, password: string) {
if (username === 'fake-username' && password === 'fake-password') {
return Observable.of(true);
} else {
return Observable.throw('Fake server error');
}
}
getProviders(): Array<any> {
return [provide(AlfrescoAuthenticationService, {useValue: this})];
}
}

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 {Observable} from 'rxjs/Observable';
import {provide, EventEmitter} from 'angular2/core';
import {LangChangeEvent} from 'ng2-translate/ng2-translate';
export class TranslationMock {
public onLangChange: EventEmitter<LangChangeEvent> = new EventEmitter<LangChangeEvent>();
setDefaultLang() {
}
use() {
}
public get(key: string|Array<string>, interpolateParams?: Object): Observable<string|any> {
if (!key) {
throw new Error('Parameter "key" required');
}
return Observable.of(key);
}
}

View File

@@ -17,49 +17,15 @@
import {TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS} from 'angular2/platform/testing/browser';
import {it, describe, expect, inject, injectAsync, beforeEach, beforeEachProviders, TestComponentBuilder, setBaseTestProviders} from 'angular2/testing';
import {Component, provide, Injector, EventEmitter} from 'angular2/core';
import {AlfrescoLoginComponent} from './alfresco-login';
import {Location, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT, Route} from 'angular2/router';
import {RootRouter} from 'angular2/src/router/router';
import {Observable} from 'rxjs/Rx';
import {AlfrescoAuthenticationService} from '../services/alfresco-authentication';
import { RootRouter } from 'angular2/src/router/router';
import { Location, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT, Route } from 'angular2/router';
import { SpyLocation } from 'angular2/src/mock/location_mock';
import {SpyLocation} from 'angular2/src/mock/location_mock';
import {dispatchEvent} from 'angular2/src/testing/utils';
import {TranslateService, LangChangeEvent} from 'ng2-translate/ng2-translate';
class AuthenticationMock {
public mockName: string = 'Mocked Service';
login(method: string, username: string, password: string) {
if (username === 'fake-username' && password === 'fake-password') {
return Observable.of(true);
} else {
return Observable.throw('Fake server error');
}
}
getProviders(): Array<any> {
return [provide(AlfrescoAuthenticationService, {useValue: this})];
}
}
class TranslationMock {
public onLangChange: EventEmitter<LangChangeEvent> = new EventEmitter<LangChangeEvent>();
setDefaultLang() {
}
use() {
}
public get(key: string|Array<string>, interpolateParams?: Object): Observable<string|any> {
if (!key) {
throw new Error('Parameter "key" required');
}
return Observable.of(key);
}
}
import {AlfrescoLoginComponent} from '../../src/components/alfresco-login';
import {AuthenticationMock} from '../assets/authentication.service.mock';
import {TranslationMock} from '../assets/translation.service.mock';
describe('AlfrescoLogin', () => {
let authService, location, router;

View File

@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Alfresco Login component Tests</title>
<link rel="stylesheet" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
<!-- #1. add the system.js library -->
<script src="../node_modules/es6-shim/es6-shim.min.js"></script>
<script src="../node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="../node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="../node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="../node_modules/systemjs/dist/system.src.js"></script>
<script src="../node_modules/rxjs/bundles/Rx.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="../node_modules/angular2/bundles/http.dev.js"></script>
<script src="../node_modules/angular2/bundles/router.dev.js"></script>
<script src="../node_modules/angular2/bundles/testing.dev.js"></script>
<script>
// #2. Configure systemjs to use the .js extension
// for imports from the app folder
System.config({
packages: {
'test': {defaultExtension: 'js'},
'src': {defaultExtension: 'js'},
'ng2-translate': {
defaultExtension: 'js'
},
'rxjs': {
defaultExtension: 'js'
}
},
map: {
'ng2-translate': '../node_modules/ng2-translate',
'rxjs': '../node_modules/rxjs'
}
});
// #3. Import the spec file explicitly
Promise.all([
System.import('test/services/alfresco-authentication.spec'),
System.import('test/components/alfresco-login.spec')
])
// #4. wait for all imports to load ...
// then re-execute `window.onload` which
// triggers the Jasmine test-runner start
// or explain what went wrong.
.then(window.onload)
.catch(console.error.bind(console));
</script>
</head>
<body>
<!-- Unit Testing Chapter #1: Proof of life. -->
<script>
</script>
</body>
</html>

View File

@@ -18,7 +18,7 @@ import {it, describe} from 'angular2/testing';
import {provide, Injector} from 'angular2/core';
import {Http, HTTP_PROVIDERS, XHRBackend, Response, ResponseOptions} from 'angular2/http';
import {MockBackend} from 'angular2/http/testing';
import {AlfrescoAuthenticationService} from './alfresco-authentication';
import {AlfrescoAuthenticationService} from '../../src/services/alfresco-authentication';
describe('AlfrescoAuthentication', () => {

View File

@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"declaration": false
},
"exclude": [
]
}

View File

@@ -1,63 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Alfresco Login component Tests</title>
<link rel="stylesheet" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
<!-- #1. add the system.js library -->
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/testing.dev.js"></script>
<script>
// #2. Configure systemjs to use the .js extension
// for imports from the app folder
System.config({
packages: {
'src': {defaultExtension: 'js'},
'ng2-translate': {
defaultExtension: 'js'
},
'rxjs': {
defaultExtension: 'js'
}
},
map: {
'ng2-translate': 'node_modules/ng2-translate',
'rxjs': 'node_modules/rxjs'
}
});
// #3. Import the spec file explicitly
Promise.all([
System.import('src/services/alfresco-authentication.spec'),
System.import('src/components/alfresco-login.spec')
])
// #4. wait for all imports to load ...
// then re-execute `window.onload` which
// triggers the Jasmine test-runner start
// or explain what went wrong.
.then(window.onload)
.catch(console.error.bind(console));
</script>
</head>
<body>
<!-- Unit Testing Chapter #1: Proof of life. -->
<script>
</script>
</body>
</html>

View File

@@ -14,9 +14,9 @@
"node_modules/angular2/typings/browser.d.ts",
"typings/browser/ambient/jasmine/index.d.ts",
"src/components/alfresco-login.ts",
"src/components/alfresco-login.spec.ts",
"test/components/alfresco-login.spec.ts",
"src/services/alfresco-authentication.ts",
"src/services/alfresco-authentication.spec.ts"
"test/services/alfresco-authentication.spec.ts"
],
"exclude": [
"**/node_modules",