]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.data.field.Integer", function() {\r |
2 | \r | |
3 | var field;\r | |
4 | \r | |
5 | function make(cfg) {\r | |
6 | field = new Ext.data.field.Integer(cfg);\r | |
7 | }\r | |
8 | \r | |
9 | function c(v) {\r | |
10 | return field.convert(v);\r | |
11 | }\r | |
12 | \r | |
13 | afterEach(function() {\r | |
14 | field = null;\r | |
15 | });\r | |
16 | \r | |
17 | describe("defaults", function() {\r | |
18 | it("should configure the type", function() {\r | |
19 | make();\r | |
20 | expect(field.getType()).toBe('int');\r | |
21 | }); \r | |
22 | });\r | |
23 | \r | |
24 | describe("convert", function() {\r | |
25 | it("should call parseInt if passed a number", function() {\r | |
26 | make();\r | |
27 | var v;\r | |
28 | spyOn(window, 'parseInt').andCallFake(function(arg1) {\r | |
29 | v = arg1;\r | |
30 | return 17;\r | |
31 | }); \r | |
32 | expect(c(17.4)).toBe(17);\r | |
33 | expect(v).toBe(17.4);\r | |
34 | });\r | |
35 | \r | |
36 | describe("''/null/undefined", function() {\r | |
37 | describe("with allowNull: true", function() {\r | |
38 | beforeEach(function() {\r | |
39 | make({\r | |
40 | allowNull: true\r | |
41 | });\r | |
42 | });\r | |
43 | \r | |
44 | it("should return null with ''", function() {\r | |
45 | expect(c('')).toBeNull();\r | |
46 | });\r | |
47 | \r | |
48 | it("should return null with null", function() {\r | |
49 | expect(c(null)).toBeNull();\r | |
50 | }); \r | |
51 | \r | |
52 | it("should return null with undefined", function() {\r | |
53 | expect(c(undefined)).toBeNull();\r | |
54 | }); \r | |
55 | });\r | |
56 | \r | |
57 | describe("without allowNull: false", function() {\r | |
58 | beforeEach(function() {\r | |
59 | make({\r | |
60 | allowNull: false\r | |
61 | });\r | |
62 | });\r | |
63 | \r | |
64 | it("should return 0 with ''", function() {\r | |
65 | expect(c('')).toBe(0);\r | |
66 | });\r | |
67 | \r | |
68 | it("should return 0 with null", function() {\r | |
69 | expect(c(null)).toBe(0);\r | |
70 | }); \r | |
71 | \r | |
72 | it("should return 0 with undefined", function() {\r | |
73 | expect(c(undefined)).toBe(0);\r | |
74 | }); \r | |
75 | });\r | |
76 | });\r | |
77 | \r | |
78 | describe("other values", function() {\r | |
79 | describe("invalid values", function() {\r | |
80 | describe("with allowNull: true", function() {\r | |
81 | beforeEach(function() {\r | |
82 | make({\r | |
83 | allowNull: true\r | |
84 | });\r | |
85 | });\r | |
86 | \r | |
87 | it("should return null where a value can't be parsed", function() {\r | |
88 | expect(c('asdf')).toBeNull(); \r | |
89 | });\r | |
90 | }); \r | |
91 | \r | |
92 | describe("with allowNull: false", function() {\r | |
93 | beforeEach(function() {\r | |
94 | make({\r | |
95 | allowNull: false\r | |
96 | });\r | |
97 | });\r | |
98 | \r | |
99 | it("should return NaN where a value can't be parsed", function() {\r | |
100 | expect(isNaN(c('asdf'))).toBe(true); \r | |
101 | });\r | |
102 | }); \r | |
103 | });\r | |
104 | \r | |
105 | it("should parse a number string", function() {\r | |
106 | make();\r | |
107 | expect(c('34')).toBe(34); \r | |
108 | });\r | |
109 | \r | |
110 | it("should parse a number string and round it", function() {\r | |
111 | make();\r | |
112 | expect(c('42.123')).toBe(42); \r | |
113 | });\r | |
114 | });\r | |
115 | \r | |
116 | describe("stripRe", function() {\r | |
117 | it("should strip the value with the stripRe", function() {\r | |
118 | make();\r | |
119 | expect(c('$100,000%')).toBe(100000);\r | |
120 | }); \r | |
121 | \r | |
122 | it("should accept a custom stripRe", function() {\r | |
123 | // \u20ac = Euro symbol\r | |
124 | make({\r | |
125 | stripRe: /\u20ac/\r | |
126 | });\r | |
127 | expect(c('\u20ac200')).toBe(200);\r | |
128 | });\r | |
129 | });\r | |
130 | });\r | |
131 | \r | |
132 | });\r |