Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 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 Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 19 | */ |
| 20 | describe('factory: fw/svg/map.js', function() { |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 21 | var $log, $httpBackend, fs, ms, d3Elem, promise; |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 22 | |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 23 | beforeEach(module('onosUtil', 'onosSvg')); |
| 24 | |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 25 | beforeEach(inject(function (_$log_, _$httpBackend_, FnService, MapService) { |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 26 | $log = _$log_; |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 27 | $httpBackend = _$httpBackend_; |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 28 | fs = FnService; |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 29 | ms = MapService; |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 30 | //ms.clearCache(); |
| 31 | d3Elem = d3.select('body').append('svg').append('g').attr('id', 'mapLayer'); |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 32 | })); |
| 33 | |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 34 | afterEach(function () { |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 35 | d3.select('svg').remove(); |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 36 | }); |
| 37 | |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 38 | it('should define MapService', function () { |
| 39 | expect(ms).toBeDefined(); |
| 40 | }); |
| 41 | |
Matteo Scandolo | 209c6c6 | 2016-05-21 10:08:57 -0700 | [diff] [blame] | 42 | it('should define api functions', function () { |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 43 | expect(fs.areFunctions(ms, [ |
Matteo Scandolo | 209c6c6 | 2016-05-21 10:08:57 -0700 | [diff] [blame] | 44 | 'loadMapRegionInto', |
| 45 | 'loadMapInto', |
| 46 | 'reshade' |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 47 | ])).toBeTruthy(); |
| 48 | }); |
| 49 | |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 50 | 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 Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 85 | |
| 86 | // todo: assert that paths are added to map layer element |
| 87 | }); |
| 88 | |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 89 | }); |