blob: 77e5d551e67cc26c665805d95b96872a4d4c331d [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 */
16import { async, ComponentFixture, TestBed } from '@angular/core/testing';
17
18import { BackgroundSvgComponent } from './backgroundsvg.component';
Sean Condon0d064ec2019-02-04 21:53:53 +000019import {MapSvgComponent} from '../mapsvg/mapsvg.component';
20import {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
32class MockHttpClient {
33 get() {
34 return from(['{"id":"app","icon":"nav_apps","cat":"PLATFORM","label":"Applications"}']);
35 }
36
37 subscribe() {}
38}
Sean Condonf4f54a12018-10-10 23:25:46 +010039
40describe('BackgroundSvgComponent', () => {
Sean Condon0d064ec2019-02-04 21:53:53 +000041 let logServiceSpy: jasmine.SpyObj<LogService>;
Sean Condonf4f54a12018-10-10 23:25:46 +010042 let component: BackgroundSvgComponent;
43 let fixture: ComponentFixture<BackgroundSvgComponent>;
Sean Condon0d064ec2019-02-04 21:53:53 +000044 const testmap: MapObject = <MapObject>{
45 scale: 1.0,
46 id: 'test',
47 description: 'test map'
48 };
Sean Condonf4f54a12018-10-10 23:25:46 +010049
50 beforeEach(async(() => {
Sean Condon0d064ec2019-02-04 21:53:53 +000051 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
52
Sean Condonf4f54a12018-10-10 23:25:46 +010053 TestBed.configureTestingModule({
Sean Condon0d064ec2019-02-04 21:53:53 +000054 declarations: [
55 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +000056 MapSvgComponent,
57 ForceSvgComponent,
58 DeviceNodeSvgComponent,
59 HostNodeSvgComponent,
60 SubRegionNodeSvgComponent,
61 LinkSvgComponent,
62 DraggableDirective
Sean Condon0d064ec2019-02-04 21:53:53 +000063 ],
64 providers: [
65 { provide: LogService, useValue: logSpy },
66 { provide: HttpClient, useClass: MockHttpClient },
67 ]
Sean Condonf4f54a12018-10-10 23:25:46 +010068 })
69 .compileComponents();
Sean Condon0d064ec2019-02-04 21:53:53 +000070
71 logServiceSpy = TestBed.get(LogService);
Sean Condonf4f54a12018-10-10 23:25:46 +010072 }));
73
74 beforeEach(() => {
75 fixture = TestBed.createComponent(BackgroundSvgComponent);
76 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +000077 component.map = testmap;
Sean Condonf4f54a12018-10-10 23:25:46 +010078 fixture.detectChanges();
79 });
80
81 it('should create', () => {
82 expect(component).toBeTruthy();
83 });
Sean Condon71910542019-02-16 18:16:42 +000084
85 it('should convert latlong to xy', () => {
Sean Condon1ae15802019-03-02 09:07:18 +000086 const result = ZoomUtils.convertGeoToCanvas(<LocMeta>{lat: 52, lng: -8});
Sean Condon71910542019-02-16 18:16:42 +000087 expect(Math.round(result.x * 100)).toEqual(45556);
88 expect(Math.round(result.y * 100)).toEqual(15333);
89 });
Sean Condonf4f54a12018-10-10 23:25:46 +010090});