blob: d796ae3b621a895daa53ade15ea825f4f9932fcd [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 -- Glyph Service - Unit Tests
Simon Hunt7ac7be92015-01-06 10:47:56 -080019 */
20describe('factory: fw/svg/glyph.js', function() {
Simon Huntc9b73162015-01-29 14:02:15 -080021 var $log, fs, gs, d3Elem, svg;
Simon Hunt7ac7be92015-01-06 10:47:56 -080022
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070023 var numBaseGlyphs = 41,
Simon Huntbc39f6d2015-01-06 17:34:28 -080024 vbBird = '352 224 113 112',
Simon Hunt6e459802015-01-06 15:05:42 -080025 vbGlyph = '0 0 110 110',
Simon Hunt58f23bb2015-01-16 16:32:24 -080026 vbBadge = '0 0 10 10',
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070027 longPrefix = 'M95.8,9.2H14.2c-2.8,0-5,2.2-5,5v81.5c0,2.8,2.2,5,5,' +
28 '5h81.5c2.8,0,5-2.2,5-5V14.2C100.8,11.5,98.5,9.2,95.8,9.2z ',
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070029 tablePrefix = 'M15.9,19.1h-8v-13h8V19.1z M90.5,6.1H75.6v13h14.9V6.1' +
30 'z M71.9,6.1H56.9v13h14.9V6.1z M53.2,6.1H38.3v13h14.9V6.1z M34.5,' +
31 '6.1H19.6v13h14.9V6.1z M102.2,6.1h-8v13h8V6.1z ',
Simon Hunt58f23bb2015-01-16 16:32:24 -080032 prefixLookup = {
33 bird: 'M427.7,300.4',
34 unknown: 'M35,40a5',
35 node: 'M15,100a5',
36 switch: 'M10,20a10',
37 roadm: 'M10,35l25-',
38 endstation: 'M10,15a5,5',
39 router: 'M10,55A45,45',
40 bgpSpeaker: 'M10,40a45,35',
41 chain: 'M60.4,77.6c-',
42 crown: 'M99.5,21.6c0,',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070043 lock: 'M79.4,48.6h',
Bri Prebilic Cole6ed04eb2015-04-27 16:26:03 -070044 topo: 'M97.2,76.3H86.6',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070045 refresh: 'M102.6,40.8L88.4',
Bri Prebilic Cole6ed04eb2015-04-27 16:26:03 -070046
47 // navigation specific glyphs
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070048 flowTable: tablePrefix + 'M102.2,23.6H7.9v',
49 portTable: tablePrefix + 'M102.6,23.6v78.5H',
50 groupTable: 'M16,19.1H8v-13h',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070051
52 // toolbar specific glyphs
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070053 summary: longPrefix + 'M16.7',
54 details: longPrefix + 'M16.9',
55 ports: 'M98,9.2H79.6c',
56 map: 'M95.8,9.2H14.2c-2.8,0-5,2.2-5,5v66',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070057 cycleLabels: 'M72.5,33.9c',
58 oblique: 'M80.9,30.2h',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070059 filters: 'M24.8,13.3L',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070060 resetZoom: 'M86,79.8L',
61 relatedIntents: 'M99.9,43.7',
Bri Prebilic Coledb4b87b2015-03-25 09:18:42 -070062 nextIntent: 'M88.1,55.7',
63 prevIntent: 'M22.5,55.6',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070064 intentTraffic: 'M14.7,71.5h',
65 allTraffic: 'M15.7,64.5h-7v',
66 flows: 'M93.8,46.1c',
Bri Prebilic Cole5a206bb2015-03-25 16:33:27 -070067 eqMaster: 'M100.1,46.9l',
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070068
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070069 // badges
Simon Hunt58f23bb2015-01-16 16:32:24 -080070 uiAttached: 'M2,2.5a.5,.5',
Simon Huntaa26adf2015-01-20 10:32:49 -080071 checkMark: 'M2.6,4.5c0',
72 xMark: 'M9.0,7.2C8.2',
Bri Prebilic Cole1dc32e62015-02-03 09:44:33 -080073 triangleUp: 'M0.5,6.2c0',
74 triangleDown: 'M9.5,4.2c0',
Simon Hunt3074fb22015-03-31 15:06:25 -070075 plus: 'M4,2h2v2h2v2',
76 minus: 'M2,4h6v2',
77 play: 'M2.5,2l5.5,3',
78 stop: 'M2.5,2.5h5',
Simon Hunt58f23bb2015-01-16 16:32:24 -080079
Simon Hunt9c1c45e2015-04-10 13:38:27 -070080 cloud: 'M37.6,79.5c-6.9,8.7-20.4,8.6',
81
Simon Hunt58f23bb2015-01-16 16:32:24 -080082 // our test ones..
83 triangle: 'M.5,.2',
84 diamond: 'M.2,.5'
Simon Hunt3074fb22015-03-31 15:06:25 -070085 },
86 glyphIds = [
87 'unknown', 'node', 'switch', 'roadm', 'endstation', 'router',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070088 'bgpSpeaker', 'chain', 'crown', 'lock', 'topo', 'refresh',
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070089 'flowTable', 'portTable', 'groupTable',
90 'summary', 'details', 'ports', 'map', 'cycleLabels',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070091 'oblique', 'filters', 'resetZoom', 'relatedIntents', 'nextIntent',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070092 'prevIntent', 'intentTraffic', 'allTraffic', 'flows', 'eqMaster'
Simon Hunt3074fb22015-03-31 15:06:25 -070093 ],
94 badgeIds = [
95 'uiAttached', 'checkMark', 'xMark', 'triangleUp', 'triangleDown',
96 'plus', 'minus', 'play', 'stop'
Simon Hunt9c1c45e2015-04-10 13:38:27 -070097 ],
98 spriteIds = [
99 'cloud'
Simon Hunt3074fb22015-03-31 15:06:25 -0700100 ];
Simon Hunt6e459802015-01-06 15:05:42 -0800101
Simon Hunt51fc40b2015-01-06 13:56:12 -0800102 beforeEach(module('onosUtil', 'onosSvg'));
Simon Hunt7ac7be92015-01-06 10:47:56 -0800103
Simon Hunt51fc40b2015-01-06 13:56:12 -0800104 beforeEach(inject(function (_$log_, FnService, GlyphService) {
Simon Huntc9b73162015-01-29 14:02:15 -0800105 var body = d3.select('body');
Simon Hunt51fc40b2015-01-06 13:56:12 -0800106 $log = _$log_;
107 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -0800108 gs = GlyphService;
Simon Huntc9b73162015-01-29 14:02:15 -0800109 d3Elem = body.append('defs').attr('id', 'myDefs');
110 svg = body.append('svg').attr('id', 'mySvg');
Simon Hunt7ac7be92015-01-06 10:47:56 -0800111 }));
112
Simon Hunt670e8252015-01-06 18:31:30 -0800113 afterEach(function () {
Simon Huntc9b73162015-01-29 14:02:15 -0800114 d3.select('#mySvg').remove();
Simon Hunt670e8252015-01-06 18:31:30 -0800115 d3.select('#myDefs').remove();
Simon Huntcacce342015-01-07 16:13:05 -0800116 gs.clear();
Simon Hunt670e8252015-01-06 18:31:30 -0800117 });
118
Simon Hunt7ac7be92015-01-06 10:47:56 -0800119 it('should define GlyphService', function () {
120 expect(gs).toBeDefined();
121 });
122
Simon Hunt6e459802015-01-06 15:05:42 -0800123 it('should define api functions', function () {
Simon Hunt51fc40b2015-01-06 13:56:12 -0800124 expect(fs.areFunctions(gs, [
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700125 'clear', 'init', 'registerGlyphs', 'registerGlyphSet',
126 'ids', 'glyph', 'loadDefs', 'addGlyph'
127 ])).toBe(true);
Simon Hunt51fc40b2015-01-06 13:56:12 -0800128 });
129
Simon Hunt6e459802015-01-06 15:05:42 -0800130 it('should start with no glyphs loaded', function () {
131 expect(gs.ids()).toEqual([]);
132 });
133
Simon Hunt58f23bb2015-01-16 16:32:24 -0800134 it('should load the base set of glyphs into the cache', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800135 gs.init();
Simon Huntbc39f6d2015-01-06 17:34:28 -0800136 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Hunt6e459802015-01-06 15:05:42 -0800137 });
138
Simon Hunt58f23bb2015-01-16 16:32:24 -0800139 it('should remove glyphs from the cache on clear', function () {
Simon Huntcacce342015-01-07 16:13:05 -0800140 gs.init();
141 expect(gs.ids().length).toEqual(numBaseGlyphs);
142 gs.clear();
143 expect(gs.ids().length).toEqual(0);
144 });
145
Simon Hunt58f23bb2015-01-16 16:32:24 -0800146 function verifyGlyphLoadedInCache(id, vbox, expPfxId) {
147 var pfxId = expPfxId || id,
148 glyph = gs.glyph(id),
149 prefix = prefixLookup[pfxId],
Simon Hunt6e459802015-01-06 15:05:42 -0800150 plen = prefix.length;
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700151 expect(fs.contains(gs.ids(), id)).toBe(true);
Simon Hunt6e459802015-01-06 15:05:42 -0800152 expect(glyph).toBeDefined();
153 expect(glyph.id).toEqual(id);
154 expect(glyph.vb).toEqual(vbox);
155 expect(glyph.d.slice(0, plen)).toEqual(prefix);
156 }
157
Simon Hunt3074fb22015-03-31 15:06:25 -0700158 it('should be configured with the correct number of glyphs', function () {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700159 var nGlyphs = 1 + glyphIds.length + badgeIds.length + spriteIds.length;
160 expect(nGlyphs).toEqual(numBaseGlyphs);
Simon Hunt3074fb22015-03-31 15:06:25 -0700161 });
162
Simon Hunt6e459802015-01-06 15:05:42 -0800163 it('should load the bird glyph', function() {
164 gs.init();
Simon Hunt58f23bb2015-01-16 16:32:24 -0800165 verifyGlyphLoadedInCache('bird', vbBird);
Simon Hunt6e459802015-01-06 15:05:42 -0800166 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700167
168 it('should load the regular glyphs', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800169 gs.init();
Simon Hunt3074fb22015-03-31 15:06:25 -0700170 glyphIds.forEach(function (id) {
171 verifyGlyphLoadedInCache(id, vbGlyph);
Bri Prebilic Cole94a856e2015-01-19 15:16:40 -0800172 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700173 });
174
175 it('should load the badge glyphs', function () {
176 gs.init();
177 badgeIds.forEach(function (id) {
178 verifyGlyphLoadedInCache(id, vbBadge);
179 });
180 });
181
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700182 it('should load the sprites', function () {
183 gs.init();
184 spriteIds.forEach(function (id) {
185 verifyGlyphLoadedInCache(id, vbGlyph);
186 });
187 });
188
Simon Huntbc39f6d2015-01-06 17:34:28 -0800189
190 // define some glyphs that we want to install
191
192 var testVbox = '0 0 1 1',
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700193 triVbox = '0 0 12 12',
194 diaVbox = '0 0 15 15',
Simon Huntbc39f6d2015-01-06 17:34:28 -0800195 dTriangle = 'M.5,.2l.3,.6,h-.6z',
196 dDiamond = 'M.2,.5l.3,-.3l.3,.3l-.3,.3z',
197 newGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700198 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800199 triangle: dTriangle,
200 diamond: dDiamond
201 },
202 dupGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700203 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800204 router: dTriangle,
205 switch: dDiamond
206 },
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700207 altNewGlyphs = {
208 _triangle: triVbox,
209 triangle: dTriangle,
210 _diamond: diaVbox,
211 diamond: dDiamond
212 },
213 altDupGlyphs = {
214 _router: triVbox,
215 router: dTriangle,
216 _switch: diaVbox,
217 switch: dDiamond
218 },
219 badGlyphSet = {
220 triangle: dTriangle,
221 diamond: dDiamond
222 },
223 warnMsg = 'GlyphService.registerGlyphs(): ',
224 warnMsgSet = 'GlyphService.registerGlyphSet(): ',
225 idCollision = warnMsg + 'ID collision: ',
226 idCollisionSet = warnMsgSet + 'ID collision: ',
227 missVbSet = warnMsgSet + 'no "_viewbox" property found',
228 missVbCustom = warnMsg + 'Missing viewbox property: ',
229 missVbTri = missVbCustom + '"_triangle"',
230 missVbDia = missVbCustom + '"_diamond"';
Simon Huntbc39f6d2015-01-06 17:34:28 -0800231
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700232
233 it('should install new glyphs as a glyph-set', function () {
Simon Huntbc39f6d2015-01-06 17:34:28 -0800234 gs.init();
235 expect(gs.ids().length).toEqual(numBaseGlyphs);
236 spyOn($log, 'warn');
237
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700238 var ok = gs.registerGlyphSet(newGlyphs);
239 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800240 expect($log.warn).not.toHaveBeenCalled();
241
242 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800243 verifyGlyphLoadedInCache('triangle', testVbox);
244 verifyGlyphLoadedInCache('diamond', testVbox);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800245 });
246
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700247 it('should not overwrite glyphs (via glyph-set) with dup IDs', function () {
248 gs.init();
249 expect(gs.ids().length).toEqual(numBaseGlyphs);
250 spyOn($log, 'warn');
251
252 var ok = gs.registerGlyphSet(dupGlyphs);
253 expect(ok).toBe(false);
254 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"switch"');
255 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"router"');
256
257 expect(gs.ids().length).toEqual(numBaseGlyphs);
258 // verify original glyphs still exist...
259 verifyGlyphLoadedInCache('router', vbGlyph);
260 verifyGlyphLoadedInCache('switch', vbGlyph);
261 });
262
263 it('should replace glyphs (via glyph-set) if asked nicely', function () {
264 gs.init();
265 expect(gs.ids().length).toEqual(numBaseGlyphs);
266 spyOn($log, 'warn');
267
268 var ok = gs.registerGlyphSet(dupGlyphs, true);
269 expect(ok).toBe(true);
270 expect($log.warn).not.toHaveBeenCalled();
271
272 expect(gs.ids().length).toEqual(numBaseGlyphs);
273 // verify glyphs have been overwritten...
274 verifyGlyphLoadedInCache('router', testVbox, 'triangle');
275 verifyGlyphLoadedInCache('switch', testVbox, 'diamond');
276 });
277
278 it ('should complain if missing _viewbox in a glyph-set', function () {
279 gs.init();
280 expect(gs.ids().length).toEqual(numBaseGlyphs);
281 spyOn($log, 'warn');
282
283 var ok = gs.registerGlyphSet(badGlyphSet);
284 expect(ok).toBe(false);
285 expect($log.warn).toHaveBeenCalledWith(missVbSet);
286 expect(gs.ids().length).toEqual(numBaseGlyphs);
287 });
288
289 it('should install new glyphs', function () {
290 gs.init();
291 expect(gs.ids().length).toEqual(numBaseGlyphs);
292 spyOn($log, 'warn');
293
294 var ok = gs.registerGlyphs(altNewGlyphs);
295 expect(ok).toBe(true);
296 expect($log.warn).not.toHaveBeenCalled();
297
298 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
299 verifyGlyphLoadedInCache('triangle', triVbox);
300 verifyGlyphLoadedInCache('diamond', diaVbox);
301 });
302
Simon Huntbc39f6d2015-01-06 17:34:28 -0800303 it('should not overwrite glyphs with dup IDs', function () {
304 gs.init();
305 expect(gs.ids().length).toEqual(numBaseGlyphs);
306 spyOn($log, 'warn');
307
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700308 var ok = gs.registerGlyphs(altDupGlyphs);
309 expect(ok).toBe(false);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800310 expect($log.warn).toHaveBeenCalledWith(idCollision + '"switch"');
311 expect($log.warn).toHaveBeenCalledWith(idCollision + '"router"');
312
313 expect(gs.ids().length).toEqual(numBaseGlyphs);
314 // verify original glyphs still exist...
Simon Hunt58f23bb2015-01-16 16:32:24 -0800315 verifyGlyphLoadedInCache('router', vbGlyph);
316 verifyGlyphLoadedInCache('switch', vbGlyph);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800317 });
318
319 it('should replace glyphs if asked nicely', function () {
320 gs.init();
321 expect(gs.ids().length).toEqual(numBaseGlyphs);
322 spyOn($log, 'warn');
323
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700324 var ok = gs.registerGlyphs(altDupGlyphs, true);
325 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800326 expect($log.warn).not.toHaveBeenCalled();
327
328 expect(gs.ids().length).toEqual(numBaseGlyphs);
329 // verify glyphs have been overwritten...
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700330 verifyGlyphLoadedInCache('router', triVbox, 'triangle');
331 verifyGlyphLoadedInCache('switch', diaVbox, 'diamond');
332 });
333
334 it ('should complain if missing custom viewbox', function () {
335 gs.init();
336 expect(gs.ids().length).toEqual(numBaseGlyphs);
337 spyOn($log, 'warn');
338
339 var ok = gs.registerGlyphs(badGlyphSet);
340 expect(ok).toBe(false);
341 expect($log.warn).toHaveBeenCalledWith(missVbTri);
342 expect($log.warn).toHaveBeenCalledWith(missVbDia);
343 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800344 });
Simon Hunt670e8252015-01-06 18:31:30 -0800345
346 function verifyPathPrefix(elem, prefix) {
347 var plen = prefix.length,
348 d = elem.select('path').attr('d');
349 expect(d.slice(0, plen)).toEqual(prefix);
350 }
351
Simon Hunt58f23bb2015-01-16 16:32:24 -0800352 function verifyLoadedInDom(id, vb, expPfxId) {
353 var pfxId = expPfxId || id,
354 symbol = d3Elem.select('#' + id);
355 expect(symbol.size()).toEqual(1);
356 expect(symbol.attr('viewBox')).toEqual(vb);
357 verifyPathPrefix(symbol, prefixLookup[pfxId]);
358 }
359
Simon Hunt670e8252015-01-06 18:31:30 -0800360 it('should load base glyphs into the DOM', function () {
361 gs.init();
362 gs.loadDefs(d3Elem);
363 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800364 verifyLoadedInDom('bgpSpeaker', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800365 });
366
367 it('should load custom glyphs into the DOM', function () {
368 gs.init();
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700369 gs.registerGlyphSet(newGlyphs);
Simon Hunt670e8252015-01-06 18:31:30 -0800370 gs.loadDefs(d3Elem);
371 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800372 verifyLoadedInDom('diamond', testVbox);
373 });
Simon Hunt670e8252015-01-06 18:31:30 -0800374
Simon Hunt58f23bb2015-01-16 16:32:24 -0800375 it('should load only specified glyphs into the DOM', function () {
376 gs.init();
377 gs.loadDefs(d3Elem, ['crown', 'chain', 'node']);
378 expect(d3Elem.selectAll('symbol').size()).toEqual(3);
379 verifyLoadedInDom('crown', vbGlyph);
380 verifyLoadedInDom('chain', vbGlyph);
381 verifyLoadedInDom('node', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800382 });
Simon Huntc9b73162015-01-29 14:02:15 -0800383
384 it('should add a glyph with default size', function () {
385 gs.init();
Simon Hunt4b668592015-01-29 17:33:53 -0800386 var retval = gs.addGlyph(svg, 'crown');
Simon Huntc9b73162015-01-29 14:02:15 -0800387 var what = svg.selectAll('use');
388 expect(what.size()).toEqual(1);
389 expect(what.attr('width')).toEqual('40');
390 expect(what.attr('height')).toEqual('40');
391 expect(what.attr('xlink:href')).toEqual('#crown');
392 expect(what.classed('glyph')).toBeTruthy();
393 expect(what.classed('overlay')).toBeFalsy();
Simon Hunt4b668592015-01-29 17:33:53 -0800394
395 // check a couple on retval, which should be the same thing..
396 expect(retval.attr('xlink:href')).toEqual('#crown');
397 expect(retval.classed('glyph')).toBeTruthy();
Simon Huntc9b73162015-01-29 14:02:15 -0800398 });
399
400 it('should add a glyph with given size', function () {
401 gs.init();
402 gs.addGlyph(svg, 'crown', 37);
403 var what = svg.selectAll('use');
404 expect(what.size()).toEqual(1);
405 expect(what.attr('width')).toEqual('37');
406 expect(what.attr('height')).toEqual('37');
407 expect(what.attr('xlink:href')).toEqual('#crown');
408 expect(what.classed('glyph')).toBeTruthy();
409 expect(what.classed('overlay')).toBeFalsy();
410 });
411
412 it('should add a glyph marked as overlay', function () {
413 gs.init();
414 gs.addGlyph(svg, 'crown', 20, true);
415 var what = svg.selectAll('use');
416 expect(what.size()).toEqual(1);
417 expect(what.attr('width')).toEqual('20');
418 expect(what.attr('height')).toEqual('20');
419 expect(what.attr('xlink:href')).toEqual('#crown');
420 expect(what.classed('glyph')).toBeTruthy();
421 expect(what.classed('overlay')).toBeTruthy();
422 });
Simon Hunt7ac7be92015-01-06 10:47:56 -0800423});