Jian Li | a9dd019 | 2016-04-18 23:15:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 -- Chart Builder Service - Unit Tests |
| 19 | */ |
| 20 | |
| 21 | describe('factory: fw/widget/chartBuilder.js', function () { |
| 22 | var $log, $rootScope, fs, cbs, is; |
| 23 | |
Thomas Vachuska | e614e3f | 2016-05-24 17:15:13 -0700 | [diff] [blame] | 24 | var mockObj, |
Jian Li | a9dd019 | 2016-04-18 23:15:17 -0700 | [diff] [blame] | 25 | mockWss = { |
| 26 | bindHandlers: function () {}, |
| 27 | sendEvent: function () {}, |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 28 | unbindHandlers: function () {}, |
| 29 | _setLoadingDelegate: function(){}, |
| 30 | isConnected: function() { |
| 31 | return true; |
| 32 | } |
Jian Li | a9dd019 | 2016-04-18 23:15:17 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 35 | beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg', 'onosLayer')); |
Jian Li | a9dd019 | 2016-04-18 23:15:17 -0700 | [diff] [blame] | 36 | |
| 37 | beforeEach(function () { |
| 38 | module(function ($provide) { |
| 39 | $provide.value('WebSocketService', mockWss); |
| 40 | }); |
| 41 | }); |
| 42 | |
| 43 | beforeEach(inject(function (_$log_, _$rootScope_, |
| 44 | FnService, ChartBuilderService, IconService) { |
| 45 | $log = _$log_; |
| 46 | $rootScope = _$rootScope_; |
| 47 | fs = FnService; |
| 48 | cbs = ChartBuilderService; |
| 49 | is = IconService; |
| 50 | })); |
| 51 | |
| 52 | beforeEach(function () { |
| 53 | mockObj = { |
| 54 | scope: $rootScope.$new(), |
| 55 | tag: 'foo' |
| 56 | }; |
| 57 | }); |
| 58 | |
| 59 | afterEach(function () { |
| 60 | mockObj = {}; |
| 61 | }); |
| 62 | |
| 63 | it('should define ChartBuilderService', function () { |
| 64 | expect(cbs).toBeDefined(); |
| 65 | }); |
| 66 | |
| 67 | it('should define api functions', function () { |
| 68 | expect(fs.areFunctions(cbs, [ |
| 69 | 'buildChart' |
| 70 | ])).toBeTruthy(); |
| 71 | }); |
| 72 | |
| 73 | it('should verify requestCb', function () { |
| 74 | spyOn(mockWss, 'sendEvent'); |
| 75 | expect(mockObj.scope.requestCallback).not.toBeDefined(); |
| 76 | cbs.buildChart(mockObj); |
| 77 | expect(mockObj.scope.requestCallback).toBeDefined(); |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 78 | mockObj.scope.requestCallback(); |
Jian Li | a9dd019 | 2016-04-18 23:15:17 -0700 | [diff] [blame] | 79 | expect(mockWss.sendEvent).toHaveBeenCalled(); |
| 80 | }); |
| 81 | |
| 82 | it('should set chartData', function () { |
| 83 | expect(mockObj.scope.chartData).not.toBeDefined(); |
| 84 | cbs.buildChart(mockObj); |
| 85 | expect(fs.isA(mockObj.scope.chartData)).toBeTruthy(); |
| 86 | expect(mockObj.scope.chartData.length).toBe(0); |
| 87 | }); |
| 88 | |
| 89 | it('should unbind handlers on destroyed scope', function () { |
| 90 | spyOn(mockWss, 'unbindHandlers'); |
| 91 | cbs.buildChart(mockObj); |
| 92 | expect(mockWss.unbindHandlers).not.toHaveBeenCalled(); |
| 93 | mockObj.scope.$destroy(); |
| 94 | expect(mockWss.unbindHandlers).toHaveBeenCalled(); |
| 95 | }); |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 96 | }); |