blob: e022ebccba3518ae909b9b9e473c28e8ed436f23 [file] [log] [blame]
Sean Condon28ecc5f2018-06-25 12:50:16 +01001/*
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 Condon2aa86092018-07-16 09:04:05 +010022import { HttpClient, HttpErrorResponse } from '@angular/common/http';
Sean Condon28ecc5f2018-06-25 12:50:16 +010023
24import { LogService } from '../../../log.service';
25import { AppsComponent } from './apps.component';
26import { AppsDetailsComponent } from '../appsdetails/appsdetails.component';
Sean Condon2aa86092018-07-16 09:04:05 +010027import { ConfirmComponent } from '../../../fw/layer/confirm/confirm.component';
Sean Condon28ecc5f2018-06-25 12:50:16 +010028import { DialogService } from '../../../fw/layer/dialog.service';
Sean Condon2aa86092018-07-16 09:04:05 +010029import { FlashComponent } from '../../../fw/layer/flash/flash.component';
Sean Condon28ecc5f2018-06-25 12:50:16 +010030import { FnService } from '../../../fw/util/fn.service';
31import { IconComponent } from '../../../fw/svg/icon/icon.component';
32import { IconService } from '../../../fw/svg/icon.service';
33import { KeyService } from '../../../fw/util/key.service';
34import { LionService } from '../../../fw/util/lion.service';
35import { LoadingService } from '../../../fw/layer/loading.service';
36import { ThemeService } from '../../../fw/util/theme.service';
37import { TableFilterPipe } from '../../../fw/widget/tablefilter.pipe';
38import { UrlFnService } from '../../../fw/remote/urlfn.service';
39import { WebSocketService } from '../../../fw/remote/websocket.service';
40import { of } from 'rxjs';
Bhavesh72ead492018-07-19 16:29:18 +053041import { } from 'jasmine';
Sean Condon28ecc5f2018-06-25 12:50:16 +010042
43class MockActivatedRoute extends ActivatedRoute {
44 constructor(params: Params) {
45 super();
46 this.queryParams = of(params);
47 }
48}
49
Bhavesh72ead492018-07-19 16:29:18 +053050class MockDialogService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010051
Bhavesh72ead492018-07-19 16:29:18 +053052class MockFnService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010053
Sean Condon2aa86092018-07-16 09:04:05 +010054class MockHttpClient {}
55
Sean Condon28ecc5f2018-06-25 12:50:16 +010056class MockIconService {
Bhavesh72ead492018-07-19 16:29:18 +053057 loadIconDef() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010058}
59
Bhavesh72ead492018-07-19 16:29:18 +053060class MockKeyService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010061
62class MockLoadingService {
Bhavesh72ead492018-07-19 16:29:18 +053063 startAnim() { }
64 stop() { }
65 waiting() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010066}
67
Bhavesh72ead492018-07-19 16:29:18 +053068class MockThemeService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010069
Bhavesh72ead492018-07-19 16:29:18 +053070class MockUrlFnService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010071
72class MockWebSocketService {
Bhavesh72ead492018-07-19 16:29:18 +053073 createWebSocket() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010074 isConnected() { return false; }
Bhavesh72ead492018-07-19 16:29:18 +053075 unbindHandlers() { }
76 bindHandlers() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010077}
78
79/**
80 * ONOS GUI -- Apps View -- Unit Tests
81 */
82describe('AppsComponent', () => {
83 let fs: FnService;
84 let ar: MockActivatedRoute;
85 let windowMock: Window;
86 let logServiceSpy: jasmine.SpyObj<LogService>;
87 let component: AppsComponent;
88 let fixture: ComponentFixture<AppsComponent>;
89 const bundleObj = {
90 'core.view.App': {
91 test: 'test1'
92 }
93 };
Bhavesh72ead492018-07-19 16:29:18 +053094 const mockLion = (key) => {
Sean Condon28ecc5f2018-06-25 12:50:16 +010095 return bundleObj[key] || '%' + key + '%';
96 };
97
98 beforeEach(async(() => {
99 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
Bhavesh72ead492018-07-19 16:29:18 +0530100 ar = new MockActivatedRoute({ 'debug': 'txrx' });
Sean Condon28ecc5f2018-06-25 12:50:16 +0100101
102 windowMock = <any>{
Bhavesh72ead492018-07-19 16:29:18 +0530103 location: <any>{
Sean Condon28ecc5f2018-06-25 12:50:16 +0100104 hostname: 'foo',
105 host: 'foo',
106 port: '80',
107 protocol: 'http',
Bhavesh72ead492018-07-19 16:29:18 +0530108 search: { debug: 'true' },
Sean Condon28ecc5f2018-06-25 12:50:16 +0100109 href: 'ws://foo:123/onos/ui/websock/path',
110 absUrl: 'ws://foo:123/onos/ui/websock/path'
111 }
112 };
113 fs = new FnService(ar, logSpy, windowMock);
114
115 TestBed.configureTestingModule({
116 imports: [ BrowserAnimationsModule, FormsModule ],
Sean Condon2aa86092018-07-16 09:04:05 +0100117 declarations: [
118 AppsComponent,
119 ConfirmComponent,
120 IconComponent,
121 AppsDetailsComponent,
122 TableFilterPipe,
123 FlashComponent
124 ],
Sean Condon28ecc5f2018-06-25 12:50:16 +0100125 providers: [
126 { provide: DialogService, useClass: MockDialogService },
127 { provide: FnService, useValue: fs },
Sean Condon2aa86092018-07-16 09:04:05 +0100128 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon28ecc5f2018-06-25 12:50:16 +0100129 { provide: IconService, useClass: MockIconService },
130 { provide: KeyService, useClass: MockKeyService },
Bhavesh72ead492018-07-19 16:29:18 +0530131 {
132 provide: LionService, useFactory: (() => {
Sean Condon28ecc5f2018-06-25 12:50:16 +0100133 return {
134 bundle: ((bundleId) => mockLion),
135 ubercache: new Array(),
136 loadCbs: new Map<string, () => void>([])
137 };
138 })
139 },
140 { provide: LoadingService, useClass: MockLoadingService },
141 { provide: LogService, useValue: logSpy },
142 { provide: ThemeService, useClass: MockThemeService },
143 { provide: UrlFnService, useClass: MockUrlFnService },
144 { provide: WebSocketService, useClass: MockWebSocketService },
145 { provide: 'Window', useValue: windowMock },
146 ]
147 })
Bhavesh72ead492018-07-19 16:29:18 +0530148 .compileComponents();
Sean Condon28ecc5f2018-06-25 12:50:16 +0100149 logServiceSpy = TestBed.get(LogService);
150 }));
151
152 beforeEach(() => {
153 fixture = TestBed.createComponent(AppsComponent);
154 component = fixture.debugElement.componentInstance;
155 fixture.detectChanges();
156 });
157
158 it('should create', () => {
159 expect(component).toBeTruthy();
160 });
161
162 it('should have a div.tabular-header inside a div#ov-app', () => {
163 const appDe: DebugElement = fixture.debugElement;
164 const divDe = appDe.query(By.css('div#ov-app div.tabular-header'));
165 expect(divDe).toBeTruthy();
166 });
167
168 it('should have a h2 inside the div.tabular-header', () => {
169 const appDe: DebugElement = fixture.debugElement;
170 const divDe = appDe.query(By.css('div#ov-app div.tabular-header h2'));
171 const div: HTMLElement = divDe.nativeElement;
172 expect(div.textContent).toEqual(' %title_apps% (0 %total%) ');
173 });
174
175 it('should have a refresh button inside the div.tabular-header', () => {
176 const appDe: DebugElement = fixture.debugElement;
177 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.refresh'));
178 expect(divDe).toBeTruthy();
179 });
180
181 it('should have an active button inside the div.tabular-header', () => {
182 const appDe: DebugElement = fixture.debugElement;
183 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.active'));
184 expect(divDe).toBeTruthy();
185 });
186
187 it('should have a div.summary-list inside a div#ov-app', () => {
188 const appDe: DebugElement = fixture.debugElement;
189 const divDe = appDe.query(By.css('div#ov-app div.summary-list'));
190 expect(divDe).toBeTruthy();
191 });
192});