blob: 4564a2660748969d2c5b5cf2248361e629778ac4 [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 Scandolo812aa5a2016-04-19 18:12:45 -070021xdescribe('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 () {},
28 unbindHandlers: function () {}
29 };
30
Matteo Scandolo812aa5a2016-04-19 18:12:45 -070031 beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg', 'onosLayer'));
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070032
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070033 beforeEach(function () {
34 module(function ($provide) {
35 $provide.value('WebSocketService', mockWss);
36 });
37 });
38
39 beforeEach(inject(function (_$log_, _$rootScope_,
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070040 FnService, TableBuilderService, IconService) {
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070041 $log = _$log_;
42 $rootScope = _$rootScope_;
43 fs = FnService;
44 tbs = TableBuilderService;
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070045 is = IconService;
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070046 }));
47
48 function mockSelCb(event, sel) {}
49
50 beforeEach(function () {
51 mockObj = {
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070052 scope: $rootScope.$new(),
53 tag: 'foo',
54 selCb: mockSelCb
55 };
56 });
57
58 afterEach(function () {
59 mockObj = {};
60 });
61
62 it('should define TableBuilderService', function () {
63 expect(tbs).toBeDefined();
64 });
65
66 it('should define api functions', function () {
67 expect(fs.areFunctions(tbs, [
68 'buildTable'
69 ])).toBeTruthy();
70 });
71
72 it('should verify sortCb', function () {
73 spyOn(mockWss, 'sendEvent');
74 expect(mockObj.scope.sortCallback).not.toBeDefined();
75 tbs.buildTable(mockObj);
76 expect(mockObj.scope.sortCallback).toBeDefined();
77 expect(mockWss.sendEvent).toHaveBeenCalled();
78 });
79
80 it('should set tableData', function () {
Bri Prebilic Colee568ead2015-05-01 09:51:28 -070081 expect(mockObj.scope.tableData).not.toBeDefined();
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070082 tbs.buildTable(mockObj);
Bri Prebilic Colee568ead2015-05-01 09:51:28 -070083 expect(fs.isA(mockObj.scope.tableData)).toBeTruthy();
84 expect(mockObj.scope.tableData.length).toBe(0);
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070085 });
86
87 it('should unbind handlers on destroyed scope', function () {
88 spyOn(mockWss, 'unbindHandlers');
89 tbs.buildTable(mockObj);
90 expect(mockWss.unbindHandlers).not.toHaveBeenCalled();
91 mockObj.scope.$destroy();
92 expect(mockWss.unbindHandlers).toHaveBeenCalled();
93 });
94
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070095});