blob: 0ce1ba09bf588a14d2779821fe20d2e837ca7c66 [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 { BrowserAnimationsModule } from '@angular/platform-browser/animations';
19import { DebugElement } from '@angular/core';
20import { By } from '@angular/platform-browser';
21
22import { LogService } from '../../../log.service';
23import { FnService } from '../../../../app/fw/util/fn.service';
24import { IconComponent } from '../../../../app/fw/svg/icon/icon.component';
25import { IconService } from '../../../../app/fw/svg/icon.service';
26import { UrlFnService } from '../../../fw/remote/urlfn.service';
27import { WebSocketService } from '../../../fw/remote/websocket.service';
28import { of } from 'rxjs';
29import { } from 'jasmine';
30
31import { HostDetailsComponent } from './hostdetails.component';
32
33class MockActivatedRoute extends ActivatedRoute {
34 constructor(params: Params) {
35 super();
36 this.queryParams = of(params);
37 }
38}
39
40class MockFnService { }
41
42class MockIconService {
43 loadIconDef() { }
44}
45
46class MockUrlFnService { }
47
48class MockWebSocketService {
49 createWebSocket() { }
50 isConnected() { return false; }
51 unbindHandlers() { }
52 bindHandlers() { }
53}
54
55/**
56 * ONOS GUI -- Host Detail Panel View -- Unit Tests
57 */
58
59describe('HostdetailsComponent', () => {
60 let fs: FnService;
61 let ar: MockActivatedRoute;
62 let windowMock: Window;
63 let logServiceSpy: jasmine.SpyObj<LogService>;
64 let component: HostDetailsComponent;
65 let fixture: ComponentFixture<HostDetailsComponent>;
66
67 const bundleObj = {
68 'core.view.Hosts': {
69 }
70 };
71
72 const mockLion = (key) => {
73 return bundleObj[key] || '%' + key + '%';
74 };
75
76 beforeEach(async(() => {
77
78 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
79 ar = new MockActivatedRoute({ 'debug': 'panel' });
80
81 windowMock = <any>{
82 location: <any>{
83 hostname: 'foo',
84 host: 'foo',
85 port: '80',
86 protocol: 'http',
87 search: { debug: 'true' },
88 href: 'ws://foo:123/onos/ui/websock/path',
89 absUrl: 'ws://foo:123/onos/ui/websock/path'
90 }
91 };
92 fs = new FnService(ar, logSpy, windowMock);
93 TestBed.configureTestingModule({
94 imports: [BrowserAnimationsModule],
95 declarations: [HostDetailsComponent, IconComponent],
96 providers: [
97 { provide: FnService, useValue: fs },
98 { provide: IconService, useClass: MockIconService },
99 { provide: LogService, useValue: logSpy },
100 { provide: UrlFnService, useClass: MockUrlFnService },
101 { provide: WebSocketService, useClass: MockWebSocketService },
102 { provide: 'Window', useValue: windowMock },
103 ]
104 })
105 .compileComponents();
106 logServiceSpy = TestBed.get(LogService);
107 }));
108
109 beforeEach(() => {
110 fixture = TestBed.createComponent(HostDetailsComponent);
111 component = fixture.componentInstance;
112 fixture.detectChanges();
113 });
114
115 it('should create', () => {
116 expect(component).toBeTruthy();
117 });
118
119 it('should have an onos-icon.close-btn inside a div.top inside a div.container', () => {
120 const hostDe: DebugElement = fixture.debugElement;
121 const divDe = hostDe.query(By.css('div.container div.top onos-icon.close-btn'));
122 expect(divDe).toBeTruthy();
123 });
124
125 it('should have a div.host-icon inside a div.container', () => {
126 const hostDe: DebugElement = fixture.debugElement;
127 const divDe = hostDe.query(By.css('div.container div.host-icon'));
128 expect(divDe).toBeTruthy();
129 });
130
131 it('should have a h2 inside the div.container', () => {
132 const hostDe: DebugElement = fixture.debugElement;
133 const divDe = hostDe.query(By.css('div#host-details-panel div.container h2'));
134 const div: HTMLElement = divDe.nativeElement;
135 expect(div.textContent).toEqual('');
136 });
137
138 it('should have a div.top-content inside a div.container', () => {
139 const hostDe: DebugElement = fixture.debugElement;
140 const divDe = hostDe.query(By.css('div.container div.top-content'));
141 expect(divDe).toBeTruthy();
142 });
143
144 it('should have a div.top-tables inside a div.top-content inside a div.container', () => {
145 const hostDe: DebugElement = fixture.debugElement;
146 const divDe = hostDe.query(By.css('div.container div.top-content div.top-tables'));
147 expect(divDe).toBeTruthy();
148 });
149
150 it('should have a div.left inside a div.top-tables inside a div.top-content inside a div.container', () => {
151 const hostDe: DebugElement = fixture.debugElement;
152 const divDe = hostDe.query(By.css('div.container div.top-content div.top-tables div.left'));
153 expect(divDe).toBeTruthy();
154 });
155
156 it('should have a div.right inside a div.top-tables inside a div.top-content inside a div.container', () => {
157 const hostDe: DebugElement = fixture.debugElement;
158 const divDe = hostDe.query(By.css('div.container div.top-content div.top-tables div.right'));
159 expect(divDe).toBeTruthy();
160 });
161
162 it('should have a div.bottom inside a div.container', () => {
163 const hostDe: DebugElement = fixture.debugElement;
164 const divDe = hostDe.query(By.css('div.container div.bottom'));
165 expect(divDe).toBeTruthy();
166 });
167});