blob: 1337cb83bf8d0a061d91d0ccb1c44c7fbe0d84a5 [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';
22import { MeterComponent } from './meter.component';
Sean Condon5ca00262018-09-06 17:55:25 +010023import {
24 FnService,
25 IconService,
26 GlyphService,
27 IconComponent,
28 LionService,
29 LoadingService,
30 LogService,
31 NavService,
32 MastService,
33 TableFilterPipe,
34 ThemeService,
35 UrlFnService,
36 WebSocketService
37} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053038import { of, Subject } from 'rxjs';
39import { } from 'jasmine';
40import { RouterTestingModule } from '@angular/router/testing';
41
42
43class MockActivatedRoute extends ActivatedRoute {
44 constructor(params: Params) {
45 super();
46 this.queryParams = of(params);
47 }
48}
49
50
Bhavesh72ead492018-07-19 16:29:18 +053051class MockFnService { }
52
53class MockIconService {
54 loadIconDef() { }
55}
56
Bhavesh72ead492018-07-19 16:29:18 +053057class MockLoadingService {
58 startAnim() { }
59 stop() { }
60 waiting() { }
61}
62
63class MockThemeService { }
64
65class MockUrlFnService { }
66
67class MockWebSocketService {
68 createWebSocket() { }
69 isConnected() { return false; }
70 unbindHandlers() { }
71 bindHandlers() { }
72}
73
74
75/**
76 * ONOS GUI -- Meter Panel View -- Unit Tests
77 */
78
79describe('MeterComponent', () => {
80
81 let fs: FnService;
82 let ar: MockActivatedRoute;
83 let windowMock: Window;
84 let logServiceSpy: jasmine.SpyObj<LogService>;
85 let component: MeterComponent;
86 let fixture: ComponentFixture<MeterComponent>;
87
88 const bundleObj = {
89 'core.view.Meter': {
90 test: 'test1'
91 }
92 };
93
94 const mockLion = (key) => {
95 return bundleObj[key] || '%' + key + '%';
96 };
97
98
99
100 beforeEach(async(() => {
101
102 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
103 ar = new MockActivatedRoute({ 'debug': 'txrx' });
104
105 windowMock = <any>{
106 location: <any>{
107 hostname: 'foo',
108 host: 'foo',
109 port: '80',
110 protocol: 'http',
111 search: { debug: 'true' },
112 href: 'ws://foo:123/onos/ui/websock/path',
113 absUrl: 'ws://foo:123/onos/ui/websock/path'
114 }
115 };
116 fs = new FnService(ar, logSpy, windowMock);
117
118 TestBed.configureTestingModule({
119 imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
120 declarations: [MeterComponent, IconComponent, TableFilterPipe],
121 providers: [
Bhavesh72ead492018-07-19 16:29:18 +0530122 { provide: FnService, useValue: fs },
123 { provide: IconService, useClass: MockIconService },
Bhavesh72ead492018-07-19 16:29:18 +0530124 {
125 provide: LionService, useFactory: (() => {
126 return {
127 bundle: ((bundleId) => mockLion),
128 ubercache: new Array(),
129 loadCbs: new Map<string, () => void>([])
130 };
131 })
132 },
133 { provide: LoadingService, useClass: MockLoadingService },
134 { provide: LogService, useValue: logSpy },
135 { provide: ThemeService, useClass: MockThemeService },
136 { provide: UrlFnService, useClass: MockUrlFnService },
137 { provide: WebSocketService, useClass: MockWebSocketService },
138 { provide: 'Window', useValue: windowMock },
139 ]
140 })
141 .compileComponents();
142 logServiceSpy = TestBed.get(LogService);
143 }));
144
145 beforeEach(() => {
146 fixture = TestBed.createComponent(MeterComponent);
147 component = fixture.componentInstance;
148 fixture.detectChanges();
149 });
150
151 it('should create', () => {
152 expect(component).toBeTruthy();
153 });
154
155
156 it('should have a div.tabular-header inside a div#ov-meter', () => {
157 const metDe: DebugElement = fixture.debugElement;
158 const divDe = metDe.query(By.css('div#ov-meter div.tabular-header'));
159 expect(divDe).toBeTruthy();
160 });
161
162 it('should have a h2 inside the div.tabular-header', () => {
163 const metDe: DebugElement = fixture.debugElement;
164 const divDe = metDe.query(By.css('div#ov-meter div.tabular-header h2'));
165 const div: HTMLElement = divDe.nativeElement;
166 expect(div.textContent).toEqual(' Meter for Device (0 Total )');
167 });
168
169 it('should have a refresh button inside the div.tabular-header', () => {
170 const metDe: DebugElement = fixture.debugElement;
171 const divDe = metDe.query(By.css('div#ov-meter div.tabular-header div.ctrl-btns div.refresh'));
172 expect(divDe).toBeTruthy();
173 });
174
175
176 it('should have a div.summary-list inside a div#ov-meter', () => {
177 const hostDe: DebugElement = fixture.debugElement;
178 const divDe = hostDe.query(By.css('div#ov-meter div.summary-list'));
179 expect(divDe).toBeTruthy();
180 });
181
182 it('should have a div.table-header inside a div.summary-list inside a div#ov-meter', () => {
183 const hostDe: DebugElement = fixture.debugElement;
184 const divDe = hostDe.query(By.css('div#ov-meter div.summary-list div.table-header'));
185 expect(divDe).toBeTruthy();
186 });
187
188 it('should have a div.table-body inside a div.summary-list inside a div#ov-meter', () => {
189 const hostDe: DebugElement = fixture.debugElement;
190 const divDe = hostDe.query(By.css('div#ov-meter div.summary-list div.table-body'));
191 expect(divDe).toBeTruthy();
192 });
193});