blob: 40edf5da33ed61ff8ca89ce186b57ea71551e9eb [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +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 Condon2bd11b72018-06-15 08:00:48 +010017import { ActivatedRoute, Params } from '@angular/router';
18import { DebugElement } from '@angular/core';
19import { By } from '@angular/platform-browser';
Sean Condon49e15be2018-05-16 16:58:29 +010020import { LogService } from '../../../../app/log.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010021import { DeviceComponent } from '../../../../app/view/device/device.component';
Sean Condonfd6d11b2018-06-02 20:29:49 +010022
Sean Condon49e15be2018-05-16 16:58:29 +010023import { DetailsPanelService } from '../../../../app/fw/layer/detailspanel.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010024import { FnService, WindowSize } from '../../../../app/fw/util/fn.service';
Sean Condon49e15be2018-05-16 16:58:29 +010025import { IconService } from '../../../../app/fw/svg/icon.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010026import { GlyphService } from '../../../../app/fw/svg/glyph.service';
Sean Condon2bd11b72018-06-15 08:00:48 +010027import { IconComponent } from '../../../../app/fw/svg/icon/icon.component';
Sean Condon49e15be2018-05-16 16:58:29 +010028import { KeyService } from '../../../../app/fw/util/key.service';
29import { LoadingService } from '../../../../app/fw/layer/loading.service';
30import { NavService } from '../../../../app/fw/nav/nav.service';
31import { MastService } from '../../../../app/fw/mast/mast.service';
32import { PanelService } from '../../../../app/fw/layer/panel.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010033import { SvgUtilService } from '../../../../app/fw/svg/svgutil.service';
Sean Condon49e15be2018-05-16 16:58:29 +010034import { TableDetailService } from '../../../../app/fw/widget/tabledetail.service';
Sean Condon2bd11b72018-06-15 08:00:48 +010035import { ThemeService } from '../../../../app/fw/util/theme.service';
Sean Condon49e15be2018-05-16 16:58:29 +010036import { WebSocketService } from '../../../../app/fw/remote/websocket.service';
Sean Condon2bd11b72018-06-15 08:00:48 +010037import { of } from 'rxjs';
Sean Condon49e15be2018-05-16 16:58:29 +010038
Sean Condon2bd11b72018-06-15 08:00:48 +010039class MockActivatedRoute extends ActivatedRoute {
40 constructor(params: Params) {
41 super();
42 this.queryParams = of(params);
Sean Condonfd6d11b2018-06-02 20:29:49 +010043 }
44}
Sean Condon49e15be2018-05-16 16:58:29 +010045
Sean Condon2bd11b72018-06-15 08:00:48 +010046class MockDetailsPanelService {}
47
48class MockFnService {}
49
50class MockIconService {
51 loadIconDef() {}
52}
Sean Condon49e15be2018-05-16 16:58:29 +010053
Sean Condonfd6d11b2018-06-02 20:29:49 +010054class MockGlyphService {}
55
Sean Condon49e15be2018-05-16 16:58:29 +010056class MockKeyService {}
57
58class MockLoadingService {
Sean Condon2bd11b72018-06-15 08:00:48 +010059 startAnim() {}
60 stop() {}
Sean Condon49e15be2018-05-16 16:58:29 +010061}
62
63class MockNavService {}
64
65class MockMastService {}
66
67class MockPanelService {}
68
69class MockTableBuilderService {}
70
71class MockTableDetailService {}
72
Sean Condon2bd11b72018-06-15 08:00:48 +010073class MockThemeService {}
74
75class MockWebSocketService {
76 createWebSocket() {}
77 isConnected() { return false; }
78 unbindHandlers() {}
79 bindHandlers() {}
80}
Sean Condon83fc39f2018-04-19 18:56:13 +010081
82/**
83 * ONOS GUI -- Device View Module - Unit Tests
84 */
85describe('DeviceComponent', () => {
Sean Condon2bd11b72018-06-15 08:00:48 +010086 let fs: FnService;
87 let ar: MockActivatedRoute;
88 let windowMock: Window;
89 let logServiceSpy: jasmine.SpyObj<LogService>;
Sean Condon49e15be2018-05-16 16:58:29 +010090 let component: DeviceComponent;
91 let fixture: ComponentFixture<DeviceComponent>;
Sean Condon83fc39f2018-04-19 18:56:13 +010092
Sean Condon49e15be2018-05-16 16:58:29 +010093 beforeEach(async(() => {
Sean Condon2bd11b72018-06-15 08:00:48 +010094 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
95 ar = new MockActivatedRoute({'debug': 'txrx'});
96
97 windowMock = <any>{
98 location: <any> {
99 hostname: 'foo',
100 host: 'foo',
101 port: '80',
102 protocol: 'http',
103 search: { debug: 'true'},
104 href: 'ws://foo:123/onos/ui/websock/path',
105 absUrl: 'ws://foo:123/onos/ui/websock/path'
106 }
107 };
108 fs = new FnService(ar, logSpy, windowMock);
109
Sean Condon83fc39f2018-04-19 18:56:13 +0100110
Sean Condon49e15be2018-05-16 16:58:29 +0100111 TestBed.configureTestingModule({
Sean Condon2bd11b72018-06-15 08:00:48 +0100112 declarations: [ DeviceComponent, IconComponent ],
Sean Condon49e15be2018-05-16 16:58:29 +0100113 providers: [
114 { provide: DetailsPanelService, useClass: MockDetailsPanelService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100115 { provide: FnService, useValue: fs },
Sean Condon49e15be2018-05-16 16:58:29 +0100116 { provide: IconService, useClass: MockIconService },
Sean Condonfd6d11b2018-06-02 20:29:49 +0100117 { provide: GlyphService, useClass: MockGlyphService },
Sean Condon49e15be2018-05-16 16:58:29 +0100118 { provide: KeyService, useClass: MockKeyService },
119 { provide: LoadingService, useClass: MockLoadingService },
120 { provide: MastService, useClass: MockMastService },
121 { provide: NavService, useClass: MockNavService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100122 { provide: LogService, useValue: logSpy },
Sean Condon49e15be2018-05-16 16:58:29 +0100123 { provide: PanelService, useClass: MockPanelService },
Sean Condon49e15be2018-05-16 16:58:29 +0100124 { provide: TableDetailService, useClass: MockTableDetailService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100125 { provide: ThemeService, useClass: MockThemeService },
Sean Condon49e15be2018-05-16 16:58:29 +0100126 { provide: WebSocketService, useClass: MockWebSocketService },
Sean Condona00bf382018-06-23 07:54:01 +0100127 { provide: 'Window', useValue: windowMock },
Sean Condon49e15be2018-05-16 16:58:29 +0100128 ]
129 })
130 .compileComponents();
Sean Condon2bd11b72018-06-15 08:00:48 +0100131 logServiceSpy = TestBed.get(LogService);
Sean Condon49e15be2018-05-16 16:58:29 +0100132 }));
Sean Condon83fc39f2018-04-19 18:56:13 +0100133
Sean Condon49e15be2018-05-16 16:58:29 +0100134 beforeEach(() => {
135 fixture = TestBed.createComponent(DeviceComponent);
Sean Condon2bd11b72018-06-15 08:00:48 +0100136 component = fixture.debugElement.componentInstance;
Sean Condon49e15be2018-05-16 16:58:29 +0100137 fixture.detectChanges();
138 });
139
140 it('should create', () => {
141 expect(component).toBeTruthy();
142 });
Sean Condon2bd11b72018-06-15 08:00:48 +0100143
144 it('should have .table-header with "Friendly Name..."', () => {
145 const appDe: DebugElement = fixture.debugElement;
146 const divDe = appDe.query(By.css('.table-header'));
147 const div: HTMLElement = divDe.nativeElement;
148 expect(div.textContent).toEqual('Friendly Name Device ID Master Ports Vendor H/W Version S/W Version Protocol ');
149 });
Sean Condon83fc39f2018-04-19 18:56:13 +0100150});