blob: 8466dbe3c3b7a549f530c7fb0d08e3aaf254c66d [file] [log] [blame]
Simon Hunt99ee1e22015-02-13 09:24:43 -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 -- Topo View -- Topo Filter Service - Unit Tests
19 */
20describe('factory: view/topo/topoFilter.js', function() {
Simon Hunteb0fa052015-02-17 19:20:28 -080021 var $log, fs, fltr, d3Elem, api;
22
23 var mockNodes = {
24 each: function () {},
25 classed: function () {}
26 },
27 mockLinks = {
28 each: function () {},
29 classed: function () {}
30 };
Simon Hunt99ee1e22015-02-13 09:24:43 -080031
Simon Hunt2d16fc82015-03-10 20:19:52 -070032 beforeEach(module('ovTopo', 'onosUtil', 'onosLayer', 'ngRoute', 'onosNav'));
Simon Hunt99ee1e22015-02-13 09:24:43 -080033
34 beforeEach(inject(function (_$log_, FnService, TopoFilterService) {
35 $log = _$log_;
36 fs = FnService;
Simon Hunteb0fa052015-02-17 19:20:28 -080037 fltr = TopoFilterService;
38 d3Elem = d3.select('body').append('div').attr('id', 'myMastDiv');
39
40 api = {
41 node: function () { return mockNodes; },
42 link: function () { return mockLinks; }
43 };
Simon Hunt99ee1e22015-02-13 09:24:43 -080044 }));
45
Simon Hunteb0fa052015-02-17 19:20:28 -080046 afterEach(function () {
47 d3.select('#myMastDiv').remove();
48 });
49
Simon Hunt99ee1e22015-02-13 09:24:43 -080050 it('should define TopoFilterService', function () {
Simon Hunteb0fa052015-02-17 19:20:28 -080051 expect(fltr).toBeDefined();
Simon Hunt99ee1e22015-02-13 09:24:43 -080052 });
53
54 it('should define api functions', function () {
Simon Hunteb0fa052015-02-17 19:20:28 -080055 expect(fs.areFunctions(fltr, [
56 'initFilter', 'destroyFilter',
Simon Huntc3c5b672015-02-20 11:32:13 -080057 'clickAction', 'selected', 'inLayer',
Simon Hunt99ee1e22015-02-13 09:24:43 -080058 ])).toBeTruthy();
59 });
60
Simon Hunteb0fa052015-02-17 19:20:28 -080061 it('should inject the buttons into the given div', function () {
62 fltr.initFilter(api, d3Elem);
63 var grpdiv = d3Elem.select('#topo-radio-group');
64 expect(grpdiv.size()).toBe(1);
65
66 var btns = grpdiv.selectAll('span');
67 expect(btns.size()).toBe(3);
68
69 var prefix = 'topo-rb-',
70 expIds = [ 'all', 'pkt', 'opt' ];
71
72 btns.each(function (d, i) {
73 var b = d3.select(this);
74 expect(b.attr('id')).toEqual(prefix + expIds[i]);
75 // 0th button is active - others are not
76 expect(b.classed('active')).toEqual(i === 0);
77 });
78 });
79
80 it('should remove the buttons from the given div', function () {
81 fltr.initFilter(api, d3Elem);
82 var grpdiv = d3Elem.select('#topo-radio-group');
83 expect(grpdiv.size()).toBe(1);
84
85 fltr.destroyFilter();
86 grpdiv = d3Elem.select('#topo-radio-group');
87 expect(grpdiv.size()).toBe(0);
88 });
89
90 it('should report the selected button', function () {
91 fltr.initFilter(api, d3Elem);
92 expect(fltr.selected()).toEqual('all');
93 });
94
95 // TODO: figure out how to trigger the click function on the spans..
96
Simon Hunt99ee1e22015-02-13 09:24:43 -080097});