blob: 207dde9399a913ecbb0872dc0fcdf731ed82fcf8 [file] [log] [blame]
Bhavesh72ead492018-07-19 16:29:18 +05301/*
2 * Copyright 2018-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 { DebugElement } from '@angular/core';
19import { By } from '@angular/platform-browser';
20import { LogService } from '../../../log.service';
21import { DeviceComponent } from './device.component';
22import { } from 'jasmine';
23
24import { FnService } from '../../../fw/util/fn.service';
25import { IconService } from '../../../fw/svg/icon.service';
26import { GlyphService } from '../../../fw/svg/glyph.service';
27import { IconComponent } from '../../../fw/svg/icon/icon.component';
28import { KeyService } from '../../../fw/util/key.service';
29import { LoadingService } from '../../../fw/layer/loading.service';
30import { NavService } from '../../../fw/nav/nav.service';
31import { MastService } from '../../../fw/mast/mast.service';
32import { TableFilterPipe } from '../../../fw/widget/tablefilter.pipe';
33import { ThemeService } from '../../../fw/util/theme.service';
34import { WebSocketService } from '../../../fw/remote/websocket.service';
35import { of } from 'rxjs';
36import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
37import { FormsModule } from '@angular/forms';
38import { DeviceDetailsComponent } from './../devicedetails/devicedetails.component';
39import { RouterTestingModule } from '@angular/router/testing';
40
41class MockActivatedRoute extends ActivatedRoute {
42 constructor(params: Params) {
43 super();
44 this.queryParams = of(params);
45 }
46}
47
48class MockIconService {
49 loadIconDef() { }
50}
51
52class MockGlyphService { }
53
54class MockKeyService { }
55
56class MockLoadingService {
57 startAnim() { }
58 stop() { }
59}
60
61class MockNavService { }
62
63class MockMastService { }
64
65class MockThemeService { }
66
67class MockWebSocketService {
68 createWebSocket() { }
69 isConnected() { return false; }
70 unbindHandlers() { }
71 bindHandlers() { }
72}
73
74/**
75 * ONOS GUI -- Device View Module - Unit Tests
76 */
77describe('DeviceComponent', () => {
78 let fs: FnService;
79 let ar: MockActivatedRoute;
80 let windowMock: Window;
81 let logServiceSpy: jasmine.SpyObj<LogService>;
82 let component: DeviceComponent;
83 let fixture: ComponentFixture<DeviceComponent>;
84
85 beforeEach(async(() => {
86 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
87 ar = new MockActivatedRoute({ 'debug': 'txrx' });
88
89 windowMock = <any>{
90 location: <any>{
91 hostname: 'foo',
92 host: 'foo',
93 port: '80',
94 protocol: 'http',
95 search: { debug: 'true' },
96 href: 'ws://foo:123/onos/ui/websock/path',
97 absUrl: 'ws://foo:123/onos/ui/websock/path'
98 }
99 };
100 fs = new FnService(ar, logSpy, windowMock);
101
102 TestBed.configureTestingModule({
103 imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
104 declarations: [DeviceComponent, IconComponent, TableFilterPipe, DeviceDetailsComponent],
105 providers: [
106 { provide: FnService, useValue: fs },
107 { provide: IconService, useClass: MockIconService },
108 { provide: GlyphService, useClass: MockGlyphService },
109 { provide: KeyService, useClass: MockKeyService },
110 { provide: LoadingService, useClass: MockLoadingService },
111 { provide: MastService, useClass: MockMastService },
112 { provide: NavService, useClass: MockNavService },
113 { provide: LogService, useValue: logSpy },
114 { provide: ThemeService, useClass: MockThemeService },
115 { provide: WebSocketService, useClass: MockWebSocketService },
116 { provide: 'Window', useValue: windowMock },
117 ]
118 }).compileComponents();
119 logServiceSpy = TestBed.get(LogService);
120 }));
121
122 beforeEach(() => {
123 fixture = TestBed.createComponent(DeviceComponent);
124 component = fixture.debugElement.componentInstance;
125 fixture.detectChanges();
126 });
127
128 it('should create', () => {
129 expect(component).toBeTruthy();
130 });
131
132 it('should have a div.tabular-header inside a div#ov-device', () => {
133 const devDe: DebugElement = fixture.debugElement;
134 const divDe = devDe.query(By.css('div#ov-device div.tabular-header'));
135 expect(divDe).toBeTruthy();
136 });
137
138 it('should have .table-header with "Friendly Name..."', () => {
139 const devDe: DebugElement = fixture.debugElement;
140 const divDe = devDe.query(By.css('div#ov-device div.table-header'));
141 const div: HTMLElement = divDe.nativeElement;
142 expect(div.textContent).toEqual('Friendly Name Device ID Master Ports Vendor H/W Version S/W Version Protocol ');
143 });
144
145 it('should have a refresh button inside the div.tabular-header', () => {
146 const devDe: DebugElement = fixture.debugElement;
147 const divDe = devDe.query(By.css('div#ov-device div.tabular-header div.ctrl-btns div.refresh'));
148 expect(divDe).toBeTruthy();
149 });
150
151
152 it('should have a div.table-body ', () => {
153 const devDe: DebugElement = fixture.debugElement;
154 const divDe = devDe.query(By.css('div#ov-device div.table-body'));
155 expect(divDe).toBeTruthy();
156 });
157});