blob: 8dcb9e029683aadafd7f3b4e0f46be69def591df [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';
38import { PanelService } from '../../app/fw/layer/panel.service';
39import { QuickHelpService } from '../../app/fw/layer/quickhelp.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010040import { SvgUtilService } from '../../app/fw/svg/svgutil.service';
Sean Condon49e15be2018-05-16 16:58:29 +010041import { ThemeService } from '../../app/fw/util/theme.service';
42import { SpriteService } from '../../app/fw/svg/sprite.service';
Sean Condonfd6d11b2018-06-02 20:29:49 +010043import { WebSocketService, WsOptions } from '../../app/fw/remote/websocket.service';
44
45class MockActivatedRoute extends ActivatedRoute {
46 constructor(params: Params) {
47 super();
48 this.queryParams = of(params);
49 }
50}
Sean Condon49e15be2018-05-16 16:58:29 +010051
52class MockDialogService {}
53
54class MockEeService {}
55
Sean Condon49e15be2018-05-16 16:58:29 +010056class MockGlyphService {}
57
58class MockIconService {}
59
60class MockKeyService {}
61
Sean Condon2bd11b72018-06-15 08:00:48 +010062class MockLionService {}
63
Sean Condon49e15be2018-05-16 16:58:29 +010064class MockNavService {}
65
66class MockOnosService {}
67
68class MockPanelService {}
69
70class MockQuickHelpService {}
71
72class MockSpriteService {}
73
74class MockThemeService {}
75
Sean Condonfd6d11b2018-06-02 20:29:49 +010076class MockVeilComponent {}
Sean Condon83fc39f2018-04-19 18:56:13 +010077
Sean Condon2bd11b72018-06-15 08:00:48 +010078class MockWebSocketService {
79 createWebSocket() {}
80 isConnected() { return false; }
81}
82
Sean Condon83fc39f2018-04-19 18:56:13 +010083/**
84 * ONOS GUI -- Onos Component - Unit Tests
85 */
86describe('OnosComponent', () => {
Sean Condon49e15be2018-05-16 16:58:29 +010087 let log: LogService;
Sean Condonfd6d11b2018-06-02 20:29:49 +010088 let fs: FnService;
89 let ar: MockActivatedRoute;
90 let windowMock: Window;
Sean Condon2bd11b72018-06-15 08:00:48 +010091 let fixture;
92 let app;
Sean Condon49e15be2018-05-16 16:58:29 +010093
94 beforeEach(async(() => {
95 log = new ConsoleLoggerService();
Sean Condonfd6d11b2018-06-02 20:29:49 +010096 ar = new MockActivatedRoute({'debug': 'TestService'});
97
98 windowMock = <any>{
99 location: <any> {
100 hostname: '',
101 host: '',
102 port: '',
103 protocol: '',
104 search: { debug: 'true'},
105 href: ''
106 },
107 innerHeight: 240,
108 innerWidth: 320
109 };
110 fs = new FnService(ar, log, windowMock);
Sean Condon49e15be2018-05-16 16:58:29 +0100111
112 TestBed.configureTestingModule({
113 declarations: [
114 IconComponent,
115 MastComponent,
116 NavComponent,
117 OnosComponent,
Sean Condonfd6d11b2018-06-02 20:29:49 +0100118 VeilComponent,
Sean Condon49e15be2018-05-16 16:58:29 +0100119 RouterOutlet
120 ],
121 providers: [
122 { provide: ChildrenOutletContexts, useClass: ChildrenOutletContexts },
123 { provide: DialogService, useClass: MockDialogService },
124 { provide: EeService, useClass: MockEeService },
Sean Condonfd6d11b2018-06-02 20:29:49 +0100125 { provide: FnService, useValue: fs },
Sean Condon49e15be2018-05-16 16:58:29 +0100126 { provide: GlyphService, useClass: MockGlyphService },
127 { provide: IconService, useClass: MockIconService },
128 { provide: KeyService, useClass: MockKeyService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100129 { provide: LionService, useClass: MockLionService },
Sean Condon49e15be2018-05-16 16:58:29 +0100130 { provide: LogService, useValue: log },
131 { provide: NavService, useClass: MockNavService },
132 { provide: OnosService, useClass: MockOnosService },
133 { provide: QuickHelpService, useClass: MockQuickHelpService },
134 { provide: PanelService, useClass: MockPanelService },
135 { provide: SpriteService, useClass: MockSpriteService },
136 { provide: ThemeService, useClass: MockThemeService },
Sean Condon2bd11b72018-06-15 08:00:48 +0100137 { provide: WebSocketService, useClass: MockWebSocketService },
Sean Condonfd6d11b2018-06-02 20:29:49 +0100138 { provide: Window, useFactory: (() => windowMock ) },
Sean Condon49e15be2018-05-16 16:58:29 +0100139 ]
140 }).compileComponents();
Sean Condon2bd11b72018-06-15 08:00:48 +0100141
142 fixture = TestBed.createComponent(OnosComponent);
143 app = fixture.componentInstance;
Sean Condon49e15be2018-05-16 16:58:29 +0100144 }));
145
146 it('should create the app', async(() => {
Sean Condon49e15be2018-05-16 16:58:29 +0100147 expect(app).toBeTruthy();
148 }));
149
Sean Condon2bd11b72018-06-15 08:00:48 +0100150// it(`should have as title 'onos'`, async(() => {
151// const fixture = TestBed.createComponent(OnosComponent);
152// const app = fixture.componentInstance;
153// expect(app.title).toEqual('onos');
154// }));
Sean Condon83fc39f2018-04-19 18:56:13 +0100155});