From a64e331255206eb2c2a8b0d2503762cbc5ac9751 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Mon, 6 Aug 2018 16:39:01 +0530 Subject: gcauth.guard.service - added test case Added test case to cover canActivate method when referenceObject is not defined. Issue-ID: APPC-1064 Change-Id: I19d08cf1e0b6426e52d1db48be89ed8e76864560 Signed-off-by: Arundathi Patil --- src/app/vnfs/GCAuthGuard/gcauth.guard.spec.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/vnfs/GCAuthGuard/gcauth.guard.spec.ts b/src/app/vnfs/GCAuthGuard/gcauth.guard.spec.ts index dc1d253..440993d 100644 --- a/src/app/vnfs/GCAuthGuard/gcauth.guard.spec.ts +++ b/src/app/vnfs/GCAuthGuard/gcauth.guard.spec.ts @@ -27,7 +27,7 @@ import {CommonModule} from '@angular/common'; import 'rxjs/Rx'; import 'rxjs/add/observable/throw'; import 'rxjs/add/operator/map'; -import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; +import { NgbModule, NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { GCAuthGuardService } from './gcauth-guard.service'; import {MappingEditorService} from '../../shared/services/mapping-editor.service'; import { promise } from 'protractor'; @@ -50,7 +50,7 @@ describe('LogginGuard', () => { loggedInGuard = TestBed.get(GCAuthGuardService); }); - it('be able to hit route when user is logged in', inject([GCAuthGuardService, MappingEditorService], (service: GCAuthGuardService, mapService: MappingEditorService) => { + it('be able to return true when referenceNameObjects is defined', inject([GCAuthGuardService, MappingEditorService], (service: GCAuthGuardService, mapService: MappingEditorService) => { localStorage['userId'] = 'abc@xyz.com'; mapService.referenceNameObjects = { data : 'data'}; let route : ActivatedRouteSnapshot; @@ -59,4 +59,15 @@ describe('LogginGuard', () => { expect(value).toBe(true); }) })); + + it('stop routing if referenceNameObjects is not defined', inject([GCAuthGuardService, MappingEditorService, NgbModal], (service: GCAuthGuardService, mapService: MappingEditorService, ngbModal: NgbModal) => { + localStorage['userId'] = 'abc@xyz.com'; + mapService.referenceNameObjects = undefined; + let spy = spyOn(NgbModal.prototype, 'open').and.returnValue(Promise.resolve(true)); + let route : ActivatedRouteSnapshot; + let state: RouterStateSnapshot; + service.canActivate(route, state).then((value)=>{ + expect(value).toBe(true); + }) + })); }); -- cgit 1.2.3-korg