blob: f1dfe0d8e1a74053e2b5c18d9306d0f12391af66 [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
Sean Condon5ca00262018-09-06 17:55:25 +010024import {
25 FnService,
26 IconService,
27 LionService,
28 LoadingService,
29 LogService,
30 TableBaseImpl, TableResponse, TableFilter, SortParams, SortDir,
31 UrlFnService,
32 WebSocketService,
33 TableFilterPipe,
34 ConfirmComponent,
35 FlashComponent,
36 IconComponent,
37 ThemeService,
38} from 'gui2-fw-lib';
39
Sean Condon28ecc5f2018-06-25 12:50:16 +010040import { AppsComponent } from './apps.component';
41import { AppsDetailsComponent } from '../appsdetails/appsdetails.component';
Sean Condon28ecc5f2018-06-25 12:50:16 +010042import { of } from 'rxjs';
Bhavesh72ead492018-07-19 16:29:18 +053043import { } from 'jasmine';
Sean Condon28ecc5f2018-06-25 12:50:16 +010044
45class MockActivatedRoute extends ActivatedRoute {
46 constructor(params: Params) {
47 super();
48 this.queryParams = of(params);
49 }
50}
51
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
Sean Condon28ecc5f2018-06-25 12:50:16 +010060class MockLoadingService {
Bhavesh72ead492018-07-19 16:29:18 +053061 startAnim() { }
62 stop() { }
63 waiting() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010064}
65
Bhavesh72ead492018-07-19 16:29:18 +053066class MockThemeService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010067
Bhavesh72ead492018-07-19 16:29:18 +053068class MockUrlFnService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010069
70class MockWebSocketService {
Bhavesh72ead492018-07-19 16:29:18 +053071 createWebSocket() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010072 isConnected() { return false; }
Bhavesh72ead492018-07-19 16:29:18 +053073 unbindHandlers() { }
74 bindHandlers() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010075}
76
77/**
78 * ONOS GUI -- Apps View -- Unit Tests
79 */
80describe('AppsComponent', () => {
81 let fs: FnService;
82 let ar: MockActivatedRoute;
83 let windowMock: Window;
84 let logServiceSpy: jasmine.SpyObj<LogService>;
85 let component: AppsComponent;
86 let fixture: ComponentFixture<AppsComponent>;
87 const bundleObj = {
88 'core.view.App': {
89 test: 'test1'
90 }
91 };
Bhavesh72ead492018-07-19 16:29:18 +053092 const mockLion = (key) => {
Sean Condon28ecc5f2018-06-25 12:50:16 +010093 return bundleObj[key] || '%' + key + '%';
94 };
95
96 beforeEach(async(() => {
97 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
Bhavesh72ead492018-07-19 16:29:18 +053098 ar = new MockActivatedRoute({ 'debug': 'txrx' });
Sean Condon28ecc5f2018-06-25 12:50:16 +010099
100 windowMock = <any>{
Bhavesh72ead492018-07-19 16:29:18 +0530101 location: <any>{
Sean Condon28ecc5f2018-06-25 12:50:16 +0100102 hostname: 'foo',
103 host: 'foo',
104 port: '80',
105 protocol: 'http',
Bhavesh72ead492018-07-19 16:29:18 +0530106 search: { debug: 'true' },
Sean Condon28ecc5f2018-06-25 12:50:16 +0100107 href: 'ws://foo:123/onos/ui/websock/path',
108 absUrl: 'ws://foo:123/onos/ui/websock/path'
109 }
110 };
111 fs = new FnService(ar, logSpy, windowMock);
112
113 TestBed.configureTestingModule({
114 imports: [ BrowserAnimationsModule, FormsModule ],
Sean Condon2aa86092018-07-16 09:04:05 +0100115 declarations: [
116 AppsComponent,
117 ConfirmComponent,
118 IconComponent,
119 AppsDetailsComponent,
120 TableFilterPipe,
121 FlashComponent
122 ],
Sean Condon28ecc5f2018-06-25 12:50:16 +0100123 providers: [
Sean Condon28ecc5f2018-06-25 12:50:16 +0100124 { provide: FnService, useValue: fs },
Sean Condon2aa86092018-07-16 09:04:05 +0100125 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon28ecc5f2018-06-25 12:50:16 +0100126 { provide: IconService, useClass: MockIconService },
Bhavesh72ead492018-07-19 16:29:18 +0530127 {
128 provide: LionService, useFactory: (() => {
Sean Condon28ecc5f2018-06-25 12:50:16 +0100129 return {
130 bundle: ((bundleId) => mockLion),
131 ubercache: new Array(),
132 loadCbs: new Map<string, () => void>([])
133 };
134 })
135 },
136 { provide: LoadingService, useClass: MockLoadingService },
137 { provide: LogService, useValue: logSpy },
138 { provide: ThemeService, useClass: MockThemeService },
139 { provide: UrlFnService, useClass: MockUrlFnService },
140 { provide: WebSocketService, useClass: MockWebSocketService },
141 { provide: 'Window', useValue: windowMock },
142 ]
143 })
Bhavesh72ead492018-07-19 16:29:18 +0530144 .compileComponents();
Sean Condon28ecc5f2018-06-25 12:50:16 +0100145 logServiceSpy = TestBed.get(LogService);
146 }));
147
148 beforeEach(() => {
149 fixture = TestBed.createComponent(AppsComponent);
150 component = fixture.debugElement.componentInstance;
151 fixture.detectChanges();
152 });
153
154 it('should create', () => {
155 expect(component).toBeTruthy();
156 });
157
158 it('should have a div.tabular-header inside a div#ov-app', () => {
159 const appDe: DebugElement = fixture.debugElement;
160 const divDe = appDe.query(By.css('div#ov-app div.tabular-header'));
161 expect(divDe).toBeTruthy();
162 });
163
164 it('should have a h2 inside the div.tabular-header', () => {
165 const appDe: DebugElement = fixture.debugElement;
166 const divDe = appDe.query(By.css('div#ov-app div.tabular-header h2'));
167 const div: HTMLElement = divDe.nativeElement;
168 expect(div.textContent).toEqual(' %title_apps% (0 %total%) ');
169 });
170
171 it('should have a refresh button inside the div.tabular-header', () => {
172 const appDe: DebugElement = fixture.debugElement;
173 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.refresh'));
174 expect(divDe).toBeTruthy();
175 });
176
177 it('should have an active button inside the div.tabular-header', () => {
178 const appDe: DebugElement = fixture.debugElement;
179 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.active'));
180 expect(divDe).toBeTruthy();
181 });
182
183 it('should have a div.summary-list inside a div#ov-app', () => {
184 const appDe: DebugElement = fixture.debugElement;
185 const divDe = appDe.query(By.css('div#ov-app div.summary-list'));
186 expect(divDe).toBeTruthy();
187 });
188});