Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 17 | |
| 18 | import { DeviceNodeSvgComponent } from './devicenodesvg.component'; |
Sean Condon | 3dd062f | 2020-04-14 09:25:00 +0100 | [diff] [blame] | 19 | import {FnService, IconService, LogService, SvgUtilService} from 'org_onosproject_onos/web/gui2-fw-lib/public_api'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 20 | import {ActivatedRoute, Params} from '@angular/router'; |
| 21 | import {of} from 'rxjs'; |
| 22 | import {ChangeDetectorRef} from '@angular/core'; |
| 23 | import {Device} from '../../models'; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 24 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; |
Sean Condon | 058804c | 2019-04-16 09:41:52 +0100 | [diff] [blame] | 25 | import {TopologyService} from '../../../../topology.service'; |
Sean Condon | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 26 | import {BadgeSvgComponent} from '../badgesvg/badgesvg.component'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 27 | |
| 28 | class MockActivatedRoute extends ActivatedRoute { |
| 29 | constructor(params: Params) { |
| 30 | super(); |
| 31 | this.queryParams = of(params); |
| 32 | } |
| 33 | } |
| 34 | |
Sean Condon | 59d3137 | 2019-02-02 20:07:00 +0000 | [diff] [blame] | 35 | class MockIconService { |
| 36 | loadIconDef() { } |
| 37 | } |
| 38 | |
Sean Condon | 058804c | 2019-04-16 09:41:52 +0100 | [diff] [blame] | 39 | class 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 | |
| 66 | class MockTopologyService { |
| 67 | public instancesIndex: Map<string, number>; |
| 68 | constructor() { |
| 69 | this.instancesIndex = new Map(); |
| 70 | } |
| 71 | } |
| 72 | |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 73 | describe('DeviceNodeSvgComponent', () => { |
Sean Condon | 64ea7d2 | 2019-04-12 19:39:13 +0100 | [diff] [blame] | 74 | let fs: FnService; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 75 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 76 | let component: DeviceNodeSvgComponent; |
| 77 | let fixture: ComponentFixture<DeviceNodeSvgComponent>; |
Sean Condon | 64ea7d2 | 2019-04-12 19:39:13 +0100 | [diff] [blame] | 78 | let windowMock: Window; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 79 | 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 Condon | 64ea7d2 | 2019-04-12 19:39:13 +0100 | [diff] [blame] | 89 | 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 Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 102 | TestBed.configureTestingModule({ |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 103 | imports: [ BrowserAnimationsModule ], |
Sean Condon | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 104 | declarations: [ DeviceNodeSvgComponent, BadgeSvgComponent ], |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 105 | providers: [ |
| 106 | { provide: LogService, useValue: logSpy }, |
| 107 | { provide: ActivatedRoute, useValue: ar }, |
Sean Condon | 59d3137 | 2019-02-02 20:07:00 +0000 | [diff] [blame] | 108 | { provide: ChangeDetectorRef, useClass: ChangeDetectorRef }, |
Sean Condon | 64ea7d2 | 2019-04-12 19:39:13 +0100 | [diff] [blame] | 109 | { provide: IconService, useClass: MockIconService }, |
Sean Condon | 058804c | 2019-04-16 09:41:52 +0100 | [diff] [blame] | 110 | { provide: SvgUtilService, useClass: MockSvgUtilService }, |
| 111 | { provide: TopologyService, useClass: MockTopologyService }, |
Sean Condon | 64ea7d2 | 2019-04-12 19:39:13 +0100 | [diff] [blame] | 112 | { provide: 'Window', useValue: windowMock }, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 113 | ] |
| 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 | }); |