blob: 994967d75dae5bd581652392fef0511655ed6750 [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 Condon058804c2019-04-16 09:41:52 +010019import {FnService, IconService, LogService, SvgUtilService} 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 Condon058804c2019-04-16 09:41:52 +010025import {TopologyService} from '../../../../topology.service';
Sean Condon0c577f62018-11-18 22:40:05 +000026
27class MockActivatedRoute extends ActivatedRoute {
28 constructor(params: Params) {
29 super();
30 this.queryParams = of(params);
31 }
32}
33
Sean Condon59d31372019-02-02 20:07:00 +000034class MockIconService {
35 loadIconDef() { }
36}
37
Sean Condon058804c2019-04-16 09:41:52 +010038class MockSvgUtilService {
39
40 cat7() {
41 const tcid = 'd3utilTestCard';
42
43 function getColor(id, muted, theme) {
44 // NOTE: since we are lazily assigning domain ids, we need to
45 // get the color from all 4 scales, to keep the domains
46 // in sync.
47 const ln = '#5b99d2';
48 const lm = '#9ebedf';
49 const dn = '#5b99d2';
50 const dm = '#9ebedf';
51 if (theme === 'dark') {
52 return muted ? dm : dn;
53 } else {
54 return muted ? lm : ln;
55 }
56 }
57
58 return {
59 // testCard: testCard,
60 getColor: getColor,
61 };
62 }
63}
64
65class MockTopologyService {
66 public instancesIndex: Map<string, number>;
67 constructor() {
68 this.instancesIndex = new Map();
69 }
70}
71
Sean Condon0c577f62018-11-18 22:40:05 +000072describe('DeviceNodeSvgComponent', () => {
Sean Condon64ea7d22019-04-12 19:39:13 +010073 let fs: FnService;
Sean Condon0c577f62018-11-18 22:40:05 +000074 let logServiceSpy: jasmine.SpyObj<LogService>;
75 let component: DeviceNodeSvgComponent;
76 let fixture: ComponentFixture<DeviceNodeSvgComponent>;
Sean Condon64ea7d22019-04-12 19:39:13 +010077 let windowMock: Window;
Sean Condon0c577f62018-11-18 22:40:05 +000078 let ar: MockActivatedRoute;
79 let testDevice: Device;
80
81
82 beforeEach(async(() => {
83 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
84 ar = new MockActivatedRoute({ 'debug': 'txrx' });
85 testDevice = new Device('test:1');
86 testDevice.online = true;
87
Sean Condon64ea7d22019-04-12 19:39:13 +010088 windowMock = <any>{
89 location: <any>{
90 hostname: 'foo',
91 host: 'foo',
92 port: '80',
93 protocol: 'http',
94 search: { debug: 'true' },
95 href: 'ws://foo:123/onos/ui/websock/path',
96 absUrl: 'ws://foo:123/onos/ui/websock/path'
97 }
98 };
99 fs = new FnService(ar, logSpy, windowMock);
100
Sean Condon0c577f62018-11-18 22:40:05 +0000101 TestBed.configureTestingModule({
Sean Condon50855cf2018-12-23 15:37:42 +0000102 imports: [ BrowserAnimationsModule ],
Sean Condon0c577f62018-11-18 22:40:05 +0000103 declarations: [ DeviceNodeSvgComponent ],
104 providers: [
105 { provide: LogService, useValue: logSpy },
106 { provide: ActivatedRoute, useValue: ar },
Sean Condon59d31372019-02-02 20:07:00 +0000107 { provide: ChangeDetectorRef, useClass: ChangeDetectorRef },
Sean Condon64ea7d22019-04-12 19:39:13 +0100108 { provide: IconService, useClass: MockIconService },
Sean Condon058804c2019-04-16 09:41:52 +0100109 { provide: SvgUtilService, useClass: MockSvgUtilService },
110 { provide: TopologyService, useClass: MockTopologyService },
Sean Condon64ea7d22019-04-12 19:39:13 +0100111 { provide: 'Window', useValue: windowMock },
Sean Condon0c577f62018-11-18 22:40:05 +0000112 ]
113 })
114 .compileComponents();
115 logServiceSpy = TestBed.get(LogService);
116 }));
117
118 beforeEach(() => {
119 fixture = TestBed.createComponent(DeviceNodeSvgComponent);
120 component = fixture.componentInstance;
121 component.device = testDevice;
122 fixture.detectChanges();
123 });
124
125 it('should create', () => {
126 expect(component).toBeTruthy();
127 });
128});