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