Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 1 | /* |
| 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 -- Layer -- Flash Service - Unit Tests |
| 19 | */ |
| 20 | describe('factory: fw/layer/flash.js', function () { |
| 21 | var $log, $timeout, fs, flash, d3Elem; |
| 22 | |
| 23 | beforeEach(module('onosLayer')); |
| 24 | |
| 25 | beforeEach(inject(function (_$log_, _$timeout_, FnService, FlashService) { |
| 26 | $log = _$log_; |
| 27 | $timeout = _$timeout_; |
| 28 | fs = FnService; |
| 29 | flash = FlashService; |
| 30 | d3Elem = d3.select('body').append('div').attr('id', 'myflashdiv'); |
| 31 | flash.initFlash(); |
| 32 | })); |
| 33 | |
| 34 | afterEach(function () { |
| 35 | d3.select('#myflashdiv').remove(); |
| 36 | }); |
| 37 | |
| 38 | function flashItemSelection() { |
| 39 | return d3Elem.selectAll('.flashItem'); |
| 40 | } |
| 41 | |
| 42 | it('should define FlashService', function () { |
| 43 | expect(flash).toBeDefined(); |
| 44 | }); |
| 45 | |
| 46 | it('should define api functions', function () { |
| 47 | expect(fs.areFunctions(flash, [ |
| 48 | 'initFlash', 'flash' |
| 49 | ])).toBeTruthy(); |
| 50 | }); |
| 51 | |
| 52 | it('should have no items to start', function () { |
| 53 | expect(flashItemSelection().size()).toBe(0); |
| 54 | }); |
| 55 | |
| 56 | it('should flash the message Foo', function () { |
| 57 | var item, rect, text; |
| 58 | flash.flash('foo'); |
| 59 | setTimeout(function () { |
| 60 | item = flashItemSelection(); |
| 61 | expect(item.size()).toEqual(1); |
| 62 | expect(item.classed('flashItem')).toBeTruthy(); |
| 63 | expect(item.select('rect').size()).toEqual(1); |
| 64 | text = item.select('text'); |
| 65 | expect(text.size()).toEqual(1); |
| 66 | expect(text.text()).toEqual('foo'); |
Bri Prebilic Cole | 902cb04 | 2015-02-11 14:04:15 -0800 | [diff] [blame^] | 67 | }, 2000); |
Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 68 | }); |
| 69 | |
| 70 | // TODO: testing these time-sensitive behaviors is hard... |
| 71 | // need to work on this some other time. |
| 72 | }); |