blob: 07320189585eef23795c875e47301e8545a4999d [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';
22import {LogService} from 'gui2-fw-lib';
23import {MapObject} from '../maputils';
Sean Condon71910542019-02-16 18:16:42 +000024import {LocMeta} from '../forcesvg/models';
25import {ForceSvgComponent} from '../forcesvg/forcesvg.component';
26import {
27 DeviceNodeSvgComponent,
28 HostNodeSvgComponent, LinkSvgComponent, SubRegionNodeSvgComponent
29} from '../forcesvg/visuals';
30import {DraggableDirective} from '../forcesvg/draggable/draggable.directive';
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', () => {
86 const result = BackgroundSvgComponent.convertGeoToCanvas(<LocMeta>{lat: 52, lng: -8});
87 expect(Math.round(result.x * 100)).toEqual(45556);
88 expect(Math.round(result.y * 100)).toEqual(15333);
89 });
90
91 /**
92 * For some reason including the following causes "ForceSvgComponent should create error
93 * TODO: Investigate
94 */
95
96 // it('should convert xy random extents to latlong', () => {
97 // const result = BackgroundSvgComponent.convertXYtoGeo(455.556, 153.33);
98 // expect(Math.round(result.equivLoc.lng)).toEqual(-8);
99 // expect(Math.round(result.equivLoc.lat)).toEqual(52);
100 // });
101
102 // it('should convert xy min extents to latlong', () => {
103 // const result = BackgroundSvgComponent.convertXYtoGeo(-500, 0);
104 // expect(Math.round(result.equivLoc.lng)).toEqual(-180);
105 // expect(Math.round(result.equivLoc.lat)).toEqual(75);
106 // });
107
108 // it('should convert xy full extents to latlong', () => {
109 // const result = BackgroundSvgComponent.convertXYtoGeo(1500, 1000);
110 // expect(Math.round(result.equivLoc.lng)).toEqual(180);
111 // expect(Math.round(result.equivLoc.lat)).toEqual(-75);
112 // });
Sean Condonf4f54a12018-10-10 23:25:46 +0100113});