blob: a808c3d7afbe340a03d2023c24d4d6ed6b373855 [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 = [
92 'unknown', 'node', 'switch', 'roadm', 'endstation', 'router',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070093 'bgpSpeaker', 'chain', 'crown', 'lock', 'topo', 'refresh',
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070094 'garbage',
Bri Prebilic Cole9467a232015-05-06 16:59:05 -070095 'flowTable', 'portTable', 'groupTable',
96 'summary', 'details', 'ports', 'map', 'cycleLabels',
Bri Prebilic Cole43f17c02015-05-01 10:43:38 -070097 'oblique', 'filters', 'resetZoom', 'relatedIntents', 'nextIntent',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070098 'prevIntent', 'intentTraffic', 'allTraffic', 'flows', 'eqMaster'
Simon Hunt3074fb22015-03-31 15:06:25 -070099 ],
100 badgeIds = [
101 'uiAttached', 'checkMark', 'xMark', 'triangleUp', 'triangleDown',
102 'plus', 'minus', 'play', 'stop'
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700103 ],
104 spriteIds = [
105 'cloud'
Simon Hunt3074fb22015-03-31 15:06:25 -0700106 ];
Simon Hunt6e459802015-01-06 15:05:42 -0800107
Simon Hunt51fc40b2015-01-06 13:56:12 -0800108 beforeEach(module('onosUtil', 'onosSvg'));
Simon Hunt7ac7be92015-01-06 10:47:56 -0800109
Simon Hunt51fc40b2015-01-06 13:56:12 -0800110 beforeEach(inject(function (_$log_, FnService, GlyphService) {
Simon Huntc9b73162015-01-29 14:02:15 -0800111 var body = d3.select('body');
Simon Hunt51fc40b2015-01-06 13:56:12 -0800112 $log = _$log_;
113 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -0800114 gs = GlyphService;
Simon Huntc9b73162015-01-29 14:02:15 -0800115 d3Elem = body.append('defs').attr('id', 'myDefs');
116 svg = body.append('svg').attr('id', 'mySvg');
Simon Hunt7ac7be92015-01-06 10:47:56 -0800117 }));
118
Simon Hunt670e8252015-01-06 18:31:30 -0800119 afterEach(function () {
Simon Huntc9b73162015-01-29 14:02:15 -0800120 d3.select('#mySvg').remove();
Simon Hunt670e8252015-01-06 18:31:30 -0800121 d3.select('#myDefs').remove();
Simon Huntcacce342015-01-07 16:13:05 -0800122 gs.clear();
Simon Hunt670e8252015-01-06 18:31:30 -0800123 });
124
Simon Hunt7ac7be92015-01-06 10:47:56 -0800125 it('should define GlyphService', function () {
126 expect(gs).toBeDefined();
127 });
128
Simon Hunt6e459802015-01-06 15:05:42 -0800129 it('should define api functions', function () {
Simon Hunt51fc40b2015-01-06 13:56:12 -0800130 expect(fs.areFunctions(gs, [
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700131 'clear', 'init', 'registerGlyphs', 'registerGlyphSet',
Matteo Scandolo209c6c62016-05-21 10:08:57 -0700132 'ids', 'glyph', 'glyphDefined', 'loadDefs', 'addGlyph'
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700133 ])).toBe(true);
Simon Hunt51fc40b2015-01-06 13:56:12 -0800134 });
135
Simon Hunt6e459802015-01-06 15:05:42 -0800136 it('should start with no glyphs loaded', function () {
137 expect(gs.ids()).toEqual([]);
138 });
139
Simon Hunt58f23bb2015-01-16 16:32:24 -0800140 it('should load the base set of glyphs into the cache', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800141 gs.init();
Simon Huntbc39f6d2015-01-06 17:34:28 -0800142 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Hunt6e459802015-01-06 15:05:42 -0800143 });
144
Simon Hunt58f23bb2015-01-16 16:32:24 -0800145 it('should remove glyphs from the cache on clear', function () {
Simon Huntcacce342015-01-07 16:13:05 -0800146 gs.init();
147 expect(gs.ids().length).toEqual(numBaseGlyphs);
148 gs.clear();
149 expect(gs.ids().length).toEqual(0);
150 });
151
Simon Hunt58f23bb2015-01-16 16:32:24 -0800152 function verifyGlyphLoadedInCache(id, vbox, expPfxId) {
153 var pfxId = expPfxId || id,
154 glyph = gs.glyph(id),
155 prefix = prefixLookup[pfxId],
Simon Hunt6e459802015-01-06 15:05:42 -0800156 plen = prefix.length;
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700157 expect(fs.contains(gs.ids(), id)).toBe(true);
Simon Hunt6e459802015-01-06 15:05:42 -0800158 expect(glyph).toBeDefined();
159 expect(glyph.id).toEqual(id);
160 expect(glyph.vb).toEqual(vbox);
161 expect(glyph.d.slice(0, plen)).toEqual(prefix);
162 }
163
Matteo Scandolo209c6c62016-05-21 10:08:57 -0700164 xit('should be configured with the correct number of glyphs', function () {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700165 var nGlyphs = 1 + glyphIds.length + badgeIds.length + spriteIds.length;
166 expect(nGlyphs).toEqual(numBaseGlyphs);
Simon Hunt3074fb22015-03-31 15:06:25 -0700167 });
168
Simon Hunt6e459802015-01-06 15:05:42 -0800169 it('should load the bird glyph', function() {
170 gs.init();
Simon Hunt58f23bb2015-01-16 16:32:24 -0800171 verifyGlyphLoadedInCache('bird', vbBird);
Simon Hunt6e459802015-01-06 15:05:42 -0800172 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700173
Matteo Scandolo209c6c62016-05-21 10:08:57 -0700174 xit('should load the regular glyphs', function () {
Simon Hunt6e459802015-01-06 15:05:42 -0800175 gs.init();
Simon Hunt3074fb22015-03-31 15:06:25 -0700176 glyphIds.forEach(function (id) {
177 verifyGlyphLoadedInCache(id, vbGlyph);
Bri Prebilic Cole94a856e2015-01-19 15:16:40 -0800178 });
Simon Hunt3074fb22015-03-31 15:06:25 -0700179 });
180
181 it('should load the badge glyphs', function () {
182 gs.init();
183 badgeIds.forEach(function (id) {
184 verifyGlyphLoadedInCache(id, vbBadge);
185 });
186 });
187
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700188 it('should load the sprites', function () {
189 gs.init();
190 spriteIds.forEach(function (id) {
191 verifyGlyphLoadedInCache(id, vbGlyph);
192 });
193 });
194
Simon Huntbc39f6d2015-01-06 17:34:28 -0800195
196 // define some glyphs that we want to install
197
198 var testVbox = '0 0 1 1',
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700199 triVbox = '0 0 12 12',
200 diaVbox = '0 0 15 15',
Simon Huntbc39f6d2015-01-06 17:34:28 -0800201 dTriangle = 'M.5,.2l.3,.6,h-.6z',
202 dDiamond = 'M.2,.5l.3,-.3l.3,.3l-.3,.3z',
203 newGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700204 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800205 triangle: dTriangle,
206 diamond: dDiamond
207 },
208 dupGlyphs = {
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700209 _viewbox: testVbox,
Simon Huntbc39f6d2015-01-06 17:34:28 -0800210 router: dTriangle,
211 switch: dDiamond
212 },
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700213 altNewGlyphs = {
214 _triangle: triVbox,
215 triangle: dTriangle,
216 _diamond: diaVbox,
217 diamond: dDiamond
218 },
219 altDupGlyphs = {
220 _router: triVbox,
221 router: dTriangle,
222 _switch: diaVbox,
223 switch: dDiamond
224 },
225 badGlyphSet = {
226 triangle: dTriangle,
227 diamond: dDiamond
228 },
229 warnMsg = 'GlyphService.registerGlyphs(): ',
230 warnMsgSet = 'GlyphService.registerGlyphSet(): ',
231 idCollision = warnMsg + 'ID collision: ',
232 idCollisionSet = warnMsgSet + 'ID collision: ',
233 missVbSet = warnMsgSet + 'no "_viewbox" property found',
234 missVbCustom = warnMsg + 'Missing viewbox property: ',
235 missVbTri = missVbCustom + '"_triangle"',
236 missVbDia = missVbCustom + '"_diamond"';
Simon Huntbc39f6d2015-01-06 17:34:28 -0800237
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700238
239 it('should install new glyphs as a glyph-set', function () {
Simon Huntbc39f6d2015-01-06 17:34:28 -0800240 gs.init();
241 expect(gs.ids().length).toEqual(numBaseGlyphs);
242 spyOn($log, 'warn');
243
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700244 var ok = gs.registerGlyphSet(newGlyphs);
245 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800246 expect($log.warn).not.toHaveBeenCalled();
247
248 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800249 verifyGlyphLoadedInCache('triangle', testVbox);
250 verifyGlyphLoadedInCache('diamond', testVbox);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800251 });
252
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700253 it('should not overwrite glyphs (via glyph-set) with dup IDs', function () {
254 gs.init();
255 expect(gs.ids().length).toEqual(numBaseGlyphs);
256 spyOn($log, 'warn');
257
258 var ok = gs.registerGlyphSet(dupGlyphs);
259 expect(ok).toBe(false);
260 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"switch"');
261 expect($log.warn).toHaveBeenCalledWith(idCollisionSet + '"router"');
262
263 expect(gs.ids().length).toEqual(numBaseGlyphs);
264 // verify original glyphs still exist...
265 verifyGlyphLoadedInCache('router', vbGlyph);
266 verifyGlyphLoadedInCache('switch', vbGlyph);
267 });
268
269 it('should replace glyphs (via glyph-set) if asked nicely', function () {
270 gs.init();
271 expect(gs.ids().length).toEqual(numBaseGlyphs);
272 spyOn($log, 'warn');
273
274 var ok = gs.registerGlyphSet(dupGlyphs, true);
275 expect(ok).toBe(true);
276 expect($log.warn).not.toHaveBeenCalled();
277
278 expect(gs.ids().length).toEqual(numBaseGlyphs);
279 // verify glyphs have been overwritten...
280 verifyGlyphLoadedInCache('router', testVbox, 'triangle');
281 verifyGlyphLoadedInCache('switch', testVbox, 'diamond');
282 });
283
284 it ('should complain if missing _viewbox in a glyph-set', function () {
285 gs.init();
286 expect(gs.ids().length).toEqual(numBaseGlyphs);
287 spyOn($log, 'warn');
288
289 var ok = gs.registerGlyphSet(badGlyphSet);
290 expect(ok).toBe(false);
291 expect($log.warn).toHaveBeenCalledWith(missVbSet);
292 expect(gs.ids().length).toEqual(numBaseGlyphs);
293 });
294
295 it('should install new glyphs', function () {
296 gs.init();
297 expect(gs.ids().length).toEqual(numBaseGlyphs);
298 spyOn($log, 'warn');
299
300 var ok = gs.registerGlyphs(altNewGlyphs);
301 expect(ok).toBe(true);
302 expect($log.warn).not.toHaveBeenCalled();
303
304 expect(gs.ids().length).toEqual(numBaseGlyphs + 2);
305 verifyGlyphLoadedInCache('triangle', triVbox);
306 verifyGlyphLoadedInCache('diamond', diaVbox);
307 });
308
Simon Huntbc39f6d2015-01-06 17:34:28 -0800309 it('should not overwrite glyphs with dup IDs', function () {
310 gs.init();
311 expect(gs.ids().length).toEqual(numBaseGlyphs);
312 spyOn($log, 'warn');
313
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700314 var ok = gs.registerGlyphs(altDupGlyphs);
315 expect(ok).toBe(false);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800316 expect($log.warn).toHaveBeenCalledWith(idCollision + '"switch"');
317 expect($log.warn).toHaveBeenCalledWith(idCollision + '"router"');
318
319 expect(gs.ids().length).toEqual(numBaseGlyphs);
320 // verify original glyphs still exist...
Simon Hunt58f23bb2015-01-16 16:32:24 -0800321 verifyGlyphLoadedInCache('router', vbGlyph);
322 verifyGlyphLoadedInCache('switch', vbGlyph);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800323 });
324
325 it('should replace glyphs if asked nicely', function () {
326 gs.init();
327 expect(gs.ids().length).toEqual(numBaseGlyphs);
328 spyOn($log, 'warn');
329
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700330 var ok = gs.registerGlyphs(altDupGlyphs, true);
331 expect(ok).toBe(true);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800332 expect($log.warn).not.toHaveBeenCalled();
333
334 expect(gs.ids().length).toEqual(numBaseGlyphs);
335 // verify glyphs have been overwritten...
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700336 verifyGlyphLoadedInCache('router', triVbox, 'triangle');
337 verifyGlyphLoadedInCache('switch', diaVbox, 'diamond');
338 });
339
340 it ('should complain if missing custom viewbox', function () {
341 gs.init();
342 expect(gs.ids().length).toEqual(numBaseGlyphs);
343 spyOn($log, 'warn');
344
345 var ok = gs.registerGlyphs(badGlyphSet);
346 expect(ok).toBe(false);
347 expect($log.warn).toHaveBeenCalledWith(missVbTri);
348 expect($log.warn).toHaveBeenCalledWith(missVbDia);
349 expect(gs.ids().length).toEqual(numBaseGlyphs);
Simon Huntbc39f6d2015-01-06 17:34:28 -0800350 });
Simon Hunt670e8252015-01-06 18:31:30 -0800351
352 function verifyPathPrefix(elem, prefix) {
353 var plen = prefix.length,
354 d = elem.select('path').attr('d');
355 expect(d.slice(0, plen)).toEqual(prefix);
356 }
357
Simon Hunt58f23bb2015-01-16 16:32:24 -0800358 function verifyLoadedInDom(id, vb, expPfxId) {
359 var pfxId = expPfxId || id,
360 symbol = d3Elem.select('#' + id);
361 expect(symbol.size()).toEqual(1);
362 expect(symbol.attr('viewBox')).toEqual(vb);
363 verifyPathPrefix(symbol, prefixLookup[pfxId]);
364 }
365
Simon Hunt670e8252015-01-06 18:31:30 -0800366 it('should load base glyphs into the DOM', function () {
367 gs.init();
368 gs.loadDefs(d3Elem);
369 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800370 verifyLoadedInDom('bgpSpeaker', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800371 });
372
373 it('should load custom glyphs into the DOM', function () {
374 gs.init();
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700375 gs.registerGlyphSet(newGlyphs);
Simon Hunt670e8252015-01-06 18:31:30 -0800376 gs.loadDefs(d3Elem);
377 expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs + 2);
Simon Hunt58f23bb2015-01-16 16:32:24 -0800378 verifyLoadedInDom('diamond', testVbox);
379 });
Simon Hunt670e8252015-01-06 18:31:30 -0800380
Simon Hunt58f23bb2015-01-16 16:32:24 -0800381 it('should load only specified glyphs into the DOM', function () {
382 gs.init();
383 gs.loadDefs(d3Elem, ['crown', 'chain', 'node']);
384 expect(d3Elem.selectAll('symbol').size()).toEqual(3);
385 verifyLoadedInDom('crown', vbGlyph);
386 verifyLoadedInDom('chain', vbGlyph);
387 verifyLoadedInDom('node', vbGlyph);
Simon Hunt670e8252015-01-06 18:31:30 -0800388 });
Simon Huntc9b73162015-01-29 14:02:15 -0800389
390 it('should add a glyph with default size', function () {
391 gs.init();
Simon Hunt4b668592015-01-29 17:33:53 -0800392 var retval = gs.addGlyph(svg, 'crown');
Simon Huntc9b73162015-01-29 14:02:15 -0800393 var what = svg.selectAll('use');
394 expect(what.size()).toEqual(1);
395 expect(what.attr('width')).toEqual('40');
396 expect(what.attr('height')).toEqual('40');
397 expect(what.attr('xlink:href')).toEqual('#crown');
398 expect(what.classed('glyph')).toBeTruthy();
399 expect(what.classed('overlay')).toBeFalsy();
Simon Hunt4b668592015-01-29 17:33:53 -0800400
401 // check a couple on retval, which should be the same thing..
402 expect(retval.attr('xlink:href')).toEqual('#crown');
403 expect(retval.classed('glyph')).toBeTruthy();
Simon Huntc9b73162015-01-29 14:02:15 -0800404 });
405
406 it('should add a glyph with given size', function () {
407 gs.init();
408 gs.addGlyph(svg, 'crown', 37);
409 var what = svg.selectAll('use');
410 expect(what.size()).toEqual(1);
411 expect(what.attr('width')).toEqual('37');
412 expect(what.attr('height')).toEqual('37');
413 expect(what.attr('xlink:href')).toEqual('#crown');
414 expect(what.classed('glyph')).toBeTruthy();
415 expect(what.classed('overlay')).toBeFalsy();
416 });
417
418 it('should add a glyph marked as overlay', function () {
419 gs.init();
420 gs.addGlyph(svg, 'crown', 20, true);
421 var what = svg.selectAll('use');
422 expect(what.size()).toEqual(1);
423 expect(what.attr('width')).toEqual('20');
424 expect(what.attr('height')).toEqual('20');
425 expect(what.attr('xlink:href')).toEqual('#crown');
426 expect(what.classed('glyph')).toBeTruthy();
427 expect(what.classed('overlay')).toBeTruthy();
428 });
Simon Hunt7ac7be92015-01-06 10:47:56 -0800429});