Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [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 | */ |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 16 | import { async, ComponentFixture, TestBed, getTestBed } from '@angular/core/testing'; |
| 17 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 18 | import { BackgroundSvgComponent } from './backgroundsvg.component'; |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 19 | import {MapSvgComponent, TopoData} from '../mapsvg/mapsvg.component'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 20 | import {from} from 'rxjs'; |
| 21 | import {HttpClient} from '@angular/common/http'; |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 22 | import {LocMeta, LogService, ZoomUtils} from 'gui2-fw-lib'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 23 | import {MapObject} from '../maputils'; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 24 | import {ForceSvgComponent} from '../forcesvg/forcesvg.component'; |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 25 | |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 26 | import {DraggableDirective} from '../forcesvg/draggable/draggable.directive'; |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 27 | import {DeviceNodeSvgComponent} from '../forcesvg/visuals/devicenodesvg/devicenodesvg.component'; |
| 28 | import {SubRegionNodeSvgComponent} from '../forcesvg/visuals/subregionnodesvg/subregionnodesvg.component'; |
| 29 | import {LinkSvgComponent} from '../forcesvg/visuals/linksvg/linksvg.component'; |
| 30 | import {HostNodeSvgComponent} from '../forcesvg/visuals/hostnodesvg/hostnodesvg.component'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 31 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 32 | |
| 33 | describe('BackgroundSvgComponent', () => { |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 34 | let httpMock: HttpTestingController; |
| 35 | |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 36 | let logServiceSpy: jasmine.SpyObj<LogService>; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 37 | let component: BackgroundSvgComponent; |
| 38 | let fixture: ComponentFixture<BackgroundSvgComponent>; |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 39 | |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 40 | const testmap: MapObject = <MapObject>{ |
| 41 | scale: 1.0, |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 42 | id: 'bayareaGEO', |
| 43 | description: 'test map', |
| 44 | filePath: 'testmap' |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 45 | }; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 46 | |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 47 | const sampleTopoData = <TopoData>require('../mapsvg/tests/bayarea.json'); |
| 48 | |
| 49 | beforeEach(() => { |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 50 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 51 | |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 52 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 53 | TestBed.configureTestingModule({ |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 54 | imports: [HttpClientTestingModule], |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 55 | declarations: [ |
| 56 | BackgroundSvgComponent, |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 57 | MapSvgComponent, |
| 58 | ForceSvgComponent, |
| 59 | DeviceNodeSvgComponent, |
| 60 | HostNodeSvgComponent, |
| 61 | SubRegionNodeSvgComponent, |
| 62 | LinkSvgComponent, |
| 63 | DraggableDirective |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 64 | ], |
| 65 | providers: [ |
| 66 | { provide: LogService, useValue: logSpy }, |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 67 | ] |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 68 | }) |
| 69 | .compileComponents(); |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 70 | |
| 71 | logServiceSpy = TestBed.get(LogService); |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 72 | httpMock = TestBed.get(HttpTestingController); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 73 | fixture = TestBed.createComponent(BackgroundSvgComponent); |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 74 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 75 | component = fixture.componentInstance; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 76 | component.map = testmap; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 77 | fixture.detectChanges(); |
| 78 | }); |
| 79 | |
| 80 | it('should create', () => { |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 81 | httpMock.expectOne('testmap.topojson').flush(sampleTopoData); |
| 82 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 83 | expect(component).toBeTruthy(); |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame^] | 84 | |
| 85 | httpMock.verify(); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 86 | }); |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 87 | |
| 88 | it('should convert latlong to xy', () => { |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 89 | const result = ZoomUtils.convertGeoToCanvas(<LocMeta>{lat: 52, lng: -8}); |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 90 | expect(Math.round(result.x * 100)).toEqual(45556); |
| 91 | expect(Math.round(result.y * 100)).toEqual(15333); |
| 92 | }); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 93 | }); |