blob: 9146ccaa7cfde584013219884a0153a63434a996 [file] [log] [blame]
Simon Hunt3b0916b2015-01-23 11:06:56 -08001/*
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 Event Service - Unit Tests
19 */
20describe('factory: fw/remote/wsevent.js', function () {
21 var $log, fs, wse;
22
23 beforeEach(module('onosRemote'));
24
25 beforeEach(inject(function (_$log_, FnService, WsEventService) {
26 $log = _$log_;
27 fs = FnService;
28 wse = WsEventService;
29 wse.resetSid();
30 }));
31
32
33 it('should define WsEventService', function () {
34 expect(wse).toBeDefined();
35 });
36
37 it('should define api functions', function () {
38 expect(fs.areFunctions(wse, [
39 'sendEvent'
40 ])).toBeTruthy();
41 });
42
43 var event,
44 fakeWs = {
45 send: function (ev) {
46 event = ev;
47 }
48 };
49
50 it('should construct an event object with no payload', function () {
51 wse.sendEvent(fakeWs, 'foo');
52 expect(event.event).toEqual('foo');
53 expect(event.sid).toEqual(1);
54 expect(event.payload).toEqual({});
55 });
56
57 it('should construct an event object with some payload', function () {
58 wse.sendEvent(fakeWs, 'bar', { val: 42 });
59 expect(event.event).toEqual('bar');
60 expect(event.sid).toEqual(1);
61 expect(event.payload).toEqual({ val: 42 });
62 });
63
64 it('should increment the sid', function () {
65 wse.sendEvent(fakeWs, 'one');
66 expect(event.event).toEqual('one');
67 expect(event.sid).toEqual(1);
68
69 wse.sendEvent(fakeWs, 'dos');
70 expect(event.event).toEqual('dos');
71 expect(event.sid).toEqual(2);
72
73 wse.sendEvent(fakeWs, 'tres');
74 expect(event.event).toEqual('tres');
75 expect(event.sid).toEqual(3);
76 });
77
78});