Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 1 | /* |
| 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 Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 19 | */ |
| 20 | describe('factory: fw/svg/glyph.js', function() { |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 21 | var $log, fs, gs, d3Elem, svg; |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 22 | |
Bri Prebilic Cole | db4b87b | 2015-03-25 09:18:42 -0700 | [diff] [blame] | 23 | var numBaseGlyphs = 22, |
Simon Hunt | bc39f6d | 2015-01-06 17:34:28 -0800 | [diff] [blame] | 24 | vbBird = '352 224 113 112', |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 25 | vbGlyph = '0 0 110 110', |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 26 | vbBadge = '0 0 10 10', |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 27 | 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 ', |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 29 | prefixLookup = { |
| 30 | bird: 'M427.7,300.4', |
| 31 | unknown: 'M35,40a5', |
| 32 | node: 'M15,100a5', |
| 33 | switch: 'M10,20a10', |
| 34 | roadm: 'M10,35l25-', |
| 35 | endstation: 'M10,15a5,5', |
| 36 | router: 'M10,55A45,45', |
| 37 | bgpSpeaker: 'M10,40a45,35', |
| 38 | chain: 'M60.4,77.6c-', |
| 39 | crown: 'M99.5,21.6c0,', |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 40 | summary: longPrefix + 'M16.7', |
| 41 | details: longPrefix + 'M16.9', |
| 42 | ports: 'M98,9.2H79.6c', |
| 43 | map: 'M95.8,9.2H14.2c-2.8,0-5,2.2-5,5v66', |
Bri Prebilic Cole | db4b87b | 2015-03-25 09:18:42 -0700 | [diff] [blame] | 44 | resetZoom: 'M86.4,81', |
| 45 | nextIntent: 'M88.1,55.7', |
| 46 | prevIntent: 'M22.5,55.6', |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 47 | |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 48 | uiAttached: 'M2,2.5a.5,.5', |
Simon Hunt | aa26adf | 2015-01-20 10:32:49 -0800 | [diff] [blame] | 49 | checkMark: 'M2.6,4.5c0', |
| 50 | xMark: 'M9.0,7.2C8.2', |
Bri Prebilic Cole | 1dc32e6 | 2015-02-03 09:44:33 -0800 | [diff] [blame] | 51 | triangleUp: 'M0.5,6.2c0', |
| 52 | triangleDown: 'M9.5,4.2c0', |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 53 | |
| 54 | // our test ones.. |
| 55 | triangle: 'M.5,.2', |
| 56 | diamond: 'M.2,.5' |
| 57 | }; |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 58 | |
Simon Hunt | 51fc40b | 2015-01-06 13:56:12 -0800 | [diff] [blame] | 59 | beforeEach(module('onosUtil', 'onosSvg')); |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 60 | |
Simon Hunt | 51fc40b | 2015-01-06 13:56:12 -0800 | [diff] [blame] | 61 | beforeEach(inject(function (_$log_, FnService, GlyphService) { |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 62 | var body = d3.select('body'); |
Simon Hunt | 51fc40b | 2015-01-06 13:56:12 -0800 | [diff] [blame] | 63 | $log = _$log_; |
| 64 | fs = FnService; |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 65 | gs = GlyphService; |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 66 | d3Elem = body.append('defs').attr('id', 'myDefs'); |
| 67 | svg = body.append('svg').attr('id', 'mySvg'); |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 68 | })); |
| 69 | |
Simon Hunt | 670e825 | 2015-01-06 18:31:30 -0800 | [diff] [blame] | 70 | afterEach(function () { |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 71 | d3.select('#mySvg').remove(); |
Simon Hunt | 670e825 | 2015-01-06 18:31:30 -0800 | [diff] [blame] | 72 | d3.select('#myDefs').remove(); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 73 | gs.clear(); |
Simon Hunt | 670e825 | 2015-01-06 18:31:30 -0800 | [diff] [blame] | 74 | }); |
| 75 | |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 76 | it('should define GlyphService', function () { |
| 77 | expect(gs).toBeDefined(); |
| 78 | }); |
| 79 | |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 80 | it('should define api functions', function () { |
Simon Hunt | 51fc40b | 2015-01-06 13:56:12 -0800 | [diff] [blame] | 81 | expect(fs.areFunctions(gs, [ |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 82 | 'clear', 'init', 'register', 'ids', 'glyph', 'loadDefs', 'addGlyph' |
Simon Hunt | 51fc40b | 2015-01-06 13:56:12 -0800 | [diff] [blame] | 83 | ])).toBeTruthy(); |
| 84 | }); |
| 85 | |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 86 | it('should start with no glyphs loaded', function () { |
| 87 | expect(gs.ids()).toEqual([]); |
| 88 | }); |
| 89 | |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 90 | it('should load the base set of glyphs into the cache', function () { |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 91 | gs.init(); |
Simon Hunt | bc39f6d | 2015-01-06 17:34:28 -0800 | [diff] [blame] | 92 | expect(gs.ids().length).toEqual(numBaseGlyphs); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 93 | }); |
| 94 | |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 95 | it('should remove glyphs from the cache on clear', function () { |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 96 | gs.init(); |
| 97 | expect(gs.ids().length).toEqual(numBaseGlyphs); |
| 98 | gs.clear(); |
| 99 | expect(gs.ids().length).toEqual(0); |
| 100 | }); |
| 101 | |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 102 | function verifyGlyphLoadedInCache(id, vbox, expPfxId) { |
| 103 | var pfxId = expPfxId || id, |
| 104 | glyph = gs.glyph(id), |
| 105 | prefix = prefixLookup[pfxId], |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 106 | plen = prefix.length; |
| 107 | expect(fs.contains(gs.ids(), id)).toBeTruthy(); |
| 108 | expect(glyph).toBeDefined(); |
| 109 | expect(glyph.id).toEqual(id); |
| 110 | expect(glyph.vb).toEqual(vbox); |
| 111 | expect(glyph.d.slice(0, plen)).toEqual(prefix); |
| 112 | } |
| 113 | |
| 114 | it('should load the bird glyph', function() { |
| 115 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 116 | verifyGlyphLoadedInCache('bird', vbBird); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 117 | }); |
| 118 | it('should load the unknown glyph', function() { |
| 119 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 120 | verifyGlyphLoadedInCache('unknown', vbGlyph); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 121 | }); |
| 122 | it('should load the node glyph', function() { |
| 123 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 124 | verifyGlyphLoadedInCache('node', vbGlyph); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 125 | }); |
| 126 | it('should load the switch glyph', function() { |
| 127 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 128 | verifyGlyphLoadedInCache('switch', vbGlyph); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 129 | }); |
| 130 | it('should load the roadm glyph', function() { |
| 131 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 132 | verifyGlyphLoadedInCache('roadm', vbGlyph); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 133 | }); |
| 134 | it('should load the endstation glyph', function() { |
| 135 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 136 | verifyGlyphLoadedInCache('endstation', vbGlyph); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 137 | }); |
| 138 | it('should load the router glyph', function() { |
| 139 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 140 | verifyGlyphLoadedInCache('router', vbGlyph); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 141 | }); |
| 142 | it('should load the bgpSpeaker glyph', function() { |
| 143 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 144 | verifyGlyphLoadedInCache('bgpSpeaker', vbGlyph); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 145 | }); |
| 146 | it('should load the chain glyph', function() { |
| 147 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 148 | verifyGlyphLoadedInCache('chain', vbGlyph); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 149 | }); |
| 150 | it('should load the crown glyph', function() { |
| 151 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 152 | verifyGlyphLoadedInCache('crown', vbGlyph); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 153 | }); |
Bri Prebilic Cole | deca6e9 | 2015-03-19 12:03:14 -0700 | [diff] [blame] | 154 | it('should load the summary glyph', function () { |
| 155 | gs.init(); |
| 156 | verifyGlyphLoadedInCache('summary', vbGlyph); |
| 157 | }); |
| 158 | it('should load the details glyph', function () { |
| 159 | gs.init(); |
| 160 | verifyGlyphLoadedInCache('details', vbGlyph); |
| 161 | }); |
| 162 | it('should load the ports glyph', function () { |
| 163 | gs.init(); |
| 164 | verifyGlyphLoadedInCache('ports', vbGlyph); |
| 165 | }); |
| 166 | it('should load the map glyph', function () { |
| 167 | gs.init(); |
| 168 | verifyGlyphLoadedInCache('map', vbGlyph); |
| 169 | }); |
Bri Prebilic Cole | db4b87b | 2015-03-25 09:18:42 -0700 | [diff] [blame] | 170 | it('should load the resetZoom glyph', function () { |
| 171 | gs.init(); |
| 172 | verifyGlyphLoadedInCache('resetZoom', vbGlyph); |
| 173 | }); |
| 174 | it('should load the nextIntent glyph', function () { |
| 175 | gs.init(); |
| 176 | verifyGlyphLoadedInCache('nextIntent', vbGlyph); |
| 177 | }); |
| 178 | it('should load the prevIntent glyph', function () { |
| 179 | gs.init(); |
| 180 | verifyGlyphLoadedInCache('prevIntent', vbGlyph); |
| 181 | }); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 182 | it('should load the uiAttached glyph', function() { |
| 183 | gs.init(); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 184 | verifyGlyphLoadedInCache('uiAttached', vbBadge); |
Simon Hunt | 6e45980 | 2015-01-06 15:05:42 -0800 | [diff] [blame] | 185 | }); |
Bri Prebilic Cole | 94a856e | 2015-01-19 15:16:40 -0800 | [diff] [blame] | 186 | it('should load the checkMark glyph', function() { |
| 187 | gs.init(); |
| 188 | verifyGlyphLoadedInCache('checkMark', vbBadge); |
| 189 | }); |
| 190 | it('should load the xMark glyph', function() { |
| 191 | gs.init(); |
| 192 | verifyGlyphLoadedInCache('xMark', vbBadge); |
| 193 | }); |
Simon Hunt | bc39f6d | 2015-01-06 17:34:28 -0800 | [diff] [blame] | 194 | |
| 195 | // define some glyphs that we want to install |
| 196 | |
| 197 | var testVbox = '0 0 1 1', |
| 198 | dTriangle = 'M.5,.2l.3,.6,h-.6z', |
| 199 | dDiamond = 'M.2,.5l.3,-.3l.3,.3l-.3,.3z', |
| 200 | newGlyphs = { |
| 201 | triangle: dTriangle, |
| 202 | diamond: dDiamond |
| 203 | }, |
| 204 | dupGlyphs = { |
| 205 | router: dTriangle, |
| 206 | switch: dDiamond |
| 207 | }, |
| 208 | idCollision = 'GlyphService.register(): ID collision: '; |
| 209 | |
| 210 | it('should install new glyphs', function () { |
| 211 | gs.init(); |
| 212 | expect(gs.ids().length).toEqual(numBaseGlyphs); |
| 213 | spyOn($log, 'warn'); |
| 214 | |
| 215 | var ok = gs.register(testVbox, newGlyphs); |
| 216 | expect(ok).toBeTruthy(); |
| 217 | expect($log.warn).not.toHaveBeenCalled(); |
| 218 | |
| 219 | expect(gs.ids().length).toEqual(numBaseGlyphs + 2); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 220 | verifyGlyphLoadedInCache('triangle', testVbox); |
| 221 | verifyGlyphLoadedInCache('diamond', testVbox); |
Simon Hunt | bc39f6d | 2015-01-06 17:34:28 -0800 | [diff] [blame] | 222 | }); |
| 223 | |
| 224 | it('should not overwrite glyphs with dup IDs', function () { |
| 225 | gs.init(); |
| 226 | expect(gs.ids().length).toEqual(numBaseGlyphs); |
| 227 | spyOn($log, 'warn'); |
| 228 | |
| 229 | var ok = gs.register(testVbox, dupGlyphs); |
| 230 | expect(ok).toBeFalsy(); |
| 231 | expect($log.warn).toHaveBeenCalledWith(idCollision + '"switch"'); |
| 232 | expect($log.warn).toHaveBeenCalledWith(idCollision + '"router"'); |
| 233 | |
| 234 | expect(gs.ids().length).toEqual(numBaseGlyphs); |
| 235 | // verify original glyphs still exist... |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 236 | verifyGlyphLoadedInCache('router', vbGlyph); |
| 237 | verifyGlyphLoadedInCache('switch', vbGlyph); |
Simon Hunt | bc39f6d | 2015-01-06 17:34:28 -0800 | [diff] [blame] | 238 | }); |
| 239 | |
| 240 | it('should replace glyphs if asked nicely', function () { |
| 241 | gs.init(); |
| 242 | expect(gs.ids().length).toEqual(numBaseGlyphs); |
| 243 | spyOn($log, 'warn'); |
| 244 | |
| 245 | var ok = gs.register(testVbox, dupGlyphs, true); |
| 246 | expect(ok).toBeTruthy(); |
| 247 | expect($log.warn).not.toHaveBeenCalled(); |
| 248 | |
| 249 | expect(gs.ids().length).toEqual(numBaseGlyphs); |
| 250 | // verify glyphs have been overwritten... |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 251 | verifyGlyphLoadedInCache('router', testVbox, 'triangle'); |
| 252 | verifyGlyphLoadedInCache('switch', testVbox, 'diamond'); |
Simon Hunt | bc39f6d | 2015-01-06 17:34:28 -0800 | [diff] [blame] | 253 | }); |
Simon Hunt | 670e825 | 2015-01-06 18:31:30 -0800 | [diff] [blame] | 254 | |
| 255 | function verifyPathPrefix(elem, prefix) { |
| 256 | var plen = prefix.length, |
| 257 | d = elem.select('path').attr('d'); |
| 258 | expect(d.slice(0, plen)).toEqual(prefix); |
| 259 | } |
| 260 | |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 261 | function verifyLoadedInDom(id, vb, expPfxId) { |
| 262 | var pfxId = expPfxId || id, |
| 263 | symbol = d3Elem.select('#' + id); |
| 264 | expect(symbol.size()).toEqual(1); |
| 265 | expect(symbol.attr('viewBox')).toEqual(vb); |
| 266 | verifyPathPrefix(symbol, prefixLookup[pfxId]); |
| 267 | } |
| 268 | |
Simon Hunt | 670e825 | 2015-01-06 18:31:30 -0800 | [diff] [blame] | 269 | it('should load base glyphs into the DOM', function () { |
| 270 | gs.init(); |
| 271 | gs.loadDefs(d3Elem); |
| 272 | expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 273 | verifyLoadedInDom('bgpSpeaker', vbGlyph); |
Simon Hunt | 670e825 | 2015-01-06 18:31:30 -0800 | [diff] [blame] | 274 | }); |
| 275 | |
| 276 | it('should load custom glyphs into the DOM', function () { |
| 277 | gs.init(); |
| 278 | gs.register(testVbox, newGlyphs); |
| 279 | gs.loadDefs(d3Elem); |
| 280 | expect(d3Elem.selectAll('symbol').size()).toEqual(numBaseGlyphs + 2); |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 281 | verifyLoadedInDom('diamond', testVbox); |
| 282 | }); |
Simon Hunt | 670e825 | 2015-01-06 18:31:30 -0800 | [diff] [blame] | 283 | |
Simon Hunt | 58f23bb | 2015-01-16 16:32:24 -0800 | [diff] [blame] | 284 | it('should load only specified glyphs into the DOM', function () { |
| 285 | gs.init(); |
| 286 | gs.loadDefs(d3Elem, ['crown', 'chain', 'node']); |
| 287 | expect(d3Elem.selectAll('symbol').size()).toEqual(3); |
| 288 | verifyLoadedInDom('crown', vbGlyph); |
| 289 | verifyLoadedInDom('chain', vbGlyph); |
| 290 | verifyLoadedInDom('node', vbGlyph); |
Simon Hunt | 670e825 | 2015-01-06 18:31:30 -0800 | [diff] [blame] | 291 | }); |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 292 | |
| 293 | it('should add a glyph with default size', function () { |
| 294 | gs.init(); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 295 | var retval = gs.addGlyph(svg, 'crown'); |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 296 | var what = svg.selectAll('use'); |
| 297 | expect(what.size()).toEqual(1); |
| 298 | expect(what.attr('width')).toEqual('40'); |
| 299 | expect(what.attr('height')).toEqual('40'); |
| 300 | expect(what.attr('xlink:href')).toEqual('#crown'); |
| 301 | expect(what.classed('glyph')).toBeTruthy(); |
| 302 | expect(what.classed('overlay')).toBeFalsy(); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 303 | |
| 304 | // check a couple on retval, which should be the same thing.. |
| 305 | expect(retval.attr('xlink:href')).toEqual('#crown'); |
| 306 | expect(retval.classed('glyph')).toBeTruthy(); |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 307 | }); |
| 308 | |
| 309 | it('should add a glyph with given size', function () { |
| 310 | gs.init(); |
| 311 | gs.addGlyph(svg, 'crown', 37); |
| 312 | var what = svg.selectAll('use'); |
| 313 | expect(what.size()).toEqual(1); |
| 314 | expect(what.attr('width')).toEqual('37'); |
| 315 | expect(what.attr('height')).toEqual('37'); |
| 316 | expect(what.attr('xlink:href')).toEqual('#crown'); |
| 317 | expect(what.classed('glyph')).toBeTruthy(); |
| 318 | expect(what.classed('overlay')).toBeFalsy(); |
| 319 | }); |
| 320 | |
| 321 | it('should add a glyph marked as overlay', function () { |
| 322 | gs.init(); |
| 323 | gs.addGlyph(svg, 'crown', 20, true); |
| 324 | var what = svg.selectAll('use'); |
| 325 | expect(what.size()).toEqual(1); |
| 326 | expect(what.attr('width')).toEqual('20'); |
| 327 | expect(what.attr('height')).toEqual('20'); |
| 328 | expect(what.attr('xlink:href')).toEqual('#crown'); |
| 329 | expect(what.classed('glyph')).toBeTruthy(); |
| 330 | expect(what.classed('overlay')).toBeTruthy(); |
| 331 | }); |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 332 | }); |