blob: 7d9a9824c6ad0c74df58952580fc31a93791eb2d [file] [log] [blame]
Simon Hunte33889d2015-02-05 11:39:28 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunte33889d2015-02-05 11:39:28 -08003 *
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 */
20describe('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 Colee1bda3f2015-02-13 17:01:49 -080030 jasmine.clock().install();
Simon Hunte33889d2015-02-05 11:39:28 -080031 d3Elem = d3.select('body').append('div').attr('id', 'myflashdiv');
32 flash.initFlash();
33 }));
34
35 afterEach(function () {
Bri Prebilic Colee1bda3f2015-02-13 17:01:49 -080036 jasmine.clock().uninstall();
Simon Hunte33889d2015-02-05 11:39:28 -080037 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 Scandolo812aa5a2016-04-19 18:12:45 -070048 xit('should define api functions', function () {
Simon Hunte33889d2015-02-05 11:39:28 -080049 expect(fs.areFunctions(flash, [
Simon Huntf41f3092015-04-16 10:33:26 -070050 'initFlash', 'flash', 'enable'
51 ])).toBe(true);
Simon Hunte33889d2015-02-05 11:39:28 -080052 });
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 Colee1bda3f2015-02-13 17:01:49 -080061 jasmine.clock().tick(101);
Simon Hunte33889d2015-02-05 11:39:28 -080062 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 Colee1bda3f2015-02-13 17:01:49 -080070 }, 100);
Simon Hunte33889d2015-02-05 11:39:28 -080071 });
Simon Hunte33889d2015-02-05 11:39:28 -080072});