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