blob: a982f7cbd4da0248abf6da4be3b2fe2e025ceca2 [file] [log] [blame]
Bri Prebilic Cole54d09382015-03-19 18:40:27 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Bri Prebilic Cole54d09382015-03-19 18:40:27 -07003 *
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 -- Widget -- Tooltip Service - Unit Tests
19 */
20describe('factory: fw/widget/tooltip.js', function () {
21 var $log, fs, tts, d3Elem;
22
23 beforeEach(module('onosWidget', 'onosUtil'));
24
25 beforeEach(inject(function (_$log_, FnService, TooltipService) {
26 $log = _$log_;
27 fs = FnService;
28 tts = TooltipService;
29 }));
30
31 beforeEach(function () {
32 d3Elem = d3.select('body').append('div').attr('id', 'tooltip');
33 });
34
35 afterEach(function () {
36 d3.select('#tooltip').remove();
37 });
38
39 it('should define TooltipService', function () {
40 expect(tts).toBeDefined();
41 });
42
Matteo Scandolo209c6c62016-05-21 10:08:57 -070043 it('should define api functions', function () {
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070044 expect(fs.areFunctions(tts, [
Matteo Scandolo209c6c62016-05-21 10:08:57 -070045 'addTooltip', 'showTooltip', 'cancelTooltip'
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070046 ])).toBeTruthy();
47 });
48
49 it('should not accept undefined arguments', function () {
50 var btn = d3.select('body').append('div');
51 expect(tts.showTooltip()).toBeFalsy();
52 expect(tts.showTooltip(btn)).toBeFalsy();
53
54 expect(tts.cancelTooltip()).toBeFalsy();
55 });
56
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070057 // TODO: figure out how to test this
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070058 // testing mouse events is tough
Bri Prebilic Cole5a206bb2015-03-25 16:33:27 -070059 // showTooltip needs a d3 event, which currently has no test backend
60 // .each is a workaround, which provides this, d, and i
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070061 xit('should show a tooltip', function () {
62 var btn = d3.select('body').append('div').attr('id', 'foo');
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070063 btn.each(function () {
64 tts.showTooltip(this, 'yay a tooltip');
65 });
Bri Prebilic Cole5a206bb2015-03-25 16:33:27 -070066 // tests here
67 });
68
69 // can't cancel a tooltip until we show one
70 // because currElemId isn't set otherwise
71 xit('should cancel an existing tooltip', function () {
72 var btn = d3.select('body').append('div').attr('id', 'foo');
73 btn.each(function () {
74 tts.cancelTooltip(this);
75 });
76 expect(d3Elem.text()).toBe('');
77 expect(d3Elem.style('display')).toBe('none');
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070078 });
79});