blob: 066a636e583f16856b80e5fd77b9db53c81a7b91 [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 Condon28ecc5f2018-06-25 12:50:16 +010020import { LogService } from '../../log.service';
21import { DeviceComponent } from './device.component';
Sean Condonfd6d11b2018-06-02 20:29:49 +010022
Sean Condon28ecc5f2018-06-25 12:50:16 +010023import { FnService, WindowSize } from '../../fw/util/fn.service';
24import { IconService } from '../../fw/svg/icon.service';
25import { GlyphService } from '../../fw/svg/glyph.service';
26import { IconComponent } from '../../fw/svg/icon/icon.component';
27import { KeyService } from '../../fw/util/key.service';
28import { LoadingService } from '../../fw/layer/loading.service';
29import { NavService } from '../../fw/nav/nav.service';
30import { MastService } from '../../fw/mast/mast.service';
31import { SvgUtilService } from '../../fw/svg/svgutil.service';
32import { ThemeService } from '../../fw/util/theme.service';
33import { WebSocketService } from '../../fw/remote/websocket.service';
Sean Condon2bd11b72018-06-15 08:00:48 +010034import { of } from 'rxjs';
Sean Condon49e15be2018-05-16 16:58:29 +010035
Sean Condon2bd11b72018-06-15 08:00:48 +010036class MockActivatedRoute extends ActivatedRoute {
37 constructor(params: Params) {
38 super();
39 this.queryParams = of(params);
Sean Condonfd6d11b2018-06-02 20:29:49 +010040 }
41}
Sean Condon49e15be2018-05-16 16:58:29 +010042
Sean Condon2bd11b72018-06-15 08:00:48 +010043class MockDetailsPanelService {}
44
45class MockFnService {}
46
47class MockIconService {
48 loadIconDef() {}
49}
Sean Condon49e15be2018-05-16 16:58:29 +010050
Sean Condonfd6d11b2018-06-02 20:29:49 +010051class MockGlyphService {}
52
Sean Condon49e15be2018-05-16 16:58:29 +010053class MockKeyService {}
54
55class MockLoadingService {
Sean Condon2bd11b72018-06-15 08:00:48 +010056 startAnim() {}
57 stop() {}
Sean Condon49e15be2018-05-16 16:58:29 +010058}
59
60class MockNavService {}
61
62class MockMastService {}
63
Sean Condon49e15be2018-05-16 16:58:29 +010064class MockTableBuilderService {}
65
66class MockTableDetailService {}
67
Sean Condon2bd11b72018-06-15 08:00:48 +010068class MockThemeService {}
69
70class MockWebSocketService {
71 createWebSocket() {}
72 isConnected() { return false; }
73 unbindHandlers() {}
74 bindHandlers() {}
75}
Sean Condon83fc39f2018-04-19 18:56:13 +010076
77/**
78 * ONOS GUI -- Device View Module - Unit Tests
79 */
80describe('DeviceComponent', () => {
Sean Condon2bd11b72018-06-15 08:00:48 +010081 let fs: FnService;
82 let ar: MockActivatedRoute;
83 let windowMock: Window;
84 let logServiceSpy: jasmine.SpyObj<LogService>;
Sean Condon49e15be2018-05-16 16:58:29 +010085 let component: DeviceComponent;
86 let fixture: ComponentFixture<DeviceComponent>;
Sean Condon83fc39f2018-04-19 18:56:13 +010087
Sean Condon49e15be2018-05-16 16:58:29 +010088 beforeEach(async(() => {
Sean Condon2bd11b72018-06-15 08:00:48 +010089 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
90 ar = new MockActivatedRoute({'debug': 'txrx'});
91
92 windowMock = <any>{
93 location: <any> {
94 hostname: 'foo',
95 host: 'foo',
96 port: '80',
97 protocol: 'http',
98 search: { debug: 'true'},
99 href: 'ws://foo:123/onos/ui/websock/path',
100 absUrl: 'ws://foo:123/onos/ui/websock/path'
101 }
102 };
103 fs = new FnService(ar, logSpy, windowMock);
104
Sean Condon49e15be2018-05-16 16:58:29 +0100105 TestBed.configureTestingModule({
Sean Condon2bd11b72018-06-15 08:00:48 +0100106 declarations: [ DeviceComponent, IconComponent ],
Sean Condon49e15be2018-05-16 16:58:29 +0100107 providers: [
Sean Condon2bd11b72018-06-15 08:00:48 +0100108 { provide: FnService, useValue: fs },
Sean Condon49e15be2018-05-16 16:58:29 +0100109 { provide: IconService, useClass: MockIconService },
Sean Condonfd6d11b2018-06-02 20:29:49 +0100110 { provide: GlyphService, useClass: MockGlyphService },
Sean Condon49e15be2018-05-16 16:58:29 +0100111 { provide: KeyService, useClass: MockKeyService },
112 { provide: LoadingService, useClass: MockLoadingService },
113 { provide: MastService, useClass: MockMastService },
114 { provide: NavService, useClass: MockNavService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100115 { provide: LogService, useValue: logSpy },
Sean Condon2bd11b72018-06-15 08:00:48 +0100116 { provide: ThemeService, useClass: MockThemeService },
Sean Condon49e15be2018-05-16 16:58:29 +0100117 { provide: WebSocketService, useClass: MockWebSocketService },
Sean Condona00bf382018-06-23 07:54:01 +0100118 { provide: 'Window', useValue: windowMock },
Sean Condon49e15be2018-05-16 16:58:29 +0100119 ]
120 })
121 .compileComponents();
Sean Condon2bd11b72018-06-15 08:00:48 +0100122 logServiceSpy = TestBed.get(LogService);
Sean Condon49e15be2018-05-16 16:58:29 +0100123 }));
Sean Condon83fc39f2018-04-19 18:56:13 +0100124
Sean Condon49e15be2018-05-16 16:58:29 +0100125 beforeEach(() => {
126 fixture = TestBed.createComponent(DeviceComponent);
Sean Condon2bd11b72018-06-15 08:00:48 +0100127 component = fixture.debugElement.componentInstance;
Sean Condon49e15be2018-05-16 16:58:29 +0100128 fixture.detectChanges();
129 });
130
131 it('should create', () => {
132 expect(component).toBeTruthy();
133 });
Sean Condon2bd11b72018-06-15 08:00:48 +0100134
135 it('should have .table-header with "Friendly Name..."', () => {
136 const appDe: DebugElement = fixture.debugElement;
137 const divDe = appDe.query(By.css('.table-header'));
138 const div: HTMLElement = divDe.nativeElement;
139 expect(div.textContent).toEqual('Friendly Name Device ID Master Ports Vendor H/W Version S/W Version Protocol ');
140 });
Sean Condon83fc39f2018-04-19 18:56:13 +0100141});