blob: a817dbcadd8856b5b8f339d37c04249fdc5ee368 [file] [log] [blame]
Bri Prebilic Cole54d09382015-03-19 18:40:27 -07001/*
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 -- 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
43 it('should define api functions', function () {
44 expect(fs.areFunctions(tts, [
45 'showTooltip', 'cancelTooltip'
46 ])).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
57 // testing mouse events is tough
Bri Prebilic Cole5a206bb2015-03-25 16:33:27 -070058 // showTooltip needs a d3 event, which currently has no test backend
59 // .each is a workaround, which provides this, d, and i
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070060 xit('should show a tooltip', function () {
61 var btn = d3.select('body').append('div').attr('id', 'foo');
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070062 btn.each(function () {
63 tts.showTooltip(this, 'yay a tooltip');
64 });
Bri Prebilic Cole5a206bb2015-03-25 16:33:27 -070065 // tests here
66 });
67
68 // can't cancel a tooltip until we show one
69 // because currElemId isn't set otherwise
70 xit('should cancel an existing tooltip', function () {
71 var btn = d3.select('body').append('div').attr('id', 'foo');
72 btn.each(function () {
73 tts.cancelTooltip(this);
74 });
75 expect(d3Elem.text()).toBe('');
76 expect(d3Elem.style('display')).toBe('none');
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070077 });
78});