blob: d482cb2678ebca04bf51fdc7db66f5965a845ccc [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 { FormsModule } from '@angular/forms';
20import { DebugElement } from '@angular/core';
21import { By } from '@angular/platform-browser';
Sean Condon5ca00262018-09-06 17:55:25 +010022import {
23 FnService,
24 IconService,
25 GlyphService,
26 IconComponent,
27 LoadingService,
28 LogService,
29 NavService,
30 MastService,
31 TableFilterPipe,
32 ThemeService,
33 UrlFnService,
34 WebSocketService
35} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053036import { HostComponent } from './host.component';
37import { HostDetailsComponent } from '../hostdetails/hostdetails.component';
Bhavesh72ead492018-07-19 16:29:18 +053038import { of } from 'rxjs';
39import { } from 'jasmine';
40
41class MockActivatedRoute extends ActivatedRoute {
42 constructor(params: Params) {
43 super();
44 this.queryParams = of(params);
45 }
46}
47
Bhavesh72ead492018-07-19 16:29:18 +053048class MockFnService { }
49
50class MockIconService {
51 loadIconDef() { }
52}
53
Bhavesh72ead492018-07-19 16:29:18 +053054class MockLoadingService {
55 startAnim() { }
56 stop() { }
57 waiting() { }
58}
59
60class MockThemeService { }
61
62class MockUrlFnService { }
63
64class MockWebSocketService {
65 createWebSocket() { }
66 isConnected() { return false; }
67 unbindHandlers() { }
68 bindHandlers() { }
69}
70
71
72describe('HostComponent', () => {
73
74 let fs: FnService;
75 let ar: MockActivatedRoute;
76 let windowMock: Window;
77 let logServiceSpy: jasmine.SpyObj<LogService>;
78 let component: HostComponent;
79 let fixture: ComponentFixture<HostComponent>;
80 const bundleObj = {
81 'core.view.Host': {
82 test: 'test1'
83 }
84 };
85 const mockLion = (key) => {
86 return bundleObj[key] || '%' + key + '%';
87 };
88
89
90 beforeEach(async(() => {
91 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
92 ar = new MockActivatedRoute({ 'debug': 'txrx' });
93
94 windowMock = <any>{
95 location: <any>{
96 hostname: 'foo',
97 host: 'foo',
98 port: '80',
99 protocol: 'http',
100 search: { debug: 'true' },
101 href: 'ws://foo:123/onos/ui/websock/path',
102 absUrl: 'ws://foo:123/onos/ui/websock/path'
103 }
104 };
105 fs = new FnService(ar, logSpy, windowMock);
106
107 TestBed.configureTestingModule({
108 imports: [BrowserAnimationsModule, FormsModule],
109 declarations: [HostComponent, HostDetailsComponent, IconComponent, TableFilterPipe],
110 providers: [
Bhavesh72ead492018-07-19 16:29:18 +0530111 { provide: FnService, useValue: fs },
112 { provide: IconService, useClass: MockIconService },
Bhavesh72ead492018-07-19 16:29:18 +0530113 { provide: LoadingService, useClass: MockLoadingService },
114 { provide: LogService, useValue: logSpy },
115 { provide: ThemeService, useClass: MockThemeService },
116 { provide: UrlFnService, useClass: MockUrlFnService },
117 { provide: WebSocketService, useClass: MockWebSocketService },
118 { provide: 'Window', useValue: windowMock },
119 ]
120 })
121 .compileComponents();
122 logServiceSpy = TestBed.get(LogService);
123 }));
124
125 beforeEach(() => {
126 fixture = TestBed.createComponent(HostComponent);
127 component = fixture.componentInstance;
128 fixture.detectChanges();
129 });
130
131 it('should create', () => {
132 expect(component).toBeTruthy();
133 });
134
135 it('should have a div.tabular-header inside a div#ov-host', () => {
136 const hostDe: DebugElement = fixture.debugElement;
137 const divDe = hostDe.query(By.css('div#ov-host div.tabular-header'));
138 expect(divDe).toBeTruthy();
139 });
140
141 it('should have a h2 inside the div.tabular-header', () => {
142 const hostDe: DebugElement = fixture.debugElement;
143 const divDe = hostDe.query(By.css('div#ov-host div.tabular-header h2'));
144 const div: HTMLElement = divDe.nativeElement;
145 expect(div.textContent).toEqual('Hosts (0 total)');
146 });
147
148 it('should have a refresh button inside the div.tabular-header', () => {
149 const hostDe: DebugElement = fixture.debugElement;
150 const divDe = hostDe.query(By.css('div#ov-host div.tabular-header div.ctrl-btns div.refresh'));
151 expect(divDe).toBeTruthy();
152 });
153
154 it('should have a div.summary-list inside a div#ov-host', () => {
155 const hostDe: DebugElement = fixture.debugElement;
156 const divDe = hostDe.query(By.css('div#ov-host div.summary-list'));
157 expect(divDe).toBeTruthy();
158 });
159
160 it('should have a div.table-header inside a div.summary-list inside a div#ov-host', () => {
161 const hostDe: DebugElement = fixture.debugElement;
162 const divDe = hostDe.query(By.css('div#ov-host div.summary-list div.table-header'));
163 expect(divDe).toBeTruthy();
164 });
165
166 it('should have a div.table-body inside a div.summary-list inside a div#ov-host', () => {
167 const hostDe: DebugElement = fixture.debugElement;
168 const divDe = hostDe.query(By.css('div#ov-host div.summary-list div.table-body'));
169 expect(divDe).toBeTruthy();
170 });
171
172});