Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 22 | describe('factory: fw/svg/map.js', function() { |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame^] | 23 | var $log, fs, ms, d3Elem, geomap; |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 24 | |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame^] | 25 | var urlPrefix = 'data/map/'; |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 26 | |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame^] | 27 | beforeEach(module('onosUtil', 'onosSvg')); |
| 28 | |
| 29 | beforeEach(inject(function (_$log_, FnService, MapService) { |
| 30 | $log = _$log_; |
| 31 | fs = FnService; |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 32 | ms = MapService; |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame^] | 33 | ms.clearCache(); |
| 34 | // TODO: d3Elem = d3.select('body').append('...').attr('id', 'myFoo'); |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 35 | })); |
| 36 | |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame^] | 37 | afterEach(function () { |
| 38 | // TODO d3.select('#myFoo').remove(); |
| 39 | }); |
| 40 | |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 41 | it('should define MapService', function () { |
| 42 | expect(ms).toBeDefined(); |
| 43 | }); |
| 44 | |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame^] | 45 | it('should define api functions', function () { |
| 46 | expect(fs.areFunctions(ms, [ |
| 47 | 'clearCache', 'fetchGeoMap' |
| 48 | ])).toBeTruthy(); |
| 49 | }); |
| 50 | |
| 51 | it('should return null when no parameters given', function () { |
| 52 | geomap = ms.fetchGeoMap(); |
| 53 | expect(geomap).toBeNull(); |
| 54 | }); |
| 55 | |
| 56 | it('should augment the id of a bundled map', function () { |
| 57 | var id = '*foo'; |
| 58 | geomap = ms.fetchGeoMap(id); |
| 59 | expect(geomap).toBeDefined(); |
| 60 | expect(geomap.id).toBe(id); |
| 61 | expect(geomap.url).toBe('data/map/foo.json'); |
| 62 | }); |
| 63 | |
| 64 | it('should treat an external id as the url itself', function () { |
| 65 | var id = 'some/path/to/foo'; |
| 66 | geomap = ms.fetchGeoMap(id); |
| 67 | expect(geomap).toBeDefined(); |
| 68 | expect(geomap.id).toBe(id); |
| 69 | expect(geomap.url).toBe(id + '.json'); |
| 70 | }); |
| 71 | |
| 72 | it('should cache the returned objects', function () { |
| 73 | var id = 'foo'; |
| 74 | geomap = ms.fetchGeoMap(id); |
| 75 | expect(geomap).toBeDefined(); |
| 76 | expect(geomap.wasCached).toBeFalsy(); |
| 77 | expect(geomap.tagged).toBeUndefined(); |
| 78 | |
| 79 | geomap.tagged = 'I woz here'; |
| 80 | |
| 81 | geomap = ms.fetchGeoMap(id); |
| 82 | expect(geomap).toBeDefined(); |
| 83 | expect(geomap.wasCached).toBeTruthy(); |
| 84 | expect(geomap.tagged).toEqual('I woz here'); |
| 85 | }); |
| 86 | |
| 87 | it('should clear the cache when asked', function () { |
| 88 | var id = 'foo'; |
| 89 | geomap = ms.fetchGeoMap(id); |
| 90 | expect(geomap.wasCached).toBeFalsy(); |
| 91 | |
| 92 | geomap = ms.fetchGeoMap(id); |
| 93 | expect(geomap.wasCached).toBeTruthy(); |
| 94 | |
| 95 | ms.clearCache(); |
| 96 | geomap = ms.fetchGeoMap(id); |
| 97 | expect(geomap.wasCached).toBeFalsy(); |
| 98 | }); |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 99 | }); |