blob: 5daa2efc20ebef35d0b28b6f8b2d1994413531f8 [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 { DeviceDetailsComponent } from './devicedetails.component';
18import { ActivatedRoute, Params } from '@angular/router';
19import { of } from 'rxjs/index';
20import { FnService } from '../../../fw/util/fn.service';
21import { LogService } from '../../../log.service';
22import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
23import { IconService } from '../../../fw/svg/icon.service';
24import { WebSocketService } from '../../../fw/remote/websocket.service';
25import { DebugElement } from '@angular/core';
26import { By } from '@angular/platform-browser';
27import { } from 'jasmine';
28import { IconComponent } from '../../../fw/svg/icon/icon.component';
29
30class MockActivatedRoute extends ActivatedRoute {
31 constructor(params: Params) {
32 super();
33 this.queryParams = of(params);
34 }
35}
36
37class MockIconService {
38 classes = 'active-close';
39 loadIconDef() { }
40}
41
42class MockWebSocketService {
43 createWebSocket() { }
44 isConnected() { return false; }
45 unbindHandlers() { }
46 bindHandlers() { }
47}
48
49describe('DeviceDetailsComponent', () => {
50 let fs: FnService;
51 let ar: MockActivatedRoute;
52 let windowMock: Window;
53 let logServiceSpy: jasmine.SpyObj<LogService>;
54 let component: DeviceDetailsComponent;
55 let fixture: ComponentFixture<DeviceDetailsComponent>;
56
57 beforeEach(async(() => {
58 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
59 ar = new MockActivatedRoute({ 'debug': 'panel' });
60 windowMock = <any>{
61 location: <any>{
62 hostname: 'foo',
63 host: 'foo',
64 port: '80',
65 protocol: 'http',
66 search: { debug: 'true' },
67 href: 'ws://foo:123/onos/ui/websock/path',
68 absUrl: 'ws://foo:123/onos/ui/websock/path'
69 }
70 };
71 fs = new FnService(ar, logSpy, windowMock);
72
73 TestBed.configureTestingModule({
74 imports: [BrowserAnimationsModule],
75 declarations: [DeviceDetailsComponent, IconComponent],
76 providers: [
77 { provide: FnService, useValue: fs },
78 { provide: IconService, useClass: MockIconService },
79 { provide: LogService, useValue: logSpy },
80 { provide: WebSocketService, useClass: MockWebSocketService },
81 { provide: 'Window', useValue: windowMock },
82 ]
83
84 }).compileComponents();
85 logServiceSpy = TestBed.get(LogService);
86 }));
87
88 beforeEach(() => {
89 fixture = TestBed.createComponent(DeviceDetailsComponent);
90 component = fixture.componentInstance;
91 fixture.detectChanges();
92 });
93
94 it('should create', () => {
95 expect(component).toBeTruthy();
96 });
97
98 it('should have an div.close-btn div.top inside a div.container', () => {
99 const devDe: DebugElement = fixture.debugElement;
100 const divDe = devDe.query(By.css('div.container div.top div.close-btn'));
101 expect(divDe).toBeTruthy();
102 });
103
104 it('should have a div.dev-icon inside a div.top inside a div.container', () => {
105 const devDe: DebugElement = fixture.debugElement;
106 const divDe = devDe.query(By.css('div.container div.top div.dev-icon'));
107 const div: HTMLElement = divDe.nativeElement;
108 expect(div.textContent).toEqual('');
109 });
110
111 it('should have a div.top-content inside a div.top inside a div.container', () => {
112 const devDe: DebugElement = fixture.debugElement;
113 const divDe = devDe.query(By.css('div.container div.top div.top-content'));
114 expect(divDe).toBeTruthy();
115 });
116
117 it('should have a dev.left inside a div.top-tables inside a div.top-content', () => {
118 const devDe: DebugElement = fixture.debugElement;
119 const divDe = devDe.query(By.css('div.top-content div.top-tables div.left'));
120 const div: HTMLElement = divDe.nativeElement;
121 expect(div.textContent).toEqual('URI :Type :Master ID :Chassis ID :Vendor :');
122 });
123
124 it('should have a dev.right inside a div.top-tables inside a div.top-content', () => {
125 const devDe: DebugElement = fixture.debugElement;
126 const divDe = devDe.query(By.css('div.top-content div.top-tables div.right'));
127 const div: HTMLElement = divDe.nativeElement;
128 expect(div.textContent).toEqual('H/W Version :S/W Version :Protocol :Serial # :Pipeconf :');
129 });
130
131 it('should have a div.bottom inside a div.container', () => {
132 const devDe: DebugElement = fixture.debugElement;
133 const divDe = devDe.query(By.css('div.container div.bottom'));
134 expect(divDe).toBeTruthy();
135 });
136
137 it('should have a h2.ports-title inside a div.bottom inside a div.container', () => {
138 const devDe: DebugElement = fixture.debugElement;
139 const divDe = devDe.query(By.css('div.container div.bottom h2.ports-title'));
140 expect(divDe).toBeTruthy();
141 });
142});