blob: b2f05922c6102c87e472a1d44bc28b1786ea018b [file] [log] [blame]
Sean Condon0c577f62018-11-18 22:40:05 +00001/*
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';
17
18import { DeviceNodeSvgComponent } from './devicenodesvg.component';
Sean Condon64ea7d22019-04-12 19:39:13 +010019import {FnService, IconService, LogService} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000020import {ActivatedRoute, Params} from '@angular/router';
21import {of} from 'rxjs';
22import {ChangeDetectorRef} from '@angular/core';
23import {Device} from '../../models';
Sean Condon50855cf2018-12-23 15:37:42 +000024import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
Sean Condon0c577f62018-11-18 22:40:05 +000025
26class MockActivatedRoute extends ActivatedRoute {
27 constructor(params: Params) {
28 super();
29 this.queryParams = of(params);
30 }
31}
32
Sean Condon59d31372019-02-02 20:07:00 +000033class MockIconService {
34 loadIconDef() { }
35}
36
Sean Condon0c577f62018-11-18 22:40:05 +000037describe('DeviceNodeSvgComponent', () => {
Sean Condon64ea7d22019-04-12 19:39:13 +010038 let fs: FnService;
Sean Condon0c577f62018-11-18 22:40:05 +000039 let logServiceSpy: jasmine.SpyObj<LogService>;
40 let component: DeviceNodeSvgComponent;
41 let fixture: ComponentFixture<DeviceNodeSvgComponent>;
Sean Condon64ea7d22019-04-12 19:39:13 +010042 let windowMock: Window;
Sean Condon0c577f62018-11-18 22:40:05 +000043 let ar: MockActivatedRoute;
44 let testDevice: Device;
45
46
47 beforeEach(async(() => {
48 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
49 ar = new MockActivatedRoute({ 'debug': 'txrx' });
50 testDevice = new Device('test:1');
51 testDevice.online = true;
52
Sean Condon64ea7d22019-04-12 19:39:13 +010053 windowMock = <any>{
54 location: <any>{
55 hostname: 'foo',
56 host: 'foo',
57 port: '80',
58 protocol: 'http',
59 search: { debug: 'true' },
60 href: 'ws://foo:123/onos/ui/websock/path',
61 absUrl: 'ws://foo:123/onos/ui/websock/path'
62 }
63 };
64 fs = new FnService(ar, logSpy, windowMock);
65
Sean Condon0c577f62018-11-18 22:40:05 +000066 TestBed.configureTestingModule({
Sean Condon50855cf2018-12-23 15:37:42 +000067 imports: [ BrowserAnimationsModule ],
Sean Condon0c577f62018-11-18 22:40:05 +000068 declarations: [ DeviceNodeSvgComponent ],
69 providers: [
70 { provide: LogService, useValue: logSpy },
71 { provide: ActivatedRoute, useValue: ar },
Sean Condon59d31372019-02-02 20:07:00 +000072 { provide: ChangeDetectorRef, useClass: ChangeDetectorRef },
Sean Condon64ea7d22019-04-12 19:39:13 +010073 { provide: IconService, useClass: MockIconService },
74 { provide: 'Window', useValue: windowMock },
Sean Condon0c577f62018-11-18 22:40:05 +000075 ]
76 })
77 .compileComponents();
78 logServiceSpy = TestBed.get(LogService);
79 }));
80
81 beforeEach(() => {
82 fixture = TestBed.createComponent(DeviceNodeSvgComponent);
83 component = fixture.componentInstance;
84 component.device = testDevice;
85 fixture.detectChanges();
86 });
87
88 it('should create', () => {
89 expect(component).toBeTruthy();
90 });
91});