blob: f6c4036cadfadad71689b1ae0a0184cf5860dc1e [file] [log] [blame]
Simon Hunt7ac7be92015-01-06 10:47:56 -08001/*
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
19
20 @author Simon Hunt
21 */
22describe('factory: fw/svg/glyph.js', function() {
Simon Hunt51fc40b2015-01-06 13:56:12 -080023 var $log, fs, gs;
Simon Hunt7ac7be92015-01-06 10:47:56 -080024
Simon Hunt6e459802015-01-06 15:05:42 -080025 var vbBird = '352 224 113 112',
26 vbGlyph = '0 0 110 110',
27 vbBadge = '0 0 10 10';
28
Simon Hunt51fc40b2015-01-06 13:56:12 -080029 beforeEach(module('onosUtil', 'onosSvg'));
Simon Hunt7ac7be92015-01-06 10:47:56 -080030
Simon Hunt51fc40b2015-01-06 13:56:12 -080031 beforeEach(inject(function (_$log_, FnService, GlyphService) {
32 $log = _$log_;
33 fs = FnService;
Simon Hunt7ac7be92015-01-06 10:47:56 -080034 gs = GlyphService;
35 }));
36
37 it('should define GlyphService', function () {
38 expect(gs).toBeDefined();
39 });
40
Simon Hunt6e459802015-01-06 15:05:42 -080041 it('should define api functions', function () {
Simon Hunt51fc40b2015-01-06 13:56:12 -080042 expect(fs.areFunctions(gs, [
Simon Hunt6e459802015-01-06 15:05:42 -080043 'init', 'register', 'ids', 'glyph', 'loadDefs'
Simon Hunt51fc40b2015-01-06 13:56:12 -080044 ])).toBeTruthy();
45 });
46
Simon Hunt6e459802015-01-06 15:05:42 -080047 it('should start with no glyphs loaded', function () {
48 expect(gs.ids()).toEqual([]);
49 });
50
51 it('should load the base set of glyphs', function () {
52 gs.init();
53 expect(gs.ids().length).toEqual(11);
54 });
55
56 function verifyGlyphLoaded(id, vbox, prefix) {
57 var glyph = gs.glyph(id),
58 plen = prefix.length;
59 expect(fs.contains(gs.ids(), id)).toBeTruthy();
60 expect(glyph).toBeDefined();
61 expect(glyph.id).toEqual(id);
62 expect(glyph.vb).toEqual(vbox);
63 expect(glyph.d.slice(0, plen)).toEqual(prefix);
64 }
65
66 it('should load the bird glyph', function() {
67 gs.init();
68 verifyGlyphLoaded('bird', vbBird, 'M427.7,300.4');
69 });
70 it('should load the unknown glyph', function() {
71 gs.init();
72 verifyGlyphLoaded('unknown', vbGlyph, 'M35,40a5');
73 });
74 it('should load the node glyph', function() {
75 gs.init();
76 verifyGlyphLoaded('node', vbGlyph, 'M15,100a5');
77 });
78 it('should load the switch glyph', function() {
79 gs.init();
80 verifyGlyphLoaded('switch', vbGlyph, 'M10,20a10');
81 });
82 it('should load the roadm glyph', function() {
83 gs.init();
84 verifyGlyphLoaded('roadm', vbGlyph, 'M10,35l25-');
85 });
86 it('should load the endstation glyph', function() {
87 gs.init();
88 verifyGlyphLoaded('endstation', vbGlyph, 'M10,15a5,5');
89 });
90 it('should load the router glyph', function() {
91 gs.init();
92 verifyGlyphLoaded('router', vbGlyph, 'M10,55A45,45');
93 });
94 it('should load the bgpSpeaker glyph', function() {
95 gs.init();
96 verifyGlyphLoaded('bgpSpeaker', vbGlyph, 'M10,40a45,35');
97 });
98 it('should load the chain glyph', function() {
99 gs.init();
100 verifyGlyphLoaded('chain', vbGlyph, 'M60.4,77.6c-');
101 });
102 it('should load the crown glyph', function() {
103 gs.init();
104 verifyGlyphLoaded('crown', vbGlyph, 'M99.5,21.6c0');
105 });
106 it('should load the uiAttached glyph', function() {
107 gs.init();
108 verifyGlyphLoaded('uiAttached', vbBadge, 'M2,2.5a.5,.5');
109 });
Simon Hunt7ac7be92015-01-06 10:47:56 -0800110});