blob: 7fb0b3fb5ca510bd4110745cfdb98e1a1543c42b [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';
25import {
26 DeviceNodeSvgComponent,
27 HostNodeSvgComponent, LinkSvgComponent, SubRegionNodeSvgComponent
28} from '../forcesvg/visuals';
29import {DraggableDirective} from '../forcesvg/draggable/draggable.directive';
Sean Condon0d064ec2019-02-04 21:53:53 +000030
31class MockHttpClient {
32 get() {
33 return from(['{"id":"app","icon":"nav_apps","cat":"PLATFORM","label":"Applications"}']);
34 }
35
36 subscribe() {}
37}
Sean Condonf4f54a12018-10-10 23:25:46 +010038
39describe('BackgroundSvgComponent', () => {
Sean Condon0d064ec2019-02-04 21:53:53 +000040 let logServiceSpy: jasmine.SpyObj<LogService>;
Sean Condonf4f54a12018-10-10 23:25:46 +010041 let component: BackgroundSvgComponent;
42 let fixture: ComponentFixture<BackgroundSvgComponent>;
Sean Condon0d064ec2019-02-04 21:53:53 +000043 const testmap: MapObject = <MapObject>{
44 scale: 1.0,
45 id: 'test',
46 description: 'test map'
47 };
Sean Condonf4f54a12018-10-10 23:25:46 +010048
49 beforeEach(async(() => {
Sean Condon0d064ec2019-02-04 21:53:53 +000050 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
51
Sean Condonf4f54a12018-10-10 23:25:46 +010052 TestBed.configureTestingModule({
Sean Condon0d064ec2019-02-04 21:53:53 +000053 declarations: [
54 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +000055 MapSvgComponent,
56 ForceSvgComponent,
57 DeviceNodeSvgComponent,
58 HostNodeSvgComponent,
59 SubRegionNodeSvgComponent,
60 LinkSvgComponent,
61 DraggableDirective
Sean Condon0d064ec2019-02-04 21:53:53 +000062 ],
63 providers: [
64 { provide: LogService, useValue: logSpy },
65 { provide: HttpClient, useClass: MockHttpClient },
66 ]
Sean Condonf4f54a12018-10-10 23:25:46 +010067 })
68 .compileComponents();
Sean Condon0d064ec2019-02-04 21:53:53 +000069
70 logServiceSpy = TestBed.get(LogService);
Sean Condonf4f54a12018-10-10 23:25:46 +010071 }));
72
73 beforeEach(() => {
74 fixture = TestBed.createComponent(BackgroundSvgComponent);
75 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +000076 component.map = testmap;
Sean Condonf4f54a12018-10-10 23:25:46 +010077 fixture.detectChanges();
78 });
79
80 it('should create', () => {
81 expect(component).toBeTruthy();
82 });
Sean Condon71910542019-02-16 18:16:42 +000083
84 it('should convert latlong to xy', () => {
Sean Condon1ae15802019-03-02 09:07:18 +000085 const result = ZoomUtils.convertGeoToCanvas(<LocMeta>{lat: 52, lng: -8});
Sean Condon71910542019-02-16 18:16:42 +000086 expect(Math.round(result.x * 100)).toEqual(45556);
87 expect(Math.round(result.y * 100)).toEqual(15333);
88 });
Sean Condonf4f54a12018-10-10 23:25:46 +010089});