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 | */ |
| 16 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 17 | |
| 18 | import { BackgroundSvgComponent } from './backgroundsvg.component'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 19 | import {MapSvgComponent} from '../mapsvg/mapsvg.component'; |
| 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 | |
| 32 | class MockHttpClient { |
| 33 | get() { |
| 34 | return from(['{"id":"app","icon":"nav_apps","cat":"PLATFORM","label":"Applications"}']); |
| 35 | } |
| 36 | |
| 37 | subscribe() {} |
| 38 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 39 | |
| 40 | describe('BackgroundSvgComponent', () => { |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 41 | let logServiceSpy: jasmine.SpyObj<LogService>; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 42 | let component: BackgroundSvgComponent; |
| 43 | let fixture: ComponentFixture<BackgroundSvgComponent>; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 44 | const testmap: MapObject = <MapObject>{ |
| 45 | scale: 1.0, |
| 46 | id: 'test', |
| 47 | description: 'test map' |
| 48 | }; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 49 | |
| 50 | beforeEach(async(() => { |
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 | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 53 | TestBed.configureTestingModule({ |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 54 | declarations: [ |
| 55 | BackgroundSvgComponent, |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 56 | MapSvgComponent, |
| 57 | ForceSvgComponent, |
| 58 | DeviceNodeSvgComponent, |
| 59 | HostNodeSvgComponent, |
| 60 | SubRegionNodeSvgComponent, |
| 61 | LinkSvgComponent, |
| 62 | DraggableDirective |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 63 | ], |
| 64 | providers: [ |
| 65 | { provide: LogService, useValue: logSpy }, |
| 66 | { provide: HttpClient, useClass: MockHttpClient }, |
| 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 | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 72 | })); |
| 73 | |
| 74 | beforeEach(() => { |
| 75 | fixture = TestBed.createComponent(BackgroundSvgComponent); |
| 76 | component = fixture.componentInstance; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 77 | component.map = testmap; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 78 | fixture.detectChanges(); |
| 79 | }); |
| 80 | |
| 81 | it('should create', () => { |
| 82 | expect(component).toBeTruthy(); |
| 83 | }); |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 84 | |
| 85 | it('should convert latlong to xy', () => { |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 86 | const result = ZoomUtils.convertGeoToCanvas(<LocMeta>{lat: 52, lng: -8}); |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 87 | expect(Math.round(result.x * 100)).toEqual(45556); |
| 88 | expect(Math.round(result.y * 100)).toEqual(15333); |
| 89 | }); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 90 | }); |