blob: c5e8c352a802c2a475c14c38248e51275ea3f320 [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';
17import { ActivatedRoute, Params } from '@angular/router';
18import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
19import { DebugElement } from '@angular/core';
20import { By } from '@angular/platform-browser';
21import { of } from 'rxjs';
22
Sean Condon5ca00262018-09-06 17:55:25 +010023import {
24 ConsoleLoggerService,
25 FnService,
26 IconComponent,
27 IconService,
28 LionService,
29 LogService,
30 NavService } from 'gui2-fw-lib';
Sean Condon28ecc5f2018-06-25 12:50:16 +010031import { NavComponent } from './nav.component';
Sean Condon28ecc5f2018-06-25 12:50:16 +010032
33class MockActivatedRoute extends ActivatedRoute {
34 constructor(params: Params) {
35 super();
36 this.queryParams = of(params);
37 }
38}
39
40class MockNavService {}
41
42class MockIconService {
43 loadIconDef() {}
44}
45
46/**
47 * ONOS GUI -- Util -- Navigation Component - Unit Tests
48 */
49describe('NavComponent', () => {
50 let log: LogService;
51 let fs: FnService;
52 let ar: MockActivatedRoute;
53 let windowMock: Window;
54 let component: NavComponent;
55 let fixture: ComponentFixture<NavComponent>;
56 const bundleObj = {
57 'core.view.App': {
58 test: 'test1'
59 }
60 };
61 const mockLion = (key) => {
62 return bundleObj[key] || '%' + key + '%';
63 };
64
65 beforeEach(async(() => {
66 log = new ConsoleLoggerService();
67 ar = new MockActivatedRoute({'debug': 'txrx'});
68
69 windowMock = <any>{
70 location: <any> {
71 hostname: 'foo',
72 host: 'foo',
73 port: '80',
74 protocol: 'http',
75 search: { debug: 'true'},
76 href: 'ws://foo:123/onos/ui/websock/path',
77 absUrl: 'ws://foo:123/onos/ui/websock/path'
78 }
79 };
80 fs = new FnService(ar, log, windowMock);
81
82 TestBed.configureTestingModule({
83 imports: [ BrowserAnimationsModule ],
84 declarations: [ NavComponent, IconComponent ],
85 providers: [
86 { provide: FnService, useValue: fs },
87 { provide: IconService, useClass: MockIconService },
88 { provide: LionService, useFactory: (() => {
89 return {
90 bundle: ((bundleId) => mockLion),
91 ubercache: new Array(),
92 loadCbs: new Map<string, () => void>([])
93 };
94 })
95 },
96 { provide: LogService, useValue: log },
97 { provide: NavService, useClass: MockNavService },
98 { provide: 'Window', useValue: windowMock },
99 ]
100 })
101 .compileComponents();
102 }));
103
104 beforeEach(() => {
105 fixture = TestBed.createComponent(NavComponent);
106 component = fixture.debugElement.componentInstance;
107 fixture.detectChanges();
108 });
109
110 it('should create', () => {
111 expect(component).toBeTruthy();
112 });
113
114 it('should have a nav#nav', () => {
115 const appDe: DebugElement = fixture.debugElement;
116 const divDe = appDe.query(By.css('nav#nav'));
117 expect(divDe).toBeTruthy();
118 });
119
120 it('should have a platform div.nav-hdr inside a nav#nav', () => {
121 const appDe: DebugElement = fixture.debugElement;
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +0530122 const divDe = appDe.query(By.css('nav#nav div#platform.nav-hdr'));
Sean Condon28ecc5f2018-06-25 12:50:16 +0100123 const div: HTMLElement = divDe.nativeElement;
124 expect(div.textContent).toEqual('%cat_platform%');
125 });
126
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +0530127 it('should have an app view link inside a nav#nav', () => {
Sean Condon28ecc5f2018-06-25 12:50:16 +0100128 const appDe: DebugElement = fixture.debugElement;
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +0530129 const divDe = appDe.query(By.css('nav#nav a#app'));
Sean Condon28ecc5f2018-06-25 12:50:16 +0100130 const div: HTMLElement = divDe.nativeElement;
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +0530131 expect(div.textContent).toEqual(' Applications');
132 });
133
Priyanka H Mfa5b77a2018-07-27 12:43:44 +0530134 it('should have an cluster view link inside a nav#nav', () => {
135 const appDe: DebugElement = fixture.debugElement;
136 const divDe = appDe.query(By.css('nav#nav a#cluster'));
137 const div: HTMLElement = divDe.nativeElement;
138 expect(div.textContent).toEqual(' Cluster Nodes');
139 });
140
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +0530141 it('should have an processor view link inside a nav#nav', () => {
142 const appDe: DebugElement = fixture.debugElement;
143 const divDe = appDe.query(By.css('nav#nav a#processor'));
144 const div: HTMLElement = divDe.nativeElement;
145 expect(div.textContent).toEqual(' Packet Processors');
146 });
147
148 it('should have a settings view link inside a nav#nav', () => {
149 const appDe: DebugElement = fixture.debugElement;
150 const divDe = appDe.query(By.css('nav#nav a#settings'));
151 const div: HTMLElement = divDe.nativeElement;
152 expect(div.textContent).toEqual(' Settings');
153 });
154
155 it('should have a partition view link inside a nav#nav', () => {
156 const appDe: DebugElement = fixture.debugElement;
157 const divDe = appDe.query(By.css('nav#nav a#partition'));
158 const div: HTMLElement = divDe.nativeElement;
159 expect(div.textContent).toEqual(' Partitions');
160 });
161
162 it('should have a network div.nav-hdr inside a nav#nav', () => {
163 const appDe: DebugElement = fixture.debugElement;
164 const divDe = appDe.query(By.css('nav#nav div#network.nav-hdr'));
165 const div: HTMLElement = divDe.nativeElement;
166 expect(div.textContent).toEqual('%cat_network%');
167 });
168
169 it('should have a device view link inside a nav#nav', () => {
170 const appDe: DebugElement = fixture.debugElement;
171 const divDe = appDe.query(By.css('nav#nav a#device'));
172 const div: HTMLElement = divDe.nativeElement;
173 expect(div.textContent).toEqual(' Devices');
174 });
175
176 it('should have a link view link inside a nav#nav', () => {
177 const appDe: DebugElement = fixture.debugElement;
178 const divDe = appDe.query(By.css('nav#nav a#link'));
179 const div: HTMLElement = divDe.nativeElement;
180 expect(div.textContent).toEqual(' Links');
181 });
182
183 it('should have a host view link inside a nav#nav', () => {
184 const appDe: DebugElement = fixture.debugElement;
185 const divDe = appDe.query(By.css('nav#nav a#host'));
186 const div: HTMLElement = divDe.nativeElement;
187 expect(div.textContent).toEqual(' Hosts');
188 });
189
190 it('should have a intent view link inside a nav#nav', () => {
191 const appDe: DebugElement = fixture.debugElement;
192 const divDe = appDe.query(By.css('nav#nav a#intent'));
193 const div: HTMLElement = divDe.nativeElement;
194 expect(div.textContent).toEqual(' Intents');
195 });
196
197 it('should have a tunnel view link inside a nav#nav', () => {
198 const appDe: DebugElement = fixture.debugElement;
199 const divDe = appDe.query(By.css('nav#nav a#tunnel'));
200 const div: HTMLElement = divDe.nativeElement;
201 expect(div.textContent).toEqual(' Tunnels');
Sean Condon28ecc5f2018-06-25 12:50:16 +0100202 });
203});