Simon Hunt | a1028c4 | 2017-02-07 20:08:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present 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 -- Sprite Service - Unit Tests |
| 19 | */ |
| 20 | |
| 21 | describe('factory: fw/svg/sprite.js', function () { |
| 22 | var $log, fs, ss, d3Elem, svg; |
| 23 | |
| 24 | // config... |
| 25 | var numBaseSprites = 1, |
| 26 | sampleData = 'M91.2,48.4C121.2,6.3,187.9-13.4,219,45.6'; |
| 27 | |
| 28 | // load modules we need |
| 29 | beforeEach(module('onosUtil', 'onosSvg')); |
| 30 | |
| 31 | // inject the services we need |
| 32 | beforeEach(inject(function (_$log_, FnService, SpriteService) { |
| 33 | var body = d3.select('body'); |
| 34 | $log = _$log_; |
| 35 | fs = FnService; |
| 36 | ss = SpriteService; |
| 37 | |
| 38 | // NOTE: once we get to loading sprites into the DOM, we'll need these: |
| 39 | // d3Elem = body.append('defs').attr('id', 'myDefs'); |
| 40 | // svg = body.append('svg').attr('id', 'mySvg'); |
| 41 | })); |
| 42 | |
| 43 | // clean up after each test |
| 44 | afterEach(function () { |
| 45 | // d3.select('#mySvg').remove(); |
| 46 | // d3.select('#myDefs').remove(); |
| 47 | ss.clear(); |
| 48 | }); |
| 49 | |
| 50 | // === UNIT TESTS === |
| 51 | |
| 52 | it('should define SpriteService', function () { |
| 53 | expect(ss).toBeDefined(); |
| 54 | }); |
| 55 | |
| 56 | it('should define api functions', function () { |
| 57 | expect(fs.areFunctions(ss, [ |
| 58 | 'clear', 'init', |
| 59 | 'createSprite', 'createLayout', |
| 60 | 'registerSprite', 'registerLayout', |
| 61 | 'sprite', 'layout', |
| 62 | 'count', 'dump' |
| 63 | ])).toBe(true); |
| 64 | }); |
| 65 | |
| 66 | it('should start no sprites or layouts', function () { |
| 67 | var c = ss.count(); |
| 68 | expect(c.sprites).toBe(0); |
| 69 | expect(c.layouts).toBe(0); |
| 70 | }); |
| 71 | |
| 72 | // Programmatic build of a sprite |
| 73 | it('should register a simple sprite', function () { |
| 74 | ss.createSprite('foo', 303, 185) |
| 75 | .addPath(sampleData) |
| 76 | .register(); |
| 77 | |
| 78 | expect(ss.count().sprites).toBe(1); |
| 79 | |
| 80 | var s = ss.sprite('foo'); |
| 81 | expect(s).toBeDefined(); |
| 82 | // TODO: verify internal structure of sprite |
| 83 | |
| 84 | }); |
| 85 | }); |