blob: bb203a7f5afed1e10125acf086a21baa5e0fbb4e [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
Simon Hunt7ac7be92015-01-06 10:47:56 -080019 */
20describe('factory: fw/svg/icon.js', function() {
Simon Hunt7f172cc2015-01-16 17:43:00 -080021 var is, d3Elem;
22
23 var viewBox = '0 0 50 50',
24 glyphSize = '50',
25 iconSize = '20';
26
Simon Hunt7ac7be92015-01-06 10:47:56 -080027
28 beforeEach(module('onosSvg'));
29
30 beforeEach(inject(function (IconService) {
31 is = IconService;
Simon Hunt7f172cc2015-01-16 17:43:00 -080032 d3Elem = d3.select('body').append('div').attr('id', 'myDiv');
Simon Hunt7ac7be92015-01-06 10:47:56 -080033 }));
34
Simon Hunt7f172cc2015-01-16 17:43:00 -080035 afterEach(function () {
36 d3.select('#myDiv').remove();
37 });
38
Simon Hunt7ac7be92015-01-06 10:47:56 -080039 it('should define IconService', function () {
40 expect(is).toBeDefined();
41 });
42
Simon Hunt7f172cc2015-01-16 17:43:00 -080043 function checkElemSize(elem, dim) {
44 expect(elem.attr('width')).toEqual(dim);
45 expect(elem.attr('height')).toEqual(dim);
46 }
47
48 function verifyIconStructure(iconClass, useHref, iSize, vBox, gSize) {
49 var isz = iSize || iconSize,
50 vbx = vBox || viewBox,
51 gsz = gSize || glyphSize;
52
53 var svg = d3Elem.selectAll('svg');
54 expect(svg.size()).toBe(1);
55 checkElemSize(svg, isz);
56 expect(svg.attr('viewBox')).toEqual(vbx);
57
58 var g = svg.selectAll('g');
59 expect(g.size()).toBe(1);
60 expect(g.classed('icon')).toBeTruthy();
61 expect(g.classed(iconClass)).toBeTruthy();
62
63 var rect = g.select('rect');
64 expect(rect.size()).toBe(1);
65 checkElemSize(rect, gsz);
Simon Hunt97225382015-01-19 13:33:09 -080066 expect(rect.attr('rx')).toEqual('5');
Simon Hunt7f172cc2015-01-16 17:43:00 -080067
68 var use = g.select('use');
69 expect(use.classed('glyph')).toBeTruthy();
70 expect(use.attr('xlink:href')).toEqual(useHref);
71 checkElemSize(use, gsz);
72 }
73
74
75 it('should load an icon into a div', function () {
76 expect(d3Elem.html()).toEqual('');
77 is.loadIcon(d3Elem, 'deviceOnline');
78 verifyIconStructure('deviceOnline', '#checkMark');
79 });
80
81 it('should allow us to specify the icon size', function () {
82 expect(d3Elem.html()).toEqual('');
83 is.loadIcon(d3Elem, 'deviceOffline', 32);
84 verifyIconStructure('deviceOffline', '#xMark', '32');
85 });
86
Simon Hunt7ac7be92015-01-06 10:47:56 -080087});