blob: c03f6807a281f5d95a45be9aaaf01a64363bb1c2 [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +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 { TestBed, async } from '@angular/core/testing';
Sean Condonfd6d11b2018-06-02 20:29:49 +010017import { RouterModule, RouterOutlet, ChildrenOutletContexts, ActivatedRoute, Params } from '@angular/router';
18import { of } from 'rxjs';
19
Sean Condon49e15be2018-05-16 16:58:29 +010020import { LogService } from '../../app/log.service';
21import { ConsoleLoggerService } from '../../app/consolelogger.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010022
Sean Condon49e15be2018-05-16 16:58:29 +010023import { IconComponent } from '../../app/fw/svg/icon/icon.component';
24import { MastComponent } from '../../app/fw/mast/mast/mast.component';
25import { NavComponent } from '../../app/fw/nav/nav/nav.component';
Sean Condon83fc39f2018-04-19 18:56:13 +010026import { OnosComponent } from '../../app/onos.component';
Sean Condonfd6d11b2018-06-02 20:29:49 +010027import { VeilComponent } from '../../app/fw/layer/veil/veil.component';
28
Sean Condon49e15be2018-05-16 16:58:29 +010029import { DialogService } from '../../app/fw/layer/dialog.service';
30import { EeService } from '../../app/fw/util/ee.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010031import { FnService } from '../../app/fw/util/fn.service';
Sean Condon49e15be2018-05-16 16:58:29 +010032import { GlyphService } from '../../app/fw/svg/glyph.service';
33import { IconService } from '../../app/fw/svg/icon.service';
34import { KeyService } from '../../app/fw/util/key.service';
35import { LionService } from '../../app/fw/util/lion.service';
36import { NavService } from '../../app/fw/nav/nav.service';
37import { OnosService } from '../../app/onos.service';
Sean Condon49e15be2018-05-16 16:58:29 +010038import { QuickHelpService } from '../../app/fw/layer/quickhelp.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010039import { SvgUtilService } from '../../app/fw/svg/svgutil.service';
Sean Condon49e15be2018-05-16 16:58:29 +010040import { ThemeService } from '../../app/fw/util/theme.service';
41import { SpriteService } from '../../app/fw/svg/sprite.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010042import { WebSocketService, WsOptions } from '../../app/fw/remote/websocket.service';
43
44class MockActivatedRoute extends ActivatedRoute {
45 constructor(params: Params) {
46 super();
47 this.queryParams = of(params);
48 }
49}
Sean Condon49e15be2018-05-16 16:58:29 +010050
51class MockDialogService {}
52
53class MockEeService {}
54
Sean Condon49e15be2018-05-16 16:58:29 +010055class MockGlyphService {}
56
57class MockIconService {}
58
59class MockKeyService {}
60
Sean Condon2bd11b72018-06-15 08:00:48 +010061class MockLionService {}
62
Sean Condon49e15be2018-05-16 16:58:29 +010063class MockNavService {}
64
65class MockOnosService {}
66
Sean Condon49e15be2018-05-16 16:58:29 +010067class MockQuickHelpService {}
68
69class MockSpriteService {}
70
71class MockThemeService {}
72
Sean Condonfd6d11b2018-06-02 20:29:49 +010073class MockVeilComponent {}
Sean Condon83fc39f2018-04-19 18:56:13 +010074
Sean Condon2bd11b72018-06-15 08:00:48 +010075class MockWebSocketService {
76 createWebSocket() {}
77 isConnected() { return false; }
78}
79
Sean Condon83fc39f2018-04-19 18:56:13 +010080/**
81 * ONOS GUI -- Onos Component - Unit Tests
82 */
83describe('OnosComponent', () => {
Sean Condon49e15be2018-05-16 16:58:29 +010084 let log: LogService;
Sean Condonfd6d11b2018-06-02 20:29:49 +010085 let fs: FnService;
86 let ar: MockActivatedRoute;
87 let windowMock: Window;
Sean Condon2bd11b72018-06-15 08:00:48 +010088 let fixture;
89 let app;
Sean Condon49e15be2018-05-16 16:58:29 +010090
91 beforeEach(async(() => {
92 log = new ConsoleLoggerService();
Sean Condonfd6d11b2018-06-02 20:29:49 +010093 ar = new MockActivatedRoute({'debug': 'TestService'});
94
95 windowMock = <any>{
96 location: <any> {
97 hostname: '',
98 host: '',
99 port: '',
100 protocol: '',
101 search: { debug: 'true'},
102 href: ''
103 },
104 innerHeight: 240,
105 innerWidth: 320
106 };
107 fs = new FnService(ar, log, windowMock);
Sean Condon49e15be2018-05-16 16:58:29 +0100108
109 TestBed.configureTestingModule({
110 declarations: [
111 IconComponent,
112 MastComponent,
113 NavComponent,
114 OnosComponent,
Sean Condonfd6d11b2018-06-02 20:29:49 +0100115 VeilComponent,
Sean Condon49e15be2018-05-16 16:58:29 +0100116 RouterOutlet
117 ],
118 providers: [
119 { provide: ChildrenOutletContexts, useClass: ChildrenOutletContexts },
120 { provide: DialogService, useClass: MockDialogService },
121 { provide: EeService, useClass: MockEeService },
Sean Condonfd6d11b2018-06-02 20:29:49 +0100122 { provide: FnService, useValue: fs },
Sean Condon49e15be2018-05-16 16:58:29 +0100123 { provide: GlyphService, useClass: MockGlyphService },
124 { provide: IconService, useClass: MockIconService },
125 { provide: KeyService, useClass: MockKeyService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100126 { provide: LionService, useClass: MockLionService },
Sean Condon49e15be2018-05-16 16:58:29 +0100127 { provide: LogService, useValue: log },
128 { provide: NavService, useClass: MockNavService },
129 { provide: OnosService, useClass: MockOnosService },
130 { provide: QuickHelpService, useClass: MockQuickHelpService },
Sean Condon49e15be2018-05-16 16:58:29 +0100131 { provide: SpriteService, useClass: MockSpriteService },
132 { provide: ThemeService, useClass: MockThemeService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100133 { provide: WebSocketService, useClass: MockWebSocketService },
Sean Condonfd6d11b2018-06-02 20:29:49 +0100134 { provide: Window, useFactory: (() => windowMock ) },
Sean Condon49e15be2018-05-16 16:58:29 +0100135 ]
136 }).compileComponents();
Sean Condon2bd11b72018-06-15 08:00:48 +0100137
138 fixture = TestBed.createComponent(OnosComponent);
139 app = fixture.componentInstance;
Sean Condon49e15be2018-05-16 16:58:29 +0100140 }));
141
142 it('should create the app', async(() => {
Sean Condon49e15be2018-05-16 16:58:29 +0100143 expect(app).toBeTruthy();
144 }));
145
Sean Condon2bd11b72018-06-15 08:00:48 +0100146// it(`should have as title 'onos'`, async(() => {
147// const fixture = TestBed.createComponent(OnosComponent);
148// const app = fixture.componentInstance;
149// expect(app.title).toEqual('onos');
150// }));
Sean Condon83fc39f2018-04-19 18:56:13 +0100151});