Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 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 | */ |
| 20 | describe('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, [ |
Bri Prebilic Cole | 9a5e006 | 2015-05-11 17:20:57 -0700 | [diff] [blame] | 45 | 'showTooltip', 'cancelTooltip' |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 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 | |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 57 | // TODO: figure out how to test this |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 58 | // testing mouse events is tough |
Bri Prebilic Cole | 5a206bb | 2015-03-25 16:33:27 -0700 | [diff] [blame] | 59 | // showTooltip needs a d3 event, which currently has no test backend |
| 60 | // .each is a workaround, which provides this, d, and i |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 61 | xit('should show a tooltip', function () { |
| 62 | var btn = d3.select('body').append('div').attr('id', 'foo'); |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 63 | btn.each(function () { |
| 64 | tts.showTooltip(this, 'yay a tooltip'); |
| 65 | }); |
Bri Prebilic Cole | 5a206bb | 2015-03-25 16:33:27 -0700 | [diff] [blame] | 66 | // 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 Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 78 | }); |
| 79 | }); |