blob: 365869b0fe67644ce8af70a70aafce8da998e88b [file] [log] [blame]
Simon Hunt7ac7be92015-01-06 10:47:56 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt7ac7be92015-01-06 10:47:56 -08003 *
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
Bri Prebilic Coledee46622015-02-03 16:36:11 -080068 if (useHref) {
69 var use = g.select('use');
70 expect(use.classed('glyph')).toBeTruthy();
71 expect(use.attr('xlink:href')).toEqual(useHref);
72 checkElemSize(use, gsz);
73 }
Simon Hunt7f172cc2015-01-16 17:43:00 -080074 }
75
Simon Hunt7f172cc2015-01-16 17:43:00 -080076 it('should load an icon into a div', function () {
77 expect(d3Elem.html()).toEqual('');
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070078 is.loadIconByClass(d3Elem, 'active');
79 verifyIconStructure('active', '#checkMark');
Simon Hunt7f172cc2015-01-16 17:43:00 -080080 });
81
82 it('should allow us to specify the icon size', function () {
83 expect(d3Elem.html()).toEqual('');
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070084 is.loadIconByClass(d3Elem, 'inactive', 32);
85 verifyIconStructure('inactive', '#xMark', '32');
Simon Hunt7f172cc2015-01-16 17:43:00 -080086 });
87
Bri Prebilic Coledee46622015-02-03 16:36:11 -080088 it('should verify triangleUp icon', function () {
89 expect(d3Elem.html()).toEqual('');
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070090 is.loadIconByClass(d3Elem, 'upArrow', 10);
91 verifyIconStructure('upArrow', '#triangleUp', '10');
Bri Prebilic Coledee46622015-02-03 16:36:11 -080092 });
93
94 it('should verify triangleDown icon', function () {
95 expect(d3Elem.html()).toEqual('');
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070096 is.loadIconByClass(d3Elem, 'downArrow', 10);
97 verifyIconStructure('downArrow', '#triangleDown', '10');
Bri Prebilic Coledee46622015-02-03 16:36:11 -080098 });
99
100 it('should verify no icon is displayed', function () {
101 expect(d3Elem.html()).toEqual('');
Bri Prebilic Cole40be6b22015-02-19 17:12:23 -0800102 is.loadIconByClass(d3Elem, 'tableColSortNone', 10);
Bri Prebilic Coledee46622015-02-03 16:36:11 -0800103 verifyIconStructure('tableColSortNone', null, '10');
104 });
105
Simon Hunt7ac7be92015-01-06 10:47:56 -0800106});