File: DataField.js

package info (click to toggle)
libjs-extjs 3.4.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 53,188 kB
  • ctags: 3,384
  • sloc: php: 819; xml: 537; python: 60; sql: 44; makefile: 35
file content (148 lines) | stat: -rw-r--r-- 5,253 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*!
 * Ext JS Library 3.4.0
 * Copyright(c) 2006-2011 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
Ext.test.session.addTest('Ext.data.Field', {
    name: 'Test data field creation',
    
    setUp: function(){
        this.t = Ext.data.Types;
        this.st = Ext.data.SortTypes;
    },
    
    tearDown: function(){
        delete this.t;
        delete this.st;
    },
    
    test_alias: function(){
        var f;
        
        f = new Ext.data.Field({type: null});
        Y.Assert.areEqual(this.t.AUTO, f.type, 'Test empty alias');
        f = new Ext.data.Field({type: 'auto'});
        Y.Assert.areEqual(this.t.AUTO, f.type, 'Test auto alias');
        
        f = new Ext.data.Field({type: 'int'});
        Y.Assert.areEqual(this.t.INT, f.type, 'Test int alias');
        f = new Ext.data.Field({type: 'integer'});
        Y.Assert.areEqual(this.t.INT, f.type, 'Test integer alias');
        
        f = new Ext.data.Field({type: 'float'});
        Y.Assert.areEqual(this.t.FLOAT, f.type, 'Test float alias');
        f = new Ext.data.Field({type: 'number'});
        Y.Assert.areEqual(this.t.FLOAT, f.type, 'Test number alias');
        
        f = new Ext.data.Field({type: 'bool'});
        Y.Assert.areEqual(this.t.BOOL, f.type, 'Test bool alias');
        f = new Ext.data.Field({type: 'boolean'});
        Y.Assert.areEqual(this.t.BOOL, f.type, 'Test boolean alias');
        
        f = new Ext.data.Field({type: 'string'});
        Y.Assert.areEqual(this.t.STRING, f.type, 'Test string alias');
        
        f = new Ext.data.Field({type: 'date'});
        Y.Assert.areEqual(this.t.DATE, f.type, 'Test date alias');
    },
    
    test_type: function(){
        var f;
        
        f = new Ext.data.Field({type: this.t.INT});
        Y.Assert.areEqual(this.t.INT, f.type, 'Test int type');
        
        f = new Ext.data.Field({type: this.t.AUTO});
        Y.Assert.areEqual(this.t.AUTO, f.type, 'Test auto type');
        
        f = new Ext.data.Field({type: this.t.STRING});
        Y.Assert.areEqual(this.t.STRING, f.type, 'Test string type');
    },
    
    test_sortType: function(){
        var f,
            s1 = function(v){
                return v * v;    
            },
            s2 = function(v){
                return Math.sqrt(v);
            };
        
        f = new Ext.data.Field({type: 'auto'});
        Y.Assert.areEqual(this.st.none, f.sortType, 'Test sort type defaults for auto');
        
        f = new Ext.data.Field({type: 'int'});
        Y.Assert.areEqual(this.st.none, f.sortType, 'Test sort type defaults for int');
        
        f = new Ext.data.Field({type: 'float'});
        Y.Assert.areEqual(this.st.none, f.sortType, 'Test sort type defaults for float');
        
        f = new Ext.data.Field({type: 'bool'});
        Y.Assert.areEqual(this.st.none, f.sortType, 'Test sort type defaults for bool');
        
        f = new Ext.data.Field({type: 'string'});
        Y.Assert.areEqual(this.st.asUCString, f.sortType, 'Test sort type defaults for string');
        
        f = new Ext.data.Field({type: 'date'});
        Y.Assert.areEqual(this.st.asDate, f.sortType, 'Test sort type defaults for date');
        
        f = new Ext.data.Field({
            type: 'auto',
            sortType: 'asDate'
        });
        Y.Assert.areEqual(this.st.asDate, f.sortType, 'Test with custom string sortType');
        
        f = new Ext.data.Field({
            type: 'int',
            sortType: s1
        });
        Y.Assert.areEqual(s1, f.sortType, 'Test with custom function sortType');
        
        f = new Ext.data.Field({
            type: 'date',
            sortType: s2
        });
        Y.Assert.areEqual(s2, f.sortType, 'Test with another custom function sortType');
    },
    
    test_convert: function(){
        var f,
            c1 = function(v){
                return v / 3;
            },
            c2 = function(v){
                return v * 4;    
            };
            
        f = new Ext.data.Field({type: 'auto'});
        Y.Assert.areEqual(this.t.AUTO.convert, f.convert, 'Test convert for auto');
        
        f = new Ext.data.Field({type: 'int'});
        Y.Assert.areEqual(this.t.INT.convert, f.convert, 'Test convert for int');
        
        f = new Ext.data.Field({type: 'float'});
        Y.Assert.areEqual(this.t.FLOAT.convert, f.convert, 'Test convert for float');
        
        f = new Ext.data.Field({type: 'bool'});
        Y.Assert.areEqual(this.t.BOOL.convert, f.convert, 'Test convert for bool');
        
        f = new Ext.data.Field({type: 'string'});
        Y.Assert.areEqual(this.t.STRING.convert, f.convert, 'Test convert for string');
        
        f = new Ext.data.Field({type: 'date'});
        Y.Assert.areEqual(this.t.DATE.convert, f.convert, 'Test convert for date');
        
        f = new Ext.data.Field({
            type: 'int',
            convert: c1
        });
        Y.Assert.areEqual(c1, f.convert, 'Test with custom function convert');
        
        f = new Ext.data.Field({
            type: 'date',
            convert: c2
        });
        Y.Assert.areEqual(c2, f.convert, 'Test with another custom function convert');
    }
});