blob: 6e3bbf845930fda7d5571a154219ee66089eadec [file] [log] [blame]
Simon Hunt3b0916b2015-01-23 11:06:56 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt3b0916b2015-01-23 11:06:56 -08003 *
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 Scandolo812aa5a2016-04-19 18:12:45 -070020
21// NOTE WsEventService does not exist
22
23xdescribe('factory: fw/remote/wsevent.js', function () {
Simon Hunt3b0916b2015-01-23 11:06:56 -080024 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 Hunt48e61672015-01-30 14:48:25 -080042 'sendEvent', 'resetSid'
Simon Hunt3b0916b2015-01-23 11:06:56 -080043 ])).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});