blob: 2d2f75f1b441e6311a8cf231ceb64851d3551500 [file] [log] [blame]
Sean Condon49e15be2018-05-16 16:58:29 +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 */
Sean Condon83fc39f2018-04-19 18:56:13 +010016import { async, ComponentFixture, TestBed } from '@angular/core/testing';
Sean Condon2bd11b72018-06-15 08:00:48 +010017import { ActivatedRoute, Params } from '@angular/router';
Sean Condon49e15be2018-05-16 16:58:29 +010018import { LogService } from '../../../../app/log.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010019import { AppsComponent } from '../../../../app/view/apps/apps.component';
Sean Condon49e15be2018-05-16 16:58:29 +010020import { DialogService } from '../../../../app/fw/layer/dialog.service';
21import { FnService } from '../../../../app/fw/util/fn.service';
Sean Condon2bd11b72018-06-15 08:00:48 +010022import { IconComponent } from '../../../../app/fw/svg/icon/icon.component';
Sean Condon49e15be2018-05-16 16:58:29 +010023import { IconService } from '../../../../app/fw/svg/icon.service';
24import { KeyService } from '../../../../app/fw/util/key.service';
25import { LionService } from '../../../../app/fw/util/lion.service';
Sean Condon2bd11b72018-06-15 08:00:48 +010026import { LoadingService } from '../../../../app/fw/layer/loading.service';
Sean Condon49e15be2018-05-16 16:58:29 +010027import { PanelService } from '../../../../app/fw/layer/panel.service';
Sean Condon2bd11b72018-06-15 08:00:48 +010028import { ThemeService } from '../../../../app/fw/util/theme.service';
Sean Condon49e15be2018-05-16 16:58:29 +010029import { UrlFnService } from '../../../../app/fw/remote/urlfn.service';
30import { WebSocketService } from '../../../../app/fw/remote/websocket.service';
Sean Condon2bd11b72018-06-15 08:00:48 +010031import { of } from 'rxjs';
32
33class MockActivatedRoute extends ActivatedRoute {
34 constructor(params: Params) {
35 super();
36 this.queryParams = of(params);
37 }
38}
Sean Condon83fc39f2018-04-19 18:56:13 +010039
Sean Condon49e15be2018-05-16 16:58:29 +010040class MockDialogService {}
41
42class MockFnService {}
43
Sean Condon2bd11b72018-06-15 08:00:48 +010044class MockIconService {
45 loadIconDef() {}
46}
Sean Condon49e15be2018-05-16 16:58:29 +010047
48class MockKeyService {}
49
Sean Condon2bd11b72018-06-15 08:00:48 +010050class MockLoadingService {
51 startAnim() {}
52 stop() {}
53 waiting() {}
54}
Sean Condon49e15be2018-05-16 16:58:29 +010055
56class MockPanelService {}
57
58class MockTableBuilderService {}
59
Sean Condon2bd11b72018-06-15 08:00:48 +010060class MockThemeService {}
61
Sean Condon49e15be2018-05-16 16:58:29 +010062class MockUrlFnService {}
63
Sean Condon2bd11b72018-06-15 08:00:48 +010064class MockWebSocketService {
65 createWebSocket() {}
66 isConnected() { return false; }
67 unbindHandlers() {}
68 bindHandlers() {}
69}
Sean Condon49e15be2018-05-16 16:58:29 +010070
71/**
72 * ONOS GUI -- Apps View -- Unit Tests
73 */
Sean Condon83fc39f2018-04-19 18:56:13 +010074describe('AppsComponent', () => {
Sean Condon2bd11b72018-06-15 08:00:48 +010075 let fs: FnService;
76 let ar: MockActivatedRoute;
77 let windowMock: Window;
78 let logServiceSpy: jasmine.SpyObj<LogService>;
Sean Condon49e15be2018-05-16 16:58:29 +010079 let component: AppsComponent;
80 let fixture: ComponentFixture<AppsComponent>;
Sean Condon2bd11b72018-06-15 08:00:48 +010081 const bundleObj = {
82 'core.view.App': {
83 test: 'test1'
84 }
85 };
86 const mockLion = (key) => {
87 return bundleObj[key] || '%' + key + '%';
88 };
Sean Condon83fc39f2018-04-19 18:56:13 +010089
Sean Condon49e15be2018-05-16 16:58:29 +010090 beforeEach(async(() => {
Sean Condon2bd11b72018-06-15 08:00:48 +010091 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
92 ar = new MockActivatedRoute({'debug': 'txrx'});
93
94 windowMock = <any>{
95 location: <any> {
96 hostname: 'foo',
97 host: 'foo',
98 port: '80',
99 protocol: 'http',
100 search: { debug: 'true'},
101 href: 'ws://foo:123/onos/ui/websock/path',
102 absUrl: 'ws://foo:123/onos/ui/websock/path'
103 }
104 };
105 fs = new FnService(ar, logSpy, windowMock);
Sean Condon83fc39f2018-04-19 18:56:13 +0100106
Sean Condon49e15be2018-05-16 16:58:29 +0100107 TestBed.configureTestingModule({
Sean Condon2bd11b72018-06-15 08:00:48 +0100108 declarations: [ AppsComponent, IconComponent ],
Sean Condon49e15be2018-05-16 16:58:29 +0100109 providers: [
110 { provide: DialogService, useClass: MockDialogService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100111 { provide: FnService, useValue: fs },
Sean Condon49e15be2018-05-16 16:58:29 +0100112 { provide: IconService, useClass: MockIconService },
113 { provide: KeyService, useClass: MockKeyService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100114 { provide: LionService, useFactory: (() => {
115 return {
116 bundle: ((bundleId) => mockLion),
117 ubercache: new Array()
118 };
119 })
120 },
121 { provide: LoadingService, useClass: MockLoadingService },
122 { provide: LogService, useValue: logSpy },
Sean Condon49e15be2018-05-16 16:58:29 +0100123 { provide: PanelService, useClass: MockPanelService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100124 { provide: ThemeService, useClass: MockThemeService },
Sean Condon49e15be2018-05-16 16:58:29 +0100125 { provide: UrlFnService, useClass: MockUrlFnService },
126 { provide: WebSocketService, useClass: MockWebSocketService },
Sean Condona00bf382018-06-23 07:54:01 +0100127 { provide: 'Window', useValue: windowMock },
Sean Condon49e15be2018-05-16 16:58:29 +0100128 ]
129 })
130 .compileComponents();
Sean Condon2bd11b72018-06-15 08:00:48 +0100131 logServiceSpy = TestBed.get(LogService);
Sean Condon49e15be2018-05-16 16:58:29 +0100132 }));
Sean Condon83fc39f2018-04-19 18:56:13 +0100133
Sean Condon49e15be2018-05-16 16:58:29 +0100134 beforeEach(() => {
135 fixture = TestBed.createComponent(AppsComponent);
Sean Condon2bd11b72018-06-15 08:00:48 +0100136 component = fixture.debugElement.componentInstance;
Sean Condon49e15be2018-05-16 16:58:29 +0100137 fixture.detectChanges();
138 });
139
140 it('should create', () => {
141 expect(component).toBeTruthy();
142 });
Sean Condon83fc39f2018-04-19 18:56:13 +0100143});