blob: 159f36b1dd823c356fc58291dfd35ccc0e8f9689 [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 Huntf044d8a2015-01-07 17:53:04 -080023 var $log, fs, ms, d3Elem, geomap;
Simon Hunt7ac7be92015-01-06 10:47:56 -080024
Simon Huntf044d8a2015-01-07 17:53:04 -080025 var urlPrefix = 'data/map/';
Simon Hunt7ac7be92015-01-06 10:47:56 -080026
Simon Huntf044d8a2015-01-07 17:53:04 -080027 beforeEach(module('onosUtil', 'onosSvg'));
28
29 beforeEach(inject(function (_$log_, FnService, MapService) {
30 $log = _$log_;
31 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -080032 ms = MapService;
Simon Huntf044d8a2015-01-07 17:53:04 -080033 ms.clearCache();
34 // TODO: d3Elem = d3.select('body').append('...').attr('id', 'myFoo');
Simon Hunt7ac7be92015-01-06 10:47:56 -080035 }));
36
Simon Huntf044d8a2015-01-07 17:53:04 -080037 afterEach(function () {
38 // TODO d3.select('#myFoo').remove();
39 });
40
Simon Hunt7ac7be92015-01-06 10:47:56 -080041 it('should define MapService', function () {
42 expect(ms).toBeDefined();
43 });
44
Simon Huntf044d8a2015-01-07 17:53:04 -080045 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 Hunt7ac7be92015-01-06 10:47:56 -080099});