blob: 3d061a5f7aaf8bac4c1769879ef4e4d5301c3a74 [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 { DebugElement } from '@angular/core';
18import { By } from '@angular/platform-browser';
19
20import { LogService } from '../../../log.service';
21import { ConsoleLoggerService } from '../../../consolelogger.service';
22import { MastComponent } from './mast.component';
23import { IconComponent } from '../../svg/icon/icon.component';
24import { LionService } from '../../util/lion.service';
25import { IconService } from '../../svg/icon.service';
26import { NavService } from '../../nav/nav.service';
27import { WebSocketService } from '../../remote/websocket.service';
28
29class MockNavService {}
30
31class MockIconService {
32 loadIconDef() {}
33}
34
35class MockWebSocketService {
36 createWebSocket() {}
37 isConnected() { return false; }
38 unbindHandlers() {}
39 bindHandlers() {}
40}
41
42/**
43 * ONOS GUI -- Masthead Controller - Unit Tests
44 */
45describe('MastComponent', () => {
46 let log: LogService;
47 let windowMock: Window;
48 let component: MastComponent;
49 let fixture: ComponentFixture<MastComponent>;
50 const bundleObj = {
51 'core.view.App': {
52 test: 'test1',
53 tt_help: 'Help!'
54 }
55 };
56 const mockLion = (key) => {
57 return bundleObj[key] || '%' + key + '%';
58 };
59
60 beforeEach(async(() => {
61 log = new ConsoleLoggerService();
62 windowMock = <any>{
63 location: <any> {
64 hostname: 'foo',
65 pathname: 'apps',
66 host: 'foo',
67 port: '80',
68 protocol: 'http',
69 search: { debug: 'true'},
70 href: 'ws://foo:123/onos/ui/websock/path',
71 absUrl: 'ws://foo:123/onos/ui/websock/path'
72 }
73 };
74
75 TestBed.configureTestingModule({
76 declarations: [ MastComponent, IconComponent ],
77 providers: [
78 { provide: LogService, useValue: log },
79 { provide: NavService, useClass: MockNavService },
80 { provide: LionService, useFactory: (() => {
81 return {
82 bundle: ((bundleId) => mockLion),
83 ubercache: new Array(),
84 loadCbs: new Map<string, () => void>([])
85 };
86 })
87 },
88 { provide: IconService, useClass: MockIconService },
89 { provide: WebSocketService, useClass: MockWebSocketService },
90 { provide: 'Window', useValue: windowMock }
91 ]
92 })
93 .compileComponents();
94 }));
95
96 beforeEach(() => {
97 fixture = TestBed.createComponent(MastComponent);
98 component = fixture.debugElement.componentInstance;
99 fixture.detectChanges();
100 });
101
102 it('should create', () => {
103 expect(component).toBeTruthy();
104 });
105
106 it('should have a div#mast-top-block', () => {
107 const appDe: DebugElement = fixture.debugElement;
108 const divDe = appDe.query(By.css('div#mast-top-block'));
109 expect(divDe).toBeTruthy();
110 });
111
112 it('should have a span.nav-menu-button inside a div#mast', () => {
113 const appDe: DebugElement = fixture.debugElement;
114 const divDe = appDe.query(By.css('div#mast span.nav-menu-button'));
115 expect(divDe).toBeTruthy();
116 });
117
118 it('should have a div.dropdown-parent inside a div#mast-right inside a div#mast', () => {
119 const appDe: DebugElement = fixture.debugElement;
120 const divDe = appDe.query(By.css('div#mast div#mast-right div.dropdown-parent'));
121 const div: HTMLElement = divDe.nativeElement;
122 expect(div.textContent).toEqual(' %logout% ');
123 });
124
125 it('should have an onos-icon inside a div#mast-right inside a div#mast', () => {
126 const appDe: DebugElement = fixture.debugElement;
127 const divDe = appDe.query(By.css('div#mast div#mast-right div.ctrl-btns div.active onos-icon'));
128 expect(divDe).toBeTruthy();
129 });
130
131});