blob: 1dfd0d667016b19232e2920e19c33806adc17263 [file] [log] [blame]
Matteo Scandolofb46ae62017-08-08 09:10:50 -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 Scandoloa7df7192017-04-11 15:37:04 -070019import * as angular from 'angular';
20import 'angular-mocks';
21import {IXosFormHelpersService, XosFormHelpers} from './form-helpers';
22
23let service: IXosFormHelpersService;
24
25describe('The XosFormHelpers service', () => {
26
27 beforeEach(() => {
28 angular.module('formHelpers', [])
29 .service('XosFormHelpers', XosFormHelpers);
30 angular.mock.module('formHelpers');
31
32 angular.mock.inject((
33 XosFormHelpers: IXosFormHelpersService,
34 ) => {
35 service = XosFormHelpers;
36 });
37 });
38
39 describe('the getFieldFormat method', () => {
40 it('should return text', () => {
41 expect(service._getFieldFormat('cordSubscriber-1')).toEqual('text');
42 expect(service._getFieldFormat('a random text')).toEqual('text');
43 expect(service._getFieldFormat(null)).toEqual('text');
44 expect(service._getFieldFormat('1')).toEqual('text');
45 });
46 it('should return mail', () => {
47 expect(service._getFieldFormat('test@onlab.us')).toEqual('email');
48 expect(service._getFieldFormat('testonlab.us')).not.toEqual('email');
49 });
50 it('should return number', () => {
51 expect(service._getFieldFormat(1)).toEqual('number');
52 });
53 it('should return boolean', () => {
54 expect(service._getFieldFormat(false)).toEqual('boolean');
55 expect(service._getFieldFormat(true)).toEqual('boolean');
56 });
57
58 it('should return date', () => {
59 expect(service._getFieldFormat('2016-04-19T23:09:1092Z')).toEqual('text');
60 expect(service._getFieldFormat(new Date())).toEqual('date');
61 expect(service._getFieldFormat('2016-04-19T23:09:10.208092Z')).toEqual('date');
62 });
63
64 it('should return array', () => {
65 expect(service._getFieldFormat([])).toEqual('array');
66 expect(service._getFieldFormat(['a', 'b'])).toEqual('array');
67 });
68
69 it('should return object', () => {
70 expect(service._getFieldFormat({})).toEqual('object');
71 expect(service._getFieldFormat({foo: 'bar'})).toEqual('object');
72 });
73 });
74});