blob: b2bc13432f2a4ae3f6ba55a6854bc41b90eb0eb7 [file] [log] [blame]
Simon Huntf3069722014-12-16 18:15:37 -08001/*
2 * Copyright 2014 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/*
Simon Huntdc6362a2014-12-18 19:55:23 -080018 ONOS GUI -- Util -- General Purpose Functions - Unit Tests
Simon Huntf3069722014-12-16 18:15:37 -080019
20 @author Simon Hunt
21 */
Yuta HIGUCHI4f39bcd2014-12-18 20:46:14 -080022describe('factory: fw/util/fn.js', function() {
Simon Huntf3069722014-12-16 18:15:37 -080023 var fs,
24 someFunction = function () {},
25 someArray = [1, 2, 3],
26 someObject = { foo: 'bar'},
27 someNumber = 42,
28 someString = 'xyyzy',
Simon Hunt59df0b22014-12-17 10:32:25 -080029 someDate = new Date(),
30 stringArray = ['foo', 'bar'];
Simon Huntf3069722014-12-16 18:15:37 -080031
Simon Huntdc6362a2014-12-18 19:55:23 -080032 beforeEach(module('onosUtil'));
Simon Huntf3069722014-12-16 18:15:37 -080033
34 beforeEach(inject(function (FnService) {
35 fs = FnService;
36 }));
37
Simon Huntf3069722014-12-16 18:15:37 -080038
39 // === Tests for isF()
40 it('isF(): null for undefined', function () {
41 expect(fs.isF(undefined)).toBeNull();
42 });
43 it('isF(): null for null', function () {
44 expect(fs.isF(null)).toBeNull();
45 });
46 it('isF(): the reference for function', function () {
47 expect(fs.isF(someFunction)).toBe(someFunction);
48 });
49 it('isF(): null for string', function () {
50 expect(fs.isF(someString)).toBeNull();
51 });
52 it('isF(): null for number', function () {
53 expect(fs.isF(someNumber)).toBeNull();
54 });
55 it('isF(): null for Date', function () {
56 expect(fs.isF(someDate)).toBeNull();
57 });
58 it('isF(): null for array', function () {
59 expect(fs.isF(someArray)).toBeNull();
60 });
61 it('isF(): null for object', function () {
62 expect(fs.isF(someObject)).toBeNull();
63 });
64
65
66 // === Tests for isA()
67 it('isA(): null for undefined', function () {
68 expect(fs.isA(undefined)).toBeNull();
69 });
70 it('isA(): null for null', function () {
71 expect(fs.isA(null)).toBeNull();
72 });
73 it('isA(): null for function', function () {
74 expect(fs.isA(someFunction)).toBeNull();
75 });
76 it('isA(): null for string', function () {
77 expect(fs.isA(someString)).toBeNull();
78 });
79 it('isA(): null for number', function () {
80 expect(fs.isA(someNumber)).toBeNull();
81 });
82 it('isA(): null for Date', function () {
83 expect(fs.isA(someDate)).toBeNull();
84 });
85 it('isA(): the reference for array', function () {
86 expect(fs.isA(someArray)).toBe(someArray);
87 });
88 it('isA(): null for object', function () {
89 expect(fs.isA(someObject)).toBeNull();
90 });
91
92
93 // === Tests for isS()
94 it('isS(): null for undefined', function () {
95 expect(fs.isS(undefined)).toBeNull();
96 });
97 it('isS(): null for null', function () {
98 expect(fs.isS(null)).toBeNull();
99 });
100 it('isS(): null for function', function () {
101 expect(fs.isS(someFunction)).toBeNull();
102 });
103 it('isS(): the reference for string', function () {
104 expect(fs.isS(someString)).toBe(someString);
105 });
106 it('isS(): null for number', function () {
107 expect(fs.isS(someNumber)).toBeNull();
108 });
109 it('isS(): null for Date', function () {
110 expect(fs.isS(someDate)).toBeNull();
111 });
112 it('isS(): null for array', function () {
113 expect(fs.isS(someArray)).toBeNull();
114 });
115 it('isS(): null for object', function () {
116 expect(fs.isS(someObject)).toBeNull();
117 });
118
119
120 // === Tests for isO()
121 it('isO(): null for undefined', function () {
122 expect(fs.isO(undefined)).toBeNull();
123 });
124 it('isO(): null for null', function () {
125 expect(fs.isO(null)).toBeNull();
126 });
127 it('isO(): null for function', function () {
128 expect(fs.isO(someFunction)).toBeNull();
129 });
130 it('isO(): null for string', function () {
131 expect(fs.isO(someString)).toBeNull();
132 });
133 it('isO(): null for number', function () {
134 expect(fs.isO(someNumber)).toBeNull();
135 });
136 it('isO(): null for Date', function () {
137 expect(fs.isO(someDate)).toBeNull();
138 });
139 it('isO(): null for array', function () {
140 expect(fs.isO(someArray)).toBeNull();
141 });
142 it('isO(): the reference for object', function () {
143 expect(fs.isO(someObject)).toBe(someObject);
144 });
Simon Hunt59df0b22014-12-17 10:32:25 -0800145
146 // === Tests for contains()
147 it('contains(): false for improper args', function () {
148 expect(fs.contains()).toBeFalsy();
149 });
150 it('contains(): false for non-array', function () {
151 expect(fs.contains(null, 1)).toBeFalsy();
152 });
Simon Huntdc6362a2014-12-18 19:55:23 -0800153 it('contains(): true for contained item', function () {
Simon Hunt59df0b22014-12-17 10:32:25 -0800154 expect(fs.contains(someArray, 1)).toBeTruthy();
155 expect(fs.contains(stringArray, 'bar')).toBeTruthy();
156 });
Simon Huntdc6362a2014-12-18 19:55:23 -0800157 it('contains(): false for non-contained item', function () {
Simon Hunt59df0b22014-12-17 10:32:25 -0800158 expect(fs.contains(someArray, 109)).toBeFalsy();
159 expect(fs.contains(stringArray, 'zonko')).toBeFalsy();
160 });
Simon Huntf3069722014-12-16 18:15:37 -0800161});