blob: 7b66d760c15a299a6f8427da2c39183b832fc9da [file] [log] [blame]
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -07003 *
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 -- Table Builder Service - Unit Tests
19 */
20
Matteo Scandolo231c7542016-05-20 11:13:11 -070021describe('factory: fw/widget/tableBuilder.js', function () {
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070022 var $log, $rootScope, fs, tbs, is;
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070023
24 var mockObj,
25 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 }
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070033 };
34
Matteo Scandolo812aa5a2016-04-19 18:12:45 -070035 beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg', 'onosLayer'));
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070036
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070037 beforeEach(function () {
38 module(function ($provide) {
39 $provide.value('WebSocketService', mockWss);
40 });
41 });
42
43 beforeEach(inject(function (_$log_, _$rootScope_,
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070044 FnService, TableBuilderService, IconService) {
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070045 $log = _$log_;
46 $rootScope = _$rootScope_;
47 fs = FnService;
48 tbs = TableBuilderService;
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070049 is = IconService;
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070050 }));
51
52 function mockSelCb(event, sel) {}
53
54 beforeEach(function () {
55 mockObj = {
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070056 scope: $rootScope.$new(),
57 tag: 'foo',
58 selCb: mockSelCb
59 };
60 });
61
62 afterEach(function () {
63 mockObj = {};
64 });
65
66 it('should define TableBuilderService', function () {
67 expect(tbs).toBeDefined();
68 });
69
70 it('should define api functions', function () {
71 expect(fs.areFunctions(tbs, [
72 'buildTable'
73 ])).toBeTruthy();
74 });
75
76 it('should verify sortCb', function () {
77 spyOn(mockWss, 'sendEvent');
78 expect(mockObj.scope.sortCallback).not.toBeDefined();
79 tbs.buildTable(mockObj);
80 expect(mockObj.scope.sortCallback).toBeDefined();
81 expect(mockWss.sendEvent).toHaveBeenCalled();
82 });
83
84 it('should set tableData', function () {
Bri Prebilic Colee568ead2015-05-01 09:51:28 -070085 expect(mockObj.scope.tableData).not.toBeDefined();
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070086 tbs.buildTable(mockObj);
Bri Prebilic Colee568ead2015-05-01 09:51:28 -070087 expect(fs.isA(mockObj.scope.tableData)).toBeTruthy();
88 expect(mockObj.scope.tableData.length).toBe(0);
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070089 });
90
91 it('should unbind handlers on destroyed scope', function () {
92 spyOn(mockWss, 'unbindHandlers');
93 tbs.buildTable(mockObj);
94 expect(mockWss.unbindHandlers).not.toHaveBeenCalled();
95 mockObj.scope.$destroy();
96 expect(mockWss.unbindHandlers).toHaveBeenCalled();
97 });
98
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070099});