blob: acc400f0872d7f27bf57db29e64378694ec26878 [file] [log] [blame]
Sean Condon28ecc5f2018-06-25 12:50:16 +01001/*
2 * Copyright 2015-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { async, ComponentFixture, TestBed } from '@angular/core/testing';
Sean Condon87b78502018-09-17 20:53:24 +010017import { RouterModule, ActivatedRoute, Params } from '@angular/router';
Sean Condon28ecc5f2018-06-25 12:50:16 +010018import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
19import { DebugElement } from '@angular/core';
20import { By } from '@angular/platform-browser';
Sean Condon87b78502018-09-17 20:53:24 +010021import { of, from } from 'rxjs';
22import { HttpClient, HttpErrorResponse } from '@angular/common/http';
Sean Condon28ecc5f2018-06-25 12:50:16 +010023
Sean Condon5ca00262018-09-06 17:55:25 +010024import {
25 ConsoleLoggerService,
26 FnService,
27 IconComponent,
28 IconService,
29 LionService,
30 LogService,
31 NavService } from 'gui2-fw-lib';
Sean Condon28ecc5f2018-06-25 12:50:16 +010032import { NavComponent } from './nav.component';
Sean Condon28ecc5f2018-06-25 12:50:16 +010033
34class MockActivatedRoute extends ActivatedRoute {
35 constructor(params: Params) {
36 super();
37 this.queryParams = of(params);
38 }
39}
40
Sean Condon87b78502018-09-17 20:53:24 +010041class MockHttpClient {
42 get() {
43 return from(['{"id":"app","icon":"nav_apps","cat":"PLATFORM","label":"Applications"},' +
44 '{"id":"settings","icon":"nav_settings","cat":"PLATFORM","label":"Settings"}']);
45 }
46
47 subscribe() {}
48}
49
50class MockNavService {
51 uiPlatformViews = [];
52 uiNetworkViews = [];
53 uiOtherViews = [];
54 uiHiddenViews = [];
55
56 getUiViews() {}
57}
Sean Condon28ecc5f2018-06-25 12:50:16 +010058
59class MockIconService {
60 loadIconDef() {}
61}
62
63/**
64 * ONOS GUI -- Util -- Navigation Component - Unit Tests
65 */
66describe('NavComponent', () => {
67 let log: LogService;
68 let fs: FnService;
69 let ar: MockActivatedRoute;
70 let windowMock: Window;
71 let component: NavComponent;
72 let fixture: ComponentFixture<NavComponent>;
73 const bundleObj = {
74 'core.view.App': {
75 test: 'test1'
76 }
77 };
78 const mockLion = (key) => {
79 return bundleObj[key] || '%' + key + '%';
80 };
81
82 beforeEach(async(() => {
83 log = new ConsoleLoggerService();
84 ar = new MockActivatedRoute({'debug': 'txrx'});
85
86 windowMock = <any>{
87 location: <any> {
88 hostname: 'foo',
89 host: 'foo',
90 port: '80',
91 protocol: 'http',
92 search: { debug: 'true'},
93 href: 'ws://foo:123/onos/ui/websock/path',
94 absUrl: 'ws://foo:123/onos/ui/websock/path'
95 }
96 };
97 fs = new FnService(ar, log, windowMock);
98
99 TestBed.configureTestingModule({
Sean Condon87b78502018-09-17 20:53:24 +0100100 imports: [ BrowserAnimationsModule, RouterModule ],
Sean Condon28ecc5f2018-06-25 12:50:16 +0100101 declarations: [ NavComponent, IconComponent ],
102 providers: [
103 { provide: FnService, useValue: fs },
104 { provide: IconService, useClass: MockIconService },
Sean Condon87b78502018-09-17 20:53:24 +0100105 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon28ecc5f2018-06-25 12:50:16 +0100106 { provide: LionService, useFactory: (() => {
107 return {
108 bundle: ((bundleId) => mockLion),
109 ubercache: new Array(),
110 loadCbs: new Map<string, () => void>([])
111 };
112 })
113 },
114 { provide: LogService, useValue: log },
115 { provide: NavService, useClass: MockNavService },
116 { provide: 'Window', useValue: windowMock },
117 ]
118 })
119 .compileComponents();
120 }));
121
122 beforeEach(() => {
123 fixture = TestBed.createComponent(NavComponent);
124 component = fixture.debugElement.componentInstance;
125 fixture.detectChanges();
126 });
127
128 it('should create', () => {
129 expect(component).toBeTruthy();
130 });
131
132 it('should have a nav#nav', () => {
133 const appDe: DebugElement = fixture.debugElement;
134 const divDe = appDe.query(By.css('nav#nav'));
135 expect(divDe).toBeTruthy();
136 });
137
138 it('should have a platform div.nav-hdr inside a nav#nav', () => {
139 const appDe: DebugElement = fixture.debugElement;
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +0530140 const divDe = appDe.query(By.css('nav#nav div#platform.nav-hdr'));
Sean Condon28ecc5f2018-06-25 12:50:16 +0100141 const div: HTMLElement = divDe.nativeElement;
142 expect(div.textContent).toEqual('%cat_platform%');
143 });
144
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +0530145 it('should have a network div.nav-hdr inside a nav#nav', () => {
146 const appDe: DebugElement = fixture.debugElement;
147 const divDe = appDe.query(By.css('nav#nav div#network.nav-hdr'));
148 const div: HTMLElement = divDe.nativeElement;
149 expect(div.textContent).toEqual('%cat_network%');
150 });
151
Sean Condon28ecc5f2018-06-25 12:50:16 +0100152});