blob: cddf9aee2daee6e7c813624c7ed1ac1df0f67911 [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';
41
42class MockActivatedRoute extends ActivatedRoute {
43 constructor(params: Params) {
44 super();
45 this.queryParams = of(params);
46 }
47}
48
49class MockDialogService {}
50
51class MockFnService {}
52
Sean Condon2aa86092018-07-16 09:04:05 +010053class MockHttpClient {}
54
Sean Condon28ecc5f2018-06-25 12:50:16 +010055class MockIconService {
56 loadIconDef() {}
57}
58
59class MockKeyService {}
60
61class MockLoadingService {
62 startAnim() {}
63 stop() {}
64 waiting() {}
65}
66
67class MockThemeService {}
68
69class MockUrlFnService {}
70
71class MockWebSocketService {
72 createWebSocket() {}
73 isConnected() { return false; }
74 unbindHandlers() {}
75 bindHandlers() {}
76}
77
78/**
79 * ONOS GUI -- Apps View -- Unit Tests
80 */
81describe('AppsComponent', () => {
82 let fs: FnService;
83 let ar: MockActivatedRoute;
84 let windowMock: Window;
85 let logServiceSpy: jasmine.SpyObj<LogService>;
86 let component: AppsComponent;
87 let fixture: ComponentFixture<AppsComponent>;
88 const bundleObj = {
89 'core.view.App': {
90 test: 'test1'
91 }
92 };
93 const mockLion = (key) => {
94 return bundleObj[key] || '%' + key + '%';
95 };
96
97 beforeEach(async(() => {
98 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
99 ar = new MockActivatedRoute({'debug': 'txrx'});
100
101 windowMock = <any>{
102 location: <any> {
103 hostname: 'foo',
104 host: 'foo',
105 port: '80',
106 protocol: 'http',
107 search: { debug: 'true'},
108 href: 'ws://foo:123/onos/ui/websock/path',
109 absUrl: 'ws://foo:123/onos/ui/websock/path'
110 }
111 };
112 fs = new FnService(ar, logSpy, windowMock);
113
114 TestBed.configureTestingModule({
115 imports: [ BrowserAnimationsModule, FormsModule ],
Sean Condon2aa86092018-07-16 09:04:05 +0100116 declarations: [
117 AppsComponent,
118 ConfirmComponent,
119 IconComponent,
120 AppsDetailsComponent,
121 TableFilterPipe,
122 FlashComponent
123 ],
Sean Condon28ecc5f2018-06-25 12:50:16 +0100124 providers: [
125 { provide: DialogService, useClass: MockDialogService },
126 { provide: FnService, useValue: fs },
Sean Condon2aa86092018-07-16 09:04:05 +0100127 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon28ecc5f2018-06-25 12:50:16 +0100128 { provide: IconService, useClass: MockIconService },
129 { provide: KeyService, useClass: MockKeyService },
130 { provide: LionService, useFactory: (() => {
131 return {
132 bundle: ((bundleId) => mockLion),
133 ubercache: new Array(),
134 loadCbs: new Map<string, () => void>([])
135 };
136 })
137 },
138 { provide: LoadingService, useClass: MockLoadingService },
139 { provide: LogService, useValue: logSpy },
140 { provide: ThemeService, useClass: MockThemeService },
141 { provide: UrlFnService, useClass: MockUrlFnService },
142 { provide: WebSocketService, useClass: MockWebSocketService },
143 { provide: 'Window', useValue: windowMock },
144 ]
145 })
146 .compileComponents();
147 logServiceSpy = TestBed.get(LogService);
148 }));
149
150 beforeEach(() => {
151 fixture = TestBed.createComponent(AppsComponent);
152 component = fixture.debugElement.componentInstance;
153 fixture.detectChanges();
154 });
155
156 it('should create', () => {
157 expect(component).toBeTruthy();
158 });
159
160 it('should have a div.tabular-header inside a div#ov-app', () => {
161 const appDe: DebugElement = fixture.debugElement;
162 const divDe = appDe.query(By.css('div#ov-app div.tabular-header'));
163 expect(divDe).toBeTruthy();
164 });
165
166 it('should have a h2 inside the div.tabular-header', () => {
167 const appDe: DebugElement = fixture.debugElement;
168 const divDe = appDe.query(By.css('div#ov-app div.tabular-header h2'));
169 const div: HTMLElement = divDe.nativeElement;
170 expect(div.textContent).toEqual(' %title_apps% (0 %total%) ');
171 });
172
173 it('should have a refresh button inside the div.tabular-header', () => {
174 const appDe: DebugElement = fixture.debugElement;
175 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.refresh'));
176 expect(divDe).toBeTruthy();
177 });
178
179 it('should have an active button inside the div.tabular-header', () => {
180 const appDe: DebugElement = fixture.debugElement;
181 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.active'));
182 expect(divDe).toBeTruthy();
183 });
184
185 it('should have a div.summary-list inside a div#ov-app', () => {
186 const appDe: DebugElement = fixture.debugElement;
187 const divDe = appDe.query(By.css('div#ov-app div.summary-list'));
188 expect(divDe).toBeTruthy();
189 });
190});