blob: cefeaea50ef41955044ef690725975c31c2101f3 [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 Condon1ae15802019-03-02 09:07:18 +000022import {LocMeta, LogService, ZoomUtils} from 'gui2-fw-lib';
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 Condon0d064ec2019-02-04 21:53:53 +000031
Sean Condonf4f54a12018-10-10 23:25:46 +010032
33describe('BackgroundSvgComponent', () => {
Sean Condon64060ff2019-05-30 15:48:11 +010034 let httpMock: HttpTestingController;
35
Sean Condon0d064ec2019-02-04 21:53:53 +000036 let logServiceSpy: jasmine.SpyObj<LogService>;
Sean Condonf4f54a12018-10-10 23:25:46 +010037 let component: BackgroundSvgComponent;
38 let fixture: ComponentFixture<BackgroundSvgComponent>;
Sean Condon64060ff2019-05-30 15:48:11 +010039
Sean Condon0d064ec2019-02-04 21:53:53 +000040 const testmap: MapObject = <MapObject>{
41 scale: 1.0,
Sean Condon64060ff2019-05-30 15:48:11 +010042 id: 'bayareaGEO',
43 description: 'test map',
44 filePath: 'testmap'
Sean Condon0d064ec2019-02-04 21:53:53 +000045 };
Sean Condonf4f54a12018-10-10 23:25:46 +010046
Sean Condon64060ff2019-05-30 15:48:11 +010047 const sampleTopoData = <TopoData>require('../mapsvg/tests/bayarea.json');
48
49 beforeEach(() => {
Sean Condon0d064ec2019-02-04 21:53:53 +000050 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
51
Sean Condon64060ff2019-05-30 15:48:11 +010052
Sean Condonf4f54a12018-10-10 23:25:46 +010053 TestBed.configureTestingModule({
Sean Condon64060ff2019-05-30 15:48:11 +010054 imports: [HttpClientTestingModule],
Sean Condon0d064ec2019-02-04 21:53:53 +000055 declarations: [
56 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +000057 MapSvgComponent,
58 ForceSvgComponent,
59 DeviceNodeSvgComponent,
60 HostNodeSvgComponent,
61 SubRegionNodeSvgComponent,
62 LinkSvgComponent,
63 DraggableDirective
Sean Condon0d064ec2019-02-04 21:53:53 +000064 ],
65 providers: [
66 { provide: LogService, useValue: logSpy },
Sean Condon0d064ec2019-02-04 21:53:53 +000067 ]
Sean Condonf4f54a12018-10-10 23:25:46 +010068 })
69 .compileComponents();
Sean Condon0d064ec2019-02-04 21:53:53 +000070
71 logServiceSpy = TestBed.get(LogService);
Sean Condon64060ff2019-05-30 15:48:11 +010072 httpMock = TestBed.get(HttpTestingController);
Sean Condonf4f54a12018-10-10 23:25:46 +010073 fixture = TestBed.createComponent(BackgroundSvgComponent);
Sean Condon64060ff2019-05-30 15:48:11 +010074
Sean Condonf4f54a12018-10-10 23:25:46 +010075 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +000076 component.map = testmap;
Sean Condonf4f54a12018-10-10 23:25:46 +010077 fixture.detectChanges();
78 });
79
80 it('should create', () => {
Sean Condon64060ff2019-05-30 15:48:11 +010081 httpMock.expectOne('testmap.topojson').flush(sampleTopoData);
82
Sean Condonf4f54a12018-10-10 23:25:46 +010083 expect(component).toBeTruthy();
Sean Condon64060ff2019-05-30 15:48:11 +010084
85 httpMock.verify();
Sean Condonf4f54a12018-10-10 23:25:46 +010086 });
Sean Condon71910542019-02-16 18:16:42 +000087
88 it('should convert latlong to xy', () => {
Sean Condon1ae15802019-03-02 09:07:18 +000089 const result = ZoomUtils.convertGeoToCanvas(<LocMeta>{lat: 52, lng: -8});
Sean Condon71910542019-02-16 18:16:42 +000090 expect(Math.round(result.x * 100)).toEqual(45556);
91 expect(Math.round(result.y * 100)).toEqual(15333);
92 });
Sean Condonf4f54a12018-10-10 23:25:46 +010093});