blob: 0e95265f8c4e350f34474b590f761293af5c7eb1 [file] [log] [blame]
Jian Lia9dd0192016-04-18 23:15:17 -07001/*
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
21describe('factory: fw/widget/chartBuilder.js', function () {
22 var $log, $rootScope, fs, cbs, is;
23
Thomas Vachuskae614e3f2016-05-24 17:15:13 -070024 var mockObj,
Jian Lia9dd0192016-04-18 23:15:17 -070025 mockWss = {
26 bindHandlers: function () {},
27 sendEvent: function () {},
Matteo Scandolo231c7542016-05-20 11:13:11 -070028 unbindHandlers: function () {},
29 _setLoadingDelegate: function(){},
30 isConnected: function() {
31 return true;
32 }
Jian Lia9dd0192016-04-18 23:15:17 -070033 };
34
Matteo Scandolo231c7542016-05-20 11:13:11 -070035 beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg', 'onosLayer'));
Jian Lia9dd0192016-04-18 23:15:17 -070036
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 Scandolo231c7542016-05-20 11:13:11 -070078 mockObj.scope.requestCallback();
Jian Lia9dd0192016-04-18 23:15:17 -070079 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 Scandolo231c7542016-05-20 11:13:11 -070096});