Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Foundation |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 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 -- Table Builder Service - Unit Tests |
| 19 | */ |
| 20 | |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 21 | describe('factory: fw/widget/tableBuilder.js', function () { |
Bri Prebilic Cole | bd0bc77 | 2015-05-13 13:02:26 -0700 | [diff] [blame] | 22 | var $log, $rootScope, fs, tbs, is; |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 23 | |
| 24 | var mockObj, |
| 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 | } |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 35 | beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg', 'onosLayer')); |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 36 | |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 37 | beforeEach(function () { |
| 38 | module(function ($provide) { |
| 39 | $provide.value('WebSocketService', mockWss); |
| 40 | }); |
| 41 | }); |
| 42 | |
| 43 | beforeEach(inject(function (_$log_, _$rootScope_, |
Bri Prebilic Cole | bd0bc77 | 2015-05-13 13:02:26 -0700 | [diff] [blame] | 44 | FnService, TableBuilderService, IconService) { |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 45 | $log = _$log_; |
| 46 | $rootScope = _$rootScope_; |
| 47 | fs = FnService; |
| 48 | tbs = TableBuilderService; |
Bri Prebilic Cole | bd0bc77 | 2015-05-13 13:02:26 -0700 | [diff] [blame] | 49 | is = IconService; |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 50 | })); |
| 51 | |
| 52 | function mockSelCb(event, sel) {} |
| 53 | |
| 54 | beforeEach(function () { |
| 55 | mockObj = { |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 56 | 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 Cole | e568ead | 2015-05-01 09:51:28 -0700 | [diff] [blame] | 85 | expect(mockObj.scope.tableData).not.toBeDefined(); |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 86 | tbs.buildTable(mockObj); |
Bri Prebilic Cole | e568ead | 2015-05-01 09:51:28 -0700 | [diff] [blame] | 87 | expect(fs.isA(mockObj.scope.tableData)).toBeTruthy(); |
| 88 | expect(mockObj.scope.tableData.length).toBe(0); |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 89 | }); |
| 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 Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 99 | }); |