blob: 2599bcdce43343ff22fc57b3ef1cfbe2c84aa64c [file] [log] [blame]
Simon Hunt7ac7be92015-01-06 10:47:56 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt7ac7be92015-01-06 10:47:56 -08003 *
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
17/*
18 ONOS GUI -- SVG -- Map Service - Unit Tests
Simon Hunt7ac7be92015-01-06 10:47:56 -080019 */
20describe('factory: fw/svg/map.js', function() {
Simon Hunt404e54c2015-01-09 11:58:49 -080021 var $log, $httpBackend, fs, ms, d3Elem, promise;
Simon Hunt7ac7be92015-01-06 10:47:56 -080022
Simon Huntf044d8a2015-01-07 17:53:04 -080023 beforeEach(module('onosUtil', 'onosSvg'));
24
Simon Hunt404e54c2015-01-09 11:58:49 -080025 beforeEach(inject(function (_$log_, _$httpBackend_, FnService, MapService) {
Simon Huntf044d8a2015-01-07 17:53:04 -080026 $log = _$log_;
Simon Hunt404e54c2015-01-09 11:58:49 -080027 $httpBackend = _$httpBackend_;
Simon Huntf044d8a2015-01-07 17:53:04 -080028 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -080029 ms = MapService;
Simon Hunt404e54c2015-01-09 11:58:49 -080030 //ms.clearCache();
31 d3Elem = d3.select('body').append('svg').append('g').attr('id', 'mapLayer');
Simon Hunt7ac7be92015-01-06 10:47:56 -080032 }));
33
Simon Huntf044d8a2015-01-07 17:53:04 -080034 afterEach(function () {
Simon Hunt404e54c2015-01-09 11:58:49 -080035 d3.select('svg').remove();
Simon Huntf044d8a2015-01-07 17:53:04 -080036 });
37
Simon Hunt7ac7be92015-01-06 10:47:56 -080038 it('should define MapService', function () {
39 expect(ms).toBeDefined();
40 });
41
Matteo Scandolo209c6c62016-05-21 10:08:57 -070042 it('should define api functions', function () {
Simon Huntf044d8a2015-01-07 17:53:04 -080043 expect(fs.areFunctions(ms, [
Matteo Scandolo209c6c62016-05-21 10:08:57 -070044 'loadMapRegionInto',
45 'loadMapInto',
46 'reshade'
Simon Huntf044d8a2015-01-07 17:53:04 -080047 ])).toBeTruthy();
48 });
49
Simon Hunt404e54c2015-01-09 11:58:49 -080050 var fakeMapId = '../tests/app/fw/svg/fake-map-data',
51 fakeMapUrl = fakeMapId + '.json';
52
53 var fakeMapData = {
54 "type": "Topology",
55 "objects": {
56 "states": {
57 "type": "GeometryCollection",
58 "geometries": [
59 { "type": "Polygon", "arcs": [[0, 1]]},
60 { "type": "Polygon", "arcs": [[2, 3]]}
61 ]
62 }
63 },
64 "arcs": [
65 [ [6347, 2300], [ -16, -9], [ -22, 1], [ -5, 3], [ 9, 6], [ 27, 7], [ 7, -8]],
66 [ [6447, 2350], [ -4, -4], [ -19, -41], [ -66, -14], [ 4, 9], [ 14, 2]],
67 [ [6290, 2347], [ -2, 83], [ -2, 76], [ -2, 75], [ -2, 76], [ -2, 76], [ -2, 75]],
68 [ [6329, 4211], [ -3, 6], [ -2, 4], [ 2, 1], [ 28, -1], [ 28, 0]]
69 ],
70 "transform": {
71 "scale": [0.005772872856602365, 0.0024829805705001468],
72 "translate": [-124.70997774915153, 24.542349340056283]
73 }
74 };
75
76
77 it('should load map into layer', function () {
78 $httpBackend.expectGET(fakeMapUrl).respond(fakeMapData);
79
80 var obj = ms.loadMapInto(d3Elem, fakeMapId);
81 //$httpBackend.flush();
82 // TODO: figure out how to test this function as a black box test.
83
84 expect(obj).toBeTruthy();
Simon Hunt404e54c2015-01-09 11:58:49 -080085
86 // todo: assert that paths are added to map layer element
87 });
88
Simon Hunt7ac7be92015-01-06 10:47:56 -080089});