blob: 9c3597625f7910b0e6f76055acf3a5545955b7a0 [file] [log] [blame]
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -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 -- General Functions - Unit Tests
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080019 */
Matteo Scandolo812aa5a2016-04-19 18:12:45 -070020
21// FIXME TypeError: $loc.search is not a function
22
23xdescribe('factory: fw/remote/urlfn.js', function () {
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080024 var $log, $loc, ufs, fs;
25
Simon Hunt1e4a0012015-01-21 11:36:08 -080026 var protocol, host, port;
27
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080028 beforeEach(module('onosRemote'));
29
30 beforeEach(module(function($provide) {
31 $provide.factory('$location', function (){
32 return {
Simon Hunt1e4a0012015-01-21 11:36:08 -080033 protocol: function () { return protocol; },
34 host: function () { return host; },
35 port: function () { return port; }
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080036 };
37 })
38 }));
39
40 beforeEach(inject(function (_$log_, $location, UrlFnService, FnService) {
41 $log = _$log_;
42 $loc = $location;
43 ufs = UrlFnService;
44 fs = FnService;
45 }));
46
Simon Hunt1e4a0012015-01-21 11:36:08 -080047 function setLoc(prot, h, p) {
48 protocol = prot;
49 host = h;
50 port = p;
51 }
52
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080053 it('should define UrlFnService', function () {
54 expect(ufs).toBeDefined();
55 });
56
57 it('should define api functions', function () {
58 expect(fs.areFunctions(ufs, [
Simon Hunt1e4a0012015-01-21 11:36:08 -080059 'rsUrl', 'wsUrl'
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080060 ])).toBeTruthy();
61 });
62
Simon Hunt1e4a0012015-01-21 11:36:08 -080063 it('should return the correct (http) RS url', function () {
64 setLoc('http', 'foo', '123');
65 expect(ufs.rsUrl('path')).toEqual('http://foo:123/onos/ui/rs/path');
66 });
67
68 it('should return the correct (https) RS url', function () {
69 setLoc('https', 'foo', '123');
70 expect(ufs.rsUrl('path')).toEqual('https://foo:123/onos/ui/rs/path');
71 });
72
73 it('should return the correct (ws) WS url', function () {
74 setLoc('http', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070075 expect(ufs.wsUrl('path')).toEqual('ws://foo:123/onos/ui/websock/path');
Simon Hunt1e4a0012015-01-21 11:36:08 -080076 });
77
78 it('should return the correct (wss) WS url', function () {
79 setLoc('https', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070080 expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/websock/path');
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080081 });
Simon Huntbb920fd2015-01-22 17:06:32 -080082
83 it('should allow us to define an alternate WS port', function () {
84 setLoc('http', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070085 expect(ufs.wsUrl('xyyzy', 456)).toEqual('ws://foo:456/onos/ui/websock/xyyzy');
Simon Huntbb920fd2015-01-22 17:06:32 -080086 });
Simon Hunt8b6d2d42015-03-11 13:04:52 -070087
88 it('should allow us to define an alternate host', function () {
89 setLoc('http', 'foo', '123');
90 expect(ufs.wsUrl('core', 456, 'bar')).toEqual('ws://bar:456/onos/ui/websock/core');
91 });
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080092});