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 | |
| 23 | beforeEach(module('onosRemote')); |
| 24 | |
| 25 | beforeEach(module(function($provide) { |
| 26 | $provide.factory('$location', function (){ |
| 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, [ |
| 48 | 'createWebSocket' |
| 49 | ])).toBeTruthy(); |
| 50 | }); |
| 51 | |
| 52 | it('should use the appropriate URL', function () { |
Simon Hunt | 970e7fd | 2015-01-22 17:46:28 -0800 | [diff] [blame^] | 53 | debugger; |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 54 | var ws = wss.createWebSocket('foo/path'); |
| 55 | expect(ws.meta.path).toEqual('ws://foo:80/onos/ui/ws/foo/path'); |
| 56 | }); |
| 57 | |
| 58 | it('should install the appropriate callbacks', function () { |
| 59 | function oo() {} |
| 60 | function om() {} |
| 61 | function oc() {} |
| 62 | |
| 63 | var ws = wss.createWebSocket('foo', { |
| 64 | onOpen: oo, |
| 65 | onMessage: om, |
| 66 | onClose: oc |
| 67 | }); |
| 68 | |
| 69 | expect(ws.meta.ws.onopen).toBe(oo); |
Simon Hunt | 970e7fd | 2015-01-22 17:46:28 -0800 | [diff] [blame^] | 70 | // TODO: om is wrapped - we can't test by reference |
| 71 | //expect(ws.meta.ws.onmessage).toBe(om); |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 72 | expect(ws.meta.ws.onclose).toBe(oc); |
| 73 | }); |
| 74 | |
| 75 | it('should install partial callbacks', function () { |
| 76 | function oo() {} |
| 77 | function om() {} |
| 78 | |
| 79 | var ws = wss.createWebSocket('foo', { |
| 80 | onOpen: oo, |
| 81 | onMessage: om |
| 82 | }); |
| 83 | |
| 84 | expect(ws.meta.ws.onopen).toBe(oo); |
Simon Hunt | 970e7fd | 2015-01-22 17:46:28 -0800 | [diff] [blame^] | 85 | // TODO: om is wrapped - we can't test by reference |
| 86 | //expect(ws.meta.ws.onmessage).toBe(om); |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 87 | expect(ws.meta.ws.onclose).toBeNull(); |
| 88 | }); |
| 89 | |
| 90 | // TODO: more testing to be done. |
| 91 | |
| 92 | }); |