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