blob: 7079b15436e58dbe6b91b26bd6e3ced88b0550d6 [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
23import { ConsoleLoggerService } from '../../../consolelogger.service';
Bhavesh72ead492018-07-19 16:29:18 +053024import { FnService } from '../../util/fn.service';
Sean Condon28ecc5f2018-06-25 12:50:16 +010025import { IconComponent } from '../../svg/icon/icon.component';
26import { IconService } from '../../svg/icon.service';
27import { LionService } from '../../util/lion.service';
28import { LogService } from '../../../log.service';
29import { NavComponent } from './nav.component';
30import { NavService } from '../nav.service';
31
32class MockActivatedRoute extends ActivatedRoute {
33 constructor(params: Params) {
34 super();
35 this.queryParams = of(params);
36 }
37}
38
39class MockNavService {}
40
41class MockIconService {
42 loadIconDef() {}
43}
44
45/**
46 * ONOS GUI -- Util -- Navigation Component - Unit Tests
47 */
48describe('NavComponent', () => {
49 let log: LogService;
50 let fs: FnService;
51 let ar: MockActivatedRoute;
52 let windowMock: Window;
53 let component: NavComponent;
54 let fixture: ComponentFixture<NavComponent>;
55 const bundleObj = {
56 'core.view.App': {
57 test: 'test1'
58 }
59 };
60 const mockLion = (key) => {
61 return bundleObj[key] || '%' + key + '%';
62 };
63
64 beforeEach(async(() => {
65 log = new ConsoleLoggerService();
66 ar = new MockActivatedRoute({'debug': 'txrx'});
67
68 windowMock = <any>{
69 location: <any> {
70 hostname: 'foo',
71 host: 'foo',
72 port: '80',
73 protocol: 'http',
74 search: { debug: 'true'},
75 href: 'ws://foo:123/onos/ui/websock/path',
76 absUrl: 'ws://foo:123/onos/ui/websock/path'
77 }
78 };
79 fs = new FnService(ar, log, windowMock);
80
81 TestBed.configureTestingModule({
82 imports: [ BrowserAnimationsModule ],
83 declarations: [ NavComponent, IconComponent ],
84 providers: [
85 { provide: FnService, useValue: fs },
86 { provide: IconService, useClass: MockIconService },
87 { provide: LionService, useFactory: (() => {
88 return {
89 bundle: ((bundleId) => mockLion),
90 ubercache: new Array(),
91 loadCbs: new Map<string, () => void>([])
92 };
93 })
94 },
95 { provide: LogService, useValue: log },
96 { provide: NavService, useClass: MockNavService },
97 { provide: 'Window', useValue: windowMock },
98 ]
99 })
100 .compileComponents();
101 }));
102
103 beforeEach(() => {
104 fixture = TestBed.createComponent(NavComponent);
105 component = fixture.debugElement.componentInstance;
106 fixture.detectChanges();
107 });
108
109 it('should create', () => {
110 expect(component).toBeTruthy();
111 });
112
113 it('should have a nav#nav', () => {
114 const appDe: DebugElement = fixture.debugElement;
115 const divDe = appDe.query(By.css('nav#nav'));
116 expect(divDe).toBeTruthy();
117 });
118
119 it('should have a platform div.nav-hdr inside a nav#nav', () => {
120 const appDe: DebugElement = fixture.debugElement;
121 const divDe = appDe.query(By.css('nav#nav div.nav-hdr'));
122 const div: HTMLElement = divDe.nativeElement;
123 expect(div.textContent).toEqual('%cat_platform%');
124 });
125
126 it('should have an apps link inside a nav#nav', () => {
127 const appDe: DebugElement = fixture.debugElement;
128 const divDe = appDe.query(By.css('nav#nav a'));
129 const div: HTMLElement = divDe.nativeElement;
Bhavesh72ead492018-07-19 16:29:18 +0530130 expect(div.textContent).toEqual(' Apps');
Sean Condon28ecc5f2018-06-25 12:50:16 +0100131 });
132});