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