blob: 00a18a08641a734402569c33f4d72ad79792edad [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
21//FIXME Size are changed
22
Matteo Scandolo209c6c62016-05-21 10:08:57 -070023describe('factory: fw/svg/glyph.js', function() {
Simon Huntc9b73162015-01-29 14:02:15 -080024 var $log, fs, gs, d3Elem, svg;
Simon Hunt7ac7be92015-01-06 10:47:56 -080025
Simon Hunt986b92f2016-06-03 15:46:59 -070026 var numBaseGlyphs = 51,
Simon Huntbc39f6d2015-01-06 17:34:28 -080027 vbBird = '352 224 113 112',
Simon Hunt6e459802015-01-06 15:05:42 -080028 vbGlyph = '0 0 110 110',
Simon Hunt58f23bb2015-01-16 16:32:24 -080029 vbBadge = '0 0 10 10',
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070030 longPrefix = 'M95.8,9.2H14.2c-2.8,0-5,2.2-5,5v81.5c0,2.8,2.2,5,5,' +
31 '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 -070032 tablePrefix = 'M15.9,19.1h-8v-13h8V19.1z M90.5,6.1H75.6v13h14.9V6.1' +
33 'z M71.9,6.1H56.9v13h14.9V6.1z M53.2,6.1H38.3v13h14.9V6.1z M34.5,' +
34 '6.1H19.6v13h14.9V6.1z M102.2,6.1h-8v13h8V6.1z ',
Simon Hunt58f23bb2015-01-16 16:32:24 -080035 prefixLookup = {
36 bird: 'M427.7,300.4',
37 unknown: 'M35,40a5',
38 node: 'M15,100a5',
39 switch: 'M10,20a10',
40 roadm: 'M10,35l25-',
41 endstation: 'M10,15a5,5',
42 router: 'M10,55A45,45',
43 bgpSpeaker: 'M10,40a45,35',
44 chain: 'M60.4,77.6c-',
45 crown: 'M99.5,21.6c0,',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070046 lock: 'M79.4,48.6h',
Bri Prebilic Cole6ed04eb2015-04-27 16:26:03 -070047 topo: 'M97.2,76.3H86.6',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070048 refresh: 'M102.6,40.8L88.4',
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070049 garbage: 'M94.6,20.2c',
Bri Prebilic Cole6ed04eb2015-04-27 16:26:03 -070050
51 // navigation specific glyphs
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070052 flowTable: tablePrefix + 'M102.2,23.6H7.9v',
53 portTable: tablePrefix + 'M102.6,23.6v78.5H',
54 groupTable: 'M16,19.1H8v-13h',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070055
56 // toolbar specific glyphs
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070057 summary: longPrefix + 'M16.7',
58 details: longPrefix + 'M16.9',
59 ports: 'M98,9.2H79.6c',
60 map: 'M95.8,9.2H14.2c-2.8,0-5,2.2-5,5v66',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070061 cycleLabels: 'M72.5,33.9c',
62 oblique: 'M80.9,30.2h',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070063 filters: 'M24.8,13.3L',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070064 resetZoom: 'M86,79.8L',
65 relatedIntents: 'M99.9,43.7',
Bri Prebilic Coledb4b87b2015-03-25 09:18:42 -070066 nextIntent: 'M88.1,55.7',
67 prevIntent: 'M22.5,55.6',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070068 intentTraffic: 'M14.7,71.5h',
69 allTraffic: 'M15.7,64.5h-7v',
70 flows: 'M93.8,46.1c',
Bri Prebilic Cole5a206bb2015-03-25 16:33:27 -070071 eqMaster: 'M100.1,46.9l',
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070072
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070073 // badges
Simon Hunt58f23bb2015-01-16 16:32:24 -080074 uiAttached: 'M2,2.5a.5,.5',
Simon Hunt5fdba202016-06-02 20:01:14 -070075 checkMark: 'M8.6,3.4L4',
Simon Hunt986b92f2016-06-03 15:46:59 -070076 xMark: 'M7.8,6.7L6.7',
Bri Prebilic Cole1dc32e62015-02-03 09:44:33 -080077 triangleUp: 'M0.5,6.2c0',
78 triangleDown: 'M9.5,4.2c0',
Simon Hunt3074fb22015-03-31 15:06:25 -070079 plus: 'M4,2h2v2h2v2',
80 minus: 'M2,4h6v2',
Simon Hunt5487ce72016-06-06 15:31:10 -070081 play: 'M3,1.5l3.5,3.5',
Simon Hunt3074fb22015-03-31 15:06:25 -070082 stop: 'M2.5,2.5h5',
Simon Hunt986b92f2016-06-03 15:46:59 -070083 xClose: 'M8.6,6.8L6.8,8.6',
Simon Hunt58f23bb2015-01-16 16:32:24 -080084
Simon Hunt9c1c45e2015-04-10 13:38:27 -070085 cloud: 'M37.6,79.5c-6.9,8.7-20.4,8.6',
86
Simon Hunt58f23bb2015-01-16 16:32:24 -080087 // our test ones..
88 triangle: 'M.5,.2',
89 diamond: 'M.2,.5'
Simon Hunt3074fb22015-03-31 15:06:25 -070090 },
91 glyphIds = [
Simon Hunta9761342016-06-10 18:02:53 -070092 'unknown', 'uiAttached',
93 'node', 'switch', 'roadm', 'endstation', 'router',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070094 'bgpSpeaker', 'chain', 'crown', 'lock', 'topo', 'refresh',
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070095 'garbage',
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070096 'flowTable', 'portTable', 'groupTable',
97 'summary', 'details', 'ports', 'map', 'cycleLabels',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070098 'oblique', 'filters', 'resetZoom', 'relatedIntents', 'nextIntent',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070099 'prevIntent', 'intentTraffic', 'allTraffic', 'flows', 'eqMaster'
Simon Hunt3074fb22015-03-31 15:06:25 -0700100 ],
101 badgeIds = [
Simon Hunta9761342016-06-10 18:02:53 -0700102 'checkMark', 'xMark', 'triangleUp', 'triangleDown',
Simon Hunt3074fb22015-03-31 15:06:25 -0700103 'plus', 'minus', 'play', 'stop'
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700104 ],
105 spriteIds = [
106 'cloud'
Simon Hunt3074fb22015-03-31 15:06:25 -0700107 ];
Simon Hunt6e459802015-01-06 15:05:42 -0800108
Simon Hunt51fc40b2015-01-06 13:56:12 -0800109 beforeEach(module('onosUtil', 'onosSvg'));
Simon Hunt7ac7be92015-01-06 10:47:56 -0800110
Simon Hunt51fc40b2015-01-06 13:56:12 -0800111 beforeEach(inject(function (_$log_, FnService, GlyphService) {
Simon Huntc9b73162015-01-29 14:02:15 -0800112 var body = d3.select('body');
Simon Hunt51fc40b2015-01-06 13:56:12 -0800113 $log = _$log_;
114 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -0800115 gs = GlyphService;
Simon Huntc9b73162015-01-29 14:02:15 -0800116 d3Elem = body.append('defs').attr('id', 'myDefs');
117 svg = body.append('svg').attr('id', 'mySvg');
Simon Hunt7ac7be92015-01-06 10:47:56 -0800118 }));
119
Simon Hunt670e8252015-01-06 18:31:30 -0800120 afterEach(function () {
Simon Huntc9b73162015-01-29 14:02:15 -0800121 d3.select('#mySvg').remove();
Simon Hunt670e8252015-01-06 18:31:30 -0800122 d3.select('#myDefs').remove();
Simon Huntcacce342015-01-07 16:13:05 -0800123 gs.clear();
Simon Hunt670e8252015-01-06 18:31:30 -0800124 });
125
Simon Hunt7ac7be92015-01-06 10:47:56 -0800126 it('should define GlyphService', function () {
127 expect(gs).toBeDefined();
128 });
129
Simon Hunt6e459802015-01-06 15:05:42 -0800130 it('should define api functions', function () {
Simon Hunt51fc40b2015-01-06 13:56:12 -0800131 expect(fs.areFunctions(gs, [
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700132 'clear', 'init', 'registerGlyphs', 'registerGlyphSet',
Matteo Scandolo209c6c62016-05-21 10:08:57 -0700133 'ids', 'glyph', 'glyphDefined', 'loadDefs', 'addGlyph'
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700134 ])).toBe(true);
Simon Hunt51fc40b2015-01-06 13:56:12 -0800135 });
136
Simon Hunt6e459802015-01-06 15:05:42 -0800137 it('should start with no glyphs loaded', function () {
138 expect(gs.ids()).toEqual([]);
139 });
140
Simon Hunt58f23bb2015-01-16 16:32:24 -0800141 it('should load the base set of glyphs into the cache', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800142 gs.init();
Simon Huntbc39f6d2015-01-06 17:34:28 -0800143 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Hunt6e459802015-01-06 15:05:42 -0800144 });
145
Simon Hunt58f23bb2015-01-16 16:32:24 -0800146 it('should remove glyphs from the cache on clear', function () {
Simon Huntcacce342015-01-07 16:13:05 -0800147 gs.init();
148 expect(gs.ids().length).toEqual(numBaseGlyphs);
149 gs.clear();
150 expect(gs.ids().length).toEqual(0);
151 });
152
Simon Hunt58f23bb2015-01-16 16:32:24 -0800153 function verifyGlyphLoadedInCache(id, vbox, expPfxId) {
154 var pfxId = expPfxId || id,
155 glyph = gs.glyph(id),
156 prefix = prefixLookup[pfxId],
Simon Hunt6e459802015-01-06 15:05:42 -0800157 plen = prefix.length;
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700158 expect(fs.contains(gs.ids(), id)).toBe(true);
Simon Hunt6e459802015-01-06 15:05:42 -0800159 expect(glyph).toBeDefined();
160 expect(glyph.id).toEqual(id);
161 expect(glyph.vb).toEqual(vbox);
162 expect(glyph.d.slice(0, plen)).toEqual(prefix);
163 }
164
Matteo Scandolo209c6c62016-05-21 10:08:57 -0700165 xit('should be configured with the correct number of glyphs', function () {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700166 var nGlyphs = 1 + glyphIds.length + badgeIds.length + spriteIds.length;
167 expect(nGlyphs).toEqual(numBaseGlyphs);
Simon Hunt3074fb22015-03-31 15:06:25 -0700168 });
169
Simon Hunt6e459802015-01-06 15:05:42 -0800170 it('should load the bird glyph', function() {
171 gs.init();
Simon Hunt58f23bb2015-01-16 16:32:24 -0800172 verifyGlyphLoadedInCache('bird', vbBird);
Simon Hunt6e459802015-01-06 15:05:42 -0800173 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700174
Matteo Scandolo209c6c62016-05-21 10:08:57 -0700175 xit('should load the regular glyphs', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800176 gs.init();
Simon Hunt3074fb22015-03-31 15:06:25 -0700177 glyphIds.forEach(function (id) {
178 verifyGlyphLoadedInCache(id, vbGlyph);
Bri Prebilic Cole94a856e2015-01-19 15:16:40 -0800179 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700180 });
181
182 it('should load the badge glyphs', function () {
183 gs.init();
184 badgeIds.forEach(function (id) {
185 verifyGlyphLoadedInCache(id, vbBadge);
186 });
187 });
188
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700189 it('should load the sprites', function () {
190 gs.init();
191 spriteIds.forEach(function (id) {
192 verifyGlyphLoadedInCache(id, vbGlyph);
193 });
194 });
195
Simon Huntbc39f6d2015-01-06 17:34:28 -0800196
197 // define some glyphs that we want to install
198
199 var testVbox = '0 0 1 1',
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700200 triVbox = '0 0 12 12',
201 diaVbox = '0 0 15 15',
Simon Huntbc39f6d2015-01-06 17:34:28 -0800202 dTriangle = 'M.5,.2l.3,.6,h-.6z',
203 dDiamond = 'M.2,.5l.3,-.3l.3,.3l-.3,.3z',
204 newGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700205 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800206 triangle: dTriangle,
207 diamond: dDiamond
208 },
209 dupGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700210 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800211 router: dTriangle,
212 switch: dDiamond
213 },
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700214 altNewGlyphs = {
215 _triangle: triVbox,
216 triangle: dTriangle,
217 _diamond: diaVbox,
218 diamond: dDiamond
219 },
220 altDupGlyphs = {
221 _router: triVbox,
222 router: dTriangle,
223 _switch: diaVbox,
224 switch: dDiamond
225 },
226 badGlyphSet = {
227 triangle: dTriangle,
228 diamond: dDiamond
229 },
230 warnMsg = 'GlyphService.registerGlyphs(): ',
231 warnMsgSet = 'GlyphService.registerGlyphSet(): ',
232 idCollision = warnMsg + 'ID collision: ',
233 idCollisionSet = warnMsgSet + 'ID collision: ',
234 missVbSet = warnMsgSet + 'no "_viewbox" property found',
235 missVbCustom = warnMsg + 'Missing viewbox property: ',
236 missVbTri = missVbCustom + '"_triangle"',
237 missVbDia = missVbCustom + '"_diamond"';
Simon Huntbc39f6d2015-01-06 17:34:28 -0800238
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700239
240 it('should install new glyphs as a glyph-set', function () {
Simon Huntbc39f6d2015-01-06 17:34:28 -0800241 gs.init();
242 expect(gs.ids().length).toEqual(numBaseGlyphs);
243 spyOn($log, 'warn');
244
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700245 var ok = gs.registerGlyphSet(newGlyphs);
246 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800247 expect($log.warn).not.toHaveBeenCalled();
248
249 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800250 verifyGlyphLoadedInCache('triangle', testVbox);
251 verifyGlyphLoadedInCache('diamond', testVbox);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800252 });
253
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700254 it('should not overwrite glyphs (via glyph-set) with dup IDs', function () {
255 gs.init();
256 expect(gs.ids().length).toEqual(numBaseGlyphs);
257 spyOn($log, 'warn');
258
259 var ok = gs.registerGlyphSet(dupGlyphs);
260 expect(ok).toBe(false);
261 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"switch"');
262 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"router"');
263
264 expect(gs.ids().length).toEqual(numBaseGlyphs);
265 // verify original glyphs still exist...
266 verifyGlyphLoadedInCache('router', vbGlyph);
267 verifyGlyphLoadedInCache('switch', vbGlyph);
268 });
269
270 it('should replace glyphs (via glyph-set) if asked nicely', function () {
271 gs.init();
272 expect(gs.ids().length).toEqual(numBaseGlyphs);
273 spyOn($log, 'warn');
274
275 var ok = gs.registerGlyphSet(dupGlyphs, true);
276 expect(ok).toBe(true);
277 expect($log.warn).not.toHaveBeenCalled();
278
279 expect(gs.ids().length).toEqual(numBaseGlyphs);
280 // verify glyphs have been overwritten...
281 verifyGlyphLoadedInCache('router', testVbox, 'triangle');
282 verifyGlyphLoadedInCache('switch', testVbox, 'diamond');
283 });
284
285 it ('should complain if missing _viewbox in a glyph-set', function () {
286 gs.init();
287 expect(gs.ids().length).toEqual(numBaseGlyphs);
288 spyOn($log, 'warn');
289
290 var ok = gs.registerGlyphSet(badGlyphSet);
291 expect(ok).toBe(false);
292 expect($log.warn).toHaveBeenCalledWith(missVbSet);
293 expect(gs.ids().length).toEqual(numBaseGlyphs);
294 });
295
296 it('should install new glyphs', function () {
297 gs.init();
298 expect(gs.ids().length).toEqual(numBaseGlyphs);
299 spyOn($log, 'warn');
300
301 var ok = gs.registerGlyphs(altNewGlyphs);
302 expect(ok).toBe(true);
303 expect($log.warn).not.toHaveBeenCalled();
304
305 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
306 verifyGlyphLoadedInCache('triangle', triVbox);
307 verifyGlyphLoadedInCache('diamond', diaVbox);
308 });
309
Simon Huntbc39f6d2015-01-06 17:34:28 -0800310 it('should not overwrite glyphs with dup IDs', function () {
311 gs.init();
312 expect(gs.ids().length).toEqual(numBaseGlyphs);
313 spyOn($log, 'warn');
314
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700315 var ok = gs.registerGlyphs(altDupGlyphs);
316 expect(ok).toBe(false);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800317 expect($log.warn).toHaveBeenCalledWith(idCollision + '"switch"');
318 expect($log.warn).toHaveBeenCalledWith(idCollision + '"router"');
319
320 expect(gs.ids().length).toEqual(numBaseGlyphs);
321 // verify original glyphs still exist...
Simon Hunt58f23bb2015-01-16 16:32:24 -0800322 verifyGlyphLoadedInCache('router', vbGlyph);
323 verifyGlyphLoadedInCache('switch', vbGlyph);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800324 });
325
326 it('should replace glyphs if asked nicely', function () {
327 gs.init();
328 expect(gs.ids().length).toEqual(numBaseGlyphs);
329 spyOn($log, 'warn');
330
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700331 var ok = gs.registerGlyphs(altDupGlyphs, true);
332 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800333 expect($log.warn).not.toHaveBeenCalled();
334
335 expect(gs.ids().length).toEqual(numBaseGlyphs);
336 // verify glyphs have been overwritten...
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700337 verifyGlyphLoadedInCache('router', triVbox, 'triangle');
338 verifyGlyphLoadedInCache('switch', diaVbox, 'diamond');
339 });
340
341 it ('should complain if missing custom viewbox', function () {
342 gs.init();
343 expect(gs.ids().length).toEqual(numBaseGlyphs);
344 spyOn($log, 'warn');
345
346 var ok = gs.registerGlyphs(badGlyphSet);
347 expect(ok).toBe(false);
348 expect($log.warn).toHaveBeenCalledWith(missVbTri);
349 expect($log.warn).toHaveBeenCalledWith(missVbDia);
350 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800351 });
Simon Hunt670e8252015-01-06 18:31:30 -0800352
353 function verifyPathPrefix(elem, prefix) {
354 var plen = prefix.length,
355 d = elem.select('path').attr('d');
356 expect(d.slice(0, plen)).toEqual(prefix);
357 }
358
Simon Hunt58f23bb2015-01-16 16:32:24 -0800359 function verifyLoadedInDom(id, vb, expPfxId) {
360 var pfxId = expPfxId || id,
361 symbol = d3Elem.select('#' + id);
362 expect(symbol.size()).toEqual(1);
363 expect(symbol.attr('viewBox')).toEqual(vb);
364 verifyPathPrefix(symbol, prefixLookup[pfxId]);
365 }
366
Simon Hunt670e8252015-01-06 18:31:30 -0800367 it('should load base glyphs into the DOM', function () {
368 gs.init();
369 gs.loadDefs(d3Elem);
370 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800371 verifyLoadedInDom('bgpSpeaker', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800372 });
373
374 it('should load custom glyphs into the DOM', function () {
375 gs.init();
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700376 gs.registerGlyphSet(newGlyphs);
Simon Hunt670e8252015-01-06 18:31:30 -0800377 gs.loadDefs(d3Elem);
378 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800379 verifyLoadedInDom('diamond', testVbox);
380 });
Simon Hunt670e8252015-01-06 18:31:30 -0800381
Simon Hunt58f23bb2015-01-16 16:32:24 -0800382 it('should load only specified glyphs into the DOM', function () {
383 gs.init();
384 gs.loadDefs(d3Elem, ['crown', 'chain', 'node']);
385 expect(d3Elem.selectAll('symbol').size()).toEqual(3);
386 verifyLoadedInDom('crown', vbGlyph);
387 verifyLoadedInDom('chain', vbGlyph);
388 verifyLoadedInDom('node', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800389 });
Simon Huntc9b73162015-01-29 14:02:15 -0800390
391 it('should add a glyph with default size', function () {
392 gs.init();
Simon Hunt4b668592015-01-29 17:33:53 -0800393 var retval = gs.addGlyph(svg, 'crown');
Simon Huntc9b73162015-01-29 14:02:15 -0800394 var what = svg.selectAll('use');
395 expect(what.size()).toEqual(1);
396 expect(what.attr('width')).toEqual('40');
397 expect(what.attr('height')).toEqual('40');
398 expect(what.attr('xlink:href')).toEqual('#crown');
399 expect(what.classed('glyph')).toBeTruthy();
400 expect(what.classed('overlay')).toBeFalsy();
Simon Hunt4b668592015-01-29 17:33:53 -0800401
402 // check a couple on retval, which should be the same thing..
403 expect(retval.attr('xlink:href')).toEqual('#crown');
404 expect(retval.classed('glyph')).toBeTruthy();
Simon Huntc9b73162015-01-29 14:02:15 -0800405 });
406
407 it('should add a glyph with given size', function () {
408 gs.init();
409 gs.addGlyph(svg, 'crown', 37);
410 var what = svg.selectAll('use');
411 expect(what.size()).toEqual(1);
412 expect(what.attr('width')).toEqual('37');
413 expect(what.attr('height')).toEqual('37');
414 expect(what.attr('xlink:href')).toEqual('#crown');
415 expect(what.classed('glyph')).toBeTruthy();
416 expect(what.classed('overlay')).toBeFalsy();
417 });
418
419 it('should add a glyph marked as overlay', function () {
420 gs.init();
421 gs.addGlyph(svg, 'crown', 20, true);
422 var what = svg.selectAll('use');
423 expect(what.size()).toEqual(1);
424 expect(what.attr('width')).toEqual('20');
425 expect(what.attr('height')).toEqual('20');
426 expect(what.attr('xlink:href')).toEqual('#crown');
427 expect(what.classed('glyph')).toBeTruthy();
428 expect(what.classed('overlay')).toBeTruthy();
429 });
Simon Hunt7ac7be92015-01-06 10:47:56 -0800430});