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