Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [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 -- 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; |
Bri Prebilic Cole | e1bda3f | 2015-02-13 17:01:49 -0800 | [diff] [blame] | 30 | jasmine.clock().install(); |
Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 31 | d3Elem = d3.select('body').append('div').attr('id', 'myflashdiv'); |
| 32 | flash.initFlash(); |
| 33 | })); |
| 34 | |
| 35 | afterEach(function () { |
Bri Prebilic Cole | e1bda3f | 2015-02-13 17:01:49 -0800 | [diff] [blame] | 36 | jasmine.clock().uninstall(); |
Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 37 | d3.select('#myflashdiv').remove(); |
| 38 | }); |
| 39 | |
| 40 | function flashItemSelection() { |
| 41 | return d3Elem.selectAll('.flashItem'); |
| 42 | } |
| 43 | |
| 44 | it('should define FlashService', function () { |
| 45 | expect(flash).toBeDefined(); |
| 46 | }); |
| 47 | |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 48 | it('should define api functions', function () { |
Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 49 | expect(fs.areFunctions(flash, [ |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 50 | 'initFlash', 'flash', 'enable', 'tempDiv' |
Simon Hunt | f41f309 | 2015-04-16 10:33:26 -0700 | [diff] [blame] | 51 | ])).toBe(true); |
Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 52 | }); |
| 53 | |
| 54 | it('should have no items to start', function () { |
| 55 | expect(flashItemSelection().size()).toBe(0); |
| 56 | }); |
| 57 | |
| 58 | it('should flash the message Foo', function () { |
| 59 | var item, rect, text; |
| 60 | flash.flash('foo'); |
Bri Prebilic Cole | e1bda3f | 2015-02-13 17:01:49 -0800 | [diff] [blame] | 61 | jasmine.clock().tick(101); |
Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 62 | setTimeout(function () { |
| 63 | item = flashItemSelection(); |
| 64 | expect(item.size()).toEqual(1); |
| 65 | expect(item.classed('flashItem')).toBeTruthy(); |
| 66 | expect(item.select('rect').size()).toEqual(1); |
| 67 | text = item.select('text'); |
| 68 | expect(text.size()).toEqual(1); |
| 69 | expect(text.text()).toEqual('foo'); |
Bri Prebilic Cole | e1bda3f | 2015-02-13 17:01:49 -0800 | [diff] [blame] | 70 | }, 100); |
Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 71 | }); |
Steven Burrows | 202034f | 2017-08-11 12:08:01 +0100 | [diff] [blame^] | 72 | |
| 73 | it('should create temp div', function () { |
| 74 | expect(flash.tempDiv()).toBeDefined(); |
| 75 | }); |
Simon Hunt | e33889d | 2015-02-05 11:39:28 -0800 | [diff] [blame] | 76 | }); |