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