blob: 8786109bf0df63b78d39892c88e9b05eb453efc4 [file] [log] [blame]
Simon Hunt584122a2015-01-21 15:32:40 -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 Service - Unit Tests
19 */
20describe('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 () {
53 var ws = wss.createWebSocket('foo/path');
54 expect(ws.meta.path).toEqual('ws://foo:80/onos/ui/ws/foo/path');
55 });
56
57 it('should install the appropriate callbacks', function () {
58 function oo() {}
59 function om() {}
60 function oc() {}
61
62 var ws = wss.createWebSocket('foo', {
63 onOpen: oo,
64 onMessage: om,
65 onClose: oc
66 });
67
68 expect(ws.meta.ws.onopen).toBe(oo);
69 expect(ws.meta.ws.onmessage).toBe(om);
70 expect(ws.meta.ws.onclose).toBe(oc);
71 });
72
73 it('should install partial callbacks', function () {
74 function oo() {}
75 function om() {}
76
77 var ws = wss.createWebSocket('foo', {
78 onOpen: oo,
79 onMessage: om
80 });
81
82 expect(ws.meta.ws.onopen).toBe(oo);
83 expect(ws.meta.ws.onmessage).toBe(om);
84 expect(ws.meta.ws.onclose).toBeNull();
85 });
86
87 // TODO: more testing to be done.
88
89});