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