blob: a11644da425baecea63e4e3d099af81d1da39328 [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 -- Icon Service - Unit Tests
19
20 @author Simon Hunt
21 */
22describe('factory: fw/svg/icon.js', function() {
Simon Hunt7f172cc2015-01-16 17:43:00 -080023 var is, d3Elem;
24
25 var viewBox = '0 0 50 50',
26 glyphSize = '50',
27 iconSize = '20';
28
Simon Hunt7ac7be92015-01-06 10:47:56 -080029
30 beforeEach(module('onosSvg'));
31
32 beforeEach(inject(function (IconService) {
33 is = IconService;
Simon Hunt7f172cc2015-01-16 17:43:00 -080034 d3Elem = d3.select('body').append('div').attr('id', 'myDiv');
Simon Hunt7ac7be92015-01-06 10:47:56 -080035 }));
36
Simon Hunt7f172cc2015-01-16 17:43:00 -080037 afterEach(function () {
38 d3.select('#myDiv').remove();
39 });
40
Simon Hunt7ac7be92015-01-06 10:47:56 -080041 it('should define IconService', function () {
42 expect(is).toBeDefined();
43 });
44
Simon Hunt7f172cc2015-01-16 17:43:00 -080045 function checkElemSize(elem, dim) {
46 expect(elem.attr('width')).toEqual(dim);
47 expect(elem.attr('height')).toEqual(dim);
48 }
49
50 function verifyIconStructure(iconClass, useHref, iSize, vBox, gSize) {
51 var isz = iSize || iconSize,
52 vbx = vBox || viewBox,
53 gsz = gSize || glyphSize;
54
55 var svg = d3Elem.selectAll('svg');
56 expect(svg.size()).toBe(1);
57 checkElemSize(svg, isz);
58 expect(svg.attr('viewBox')).toEqual(vbx);
59
60 var g = svg.selectAll('g');
61 expect(g.size()).toBe(1);
62 expect(g.classed('icon')).toBeTruthy();
63 expect(g.classed(iconClass)).toBeTruthy();
64
65 var rect = g.select('rect');
66 expect(rect.size()).toBe(1);
67 checkElemSize(rect, gsz);
Simon Hunt97225382015-01-19 13:33:09 -080068 expect(rect.attr('rx')).toEqual('5');
Simon Hunt7f172cc2015-01-16 17:43:00 -080069
70 var use = g.select('use');
71 expect(use.classed('glyph')).toBeTruthy();
72 expect(use.attr('xlink:href')).toEqual(useHref);
73 checkElemSize(use, gsz);
74 }
75
76
77 it('should load an icon into a div', function () {
78 expect(d3Elem.html()).toEqual('');
79 is.loadIcon(d3Elem, 'deviceOnline');
80 verifyIconStructure('deviceOnline', '#checkMark');
81 });
82
83 it('should allow us to specify the icon size', function () {
84 expect(d3Elem.html()).toEqual('');
85 is.loadIcon(d3Elem, 'deviceOffline', 32);
86 verifyIconStructure('deviceOffline', '#xMark', '32');
87 });
88
Simon Hunt7ac7be92015-01-06 10:47:56 -080089});