blob: 23746f46598557fc07126e6056cbf314d5b95c28 [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
19
20 @author Simon Hunt
21 */
22describe('factory: fw/svg/map.js', function() {
Simon Hunt404e54c2015-01-09 11:58:49 -080023 var $log, $httpBackend, fs, ms, d3Elem, promise;
Simon Hunt7ac7be92015-01-06 10:47:56 -080024
Simon Huntf044d8a2015-01-07 17:53:04 -080025 beforeEach(module('onosUtil', 'onosSvg'));
26
Simon Hunt404e54c2015-01-09 11:58:49 -080027 beforeEach(inject(function (_$log_, _$httpBackend_, FnService, MapService) {
Simon Huntf044d8a2015-01-07 17:53:04 -080028 $log = _$log_;
Simon Hunt404e54c2015-01-09 11:58:49 -080029 $httpBackend = _$httpBackend_;
Simon Huntf044d8a2015-01-07 17:53:04 -080030 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -080031 ms = MapService;
Simon Hunt404e54c2015-01-09 11:58:49 -080032 //ms.clearCache();
33 d3Elem = d3.select('body').append('svg').append('g').attr('id', 'mapLayer');
Simon Hunt7ac7be92015-01-06 10:47:56 -080034 }));
35
Simon Huntf044d8a2015-01-07 17:53:04 -080036 afterEach(function () {
Simon Hunt404e54c2015-01-09 11:58:49 -080037 d3.select('svg').remove();
Simon Huntf044d8a2015-01-07 17:53:04 -080038 });
39
Simon Hunt7ac7be92015-01-06 10:47:56 -080040 it('should define MapService', function () {
41 expect(ms).toBeDefined();
42 });
43
Simon Huntf044d8a2015-01-07 17:53:04 -080044 it('should define api functions', function () {
45 expect(fs.areFunctions(ms, [
Simon Hunt404e54c2015-01-09 11:58:49 -080046 'loadMapInto'
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();
85 debugger;
86
87 // todo: assert that paths are added to map layer element
88 });
89
90/*
91
92
93
Simon Huntf044d8a2015-01-07 17:53:04 -080094 it('should return null when no parameters given', function () {
Simon Hunt1e8eff42015-01-08 17:19:02 -080095 promise = ms.fetchGeoMap();
96 expect(promise).toBeNull();
Simon Huntf044d8a2015-01-07 17:53:04 -080097 });
98
99 it('should augment the id of a bundled map', function () {
100 var id = '*foo';
Simon Hunt1e8eff42015-01-08 17:19:02 -0800101 promise = ms.fetchGeoMap(id);
102 expect(promise.meta).toBeDefined();
103 expect(promise.meta.id).toBe(id);
104 expect(promise.meta.url).toBe('../data/map/foo.json');
Simon Huntf044d8a2015-01-07 17:53:04 -0800105 });
106
107 it('should treat an external id as the url itself', function () {
108 var id = 'some/path/to/foo';
Simon Hunt1e8eff42015-01-08 17:19:02 -0800109 promise = ms.fetchGeoMap(id);
110 expect(promise.meta).toBeDefined();
111 expect(promise.meta.id).toBe(id);
112 expect(promise.meta.url).toBe(id + '.json');
Simon Huntf044d8a2015-01-07 17:53:04 -0800113 });
114
115 it('should cache the returned objects', function () {
116 var id = 'foo';
Simon Hunt1e8eff42015-01-08 17:19:02 -0800117 promise = ms.fetchGeoMap(id);
118 expect(promise).toBeDefined();
119 expect(promise.meta.wasCached).toBeFalsy();
120 expect(promise.tagged).toBeUndefined();
Simon Huntf044d8a2015-01-07 17:53:04 -0800121
Simon Hunt1e8eff42015-01-08 17:19:02 -0800122 promise.tagged = 'I woz here';
Simon Huntf044d8a2015-01-07 17:53:04 -0800123
Simon Hunt1e8eff42015-01-08 17:19:02 -0800124 promise = ms.fetchGeoMap(id);
125 expect(promise).toBeDefined();
126 expect(promise.meta.wasCached).toBeTruthy();
127 expect(promise.tagged).toEqual('I woz here');
Simon Huntf044d8a2015-01-07 17:53:04 -0800128 });
129
130 it('should clear the cache when asked', function () {
131 var id = 'foo';
Simon Hunt1e8eff42015-01-08 17:19:02 -0800132 promise = ms.fetchGeoMap(id);
133 expect(promise.meta.wasCached).toBeFalsy();
Simon Huntf044d8a2015-01-07 17:53:04 -0800134
Simon Hunt1e8eff42015-01-08 17:19:02 -0800135 promise = ms.fetchGeoMap(id);
136 expect(promise.meta.wasCached).toBeTruthy();
Simon Huntf044d8a2015-01-07 17:53:04 -0800137
138 ms.clearCache();
Simon Hunt1e8eff42015-01-08 17:19:02 -0800139 promise = ms.fetchGeoMap(id);
140 expect(promise.meta.wasCached).toBeFalsy();
141 });
142
Simon Hunt404e54c2015-01-09 11:58:49 -0800143
144 it('should log a warning if data fails to load', function () {
145 $httpBackend.expectGET(mapurl).respond(404, 'Not found');
146 spyOn($log, 'warn');
147
148 promise = ms.fetchGeoMap(mapid);
149 $httpBackend.flush();
150 expect(promise.mapdata).toBeUndefined();
151 expect($log.warn)
152 .toHaveBeenCalledWith('Failed to retrieve map data: ' + mapurl,
153 404, 'Not found');
Simon Hunt1e8eff42015-01-08 17:19:02 -0800154
Simon Huntf044d8a2015-01-07 17:53:04 -0800155 });
Simon Hunt404e54c2015-01-09 11:58:49 -0800156*/
Simon Hunt7ac7be92015-01-06 10:47:56 -0800157});