Fix test login

This commit is contained in:
mauriziovitale84
2016-06-16 12:21:10 +01:00
parent 950cc4d076
commit 530affb3dd
2 changed files with 25 additions and 50 deletions

View File

@@ -4,7 +4,7 @@ module.exports = function (config) {
var configuration = { var configuration = {
basePath: '.', basePath: '.',
frameworks: ['jasmine-ajax', 'jasmine'], frameworks: ['jasmine'],
files: [ files: [
// paths loaded by Karma // paths loaded by Karma
@@ -63,7 +63,6 @@ module.exports = function (config) {
plugins: [ plugins: [
'karma-jasmine', 'karma-jasmine',
'karma-coverage', 'karma-coverage',
'karma-jasmine-ajax',
'karma-chrome-launcher', 'karma-chrome-launcher',
'karma-mocha-reporter', 'karma-mocha-reporter',
'karma-jasmine-html-reporter' 'karma-jasmine-html-reporter'

View File

@@ -15,59 +15,42 @@
* limitations under the License. * limitations under the License.
*/ */
describe('AlfrescoLogin', () => {
it('should be upgraded to angular 2.0.0-rc.1', () => {
expect(false).toBe(true);
});
});
/* import {
import { TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS } from 'angular2/platform/testing/browser'; TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
} from '@angular/platform-browser-dynamic/testing';
import { import {
it, it,
describe, describe,
expect, expect,
inject, inject,
injectAsync,
beforeEach,
beforeEachProviders, beforeEachProviders,
TestComponentBuilder,
setBaseTestProviders setBaseTestProviders
} from '@angular/core/testing'; } from '@angular/core/testing';
import { TestComponentBuilder } from '@angular/compiler/testing';
import { provide } from '@angular/core'; import { provide } from '@angular/core';
import { Location, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT, Route } from 'angular2/router'; import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { RootRouter } from 'angular2/src/router/router';
import { SpyLocation } from 'angular2/src/mock/location_mock';
import { AlfrescoTranslationService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { AlfrescoLoginComponent } from './alfresco-login.component'; import { AlfrescoLoginComponent } from './alfresco-login.component';
import { AuthenticationMock } from './../assets/authentication.service.mock'; import { AuthenticationMock } from './../assets/authentication.service.mock';
import { TranslationMock } from './../assets/translation.service.mock'; import { TranslationMock } from './../assets/translation.service.mock';
describe('AlfrescoLogin', () => { describe('AlfrescoLogin', () => {
let authService, location, router; let authService;
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS); setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
beforeEachProviders(() => { beforeEachProviders(() => {
authService = new AuthenticationMock(); authService = new AuthenticationMock();
return [ return [
authService.getProviders(), authService.getProviders(),
RouteRegistry,
provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AlfrescoLoginComponent}),
provide(Router, {useClass: RootRouter}),
provide(AlfrescoTranslationService, {useClass: TranslationMock}) provide(AlfrescoTranslationService, {useClass: TranslationMock})
]; ];
}); });
beforeEach(inject([Router, Location], (r, l) => {
router = r;
location = l;
}));
it('should render `Login` form with all the keys to be translated', it('should render `Login` form with all the keys to be translated',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@@ -92,7 +75,7 @@ describe('AlfrescoLogin', () => {
})); }));
it('should render user and password input fields with default values', it('should render user and password input fields with default values',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@@ -106,7 +89,7 @@ describe('AlfrescoLogin', () => {
})); }));
it('should render min-length error when the username is lower than 4 characters', it('should render min-length error when the username is lower than 4 characters',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@@ -133,7 +116,7 @@ describe('AlfrescoLogin', () => {
})); }));
it('should render no errors when the username and password are correct', it('should render no errors when the username and password are correct',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@@ -161,7 +144,7 @@ describe('AlfrescoLogin', () => {
})); }));
it('should render the new values after user and password values are changed', it('should render the new values after user and password values are changed',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@@ -182,13 +165,11 @@ describe('AlfrescoLogin', () => {
}); });
})); }));
it('should navigate to Home route after the login have succeeded ', it('should return success true after the login have succeeded ',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
router.config([new Route({path: '/home', name: 'Home', component: AlfrescoLoginComponent})]);
spyOn(router, 'navigate').and.callThrough();
let component = fixture.componentInstance; let component = fixture.componentInstance;
component.isErrorStyle = function () { component.isErrorStyle = function () {
console.log('mock'); console.log('mock');
@@ -207,16 +188,15 @@ describe('AlfrescoLogin', () => {
fixture.detectChanges(); fixture.detectChanges();
expect(component.error).toBe(false); expect(component.error).toBe(false);
expect(router.navigate).toHaveBeenCalledWith(['Home']); expect(component.success).toBe(true);
}); });
})); }));
it('should return error with a wrong username ', it('should return error with a wrong username ',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
spyOn(router, 'navigate').and.callThrough();
let component = fixture.componentInstance; let component = fixture.componentInstance;
component.isErrorStyle = function () { component.isErrorStyle = function () {
console.log('mock'); console.log('mock');
@@ -240,11 +220,10 @@ describe('AlfrescoLogin', () => {
})); }));
it('should return error with a wrong password ', it('should return error with a wrong password ',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
spyOn(router, 'navigate').and.callThrough();
let component = fixture.componentInstance; let component = fixture.componentInstance;
component.isErrorStyle = function () { component.isErrorStyle = function () {
console.log('mock'); console.log('mock');
@@ -268,11 +247,10 @@ describe('AlfrescoLogin', () => {
})); }));
it('should return error with a wrong username and password ', it('should return error with a wrong username and password ',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
spyOn(router, 'navigate').and.callThrough();
let component = fixture.componentInstance; let component = fixture.componentInstance;
component.isErrorStyle = function () { component.isErrorStyle = function () {
console.log('mock'); console.log('mock');
@@ -297,7 +275,7 @@ describe('AlfrescoLogin', () => {
it('should emit onSuccess event after the login has succeeded', it('should emit onSuccess event after the login has succeeded',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@@ -329,7 +307,7 @@ describe('AlfrescoLogin', () => {
})); }));
it('should emit onError event after the login has failed', it('should emit onError event after the login has failed',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@@ -362,7 +340,7 @@ describe('AlfrescoLogin', () => {
})); }));
it('should render the password in clear when the toggleShowPassword is call', it('should render the password in clear when the toggleShowPassword is call',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@@ -383,7 +361,7 @@ describe('AlfrescoLogin', () => {
})); }));
it('should render the hide password when the password is in clear and the toggleShowPassword is call', it('should render the hide password when the password is in clear and the toggleShowPassword is call',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(AlfrescoLoginComponent) .createAsync(AlfrescoLoginComponent)
.then((fixture) => { .then((fixture) => {
@@ -403,7 +381,5 @@ describe('AlfrescoLogin', () => {
}); });
})); }));
}); });
*/