blob: 5b1355d8e1af479aab1bf56f0ada044e81db0600 [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';
Bhavesh72ead492018-07-19 16:29:18 +053020import { DeviceComponent } from './device.component';
21import { } from 'jasmine';
22
Sean Condon5ca00262018-09-06 17:55:25 +010023import {
24 FnService,
25 IconService,
26 GlyphService,
27 IconComponent,
Sean Condon5ca00262018-09-06 17:55:25 +010028 LogService,
29 NavService,
30 MastService,
31 TableFilterPipe,
32 ThemeService,
Sean Condon95fb5742019-04-02 12:16:55 +010033 WebSocketService, LoadingComponent
Sean Condon5ca00262018-09-06 17:55:25 +010034} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053035import { 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
Bhavesh72ead492018-07-19 16:29:18 +053054class MockNavService { }
55
56class MockMastService { }
57
58class MockThemeService { }
59
60class MockWebSocketService {
61 createWebSocket() { }
62 isConnected() { return false; }
63 unbindHandlers() { }
64 bindHandlers() { }
65}
66
67/**
68 * ONOS GUI -- Device View Module - Unit Tests
69 */
70describe('DeviceComponent', () => {
71 let fs: FnService;
72 let ar: MockActivatedRoute;
73 let windowMock: Window;
74 let logServiceSpy: jasmine.SpyObj<LogService>;
75 let component: DeviceComponent;
76 let fixture: ComponentFixture<DeviceComponent>;
77
78 beforeEach(async(() => {
79 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
80 ar = new MockActivatedRoute({ 'debug': 'txrx' });
81
82 windowMock = <any>{
83 location: <any>{
84 hostname: 'foo',
85 host: 'foo',
86 port: '80',
87 protocol: 'http',
88 search: { debug: 'true' },
89 href: 'ws://foo:123/onos/ui/websock/path',
90 absUrl: 'ws://foo:123/onos/ui/websock/path'
91 }
92 };
93 fs = new FnService(ar, logSpy, windowMock);
94
95 TestBed.configureTestingModule({
96 imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
Sean Condon95fb5742019-04-02 12:16:55 +010097 declarations: [
98 DeviceComponent,
99 IconComponent,
100 TableFilterPipe,
101 DeviceDetailsComponent,
102 LoadingComponent
103 ],
Bhavesh72ead492018-07-19 16:29:18 +0530104 providers: [
105 { provide: FnService, useValue: fs },
106 { provide: IconService, useClass: MockIconService },
107 { provide: GlyphService, useClass: MockGlyphService },
Bhavesh72ead492018-07-19 16:29:18 +0530108 { provide: MastService, useClass: MockMastService },
109 { provide: NavService, useClass: MockNavService },
110 { provide: LogService, useValue: logSpy },
111 { provide: ThemeService, useClass: MockThemeService },
112 { provide: WebSocketService, useClass: MockWebSocketService },
113 { provide: 'Window', useValue: windowMock },
114 ]
115 }).compileComponents();
116 logServiceSpy = TestBed.get(LogService);
117 }));
118
119 beforeEach(() => {
120 fixture = TestBed.createComponent(DeviceComponent);
121 component = fixture.debugElement.componentInstance;
122 fixture.detectChanges();
123 });
124
125 it('should create', () => {
126 expect(component).toBeTruthy();
127 });
128
129 it('should have a div.tabular-header inside a div#ov-device', () => {
130 const devDe: DebugElement = fixture.debugElement;
131 const divDe = devDe.query(By.css('div#ov-device div.tabular-header'));
132 expect(divDe).toBeTruthy();
133 });
134
135 it('should have .table-header with "Friendly Name..."', () => {
136 const devDe: DebugElement = fixture.debugElement;
137 const divDe = devDe.query(By.css('div#ov-device div.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 });
141
142 it('should have a refresh button inside the div.tabular-header', () => {
143 const devDe: DebugElement = fixture.debugElement;
144 const divDe = devDe.query(By.css('div#ov-device div.tabular-header div.ctrl-btns div.refresh'));
145 expect(divDe).toBeTruthy();
146 });
147
148
149 it('should have a div.table-body ', () => {
150 const devDe: DebugElement = fixture.debugElement;
151 const divDe = devDe.query(By.css('div#ov-device div.table-body'));
152 expect(divDe).toBeTruthy();
153 });
154});