blob: 4262411e0dc5ca6b545bd66f643ce81cc515a8da [file] [log] [blame]
Matteo Scandolo686547a2017-08-08 13:05:25 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandoloa5d03d52016-07-21 11:35:46 -070019(function () {
20 'use strict';
21
22 describe('The xos.helper module', function(){
23 describe('The Comparator service', () => {
24
25 let service;
26
27 // load the application module
28 beforeEach(module('xos.helpers'));
29
30 // inject the cartService
31 beforeEach(inject(function (_Comparator_) {
32 // The injector unwraps the underscores (_) from around the parameter names when matching
33 service = _Comparator_;
34 }));
35
36 describe('given a string', () => {
37 it('should return true if expected is substring of actual', () => {
38 const res = service('test', 'te');
39 expect(res).toBeTruthy();
40 });
41
42 it('should return false if expected is not substring of actual', () => {
43 const res = service('test', 'ab');
44 expect(res).toBeFalsy();
45 });
46 });
47
48 describe('given a boolean', () => {
49 it('should return true if values match', () => {
50 expect(service(false, false)).toBeTruthy();
51 expect(service(true, true)).toBeTruthy();
52 expect(service(0, false)).toBeTruthy();
53 expect(service(1, true)).toBeTruthy();
54 });
55
56 it('should return false if values doesn\'t match', () => {
57 expect(service(false, true)).toBeFalsy();
58 expect(service(true, false)).toBeFalsy();
59 expect(service(1, false)).toBeFalsy();
60 expect(service(0, true)).toBeFalsy();
61 });
62 });
63
64 describe('given a number', () => {
65 // NOTE if numbers should we compare with === ??
66 it('should return true if expected is substring of actual', () => {
67 expect(service(12, 1)).toBeTruthy();
68 });
69
70 it('should return false if expected is not substring of actual', () => {
71 expect(service(12, 3)).toBeFalsy();
72 });
73 });
74
75 });
76 });
77
78})();