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