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