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 | |
| 24 | var mockObj; |
| 25 | mockWss = { |
| 26 | bindHandlers: function () {}, |
| 27 | sendEvent: function () {}, |
| 28 | unbindHandlers: function () {} |
| 29 | }; |
| 30 | |
| 31 | beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg')); |
| 32 | |
| 33 | beforeEach(function () { |
| 34 | module(function ($provide) { |
| 35 | $provide.value('WebSocketService', mockWss); |
| 36 | }); |
| 37 | }); |
| 38 | |
| 39 | beforeEach(inject(function (_$log_, _$rootScope_, |
| 40 | FnService, ChartBuilderService, IconService) { |
| 41 | $log = _$log_; |
| 42 | $rootScope = _$rootScope_; |
| 43 | fs = FnService; |
| 44 | cbs = ChartBuilderService; |
| 45 | is = IconService; |
| 46 | })); |
| 47 | |
| 48 | beforeEach(function () { |
| 49 | mockObj = { |
| 50 | scope: $rootScope.$new(), |
| 51 | tag: 'foo' |
| 52 | }; |
| 53 | }); |
| 54 | |
| 55 | afterEach(function () { |
| 56 | mockObj = {}; |
| 57 | }); |
| 58 | |
| 59 | it('should define ChartBuilderService', function () { |
| 60 | expect(cbs).toBeDefined(); |
| 61 | }); |
| 62 | |
| 63 | it('should define api functions', function () { |
| 64 | expect(fs.areFunctions(cbs, [ |
| 65 | 'buildChart' |
| 66 | ])).toBeTruthy(); |
| 67 | }); |
| 68 | |
| 69 | it('should verify requestCb', function () { |
| 70 | spyOn(mockWss, 'sendEvent'); |
| 71 | expect(mockObj.scope.requestCallback).not.toBeDefined(); |
| 72 | cbs.buildChart(mockObj); |
| 73 | expect(mockObj.scope.requestCallback).toBeDefined(); |
| 74 | expect(mockWss.sendEvent).toHaveBeenCalled(); |
| 75 | }); |
| 76 | |
| 77 | it('should set chartData', function () { |
| 78 | expect(mockObj.scope.chartData).not.toBeDefined(); |
| 79 | cbs.buildChart(mockObj); |
| 80 | expect(fs.isA(mockObj.scope.chartData)).toBeTruthy(); |
| 81 | expect(mockObj.scope.chartData.length).toBe(0); |
| 82 | }); |
| 83 | |
| 84 | it('should unbind handlers on destroyed scope', function () { |
| 85 | spyOn(mockWss, 'unbindHandlers'); |
| 86 | cbs.buildChart(mockObj); |
| 87 | expect(mockWss.unbindHandlers).not.toHaveBeenCalled(); |
| 88 | mockObj.scope.$destroy(); |
| 89 | expect(mockWss.unbindHandlers).toHaveBeenCalled(); |
| 90 | }); |
| 91 | } |