blob: afd4c95f950a55d93ed04b854fcb65514bc0c7f6 [file] [log] [blame]
Simon Hunt7ac7be92015-01-06 10:47:56 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt7ac7be92015-01-06 10:47:56 -08003 *
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 */
Matteo Scandolo812aa5a2016-04-19 18:12:45 -070020
Matteo Scandolo209c6c62016-05-21 10:08:57 -070021describe('factory: fw/svg/glyph.js', function() {
Simon Huntc9b73162015-01-29 14:02:15 -080022 var $log, fs, gs, d3Elem, svg;
Simon Hunt7ac7be92015-01-06 10:47:56 -080023
Simon Hunt50d68b92016-11-10 19:32:05 -080024 var numBaseGlyphs = 92,
Simon Huntbc39f6d2015-01-06 17:34:28 -080025 vbBird = '352 224 113 112',
Simon Hunt6e459802015-01-06 15:05:42 -080026 vbGlyph = '0 0 110 110',
Simon Hunt58f23bb2015-01-16 16:32:24 -080027 vbBadge = '0 0 10 10',
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070028 longPrefix = 'M95.8,9.2H14.2c-2.8,0-5,2.2-5,5v81.5c0,2.8,2.2,5,5,' +
29 '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 -070030 tablePrefix = 'M15.9,19.1h-8v-13h8V19.1z M90.5,6.1H75.6v13h14.9V6.1' +
31 'z M71.9,6.1H56.9v13h14.9V6.1z M53.2,6.1H38.3v13h14.9V6.1z M34.5,' +
32 '6.1H19.6v13h14.9V6.1z M102.2,6.1h-8v13h8V6.1z ',
Simon Hunt58f23bb2015-01-16 16:32:24 -080033 prefixLookup = {
34 bird: 'M427.7,300.4',
35 unknown: 'M35,40a5',
36 node: 'M15,100a5',
37 switch: 'M10,20a10',
38 roadm: 'M10,35l25-',
39 endstation: 'M10,15a5,5',
40 router: 'M10,55A45,45',
41 bgpSpeaker: 'M10,40a45,35',
42 chain: 'M60.4,77.6c-',
43 crown: 'M99.5,21.6c0,',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070044 lock: 'M79.4,48.6h',
Bri Prebilic Cole6ed04eb2015-04-27 16:26:03 -070045 topo: 'M97.2,76.3H86.6',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070046 refresh: 'M102.6,40.8L88.4',
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070047 garbage: 'M94.6,20.2c',
Bri Prebilic Cole6ed04eb2015-04-27 16:26:03 -070048
49 // navigation specific glyphs
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070050 flowTable: tablePrefix + 'M102.2,23.6H7.9v',
51 portTable: tablePrefix + 'M102.6,23.6v78.5H',
52 groupTable: 'M16,19.1H8v-13h',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070053
54 // toolbar specific glyphs
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070055 summary: longPrefix + 'M16.7',
56 details: longPrefix + 'M16.9',
57 ports: 'M98,9.2H79.6c',
58 map: 'M95.8,9.2H14.2c-2.8,0-5,2.2-5,5v66',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070059 cycleLabels: 'M72.5,33.9c',
60 oblique: 'M80.9,30.2h',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070061 filters: 'M24.8,13.3L',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070062 resetZoom: 'M86,79.8L',
63 relatedIntents: 'M99.9,43.7',
Bri Prebilic Coledb4b87b2015-03-25 09:18:42 -070064 nextIntent: 'M88.1,55.7',
65 prevIntent: 'M22.5,55.6',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070066 intentTraffic: 'M14.7,71.5h',
67 allTraffic: 'M15.7,64.5h-7v',
68 flows: 'M93.8,46.1c',
Bri Prebilic Cole5a206bb2015-03-25 16:33:27 -070069 eqMaster: 'M100.1,46.9l',
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070070
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070071 // badges
Simon Hunt58f23bb2015-01-16 16:32:24 -080072 uiAttached: 'M2,2.5a.5,.5',
Simon Hunt5fdba202016-06-02 20:01:14 -070073 checkMark: 'M8.6,3.4L4',
Simon Hunt986b92f2016-06-03 15:46:59 -070074 xMark: 'M7.8,6.7L6.7',
Bri Prebilic Cole1dc32e62015-02-03 09:44:33 -080075 triangleUp: 'M0.5,6.2c0',
76 triangleDown: 'M9.5,4.2c0',
Simon Hunt3074fb22015-03-31 15:06:25 -070077 plus: 'M4,2h2v2h2v2',
78 minus: 'M2,4h6v2',
Simon Hunt5487ce72016-06-06 15:31:10 -070079 play: 'M3,1.5l3.5,3.5',
Simon Hunt3074fb22015-03-31 15:06:25 -070080 stop: 'M2.5,2.5h5',
Simon Hunt986b92f2016-06-03 15:46:59 -070081 xClose: 'M8.6,6.8L6.8,8.6',
Simon Hunt58f23bb2015-01-16 16:32:24 -080082
Simon Hunt9c1c45e2015-04-10 13:38:27 -070083 cloud: 'M37.6,79.5c-6.9,8.7-20.4,8.6',
84
Simon Hunt58f23bb2015-01-16 16:32:24 -080085 // our test ones..
86 triangle: 'M.5,.2',
87 diamond: 'M.2,.5'
Simon Hunt3074fb22015-03-31 15:06:25 -070088 },
89 glyphIds = [
Simon Hunta9761342016-06-10 18:02:53 -070090 'unknown', 'uiAttached',
91 'node', 'switch', 'roadm', 'endstation', 'router',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070092 'bgpSpeaker', 'chain', 'crown', 'lock', 'topo', 'refresh',
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070093 'garbage',
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070094 'flowTable', 'portTable', 'groupTable',
95 'summary', 'details', 'ports', 'map', 'cycleLabels',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070096 'oblique', 'filters', 'resetZoom', 'relatedIntents', 'nextIntent',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070097 'prevIntent', 'intentTraffic', 'allTraffic', 'flows', 'eqMaster'
Simon Hunt3074fb22015-03-31 15:06:25 -070098 ],
99 badgeIds = [
Simon Hunta9761342016-06-10 18:02:53 -0700100 'checkMark', 'xMark', 'triangleUp', 'triangleDown',
Simon Hunt3074fb22015-03-31 15:06:25 -0700101 'plus', 'minus', 'play', 'stop'
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700102 ],
103 spriteIds = [
104 'cloud'
Simon Hunt3074fb22015-03-31 15:06:25 -0700105 ];
Simon Hunt6e459802015-01-06 15:05:42 -0800106
Simon Hunt51fc40b2015-01-06 13:56:12 -0800107 beforeEach(module('onosUtil', 'onosSvg'));
Simon Hunt7ac7be92015-01-06 10:47:56 -0800108
Simon Hunt51fc40b2015-01-06 13:56:12 -0800109 beforeEach(inject(function (_$log_, FnService, GlyphService) {
Simon Huntc9b73162015-01-29 14:02:15 -0800110 var body = d3.select('body');
Simon Hunt51fc40b2015-01-06 13:56:12 -0800111 $log = _$log_;
112 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -0800113 gs = GlyphService;
Simon Huntc9b73162015-01-29 14:02:15 -0800114 d3Elem = body.append('defs').attr('id', 'myDefs');
115 svg = body.append('svg').attr('id', 'mySvg');
Simon Hunt7ac7be92015-01-06 10:47:56 -0800116 }));
117
Simon Hunt670e8252015-01-06 18:31:30 -0800118 afterEach(function () {
Simon Huntc9b73162015-01-29 14:02:15 -0800119 d3.select('#mySvg').remove();
Simon Hunt670e8252015-01-06 18:31:30 -0800120 d3.select('#myDefs').remove();
Simon Huntcacce342015-01-07 16:13:05 -0800121 gs.clear();
Simon Hunt670e8252015-01-06 18:31:30 -0800122 });
123
Simon Hunt7ac7be92015-01-06 10:47:56 -0800124 it('should define GlyphService', function () {
125 expect(gs).toBeDefined();
126 });
127
Simon Hunt6e459802015-01-06 15:05:42 -0800128 it('should define api functions', function () {
Simon Hunt51fc40b2015-01-06 13:56:12 -0800129 expect(fs.areFunctions(gs, [
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700130 'clear', 'init', 'registerGlyphs', 'registerGlyphSet',
Matteo Scandolo209c6c62016-05-21 10:08:57 -0700131 'ids', 'glyph', 'glyphDefined', 'loadDefs', 'addGlyph'
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700132 ])).toBe(true);
Simon Hunt51fc40b2015-01-06 13:56:12 -0800133 });
134
Simon Hunt6e459802015-01-06 15:05:42 -0800135 it('should start with no glyphs loaded', function () {
136 expect(gs.ids()).toEqual([]);
137 });
138
Simon Hunt58f23bb2015-01-16 16:32:24 -0800139 it('should load the base set of glyphs into the cache', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800140 gs.init();
Simon Huntbc39f6d2015-01-06 17:34:28 -0800141 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Hunt6e459802015-01-06 15:05:42 -0800142 });
143
Simon Hunt58f23bb2015-01-16 16:32:24 -0800144 it('should remove glyphs from the cache on clear', function () {
Simon Huntcacce342015-01-07 16:13:05 -0800145 gs.init();
146 expect(gs.ids().length).toEqual(numBaseGlyphs);
147 gs.clear();
148 expect(gs.ids().length).toEqual(0);
149 });
150
Simon Hunt58f23bb2015-01-16 16:32:24 -0800151 function verifyGlyphLoadedInCache(id, vbox, expPfxId) {
152 var pfxId = expPfxId || id,
153 glyph = gs.glyph(id),
154 prefix = prefixLookup[pfxId],
Simon Hunt6e459802015-01-06 15:05:42 -0800155 plen = prefix.length;
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700156 expect(fs.contains(gs.ids(), id)).toBe(true);
Simon Hunt6e459802015-01-06 15:05:42 -0800157 expect(glyph).toBeDefined();
158 expect(glyph.id).toEqual(id);
159 expect(glyph.vb).toEqual(vbox);
160 expect(glyph.d.slice(0, plen)).toEqual(prefix);
161 }
162
Matteo Scandolo209c6c62016-05-21 10:08:57 -0700163 xit('should be configured with the correct number of glyphs', function () {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700164 var nGlyphs = 1 + glyphIds.length + badgeIds.length + spriteIds.length;
165 expect(nGlyphs).toEqual(numBaseGlyphs);
Simon Hunt3074fb22015-03-31 15:06:25 -0700166 });
167
Simon Hunt6e459802015-01-06 15:05:42 -0800168 it('should load the bird glyph', function() {
169 gs.init();
Simon Hunt58f23bb2015-01-16 16:32:24 -0800170 verifyGlyphLoadedInCache('bird', vbBird);
Simon Hunt6e459802015-01-06 15:05:42 -0800171 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700172
Matteo Scandolo209c6c62016-05-21 10:08:57 -0700173 xit('should load the regular glyphs', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800174 gs.init();
Simon Hunt3074fb22015-03-31 15:06:25 -0700175 glyphIds.forEach(function (id) {
176 verifyGlyphLoadedInCache(id, vbGlyph);
Bri Prebilic Cole94a856e2015-01-19 15:16:40 -0800177 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700178 });
179
180 it('should load the badge glyphs', function () {
181 gs.init();
182 badgeIds.forEach(function (id) {
183 verifyGlyphLoadedInCache(id, vbBadge);
184 });
185 });
186
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700187 it('should load the sprites', function () {
188 gs.init();
189 spriteIds.forEach(function (id) {
190 verifyGlyphLoadedInCache(id, vbGlyph);
191 });
192 });
193
Simon Huntbc39f6d2015-01-06 17:34:28 -0800194
195 // define some glyphs that we want to install
196
197 var testVbox = '0 0 1 1',
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700198 triVbox = '0 0 12 12',
199 diaVbox = '0 0 15 15',
Simon Huntbc39f6d2015-01-06 17:34:28 -0800200 dTriangle = 'M.5,.2l.3,.6,h-.6z',
201 dDiamond = 'M.2,.5l.3,-.3l.3,.3l-.3,.3z',
202 newGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700203 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800204 triangle: dTriangle,
205 diamond: dDiamond
206 },
207 dupGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700208 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800209 router: dTriangle,
210 switch: dDiamond
211 },
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700212 altNewGlyphs = {
213 _triangle: triVbox,
214 triangle: dTriangle,
215 _diamond: diaVbox,
216 diamond: dDiamond
217 },
218 altDupGlyphs = {
219 _router: triVbox,
220 router: dTriangle,
221 _switch: diaVbox,
222 switch: dDiamond
223 },
224 badGlyphSet = {
225 triangle: dTriangle,
226 diamond: dDiamond
227 },
228 warnMsg = 'GlyphService.registerGlyphs(): ',
229 warnMsgSet = 'GlyphService.registerGlyphSet(): ',
230 idCollision = warnMsg + 'ID collision: ',
231 idCollisionSet = warnMsgSet + 'ID collision: ',
232 missVbSet = warnMsgSet + 'no "_viewbox" property found',
233 missVbCustom = warnMsg + 'Missing viewbox property: ',
234 missVbTri = missVbCustom + '"_triangle"',
235 missVbDia = missVbCustom + '"_diamond"';
Simon Huntbc39f6d2015-01-06 17:34:28 -0800236
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700237
238 it('should install new glyphs as a glyph-set', function () {
Simon Huntbc39f6d2015-01-06 17:34:28 -0800239 gs.init();
240 expect(gs.ids().length).toEqual(numBaseGlyphs);
241 spyOn($log, 'warn');
242
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700243 var ok = gs.registerGlyphSet(newGlyphs);
244 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800245 expect($log.warn).not.toHaveBeenCalled();
246
247 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800248 verifyGlyphLoadedInCache('triangle', testVbox);
249 verifyGlyphLoadedInCache('diamond', testVbox);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800250 });
251
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700252 it('should not overwrite glyphs (via glyph-set) with dup IDs', function () {
253 gs.init();
254 expect(gs.ids().length).toEqual(numBaseGlyphs);
255 spyOn($log, 'warn');
256
257 var ok = gs.registerGlyphSet(dupGlyphs);
258 expect(ok).toBe(false);
259 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"switch"');
260 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"router"');
261
262 expect(gs.ids().length).toEqual(numBaseGlyphs);
263 // verify original glyphs still exist...
264 verifyGlyphLoadedInCache('router', vbGlyph);
265 verifyGlyphLoadedInCache('switch', vbGlyph);
266 });
267
268 it('should replace glyphs (via glyph-set) if asked nicely', function () {
269 gs.init();
270 expect(gs.ids().length).toEqual(numBaseGlyphs);
271 spyOn($log, 'warn');
272
273 var ok = gs.registerGlyphSet(dupGlyphs, true);
274 expect(ok).toBe(true);
275 expect($log.warn).not.toHaveBeenCalled();
276
277 expect(gs.ids().length).toEqual(numBaseGlyphs);
278 // verify glyphs have been overwritten...
279 verifyGlyphLoadedInCache('router', testVbox, 'triangle');
280 verifyGlyphLoadedInCache('switch', testVbox, 'diamond');
281 });
282
283 it ('should complain if missing _viewbox in a glyph-set', function () {
284 gs.init();
285 expect(gs.ids().length).toEqual(numBaseGlyphs);
286 spyOn($log, 'warn');
287
288 var ok = gs.registerGlyphSet(badGlyphSet);
289 expect(ok).toBe(false);
290 expect($log.warn).toHaveBeenCalledWith(missVbSet);
291 expect(gs.ids().length).toEqual(numBaseGlyphs);
292 });
293
294 it('should install new glyphs', function () {
295 gs.init();
296 expect(gs.ids().length).toEqual(numBaseGlyphs);
297 spyOn($log, 'warn');
298
299 var ok = gs.registerGlyphs(altNewGlyphs);
300 expect(ok).toBe(true);
301 expect($log.warn).not.toHaveBeenCalled();
302
303 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
304 verifyGlyphLoadedInCache('triangle', triVbox);
305 verifyGlyphLoadedInCache('diamond', diaVbox);
306 });
307
Simon Huntbc39f6d2015-01-06 17:34:28 -0800308 it('should not overwrite glyphs with dup IDs', function () {
309 gs.init();
310 expect(gs.ids().length).toEqual(numBaseGlyphs);
311 spyOn($log, 'warn');
312
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700313 var ok = gs.registerGlyphs(altDupGlyphs);
314 expect(ok).toBe(false);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800315 expect($log.warn).toHaveBeenCalledWith(idCollision + '"switch"');
316 expect($log.warn).toHaveBeenCalledWith(idCollision + '"router"');
317
318 expect(gs.ids().length).toEqual(numBaseGlyphs);
319 // verify original glyphs still exist...
Simon Hunt58f23bb2015-01-16 16:32:24 -0800320 verifyGlyphLoadedInCache('router', vbGlyph);
321 verifyGlyphLoadedInCache('switch', vbGlyph);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800322 });
323
324 it('should replace glyphs if asked nicely', function () {
325 gs.init();
326 expect(gs.ids().length).toEqual(numBaseGlyphs);
327 spyOn($log, 'warn');
328
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700329 var ok = gs.registerGlyphs(altDupGlyphs, true);
330 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800331 expect($log.warn).not.toHaveBeenCalled();
332
333 expect(gs.ids().length).toEqual(numBaseGlyphs);
334 // verify glyphs have been overwritten...
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700335 verifyGlyphLoadedInCache('router', triVbox, 'triangle');
336 verifyGlyphLoadedInCache('switch', diaVbox, 'diamond');
337 });
338
339 it ('should complain if missing custom viewbox', function () {
340 gs.init();
341 expect(gs.ids().length).toEqual(numBaseGlyphs);
342 spyOn($log, 'warn');
343
344 var ok = gs.registerGlyphs(badGlyphSet);
345 expect(ok).toBe(false);
346 expect($log.warn).toHaveBeenCalledWith(missVbTri);
347 expect($log.warn).toHaveBeenCalledWith(missVbDia);
348 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800349 });
Simon Hunt670e8252015-01-06 18:31:30 -0800350
351 function verifyPathPrefix(elem, prefix) {
352 var plen = prefix.length,
353 d = elem.select('path').attr('d');
354 expect(d.slice(0, plen)).toEqual(prefix);
355 }
356
Simon Hunt58f23bb2015-01-16 16:32:24 -0800357 function verifyLoadedInDom(id, vb, expPfxId) {
358 var pfxId = expPfxId || id,
359 symbol = d3Elem.select('#' + id);
360 expect(symbol.size()).toEqual(1);
361 expect(symbol.attr('viewBox')).toEqual(vb);
362 verifyPathPrefix(symbol, prefixLookup[pfxId]);
363 }
364
Simon Hunt670e8252015-01-06 18:31:30 -0800365 it('should load base glyphs into the DOM', function () {
366 gs.init();
367 gs.loadDefs(d3Elem);
368 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800369 verifyLoadedInDom('bgpSpeaker', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800370 });
371
372 it('should load custom glyphs into the DOM', function () {
373 gs.init();
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700374 gs.registerGlyphSet(newGlyphs);
Simon Hunt670e8252015-01-06 18:31:30 -0800375 gs.loadDefs(d3Elem);
376 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800377 verifyLoadedInDom('diamond', testVbox);
378 });
Simon Hunt670e8252015-01-06 18:31:30 -0800379
Simon Hunt58f23bb2015-01-16 16:32:24 -0800380 it('should load only specified glyphs into the DOM', function () {
381 gs.init();
382 gs.loadDefs(d3Elem, ['crown', 'chain', 'node']);
383 expect(d3Elem.selectAll('symbol').size()).toEqual(3);
384 verifyLoadedInDom('crown', vbGlyph);
385 verifyLoadedInDom('chain', vbGlyph);
386 verifyLoadedInDom('node', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800387 });
Simon Huntc9b73162015-01-29 14:02:15 -0800388
389 it('should add a glyph with default size', function () {
390 gs.init();
Simon Hunt4b668592015-01-29 17:33:53 -0800391 var retval = gs.addGlyph(svg, 'crown');
Simon Huntc9b73162015-01-29 14:02:15 -0800392 var what = svg.selectAll('use');
393 expect(what.size()).toEqual(1);
394 expect(what.attr('width')).toEqual('40');
395 expect(what.attr('height')).toEqual('40');
396 expect(what.attr('xlink:href')).toEqual('#crown');
397 expect(what.classed('glyph')).toBeTruthy();
398 expect(what.classed('overlay')).toBeFalsy();
Simon Hunt4b668592015-01-29 17:33:53 -0800399
400 // check a couple on retval, which should be the same thing..
401 expect(retval.attr('xlink:href')).toEqual('#crown');
402 expect(retval.classed('glyph')).toBeTruthy();
Simon Huntc9b73162015-01-29 14:02:15 -0800403 });
404
405 it('should add a glyph with given size', function () {
406 gs.init();
407 gs.addGlyph(svg, 'crown', 37);
408 var what = svg.selectAll('use');
409 expect(what.size()).toEqual(1);
410 expect(what.attr('width')).toEqual('37');
411 expect(what.attr('height')).toEqual('37');
412 expect(what.attr('xlink:href')).toEqual('#crown');
413 expect(what.classed('glyph')).toBeTruthy();
414 expect(what.classed('overlay')).toBeFalsy();
415 });
416
417 it('should add a glyph marked as overlay', function () {
418 gs.init();
419 gs.addGlyph(svg, 'crown', 20, true);
420 var what = svg.selectAll('use');
421 expect(what.size()).toEqual(1);
422 expect(what.attr('width')).toEqual('20');
423 expect(what.attr('height')).toEqual('20');
424 expect(what.attr('xlink:href')).toEqual('#crown');
425 expect(what.classed('glyph')).toBeTruthy();
426 expect(what.classed('overlay')).toBeTruthy();
427 });
Simon Hunt7ac7be92015-01-06 10:47:56 -0800428});