blob: 5dfb1d606df0f957e2256c0dd0c862a99555df91 [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 Hunt1e8eff42015-01-08 17:19:02 -080023 var $log, 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
27 beforeEach(inject(function (_$log_, FnService, MapService) {
28 $log = _$log_;
29 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -080030 ms = MapService;
Simon Huntf044d8a2015-01-07 17:53:04 -080031 ms.clearCache();
32 // TODO: d3Elem = d3.select('body').append('...').attr('id', 'myFoo');
Simon Hunt7ac7be92015-01-06 10:47:56 -080033 }));
34
Simon Huntf044d8a2015-01-07 17:53:04 -080035 afterEach(function () {
36 // TODO d3.select('#myFoo').remove();
37 });
38
Simon Hunt7ac7be92015-01-06 10:47:56 -080039 it('should define MapService', function () {
40 expect(ms).toBeDefined();
41 });
42
Simon Huntf044d8a2015-01-07 17:53:04 -080043 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 Hunt1e8eff42015-01-08 17:19:02 -080050 promise = ms.fetchGeoMap();
51 expect(promise).toBeNull();
Simon Huntf044d8a2015-01-07 17:53:04 -080052 });
53
54 it('should augment the id of a bundled map', function () {
55 var id = '*foo';
Simon Hunt1e8eff42015-01-08 17:19:02 -080056 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 Huntf044d8a2015-01-07 17:53:04 -080060 });
61
62 it('should treat an external id as the url itself', function () {
63 var id = 'some/path/to/foo';
Simon Hunt1e8eff42015-01-08 17:19:02 -080064 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 Huntf044d8a2015-01-07 17:53:04 -080068 });
69
70 it('should cache the returned objects', function () {
71 var id = 'foo';
Simon Hunt1e8eff42015-01-08 17:19:02 -080072 promise = ms.fetchGeoMap(id);
73 expect(promise).toBeDefined();
74 expect(promise.meta.wasCached).toBeFalsy();
75 expect(promise.tagged).toBeUndefined();
Simon Huntf044d8a2015-01-07 17:53:04 -080076
Simon Hunt1e8eff42015-01-08 17:19:02 -080077 promise.tagged = 'I woz here';
Simon Huntf044d8a2015-01-07 17:53:04 -080078
Simon Hunt1e8eff42015-01-08 17:19:02 -080079 promise = ms.fetchGeoMap(id);
80 expect(promise).toBeDefined();
81 expect(promise.meta.wasCached).toBeTruthy();
82 expect(promise.tagged).toEqual('I woz here');
Simon Huntf044d8a2015-01-07 17:53:04 -080083 });
84
85 it('should clear the cache when asked', function () {
86 var id = 'foo';
Simon Hunt1e8eff42015-01-08 17:19:02 -080087 promise = ms.fetchGeoMap(id);
88 expect(promise.meta.wasCached).toBeFalsy();
Simon Huntf044d8a2015-01-07 17:53:04 -080089
Simon Hunt1e8eff42015-01-08 17:19:02 -080090 promise = ms.fetchGeoMap(id);
91 expect(promise.meta.wasCached).toBeTruthy();
Simon Huntf044d8a2015-01-07 17:53:04 -080092
93 ms.clearCache();
Simon Hunt1e8eff42015-01-08 17:19:02 -080094 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 Huntf044d8a2015-01-07 17:53:04 -0800106 });
Simon Hunt7ac7be92015-01-06 10:47:56 -0800107});