Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 -- Remote -- Web Socket Service - Unit Tests |
| 19 | */ |
| 20 | describe('factory: fw/remote/websocket.js', function () { |
| 21 | var $log, fs, wss; |
| 22 | |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 23 | beforeEach(module('onosRemote', 'onosLayer', 'ngRoute', 'onosNav', 'onosSvg')); |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 24 | |
| 25 | beforeEach(module(function($provide) { |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 26 | $provide.factory('$location', function () { |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 27 | return { |
| 28 | protocol: function () { return 'http'; }, |
| 29 | host: function () { return 'foo'; }, |
| 30 | port: function () { return '80'; } |
| 31 | }; |
| 32 | }) |
| 33 | })); |
| 34 | |
| 35 | beforeEach(inject(function (_$log_, FnService, WebSocketService) { |
| 36 | $log = _$log_; |
| 37 | fs = FnService; |
| 38 | wss = WebSocketService; |
| 39 | })); |
| 40 | |
| 41 | |
| 42 | it('should define WebSocketService', function () { |
| 43 | expect(wss).toBeDefined(); |
| 44 | }); |
| 45 | |
| 46 | it('should define api functions', function () { |
| 47 | expect(fs.areFunctions(wss, [ |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 48 | 'resetSid', 'createWebSocket', 'bindHandlers', 'unbindHandlers', |
| 49 | 'sendEvent' |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 50 | ])).toBeTruthy(); |
| 51 | }); |
| 52 | |
| 53 | it('should use the appropriate URL', function () { |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 54 | var url = wss.createWebSocket(); |
| 55 | expect(url).toEqual('ws://foo:80/onos/ui/websock/core'); |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 56 | }); |
| 57 | |
Simon Hunt | acf410b | 2015-01-23 10:05:48 -0800 | [diff] [blame] | 58 | it('should use the appropriate URL with modified port', function () { |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 59 | var url = wss.createWebSocket({ wsport: 1243 }); |
| 60 | expect(url).toEqual('ws://foo:1243/onos/ui/websock/core'); |
Simon Hunt | acf410b | 2015-01-23 10:05:48 -0800 | [diff] [blame] | 61 | }); |
| 62 | |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 63 | // TODO: inject mock WSock service and write more tests ... |
Simon Hunt | acf410b | 2015-01-23 10:05:48 -0800 | [diff] [blame] | 64 | |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 65 | }); |