blob: 5c5c4fb731bbc469dd44df381846c349ae0970ac [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 */
Sean Condon64060ff2019-05-30 15:48:11 +010016import { async, ComponentFixture, TestBed, getTestBed } from '@angular/core/testing';
17import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
Sean Condonf4f54a12018-10-10 23:25:46 +010018import { BackgroundSvgComponent } from './backgroundsvg.component';
Sean Condon64060ff2019-05-30 15:48:11 +010019import {MapSvgComponent, TopoData} from '../mapsvg/mapsvg.component';
Sean Condon0d064ec2019-02-04 21:53:53 +000020import {from} from 'rxjs';
21import {HttpClient} from '@angular/common/http';
Sean Condon3dd062f2020-04-14 09:25:00 +010022import {LocMeta, LogService, ZoomUtils} from 'org_onosproject_onos/web/gui2-fw-lib/public_api';
Sean Condon0d064ec2019-02-04 21:53:53 +000023import {MapObject} from '../maputils';
Sean Condon71910542019-02-16 18:16:42 +000024import {ForceSvgComponent} from '../forcesvg/forcesvg.component';
Sean Condonff85fbe2019-03-16 14:28:46 +000025
Sean Condon71910542019-02-16 18:16:42 +000026import {DraggableDirective} from '../forcesvg/draggable/draggable.directive';
Sean Condonff85fbe2019-03-16 14:28:46 +000027import {DeviceNodeSvgComponent} from '../forcesvg/visuals/devicenodesvg/devicenodesvg.component';
28import {SubRegionNodeSvgComponent} from '../forcesvg/visuals/subregionnodesvg/subregionnodesvg.component';
29import {LinkSvgComponent} from '../forcesvg/visuals/linksvg/linksvg.component';
30import {HostNodeSvgComponent} from '../forcesvg/visuals/hostnodesvg/hostnodesvg.component';
Sean Condon590b34b2019-12-04 18:44:37 +000031import {BadgeSvgComponent} from '../forcesvg/visuals/badgesvg/badgesvg.component';
Sean Condon0d064ec2019-02-04 21:53:53 +000032
Sean Condonf4f54a12018-10-10 23:25:46 +010033
34describe('BackgroundSvgComponent', () => {
Sean Condon64060ff2019-05-30 15:48:11 +010035 let httpMock: HttpTestingController;
36
Sean Condon0d064ec2019-02-04 21:53:53 +000037 let logServiceSpy: jasmine.SpyObj<LogService>;
Sean Condonf4f54a12018-10-10 23:25:46 +010038 let component: BackgroundSvgComponent;
39 let fixture: ComponentFixture<BackgroundSvgComponent>;
Sean Condon64060ff2019-05-30 15:48:11 +010040
Sean Condon0d064ec2019-02-04 21:53:53 +000041 const testmap: MapObject = <MapObject>{
42 scale: 1.0,
Sean Condon64060ff2019-05-30 15:48:11 +010043 id: 'bayareaGEO',
44 description: 'test map',
45 filePath: 'testmap'
Sean Condon0d064ec2019-02-04 21:53:53 +000046 };
Sean Condonf4f54a12018-10-10 23:25:46 +010047
Sean Condon64060ff2019-05-30 15:48:11 +010048 const sampleTopoData = <TopoData>require('../mapsvg/tests/bayarea.json');
49
50 beforeEach(() => {
Sean Condon0d064ec2019-02-04 21:53:53 +000051 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
52
Sean Condon64060ff2019-05-30 15:48:11 +010053
Sean Condonf4f54a12018-10-10 23:25:46 +010054 TestBed.configureTestingModule({
Sean Condon64060ff2019-05-30 15:48:11 +010055 imports: [HttpClientTestingModule],
Sean Condon0d064ec2019-02-04 21:53:53 +000056 declarations: [
57 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +000058 MapSvgComponent,
59 ForceSvgComponent,
60 DeviceNodeSvgComponent,
61 HostNodeSvgComponent,
62 SubRegionNodeSvgComponent,
63 LinkSvgComponent,
Sean Condon590b34b2019-12-04 18:44:37 +000064 DraggableDirective,
65 BadgeSvgComponent
Sean Condon0d064ec2019-02-04 21:53:53 +000066 ],
67 providers: [
68 { provide: LogService, useValue: logSpy },
Sean Condon0d064ec2019-02-04 21:53:53 +000069 ]
Sean Condonf4f54a12018-10-10 23:25:46 +010070 })
71 .compileComponents();
Sean Condon0d064ec2019-02-04 21:53:53 +000072
73 logServiceSpy = TestBed.get(LogService);
Sean Condon64060ff2019-05-30 15:48:11 +010074 httpMock = TestBed.get(HttpTestingController);
Sean Condonf4f54a12018-10-10 23:25:46 +010075 fixture = TestBed.createComponent(BackgroundSvgComponent);
Sean Condon64060ff2019-05-30 15:48:11 +010076
Sean Condonf4f54a12018-10-10 23:25:46 +010077 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +000078 component.map = testmap;
Sean Condonf4f54a12018-10-10 23:25:46 +010079 fixture.detectChanges();
80 });
81
82 it('should create', () => {
Sean Condon64060ff2019-05-30 15:48:11 +010083 httpMock.expectOne('testmap.topojson').flush(sampleTopoData);
84
Sean Condonf4f54a12018-10-10 23:25:46 +010085 expect(component).toBeTruthy();
Sean Condon64060ff2019-05-30 15:48:11 +010086
87 httpMock.verify();
Sean Condonf4f54a12018-10-10 23:25:46 +010088 });
Sean Condon71910542019-02-16 18:16:42 +000089
90 it('should convert latlong to xy', () => {
Sean Condon1ae15802019-03-02 09:07:18 +000091 const result = ZoomUtils.convertGeoToCanvas(<LocMeta>{lat: 52, lng: -8});
Sean Condon71910542019-02-16 18:16:42 +000092 expect(Math.round(result.x * 100)).toEqual(45556);
93 expect(Math.round(result.y * 100)).toEqual(15333);
94 });
Sean Condonf4f54a12018-10-10 23:25:46 +010095});