Fixed error in user-login-form spec file 01/58001/4
authorArundathi Patil <arundpil@in.ibm.com>
Mon, 30 Jul 2018 10:15:23 +0000 (15:45 +0530)
committerTakamune Cho <tc012c@att.com>
Wed, 1 Aug 2018 18:03:12 +0000 (18:03 +0000)
Test cases in userLogin-form spec file failed with below error,
Error: Cannot read property 'root' of undefined.

This error was because, activated route was not injected into the
testingbed. Fixed this error.

Issue-ID: APPC-1064
Change-Id: Ib9978b73be744204e8dd64b97abbc0959a4e5839
Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
src/app/vnfs/userlogin-form/userlogin-form.component.spec.ts

index d253cb7..16863a4 100644 (file)
@@ -2,6 +2,8 @@
 ============LICENSE_START==========================================
 ===================================================================
 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+
+Modification Copyright (C) 2018 IBM
 ===================================================================
 
 Unless otherwise specified, all software contained herein is licensed
@@ -24,6 +26,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
 /* tslint:disable:no-unused-variable */
 import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
 import { NO_ERRORS_SCHEMA } from '@angular/core';
+import { ActivatedRoute } from '@angular/router';
 import { userloginFormComponent } from './userlogin-form.component';
 import { FormsModule } from '@angular/forms';
 import { NotificationService } from './../../shared/services/notification.service';
@@ -39,15 +42,21 @@ import {NotificationsService} from 'angular2-notifications';
 describe('userloginFormComponent', () => {
     let component: userloginFormComponent;
     let fixture: ComponentFixture<userloginFormComponent>;
+    let mockActiveRoute = {
+        snapshot: {
+          queryParams: {
+            returnUrl: '/home',
+          }
+        }
+     };
     beforeEach(async(() => {
         TestBed.configureTestingModule({
             declarations: [userloginFormComponent],
             schemas: [NO_ERRORS_SCHEMA],
             imports: [FormsModule, RouterTestingModule,],
-            providers: [UtilityService, ParamShareService, DialogService, NotificationService,NotificationsService, HttpUtilService, MappingEditorService, {
-                provide: Router,
-                useClass: MockRouter
-            }, { provide: Router, useClass: MockRouter }]
+            providers: [UtilityService, ParamShareService, DialogService,NotificationsService, HttpUtilService, MappingEditorService,
+                {provide: ActivatedRoute, useValue: mockActiveRoute}, 
+                { provide: Router, useClass: MockRouter }]
         })
             .compileComponents();
     }));
@@ -82,7 +91,7 @@ describe('userloginFormComponent', () => {
     });
 
     it('should route to myvnfform', inject([Router], (router: Router) => {
-        const spy = spyOn(router, 'navigate');
+        const spy = spyOn(router, 'navigateByUrl');
         component.getData();
         const url = spy.calls.first().args[0];