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