blob: 27848d1a5f8c8ce0f92b6a888fa5c55f544885bf [file] [log] [blame]
Simon Hunt7ac7be92015-01-06 10:47:56 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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
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
Simon Huntf044d8a2015-01-07 17:53:04 -080042 it('should define api functions', function () {
43 expect(fs.areFunctions(ms, [
Simon Hunt404e54c2015-01-09 11:58:49 -080044 'loadMapInto'
Simon Huntf044d8a2015-01-07 17:53:04 -080045 ])).toBeTruthy();
46 });
47
Simon Hunt404e54c2015-01-09 11:58:49 -080048 var fakeMapId = '../tests/app/fw/svg/fake-map-data',
49 fakeMapUrl = fakeMapId + '.json';
50
51 var fakeMapData = {
52 "type": "Topology",
53 "objects": {
54 "states": {
55 "type": "GeometryCollection",
56 "geometries": [
57 { "type": "Polygon", "arcs": [[0, 1]]},
58 { "type": "Polygon", "arcs": [[2, 3]]}
59 ]
60 }
61 },
62 "arcs": [
63 [ [6347, 2300], [ -16, -9], [ -22, 1], [ -5, 3], [ 9, 6], [ 27, 7], [ 7, -8]],
64 [ [6447, 2350], [ -4, -4], [ -19, -41], [ -66, -14], [ 4, 9], [ 14, 2]],
65 [ [6290, 2347], [ -2, 83], [ -2, 76], [ -2, 75], [ -2, 76], [ -2, 76], [ -2, 75]],
66 [ [6329, 4211], [ -3, 6], [ -2, 4], [ 2, 1], [ 28, -1], [ 28, 0]]
67 ],
68 "transform": {
69 "scale": [0.005772872856602365, 0.0024829805705001468],
70 "translate": [-124.70997774915153, 24.542349340056283]
71 }
72 };
73
74
75 it('should load map into layer', function () {
76 $httpBackend.expectGET(fakeMapUrl).respond(fakeMapData);
77
78 var obj = ms.loadMapInto(d3Elem, fakeMapId);
79 //$httpBackend.flush();
80 // TODO: figure out how to test this function as a black box test.
81
82 expect(obj).toBeTruthy();
Simon Hunt404e54c2015-01-09 11:58:49 -080083
84 // todo: assert that paths are added to map layer element
85 });
86
Simon Hunt7ac7be92015-01-06 10:47:56 -080087});