Simon Hunt | 3b0916b | 2015-01-23 11:06:56 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 3b0916b | 2015-01-23 11:06:56 -0800 | [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 -- Remote -- Web Socket Event Service - Unit Tests |
| 19 | */ |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 20 | |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame^] | 21 | // NOTE WsEventService does not exist, it has been removed? |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 22 | |
| 23 | xdescribe('factory: fw/remote/wsevent.js', function () { |
Simon Hunt | 3b0916b | 2015-01-23 11:06:56 -0800 | [diff] [blame] | 24 | var $log, fs, wse; |
| 25 | |
| 26 | beforeEach(module('onosRemote')); |
| 27 | |
| 28 | beforeEach(inject(function (_$log_, FnService, WsEventService) { |
| 29 | $log = _$log_; |
| 30 | fs = FnService; |
| 31 | wse = WsEventService; |
| 32 | wse.resetSid(); |
| 33 | })); |
| 34 | |
| 35 | |
| 36 | it('should define WsEventService', function () { |
| 37 | expect(wse).toBeDefined(); |
| 38 | }); |
| 39 | |
| 40 | it('should define api functions', function () { |
| 41 | expect(fs.areFunctions(wse, [ |
Simon Hunt | 48e6167 | 2015-01-30 14:48:25 -0800 | [diff] [blame] | 42 | 'sendEvent', 'resetSid' |
Simon Hunt | 3b0916b | 2015-01-23 11:06:56 -0800 | [diff] [blame] | 43 | ])).toBeTruthy(); |
| 44 | }); |
| 45 | |
| 46 | var event, |
| 47 | fakeWs = { |
| 48 | send: function (ev) { |
| 49 | event = ev; |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | it('should construct an event object with no payload', function () { |
| 54 | wse.sendEvent(fakeWs, 'foo'); |
| 55 | expect(event.event).toEqual('foo'); |
| 56 | expect(event.sid).toEqual(1); |
| 57 | expect(event.payload).toEqual({}); |
| 58 | }); |
| 59 | |
| 60 | it('should construct an event object with some payload', function () { |
| 61 | wse.sendEvent(fakeWs, 'bar', { val: 42 }); |
| 62 | expect(event.event).toEqual('bar'); |
| 63 | expect(event.sid).toEqual(1); |
| 64 | expect(event.payload).toEqual({ val: 42 }); |
| 65 | }); |
| 66 | |
| 67 | it('should increment the sid', function () { |
| 68 | wse.sendEvent(fakeWs, 'one'); |
| 69 | expect(event.event).toEqual('one'); |
| 70 | expect(event.sid).toEqual(1); |
| 71 | |
| 72 | wse.sendEvent(fakeWs, 'dos'); |
| 73 | expect(event.event).toEqual('dos'); |
| 74 | expect(event.sid).toEqual(2); |
| 75 | |
| 76 | wse.sendEvent(fakeWs, 'tres'); |
| 77 | expect(event.event).toEqual('tres'); |
| 78 | expect(event.sid).toEqual(3); |
| 79 | }); |
| 80 | |
| 81 | }); |