diff options
author | sj108s <sj108s@us.att.com> | 2018-03-15 20:26:47 +0530 |
---|---|---|
committer | sj108s <sj108s@us.att.com> | 2018-03-15 20:33:07 +0530 |
commit | 90174648e4553018398f88c6acbd9dc905aa17ff (patch) | |
tree | e2f1ad12c68d10020e8fb7681910f4ec7c4d8915 /src/app/shared | |
parent | 7cf978ff9f510733dce1cf70693feedcb5ffbccd (diff) |
Added few more test case & fixed modal in template
Added few more test cases to improve code coverage and changed trigger
command for modal in template page from Enter to ctrl-4
Issue-ID: APPC-697
Change-Id: I4a158ba687bad0bb2f808428333083200714f18a
Signed-off-by: sj108s <sj108s@us.att.com>
Diffstat (limited to 'src/app/shared')
-rw-r--r-- | src/app/shared/components/navigation/navigation.component.spec.ts | 67 | ||||
-rw-r--r-- | src/app/shared/directives/collapse.component.spec.ts | 22 |
2 files changed, 50 insertions, 39 deletions
diff --git a/src/app/shared/components/navigation/navigation.component.spec.ts b/src/app/shared/components/navigation/navigation.component.spec.ts index 9516e3d..2d4aafe 100644 --- a/src/app/shared/components/navigation/navigation.component.spec.ts +++ b/src/app/shared/components/navigation/navigation.component.spec.ts @@ -17,28 +17,17 @@ 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. -ECOMP is a trademark and service mark of AT&T Intellectual Property. ============LICENSE_END============================================ */ import { async, ComponentFixture, TestBed, fakeAsync, tick, inject } from '@angular/core/testing'; import { RouterTestingModule } from "@angular/router/testing"; +import { BaseRequestOptions, Response, ResponseOptions, Http } from '@angular/http'; +import { MockBackend, MockConnection } from '@angular/http/testing'; import { Router, ActivatedRoute } from "@angular/router"; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/empty'; -import {DialogService} from 'ng2-bootstrap-modal'; -import {FormsModule} from '@angular/forms'; -import {HttpModule} from '@angular/http'; -import {HttpUtilService} from '../../../shared/services/httpUtil/http-util.service'; -import {MappingEditorService} from '../../..//shared/services/mapping-editor.service'; -import {NO_ERRORS_SCHEMA} from '@angular/core'; -import {NgModule} from '@angular/core'; -import {NgProgress} from 'ngx-progressbar'; -import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; -import {NotificationService} from '../../../shared/services/notification.service'; -import {ParamShareService} from '../../..//shared/services/paramShare.service'; -import {SharedModule} from '../../../shared/shared.module'; -import {environment} from '../../../../environments/environment'; +import 'rxjs/add/observable/of'; import { NavigationComponent } from './navigation.component'; import { EmitterService } from '../../services/emitter.service'; @@ -50,8 +39,14 @@ describe('NavigationComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [NavigationComponent], - imports: [RouterTestingModule.withRoutes([]),FormsModule, RouterTestingModule, HttpModule, NgbModule.forRoot()], - providers: [] + imports: [RouterTestingModule.withRoutes([])], + providers: [EmitterService, MockBackend, BaseRequestOptions, { + provide: Http, + useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { + return new Http(backend, defaultOptions); + }, + deps: [MockBackend, BaseRequestOptions], + }] }) .compileComponents(); })); @@ -72,15 +67,26 @@ describe('NavigationComponent', () => { component.ngOnInit(); }); - it('should validate on ngOnChanges', () => { - let spy = spyOn(EmitterService, 'get').and.callFake( ({}) => { - return Observable.empty(); + describe('Should test ngOnChanges', () => { + it('should validate on ngOnChanges subscribe return', () => { + let spy = spyOn(EmitterService, 'get').and.returnValue(Observable.of('you object')); + component.id = 'userLogin'; + + component.ngOnChanges(); + + expect(spy).toHaveBeenCalled(); }); - component.id = 'userLogin'; - component.ngOnChanges(); + it('should validate on ngOnChanges if subscribe return null or undefined', inject([Router],(router: Router) => { + let spy = spyOn(EmitterService, 'get').and.returnValue(Observable.of('')); + let spy1 = spyOn(component, 'logout'); + component.id = 'userLogin'; + component.ngOnChanges(); - expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalled(); + + expect(spy1).toHaveBeenCalled() + })); }); it('should go to /vnfs/list if url = vnfs and userId is not null or undefined', inject([Router],(router: Router) => { @@ -111,21 +117,4 @@ describe('NavigationComponent', () => { component.logout(); })); - it('should ngOnChanges', () => { - component.id="uday" - component.ngOnChanges() - expect(component.userLoggedIn).toBeFalsy(); - }); - it('should ngOnInit()', () => { - localStorage['userId']="uday" - component.ngOnInit() - expect(component.userLoggedIn).toBeTruthy(); - }); - it('should gotoDetail(url)', () => { - component.gotoDetail('vnfs') - }); - it('should logout()', () => { - component.logout() - expect(component.userLoggedIn).toBeFalsy(); - }); }); diff --git a/src/app/shared/directives/collapse.component.spec.ts b/src/app/shared/directives/collapse.component.spec.ts index 0d234d7..7bb7e26 100644 --- a/src/app/shared/directives/collapse.component.spec.ts +++ b/src/app/shared/directives/collapse.component.spec.ts @@ -1,3 +1,25 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software 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. + +============LICENSE_END============================================ +*/ + import { Collapse } from './collapse.component'; import { ElementRef } from '@angular/core'; |