#17 Provide translationServiceMock to fix the failures test

This commit is contained in:
mauriziovitale84 2016-04-29 12:09:30 +01:00
parent cc6b129403
commit b4e90cb71a
8 changed files with 59 additions and 39 deletions

View File

@ -1,12 +1,10 @@
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { Http } from 'angular2/http'; import { Http } from 'angular2/http';
import { AlfrescoSettingsService } from '../../ng2-alfresco-core/services';
/** /**
* The AlfrescoAuthenticationService provide the login service and store the token in the localStorage * The AlfrescoAuthenticationService provide the login service and store the token in the localStorage
*/ */
export declare class AlfrescoAuthenticationService { export declare class AlfrescoAuthenticationService {
http: Http; http: Http;
private settings;
token: string; token: string;
private _host; private _host;
private _baseUrl; private _baseUrl;
@ -14,7 +12,7 @@ export declare class AlfrescoAuthenticationService {
* Constructor * Constructor
* @param http * @param http
*/ */
constructor(http: Http, settings: AlfrescoSettingsService); constructor(http: Http);
/** /**
* The method return tru if the user is logged in * The method return tru if the user is logged in
* @returns {boolean} * @returns {boolean}

View File

@ -1,4 +1,4 @@
System.register(['angular2/core', 'rxjs/Rx', 'angular2/http', '../../ng2-alfresco-core/services'], function(exports_1, context_1) { System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_1, context_1) {
"use strict"; "use strict";
var __moduleName = context_1 && context_1.id; var __moduleName = context_1 && context_1.id;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
@ -10,7 +10,7 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http', '../../ng2-alfresc
var __metadata = (this && this.__metadata) || function (k, v) { var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
}; };
var core_1, Rx_1, http_1, services_1; var core_1, Rx_1, http_1;
var AlfrescoAuthenticationService; var AlfrescoAuthenticationService;
return { return {
setters:[ setters:[
@ -22,9 +22,6 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http', '../../ng2-alfresc
}, },
function (http_1_1) { function (http_1_1) {
http_1 = http_1_1; http_1 = http_1_1;
},
function (services_1_1) {
services_1 = services_1_1;
}], }],
execute: function() { execute: function() {
/** /**
@ -35,13 +32,11 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http', '../../ng2-alfresc
* Constructor * Constructor
* @param http * @param http
*/ */
function AlfrescoAuthenticationService(http, settings) { function AlfrescoAuthenticationService(http) {
this.http = http; this.http = http;
this.settings = settings;
this._host = 'http://192.168.99.100:8080'; this._host = 'http://192.168.99.100:8080';
this._baseUrl = this._host + '/alfresco/service/api/'; this._baseUrl = this._host + '/alfresco/service/api/';
this.token = localStorage.getItem('token'); this.token = localStorage.getItem('token');
this._host = settings.host;
} }
/** /**
* The method return tru if the user is logged in * The method return tru if the user is logged in
@ -134,7 +129,7 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http', '../../ng2-alfresc
}; };
AlfrescoAuthenticationService = __decorate([ AlfrescoAuthenticationService = __decorate([
core_1.Injectable(), core_1.Injectable(),
__metadata('design:paramtypes', [http_1.Http, services_1.AlfrescoSettingsService]) __metadata('design:paramtypes', [http_1.Http])
], AlfrescoAuthenticationService); ], AlfrescoAuthenticationService);
return AlfrescoAuthenticationService; return AlfrescoAuthenticationService;
}()); }());

View File

@ -1 +1 @@
{"version":3,"file":"alfresco-authentication.service.js","sourceRoot":"","sources":["alfresco-authentication.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAwBA;;eAEG;YAEH;gBAMI;;;mBAGG;gBACH,uCAAmB,IAAS,EACR,QAAiC;oBADlC,SAAI,GAAJ,IAAI,CAAK;oBACR,aAAQ,GAAR,QAAQ,CAAyB;oBAR7C,UAAK,GAAU,4BAA4B,CAAC;oBAC5C,aAAQ,GAAU,IAAI,CAAC,KAAK,GAAG,wBAAwB,CAAC;oBAQ5D,IAAI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CAAC;wBAClC,KAAI,CAAC,OAAO,CAAC,KAAI,CAAC,KAAK,CAAC,CAAC;oBAC7B,CAAC,CAAC;yBACD,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBACjC,CAAC;gBAED;;;mBAGG;gBACH,+CAAO,GAAP,UAAQ,GAAG;oBACP,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;wBACN,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;oBACvC,CAAC;gBACL,CAAC;gBAED;;;mBAGG;gBACH,8CAAM,GAAN;oBACI,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;oBACvB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;oBAEjC,MAAM,CAAC,eAAU,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC;gBAED;;;;mBAIG;gBACK,mDAAW,GAAnB,UAAoB,KAAc;oBAC9B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACrB,MAAM,CAAC,eAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC;gBAClE,CAAC;gBA7GL;oBAAC,iBAAU,EAAE;;iDAAA;gBA8Gb,oCAAC;YAAD,CAAC,AA7GD,IA6GC;YA7GD,yEA6GC,CAAA"}

View File

@ -17,8 +17,6 @@
import {Injectable} from 'angular2/core'; import {Injectable} from 'angular2/core';
import {Observable} from 'rxjs/Rx'; import {Observable} from 'rxjs/Rx';
import {Http, Headers, URLSearchParams, Response} from 'angular2/http'; import {Http, Headers, URLSearchParams, Response} from 'angular2/http';
import {AlfrescoSettingsService} from '../../ng2-alfresco-core/services';
declare let xml2json:any; declare let xml2json:any;
@ -36,10 +34,8 @@ export class AlfrescoAuthenticationService {
* Constructor * Constructor
* @param http * @param http
*/ */
constructor(public http:Http, constructor(public http:Http) {
private settings: AlfrescoSettingsService) {
this.token = localStorage.getItem('token'); this.token = localStorage.getItem('token');
this._host = settings.host;
} }
/** /**
* The method return tru if the user is logged in * The method return tru if the user is logged in

View File

@ -1,8 +1,8 @@
System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angular2/core', './alfresco-login.component', 'rxjs/Rx', './alfresco-authentication.service', 'angular2/src/router/router', 'angular2/router', 'angular2/src/mock/location_mock'], function(exports_1, context_1) { System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angular2/core', './alfresco-login.component', 'rxjs/Rx', './alfresco-authentication.service', 'angular2/src/router/router', 'angular2/router', 'angular2/src/mock/location_mock', 'ng2-translate/ng2-translate'], function(exports_1, context_1) {
"use strict"; "use strict";
var __moduleName = context_1 && context_1.id; var __moduleName = context_1 && context_1.id;
var browser_1, testing_1, core_1, alfresco_login_component_1, Rx_1, alfresco_authentication_service_1, router_1, router_2, location_mock_1; var browser_1, testing_1, core_1, alfresco_login_component_1, Rx_1, alfresco_authentication_service_1, router_1, router_2, location_mock_1, ng2_translate_1;
var AuthenticationMock; var AuthenticationMock, TranslationMock;
return { return {
setters:[ setters:[
function (browser_1_1) { function (browser_1_1) {
@ -31,6 +31,9 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
}, },
function (location_mock_1_1) { function (location_mock_1_1) {
location_mock_1 = 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() { execute: function() {
AuthenticationMock = (function () { AuthenticationMock = (function () {
@ -50,6 +53,15 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
}; };
return AuthenticationMock; return AuthenticationMock;
}()); }());
TranslationMock = (function () {
function TranslationMock() {
}
TranslationMock.prototype.setDefaultLang = function () {
};
TranslationMock.prototype.use = function () {
};
return TranslationMock;
}());
testing_1.describe('AlfrescoLogin', function () { testing_1.describe('AlfrescoLogin', function () {
var authService, location, router; var authService, location, router;
testing_1.setBaseTestProviders(browser_1.TEST_BROWSER_PLATFORM_PROVIDERS, browser_1.TEST_BROWSER_APPLICATION_PROVIDERS); testing_1.setBaseTestProviders(browser_1.TEST_BROWSER_PLATFORM_PROVIDERS, browser_1.TEST_BROWSER_APPLICATION_PROVIDERS);
@ -60,14 +72,15 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
router_2.RouteRegistry, router_2.RouteRegistry,
core_1.provide(router_2.Location, { useClass: location_mock_1.SpyLocation }), core_1.provide(router_2.Location, { useClass: location_mock_1.SpyLocation }),
core_1.provide(router_2.ROUTER_PRIMARY_COMPONENT, { useValue: alfresco_login_component_1.AlfrescoLoginComponent }), core_1.provide(router_2.ROUTER_PRIMARY_COMPONENT, { useValue: alfresco_login_component_1.AlfrescoLoginComponent }),
core_1.provide(router_2.Router, { useClass: router_1.RootRouter }) 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) { testing_1.beforeEach(testing_1.inject([router_2.Router, router_2.Location], function (r, l) {
router = r; router = r;
location = l; location = l;
})); }));
testing_1.it('should render `Login` form with input fields user and password with default value', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) { testing_1.it('should render `Login` form with input fields user and password with default value', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb return tcb
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent) .createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) { .then(function (fixture) {
@ -79,7 +92,7 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(element.querySelector('input[type="text"]').value).toEqual(''); testing_1.expect(element.querySelector('input[type="text"]').value).toEqual('');
}); });
})); }));
testing_1.it('should render the new values after change the user and password values', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) { testing_1.it('should render the new values after change the user and password values', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb return tcb
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent) .createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) { .then(function (fixture) {
@ -92,7 +105,7 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(compiled.querySelector('input[type="text"]').value).toEqual('my username'); testing_1.expect(compiled.querySelector('input[type="text"]').value).toEqual('my username');
}); });
})); }));
testing_1.it('should navigate to Home route after the login OK ', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) { testing_1.it('should navigate to Home route after the login OK ', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb return tcb
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent) .createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) { .then(function (fixture) {
@ -108,7 +121,7 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(router.navigate).toHaveBeenCalledWith(['Home']); testing_1.expect(router.navigate).toHaveBeenCalledWith(['Home']);
}); });
})); }));
testing_1.it('should return error with a wrong username ', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) { testing_1.it('should return error with a wrong username ', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb return tcb
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent) .createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) { .then(function (fixture) {
@ -122,7 +135,7 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(fixture.componentInstance.error).toBe(true); testing_1.expect(fixture.componentInstance.error).toBe(true);
}); });
})); }));
testing_1.it('should return error with a wrong password ', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) { testing_1.it('should return error with a wrong password ', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb return tcb
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent) .createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) { .then(function (fixture) {
@ -136,7 +149,7 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(fixture.componentInstance.error).toBe(true); testing_1.expect(fixture.componentInstance.error).toBe(true);
}); });
})); }));
testing_1.it('should return error with a wrong username and password ', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) { testing_1.it('should return error with a wrong username and password ', testing_1.injectAsync([testing_1.TestComponentBuilder], function (tcb) {
return tcb return tcb
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent) .createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) { .then(function (fixture) {

File diff suppressed because one or more lines are too long

View File

@ -24,6 +24,7 @@ import { RootRouter } from 'angular2/src/router/router';
import { Location, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT, Route } from 'angular2/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 {dispatchEvent} from 'angular2/src/testing/utils';
import {TranslateService} from 'ng2-translate/ng2-translate';
class AuthenticationMock { class AuthenticationMock {
public mockName:string = 'Mocked Service'; public mockName:string = 'Mocked Service';
@ -41,6 +42,16 @@ class AuthenticationMock {
} }
} }
class TranslationMock {
setDefaultLang() {
}
use() {
}
}
describe('AlfrescoLogin', () => { describe('AlfrescoLogin', () => {
let authService, location, router; let authService, location, router;
@ -54,7 +65,8 @@ describe('AlfrescoLogin', () => {
RouteRegistry, RouteRegistry,
provide(Location, {useClass: SpyLocation}), provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AlfrescoLoginComponent}), provide(ROUTER_PRIMARY_COMPONENT, {useValue: AlfrescoLoginComponent}),
provide(Router, {useClass: RootRouter}) provide(Router, {useClass: RootRouter}),
provide(TranslateService, {useClass: TranslationMock})
]; ];
}); });
@ -63,7 +75,7 @@ describe('AlfrescoLogin', () => {
location = l; location = l;
})); }));
it('should render `Login` form with input fields user and password with default value', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => { it('should render `Login` form with input fields user and password with default value', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@ -77,7 +89,7 @@ describe('AlfrescoLogin', () => {
})); }));
it('should render the new values after change the user and password values', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => { it('should render the new values after change the user and password values', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@ -94,7 +106,7 @@ describe('AlfrescoLogin', () => {
}); });
})); }));
it('should navigate to Home route after the login OK ', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => { it('should navigate to Home route after the login OK ', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@ -115,7 +127,7 @@ describe('AlfrescoLogin', () => {
}); });
})); }));
it('should return error with a wrong username ', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => { it('should return error with a wrong username ', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@ -134,7 +146,7 @@ describe('AlfrescoLogin', () => {
}); });
})); }));
it('should return error with a wrong password ', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => { it('should return error with a wrong password ', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@ -153,7 +165,7 @@ describe('AlfrescoLogin', () => {
}); });
})); }));
it('should return error with a wrong username and password ', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => { it('should return error with a wrong username and password ', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {

View File

@ -10,9 +10,15 @@
"noImplicitAny": false, "noImplicitAny": false,
"declaration": true "declaration": true
}, },
"files":[
"src/alfresco-login.component.ts",
"src/alfresco-login.component.spec.ts",
"src/alfresco-authentication.service.ts",
"src/alfresco-authentication.service.spec.ts"
],
"exclude": [ "exclude": [
"node_modules", "**/node_modules",
"typings/main", "**/typings/main",
"typings/main.d.ts" "**/typings/main.d.ts"
] ]
} }