blob: 08014943bb5e12f6ae345458c21dbfea08daf06e [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +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 { ComponentFixture, TestBed, async } from '@angular/core/testing';
17import { ActivatedRoute, Params } from '@angular/router';
18import { RouterTestingModule } from '@angular/router/testing';
19import { BrowserModule } from '@angular/platform-browser';
20import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
21import { FormsModule } from '@angular/forms';
22import { of } from 'rxjs';
23
24import { NavComponent } from './nav/nav.component';
25import { OnosComponent } from './onos.component';
26
27import {
28 LogService, ConsoleLoggerService,
29 ConfirmComponent,
30 IconComponent,
31 MastComponent,
32 VeilComponent,
33 FnService,
34 GlyphService,
35 IconService,
36 LionService,
37 NavService, UiView,
38 OnosService,
39 SvgUtilService,
40 ThemeService,
41 WebSocketService,
42 WsOptions
43} from 'gui2-fw-lib';
44
45class MockActivatedRoute extends ActivatedRoute {
46 constructor(params: Params) {
47 super();
48 this.queryParams = of(params);
49 }
50}
51
52class MockDialogService {}
53
54class MockGlyphService {}
55
56class MockIconService {}
57
58class MockLionService {}
59
60class MockNavService {
61 uiPlatformViews = new Array<UiView>();
62 uiNetworkViews = new Array<UiView>();
63 uiOtherViews = new Array<UiView>();
64 uiHiddenViews = new Array<UiView>();
65}
66
67class MockOnosService {}
68
69class MockThemeService {}
70
71class MockVeilComponent {}
72
73class MockWebSocketService {
74 createWebSocket() { }
75 isConnected() { return false; }
76 unbindHandlers() { }
77 bindHandlers() { }
78}
79
80/**
81 * ONOS GUI -- Onos Component - Unit Tests
82 */
83describe('OnosComponent', () => {
84 let logServiceSpy: jasmine.SpyObj<LogService>;
85 let fs: FnService;
86 let ar: MockActivatedRoute;
87 let windowMock: Window;
88 let component: OnosComponent;
89 let fixture: ComponentFixture<OnosComponent>;
90
91 beforeEach(async(() => {
92 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
93 ar = new MockActivatedRoute({'debug': 'TestService'});
94
95 windowMock = <any>{
96 location: <any>{
97 hostname: 'foo',
98 host: 'foo',
99 port: '80',
100 protocol: 'http',
101 search: { debug: 'true' },
102 href: 'ws://foo:123/onos/ui/websock/path',
103 absUrl: 'ws://foo:123/onos/ui/websock/path'
104 },
105 innerHeight: 240,
106 innerWidth: 320
107 };
108 fs = new FnService(ar, logSpy, windowMock);
109
110 TestBed.configureTestingModule({
111 imports: [
112 RouterTestingModule,
113 BrowserModule,
114 BrowserAnimationsModule,
115 FormsModule
116 ],
117 declarations: [
118 ConfirmComponent,
119 IconComponent,
120 MastComponent,
121 NavComponent,
122 OnosComponent,
123 VeilComponent,
124 ],
125 providers: [
126 { provide: FnService, useValue: fs },
127 { provide: GlyphService, useClass: MockGlyphService },
128 { provide: IconService, useClass: MockIconService },
129 { provide: LionService, useClass: MockLionService },
130 { provide: LogService, useValue: logSpy },
131 { provide: NavService, useClass: MockNavService },
132 { provide: OnosService, useClass: MockOnosService },
133 { provide: ThemeService, useClass: MockThemeService },
134 { provide: WebSocketService, useClass: MockWebSocketService },
135 { provide: Window, useFactory: (() => windowMock ) },
136 ]
137 }).compileComponents();
138 logServiceSpy = TestBed.get(LogService);
139 }));
140
141 beforeEach(() => {
142 fixture = TestBed.createComponent(OnosComponent);
143 component = fixture.debugElement.componentInstance;
144 fixture.detectChanges();
145 });
146
147// TODO: Reimplemt this - it's compaining about "no provider for Window"
148// it('should create the component', () => {
149// expect(component).toBeTruthy();
150// });
151
152// it(`should have as title 'onos'`, async(() => {
153// const fixture = TestBed.createComponent(OnosComponent);
154// const app = fixture.componentInstance;
155// expect(app.title).toEqual('onos');
156// }));
157});