blob: bdc8a8260489a4c946058c0c6e3b9bfbaee84d79 [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 */
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 Colebd0bc772015-05-13 13:02:26 -070023 var numBaseGlyphs = 42,
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 Colebd0bc772015-05-13 13:02:26 -070046 garbage: 'M94.6,20.2c',
Bri Prebilic Cole6ed04eb2015-04-27 16:26:03 -070047
48 // navigation specific glyphs
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070049 flowTable: tablePrefix + 'M102.2,23.6H7.9v',
50 portTable: tablePrefix + 'M102.6,23.6v78.5H',
51 groupTable: 'M16,19.1H8v-13h',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070052
53 // toolbar specific glyphs
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070054 summary: longPrefix + 'M16.7',
55 details: longPrefix + 'M16.9',
56 ports: 'M98,9.2H79.6c',
57 map: 'M95.8,9.2H14.2c-2.8,0-5,2.2-5,5v66',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070058 cycleLabels: 'M72.5,33.9c',
59 oblique: 'M80.9,30.2h',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070060 filters: 'M24.8,13.3L',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070061 resetZoom: 'M86,79.8L',
62 relatedIntents: 'M99.9,43.7',
Bri Prebilic Coledb4b87b2015-03-25 09:18:42 -070063 nextIntent: 'M88.1,55.7',
64 prevIntent: 'M22.5,55.6',
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070065 intentTraffic: 'M14.7,71.5h',
66 allTraffic: 'M15.7,64.5h-7v',
67 flows: 'M93.8,46.1c',
Bri Prebilic Cole5a206bb2015-03-25 16:33:27 -070068 eqMaster: 'M100.1,46.9l',
Bri Prebilic Coledeca6e92015-03-19 12:03:14 -070069
Bri Prebilic Cole7c980512015-03-25 12:31:29 -070070 // badges
Simon Hunt58f23bb2015-01-16 16:32:24 -080071 uiAttached: 'M2,2.5a.5,.5',
Simon Huntaa26adf2015-01-20 10:32:49 -080072 checkMark: 'M2.6,4.5c0',
73 xMark: 'M9.0,7.2C8.2',
Bri Prebilic Cole1dc32e62015-02-03 09:44:33 -080074 triangleUp: 'M0.5,6.2c0',
75 triangleDown: 'M9.5,4.2c0',
Simon Hunt3074fb22015-03-31 15:06:25 -070076 plus: 'M4,2h2v2h2v2',
77 minus: 'M2,4h6v2',
78 play: 'M2.5,2l5.5,3',
79 stop: 'M2.5,2.5h5',
Simon Hunt58f23bb2015-01-16 16:32:24 -080080
Simon Hunt9c1c45e2015-04-10 13:38:27 -070081 cloud: 'M37.6,79.5c-6.9,8.7-20.4,8.6',
82
Simon Hunt58f23bb2015-01-16 16:32:24 -080083 // our test ones..
84 triangle: 'M.5,.2',
85 diamond: 'M.2,.5'
Simon Hunt3074fb22015-03-31 15:06:25 -070086 },
87 glyphIds = [
88 'unknown', 'node', 'switch', 'roadm', 'endstation', 'router',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070089 'bgpSpeaker', 'chain', 'crown', 'lock', 'topo', 'refresh',
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070090 'garbage',
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070091 'flowTable', 'portTable', 'groupTable',
92 'summary', 'details', 'ports', 'map', 'cycleLabels',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070093 'oblique', 'filters', 'resetZoom', 'relatedIntents', 'nextIntent',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070094 'prevIntent', 'intentTraffic', 'allTraffic', 'flows', 'eqMaster'
Simon Hunt3074fb22015-03-31 15:06:25 -070095 ],
96 badgeIds = [
97 'uiAttached', 'checkMark', 'xMark', 'triangleUp', 'triangleDown',
98 'plus', 'minus', 'play', 'stop'
Simon Hunt9c1c45e2015-04-10 13:38:27 -070099 ],
100 spriteIds = [
101 'cloud'
Simon Hunt3074fb22015-03-31 15:06:25 -0700102 ];
Simon Hunt6e459802015-01-06 15:05:42 -0800103
Simon Hunt51fc40b2015-01-06 13:56:12 -0800104 beforeEach(module('onosUtil', 'onosSvg'));
Simon Hunt7ac7be92015-01-06 10:47:56 -0800105
Simon Hunt51fc40b2015-01-06 13:56:12 -0800106 beforeEach(inject(function (_$log_, FnService, GlyphService) {
Simon Huntc9b73162015-01-29 14:02:15 -0800107 var body = d3.select('body');
Simon Hunt51fc40b2015-01-06 13:56:12 -0800108 $log = _$log_;
109 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -0800110 gs = GlyphService;
Simon Huntc9b73162015-01-29 14:02:15 -0800111 d3Elem = body.append('defs').attr('id', 'myDefs');
112 svg = body.append('svg').attr('id', 'mySvg');
Simon Hunt7ac7be92015-01-06 10:47:56 -0800113 }));
114
Simon Hunt670e8252015-01-06 18:31:30 -0800115 afterEach(function () {
Simon Huntc9b73162015-01-29 14:02:15 -0800116 d3.select('#mySvg').remove();
Simon Hunt670e8252015-01-06 18:31:30 -0800117 d3.select('#myDefs').remove();
Simon Huntcacce342015-01-07 16:13:05 -0800118 gs.clear();
Simon Hunt670e8252015-01-06 18:31:30 -0800119 });
120
Simon Hunt7ac7be92015-01-06 10:47:56 -0800121 it('should define GlyphService', function () {
122 expect(gs).toBeDefined();
123 });
124
Simon Hunt6e459802015-01-06 15:05:42 -0800125 it('should define api functions', function () {
Simon Hunt51fc40b2015-01-06 13:56:12 -0800126 expect(fs.areFunctions(gs, [
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700127 'clear', 'init', 'registerGlyphs', 'registerGlyphSet',
128 'ids', 'glyph', 'loadDefs', 'addGlyph'
129 ])).toBe(true);
Simon Hunt51fc40b2015-01-06 13:56:12 -0800130 });
131
Simon Hunt6e459802015-01-06 15:05:42 -0800132 it('should start with no glyphs loaded', function () {
133 expect(gs.ids()).toEqual([]);
134 });
135
Simon Hunt58f23bb2015-01-16 16:32:24 -0800136 it('should load the base set of glyphs into the cache', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800137 gs.init();
Simon Huntbc39f6d2015-01-06 17:34:28 -0800138 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Hunt6e459802015-01-06 15:05:42 -0800139 });
140
Simon Hunt58f23bb2015-01-16 16:32:24 -0800141 it('should remove glyphs from the cache on clear', function () {
Simon Huntcacce342015-01-07 16:13:05 -0800142 gs.init();
143 expect(gs.ids().length).toEqual(numBaseGlyphs);
144 gs.clear();
145 expect(gs.ids().length).toEqual(0);
146 });
147
Simon Hunt58f23bb2015-01-16 16:32:24 -0800148 function verifyGlyphLoadedInCache(id, vbox, expPfxId) {
149 var pfxId = expPfxId || id,
150 glyph = gs.glyph(id),
151 prefix = prefixLookup[pfxId],
Simon Hunt6e459802015-01-06 15:05:42 -0800152 plen = prefix.length;
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700153 expect(fs.contains(gs.ids(), id)).toBe(true);
Simon Hunt6e459802015-01-06 15:05:42 -0800154 expect(glyph).toBeDefined();
155 expect(glyph.id).toEqual(id);
156 expect(glyph.vb).toEqual(vbox);
157 expect(glyph.d.slice(0, plen)).toEqual(prefix);
158 }
159
Simon Hunt3074fb22015-03-31 15:06:25 -0700160 it('should be configured with the correct number of glyphs', function () {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700161 var nGlyphs = 1 + glyphIds.length + badgeIds.length + spriteIds.length;
162 expect(nGlyphs).toEqual(numBaseGlyphs);
Simon Hunt3074fb22015-03-31 15:06:25 -0700163 });
164
Simon Hunt6e459802015-01-06 15:05:42 -0800165 it('should load the bird glyph', function() {
166 gs.init();
Simon Hunt58f23bb2015-01-16 16:32:24 -0800167 verifyGlyphLoadedInCache('bird', vbBird);
Simon Hunt6e459802015-01-06 15:05:42 -0800168 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700169
170 it('should load the regular glyphs', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800171 gs.init();
Simon Hunt3074fb22015-03-31 15:06:25 -0700172 glyphIds.forEach(function (id) {
173 verifyGlyphLoadedInCache(id, vbGlyph);
Bri Prebilic Cole94a856e2015-01-19 15:16:40 -0800174 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700175 });
176
177 it('should load the badge glyphs', function () {
178 gs.init();
179 badgeIds.forEach(function (id) {
180 verifyGlyphLoadedInCache(id, vbBadge);
181 });
182 });
183
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700184 it('should load the sprites', function () {
185 gs.init();
186 spriteIds.forEach(function (id) {
187 verifyGlyphLoadedInCache(id, vbGlyph);
188 });
189 });
190
Simon Huntbc39f6d2015-01-06 17:34:28 -0800191
192 // define some glyphs that we want to install
193
194 var testVbox = '0 0 1 1',
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700195 triVbox = '0 0 12 12',
196 diaVbox = '0 0 15 15',
Simon Huntbc39f6d2015-01-06 17:34:28 -0800197 dTriangle = 'M.5,.2l.3,.6,h-.6z',
198 dDiamond = 'M.2,.5l.3,-.3l.3,.3l-.3,.3z',
199 newGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700200 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800201 triangle: dTriangle,
202 diamond: dDiamond
203 },
204 dupGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700205 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800206 router: dTriangle,
207 switch: dDiamond
208 },
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700209 altNewGlyphs = {
210 _triangle: triVbox,
211 triangle: dTriangle,
212 _diamond: diaVbox,
213 diamond: dDiamond
214 },
215 altDupGlyphs = {
216 _router: triVbox,
217 router: dTriangle,
218 _switch: diaVbox,
219 switch: dDiamond
220 },
221 badGlyphSet = {
222 triangle: dTriangle,
223 diamond: dDiamond
224 },
225 warnMsg = 'GlyphService.registerGlyphs(): ',
226 warnMsgSet = 'GlyphService.registerGlyphSet(): ',
227 idCollision = warnMsg + 'ID collision: ',
228 idCollisionSet = warnMsgSet + 'ID collision: ',
229 missVbSet = warnMsgSet + 'no "_viewbox" property found',
230 missVbCustom = warnMsg + 'Missing viewbox property: ',
231 missVbTri = missVbCustom + '"_triangle"',
232 missVbDia = missVbCustom + '"_diamond"';
Simon Huntbc39f6d2015-01-06 17:34:28 -0800233
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700234
235 it('should install new glyphs as a glyph-set', function () {
Simon Huntbc39f6d2015-01-06 17:34:28 -0800236 gs.init();
237 expect(gs.ids().length).toEqual(numBaseGlyphs);
238 spyOn($log, 'warn');
239
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700240 var ok = gs.registerGlyphSet(newGlyphs);
241 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800242 expect($log.warn).not.toHaveBeenCalled();
243
244 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800245 verifyGlyphLoadedInCache('triangle', testVbox);
246 verifyGlyphLoadedInCache('diamond', testVbox);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800247 });
248
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700249 it('should not overwrite glyphs (via glyph-set) with dup IDs', function () {
250 gs.init();
251 expect(gs.ids().length).toEqual(numBaseGlyphs);
252 spyOn($log, 'warn');
253
254 var ok = gs.registerGlyphSet(dupGlyphs);
255 expect(ok).toBe(false);
256 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"switch"');
257 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"router"');
258
259 expect(gs.ids().length).toEqual(numBaseGlyphs);
260 // verify original glyphs still exist...
261 verifyGlyphLoadedInCache('router', vbGlyph);
262 verifyGlyphLoadedInCache('switch', vbGlyph);
263 });
264
265 it('should replace glyphs (via glyph-set) if asked nicely', function () {
266 gs.init();
267 expect(gs.ids().length).toEqual(numBaseGlyphs);
268 spyOn($log, 'warn');
269
270 var ok = gs.registerGlyphSet(dupGlyphs, true);
271 expect(ok).toBe(true);
272 expect($log.warn).not.toHaveBeenCalled();
273
274 expect(gs.ids().length).toEqual(numBaseGlyphs);
275 // verify glyphs have been overwritten...
276 verifyGlyphLoadedInCache('router', testVbox, 'triangle');
277 verifyGlyphLoadedInCache('switch', testVbox, 'diamond');
278 });
279
280 it ('should complain if missing _viewbox in a glyph-set', function () {
281 gs.init();
282 expect(gs.ids().length).toEqual(numBaseGlyphs);
283 spyOn($log, 'warn');
284
285 var ok = gs.registerGlyphSet(badGlyphSet);
286 expect(ok).toBe(false);
287 expect($log.warn).toHaveBeenCalledWith(missVbSet);
288 expect(gs.ids().length).toEqual(numBaseGlyphs);
289 });
290
291 it('should install new glyphs', function () {
292 gs.init();
293 expect(gs.ids().length).toEqual(numBaseGlyphs);
294 spyOn($log, 'warn');
295
296 var ok = gs.registerGlyphs(altNewGlyphs);
297 expect(ok).toBe(true);
298 expect($log.warn).not.toHaveBeenCalled();
299
300 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
301 verifyGlyphLoadedInCache('triangle', triVbox);
302 verifyGlyphLoadedInCache('diamond', diaVbox);
303 });
304
Simon Huntbc39f6d2015-01-06 17:34:28 -0800305 it('should not overwrite glyphs with dup IDs', function () {
306 gs.init();
307 expect(gs.ids().length).toEqual(numBaseGlyphs);
308 spyOn($log, 'warn');
309
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700310 var ok = gs.registerGlyphs(altDupGlyphs);
311 expect(ok).toBe(false);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800312 expect($log.warn).toHaveBeenCalledWith(idCollision + '"switch"');
313 expect($log.warn).toHaveBeenCalledWith(idCollision + '"router"');
314
315 expect(gs.ids().length).toEqual(numBaseGlyphs);
316 // verify original glyphs still exist...
Simon Hunt58f23bb2015-01-16 16:32:24 -0800317 verifyGlyphLoadedInCache('router', vbGlyph);
318 verifyGlyphLoadedInCache('switch', vbGlyph);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800319 });
320
321 it('should replace glyphs if asked nicely', function () {
322 gs.init();
323 expect(gs.ids().length).toEqual(numBaseGlyphs);
324 spyOn($log, 'warn');
325
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700326 var ok = gs.registerGlyphs(altDupGlyphs, true);
327 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800328 expect($log.warn).not.toHaveBeenCalled();
329
330 expect(gs.ids().length).toEqual(numBaseGlyphs);
331 // verify glyphs have been overwritten...
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700332 verifyGlyphLoadedInCache('router', triVbox, 'triangle');
333 verifyGlyphLoadedInCache('switch', diaVbox, 'diamond');
334 });
335
336 it ('should complain if missing custom viewbox', function () {
337 gs.init();
338 expect(gs.ids().length).toEqual(numBaseGlyphs);
339 spyOn($log, 'warn');
340
341 var ok = gs.registerGlyphs(badGlyphSet);
342 expect(ok).toBe(false);
343 expect($log.warn).toHaveBeenCalledWith(missVbTri);
344 expect($log.warn).toHaveBeenCalledWith(missVbDia);
345 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800346 });
Simon Hunt670e8252015-01-06 18:31:30 -0800347
348 function verifyPathPrefix(elem, prefix) {
349 var plen = prefix.length,
350 d = elem.select('path').attr('d');
351 expect(d.slice(0, plen)).toEqual(prefix);
352 }
353
Simon Hunt58f23bb2015-01-16 16:32:24 -0800354 function verifyLoadedInDom(id, vb, expPfxId) {
355 var pfxId = expPfxId || id,
356 symbol = d3Elem.select('#' + id);
357 expect(symbol.size()).toEqual(1);
358 expect(symbol.attr('viewBox')).toEqual(vb);
359 verifyPathPrefix(symbol, prefixLookup[pfxId]);
360 }
361
Simon Hunt670e8252015-01-06 18:31:30 -0800362 it('should load base glyphs into the DOM', function () {
363 gs.init();
364 gs.loadDefs(d3Elem);
365 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800366 verifyLoadedInDom('bgpSpeaker', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800367 });
368
369 it('should load custom glyphs into the DOM', function () {
370 gs.init();
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700371 gs.registerGlyphSet(newGlyphs);
Simon Hunt670e8252015-01-06 18:31:30 -0800372 gs.loadDefs(d3Elem);
373 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800374 verifyLoadedInDom('diamond', testVbox);
375 });
Simon Hunt670e8252015-01-06 18:31:30 -0800376
Simon Hunt58f23bb2015-01-16 16:32:24 -0800377 it('should load only specified glyphs into the DOM', function () {
378 gs.init();
379 gs.loadDefs(d3Elem, ['crown', 'chain', 'node']);
380 expect(d3Elem.selectAll('symbol').size()).toEqual(3);
381 verifyLoadedInDom('crown', vbGlyph);
382 verifyLoadedInDom('chain', vbGlyph);
383 verifyLoadedInDom('node', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800384 });
Simon Huntc9b73162015-01-29 14:02:15 -0800385
386 it('should add a glyph with default size', function () {
387 gs.init();
Simon Hunt4b668592015-01-29 17:33:53 -0800388 var retval = gs.addGlyph(svg, 'crown');
Simon Huntc9b73162015-01-29 14:02:15 -0800389 var what = svg.selectAll('use');
390 expect(what.size()).toEqual(1);
391 expect(what.attr('width')).toEqual('40');
392 expect(what.attr('height')).toEqual('40');
393 expect(what.attr('xlink:href')).toEqual('#crown');
394 expect(what.classed('glyph')).toBeTruthy();
395 expect(what.classed('overlay')).toBeFalsy();
Simon Hunt4b668592015-01-29 17:33:53 -0800396
397 // check a couple on retval, which should be the same thing..
398 expect(retval.attr('xlink:href')).toEqual('#crown');
399 expect(retval.classed('glyph')).toBeTruthy();
Simon Huntc9b73162015-01-29 14:02:15 -0800400 });
401
402 it('should add a glyph with given size', function () {
403 gs.init();
404 gs.addGlyph(svg, 'crown', 37);
405 var what = svg.selectAll('use');
406 expect(what.size()).toEqual(1);
407 expect(what.attr('width')).toEqual('37');
408 expect(what.attr('height')).toEqual('37');
409 expect(what.attr('xlink:href')).toEqual('#crown');
410 expect(what.classed('glyph')).toBeTruthy();
411 expect(what.classed('overlay')).toBeFalsy();
412 });
413
414 it('should add a glyph marked as overlay', function () {
415 gs.init();
416 gs.addGlyph(svg, 'crown', 20, true);
417 var what = svg.selectAll('use');
418 expect(what.size()).toEqual(1);
419 expect(what.attr('width')).toEqual('20');
420 expect(what.attr('height')).toEqual('20');
421 expect(what.attr('xlink:href')).toEqual('#crown');
422 expect(what.classed('glyph')).toBeTruthy();
423 expect(what.classed('overlay')).toBeTruthy();
424 });
Simon Hunt7ac7be92015-01-06 10:47:56 -0800425});