blob: 44c12b5701847aa601fd143871775d007f47f541 [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/*
18 ONOS GUI -- General Purpose Functions - Unit Tests
19
20 @author Simon Hunt
21 */
22describe('factory: fw/lib/fn.js', function() {
23 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
32 beforeEach(module('onosApp'));
33
34 beforeEach(inject(function (FnService) {
35 fs = FnService;
36 }));
37
38 it('should have ONOS defined', function () {
39 expect(ONOS).toBeDefined();
40 });
41
42 it('should have FnService defined', function () {
43 expect(fs).toBeDefined();
44 });
45
46
47 // === Tests for isF()
48 it('isF(): null for undefined', function () {
49 expect(fs.isF(undefined)).toBeNull();
50 });
51 it('isF(): null for null', function () {
52 expect(fs.isF(null)).toBeNull();
53 });
54 it('isF(): the reference for function', function () {
55 expect(fs.isF(someFunction)).toBe(someFunction);
56 });
57 it('isF(): null for string', function () {
58 expect(fs.isF(someString)).toBeNull();
59 });
60 it('isF(): null for number', function () {
61 expect(fs.isF(someNumber)).toBeNull();
62 });
63 it('isF(): null for Date', function () {
64 expect(fs.isF(someDate)).toBeNull();
65 });
66 it('isF(): null for array', function () {
67 expect(fs.isF(someArray)).toBeNull();
68 });
69 it('isF(): null for object', function () {
70 expect(fs.isF(someObject)).toBeNull();
71 });
72
73
74 // === Tests for isA()
75 it('isA(): null for undefined', function () {
76 expect(fs.isA(undefined)).toBeNull();
77 });
78 it('isA(): null for null', function () {
79 expect(fs.isA(null)).toBeNull();
80 });
81 it('isA(): null for function', function () {
82 expect(fs.isA(someFunction)).toBeNull();
83 });
84 it('isA(): null for string', function () {
85 expect(fs.isA(someString)).toBeNull();
86 });
87 it('isA(): null for number', function () {
88 expect(fs.isA(someNumber)).toBeNull();
89 });
90 it('isA(): null for Date', function () {
91 expect(fs.isA(someDate)).toBeNull();
92 });
93 it('isA(): the reference for array', function () {
94 expect(fs.isA(someArray)).toBe(someArray);
95 });
96 it('isA(): null for object', function () {
97 expect(fs.isA(someObject)).toBeNull();
98 });
99
100
101 // === Tests for isS()
102 it('isS(): null for undefined', function () {
103 expect(fs.isS(undefined)).toBeNull();
104 });
105 it('isS(): null for null', function () {
106 expect(fs.isS(null)).toBeNull();
107 });
108 it('isS(): null for function', function () {
109 expect(fs.isS(someFunction)).toBeNull();
110 });
111 it('isS(): the reference for string', function () {
112 expect(fs.isS(someString)).toBe(someString);
113 });
114 it('isS(): null for number', function () {
115 expect(fs.isS(someNumber)).toBeNull();
116 });
117 it('isS(): null for Date', function () {
118 expect(fs.isS(someDate)).toBeNull();
119 });
120 it('isS(): null for array', function () {
121 expect(fs.isS(someArray)).toBeNull();
122 });
123 it('isS(): null for object', function () {
124 expect(fs.isS(someObject)).toBeNull();
125 });
126
127
128 // === Tests for isO()
129 it('isO(): null for undefined', function () {
130 expect(fs.isO(undefined)).toBeNull();
131 });
132 it('isO(): null for null', function () {
133 expect(fs.isO(null)).toBeNull();
134 });
135 it('isO(): null for function', function () {
136 expect(fs.isO(someFunction)).toBeNull();
137 });
138 it('isO(): null for string', function () {
139 expect(fs.isO(someString)).toBeNull();
140 });
141 it('isO(): null for number', function () {
142 expect(fs.isO(someNumber)).toBeNull();
143 });
144 it('isO(): null for Date', function () {
145 expect(fs.isO(someDate)).toBeNull();
146 });
147 it('isO(): null for array', function () {
148 expect(fs.isO(someArray)).toBeNull();
149 });
150 it('isO(): the reference for object', function () {
151 expect(fs.isO(someObject)).toBe(someObject);
152 });
Simon Hunt59df0b22014-12-17 10:32:25 -0800153
154 // === Tests for contains()
155 it('contains(): false for improper args', function () {
156 expect(fs.contains()).toBeFalsy();
157 });
158 it('contains(): false for non-array', function () {
159 expect(fs.contains(null, 1)).toBeFalsy();
160 });
161 it ('contains(): true for contained item', function () {
162 expect(fs.contains(someArray, 1)).toBeTruthy();
163 expect(fs.contains(stringArray, 'bar')).toBeTruthy();
164 });
165 it ('contains(): false for non-contained item', function () {
166 expect(fs.contains(someArray, 109)).toBeFalsy();
167 expect(fs.contains(stringArray, 'zonko')).toBeFalsy();
168 });
Simon Huntf3069722014-12-16 18:15:37 -0800169});