2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
20 ============LICENSE_END============================================
23 import { async, ComponentFixture, TestBed, fakeAsync, tick, inject } from '@angular/core/testing';
24 import { RouterTestingModule } from "@angular/router/testing";
25 import { BaseRequestOptions, Response, ResponseOptions, Http } from '@angular/http';
26 import { MockBackend, MockConnection } from '@angular/http/testing';
27 import { Router, ActivatedRoute } from "@angular/router";
28 import { Observable } from 'rxjs/Observable';
29 import 'rxjs/add/observable/empty';
30 import 'rxjs/add/observable/of';
32 import { NavigationComponent } from './navigation.component';
33 import { EmitterService } from '../../services/emitter.service';
35 describe('NavigationComponent', () => {
36 let component: NavigationComponent;
37 let fixture: ComponentFixture<NavigationComponent>;
39 beforeEach(async(() => {
40 TestBed.configureTestingModule({
41 declarations: [NavigationComponent],
42 imports: [RouterTestingModule.withRoutes([])],
43 providers: [EmitterService, MockBackend, BaseRequestOptions, {
45 useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
46 return new Http(backend, defaultOptions);
48 deps: [MockBackend, BaseRequestOptions],
55 fixture = TestBed.createComponent(NavigationComponent);
56 component = fixture.componentInstance;
57 fixture.detectChanges();
60 it('should create', () => {
61 expect(component).toBeTruthy();
64 it('should set userLoggedIn on ngOnInit', () => {
65 component.userId = 'testingId';
70 describe('Should test ngOnChanges', () => {
71 it('should validate on ngOnChanges subscribe return', () => {
72 let spy = spyOn(EmitterService, 'get').and.returnValue(Observable.of('you object'));
73 component.id = 'userLogin';
75 component.ngOnChanges();
77 expect(spy).toHaveBeenCalled();
80 it('should validate on ngOnChanges if subscribe return null or undefined', inject([Router],(router: Router) => {
81 let spy = spyOn(EmitterService, 'get').and.returnValue(Observable.of(''));
82 let spy1 = spyOn(component, 'logout');
83 component.id = 'userLogin';
84 component.ngOnChanges();
86 expect(spy).toHaveBeenCalled();
88 expect(spy1).toHaveBeenCalled()
92 it('should go to /vnfs/list if url = vnfs and userId is not null or undefined', inject([Router],(router: Router) => {
93 let navigateSpy = spyOn(router, 'navigate');
94 sessionStorage['userId'] = 'testingId';
97 component.gotoDetail(testUrl);
100 it('should go to /vnfs if url = vnfs and userId is null or undefined', inject([Router],(router: Router) => {
101 let navigateSpy = spyOn(router, 'navigate');
102 sessionStorage['userId'] = '';
103 let testUrl = 'vnfs';
105 component.gotoDetail(testUrl);
108 it('should go to passed url if url != vnfs', inject([Router],(router: Router) => {
109 let navigateSpy = spyOn(router, 'navigate');
110 let testUrl = 'test';
112 component.gotoDetail(testUrl);
115 it('should logout', inject([Router],(router: Router) => {
116 let navigateSpy = spyOn(router, 'navigate');