]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.field.DatePicker", function() {\r |
2 | \r | |
3 | var field;\r | |
4 | \r | |
5 | function makeField(cfg) {\r | |
6 | field = new Ext.field.DatePicker(cfg);\r | |
7 | field.renderTo(Ext.getBody())\r | |
8 | }\r | |
9 | \r | |
10 | afterEach(function() {\r | |
11 | field = Ext.destroy(field);\r | |
12 | });\r | |
13 | \r | |
14 | describe("setValue", function() {\r | |
15 | it("should take accept a date object", function() {\r | |
16 | makeField();\r | |
17 | field.setValue(new Date(2010, 0, 1));\r | |
18 | expect(field.getValue()).toEqual(new Date(2010, 0, 1));\r | |
19 | });\r | |
20 | \r | |
21 | it("should accept a string that matches the dateFormat", function() {\r | |
22 | makeField({\r | |
23 | dateFormat: 'Y-m-d'\r | |
24 | });\r | |
25 | field.setValue('2010-01-01');\r | |
26 | expect(field.getValue()).toEqual(new Date(2010, 0, 1));\r | |
27 | });\r | |
28 | \r | |
29 | it("should return null for a string that does not match the format", function() {\r | |
30 | makeField({\r | |
31 | dateFormat: 'Y-m-d'\r | |
32 | });\r | |
33 | field.setValue('01/01/2010');\r | |
34 | expect(field.getValue()).toBeNull();\r | |
35 | });\r | |
36 | \r | |
37 | it("should update the text field with the formatted value when specifying a date", function() {\r | |
38 | makeField({\r | |
39 | dateFormat: 'Y-m-d'\r | |
40 | });\r | |
41 | field.setValue(new Date(2010, 0, 1));\r | |
42 | expect(field.getComponent().input.dom.value).toBe('2010-01-01');\r | |
43 | });\r | |
44 | \r | |
45 | it("should clear the text field when specifying null", function() {\r | |
46 | makeField({\r | |
47 | dateFormat: 'Y-m-d'\r | |
48 | });\r | |
49 | field.setValue(new Date(2010, 0, 1));\r | |
50 | field.setValue(null);\r | |
51 | expect(field.getComponent().input.dom.value).toBe('');\r | |
52 | });\r | |
53 | \r | |
54 | describe("events", function() {\r | |
55 | var spy;\r | |
56 | beforeEach(function() {\r | |
57 | spy = jasmine.createSpy();\r | |
58 | makeField();\r | |
59 | field.on('change', spy);\r | |
60 | });\r | |
61 | \r | |
62 | afterEach(function() {\r | |
63 | spy = null;\r | |
64 | });\r | |
65 | \r | |
66 | it("should fire the change event when setting a value", function() {\r | |
67 | field.setValue(new Date(2010, 0, 1));\r | |
68 | expect(spy.callCount).toBe(1);\r | |
69 | expect(spy.mostRecentCall.args[0]).toBe(field);\r | |
70 | expect(spy.mostRecentCall.args[1]).toEqual(new Date(2010, 0, 1));\r | |
71 | expect(spy.mostRecentCall.args[2]).toBeNull(field);\r | |
72 | });\r | |
73 | \r | |
74 | it("should fire the change event when changing a value", function() {\r | |
75 | field.setValue(new Date(2010, 0, 1));\r | |
76 | spy.reset();\r | |
77 | field.setValue(new Date(2010, 11, 31));\r | |
78 | expect(spy.callCount).toBe(1);\r | |
79 | expect(spy.mostRecentCall.args[0]).toBe(field);\r | |
80 | expect(spy.mostRecentCall.args[1]).toEqual(new Date(2010, 11, 31));\r | |
81 | expect(spy.mostRecentCall.args[2]).toEqual(new Date(2010, 0, 1));\r | |
82 | });\r | |
83 | \r | |
84 | it("should fire the change event when clearing a value", function() {\r | |
85 | field.setValue(new Date(2010, 0, 1));\r | |
86 | spy.reset();\r | |
87 | field.setValue(null);\r | |
88 | expect(spy.callCount).toBe(1);\r | |
89 | expect(spy.mostRecentCall.args[0]).toBe(field);\r | |
90 | expect(spy.mostRecentCall.args[1]).toBeNull();\r | |
91 | expect(spy.mostRecentCall.args[2]).toEqual(new Date(2010, 0, 1));\r | |
92 | });\r | |
93 | \r | |
94 | it("should not fire the change event when setting the same date", function() {\r | |
95 | field.setValue(new Date(2010, 0, 1));\r | |
96 | spy.reset();\r | |
97 | field.setValue(new Date(2010, 0, 1));\r | |
98 | expect(spy).not.toHaveBeenCalled();\r | |
99 | });\r | |
100 | });\r | |
101 | });\r | |
102 | \r | |
103 | describe("getValue", function() {\r | |
104 | it("should return a date object when configured with a value", function() {\r | |
105 | makeField({\r | |
106 | value: new Date(2010, 0, 1)\r | |
107 | });\r | |
108 | expect(field.getValue()).toEqual(new Date(2010, 0, 1));\r | |
109 | });\r | |
110 | \r | |
111 | it("should return a date object after having a value set", function() {\r | |
112 | makeField();\r | |
113 | field.setValue(new Date(2010, 0, 1));\r | |
114 | expect(field.getValue()).toEqual(new Date(2010, 0, 1));\r | |
115 | });\r | |
116 | \r | |
117 | it("should return null when not configured with a value", function() {\r | |
118 | makeField();\r | |
119 | expect(field.getValue()).toBeNull();\r | |
120 | });\r | |
121 | \r | |
122 | it("should return null after clearing a value", function() {\r | |
123 | makeField({\r | |
124 | value: new Date(2010, 0, 1)\r | |
125 | });\r | |
126 | field.setValue(null);\r | |
127 | expect(field.getValue()).toBeNull();\r | |
128 | });\r | |
129 | });\r | |
130 | \r | |
131 | describe("getFormattedValue", function() {\r | |
132 | it("should return the formatted value when configured with a value", function() {\r | |
133 | makeField({\r | |
134 | dateFormat: 'Y-m-d',\r | |
135 | value: new Date(2010, 0, 1)\r | |
136 | });\r | |
137 | expect(field.getFormattedValue()).toBe('2010-01-01');\r | |
138 | });\r | |
139 | \r | |
140 | it("should return the formatted value after having a value set", function() {\r | |
141 | makeField({\r | |
142 | dateFormat: 'Y-m-d'\r | |
143 | });\r | |
144 | field.setValue(new Date(2010, 0, 1));\r | |
145 | expect(field.getFormattedValue()).toBe('2010-01-01');\r | |
146 | });\r | |
147 | \r | |
148 | it("should favour a passed format over the class format", function() {\r | |
149 | makeField({\r | |
150 | dateFormat: 'd/m/Y'\r | |
151 | });\r | |
152 | field.setValue(new Date(2010, 0, 1));\r | |
153 | expect(field.getFormattedValue('Y-m-d')).toBe('2010-01-01');\r | |
154 | });\r | |
155 | \r | |
156 | it("should return '' when not configured with a value", function() {\r | |
157 | makeField();\r | |
158 | expect(field.getFormattedValue()).toBe('');\r | |
159 | });\r | |
160 | \r | |
161 | it("should return '' after clearing a value", function() {\r | |
162 | makeField({\r | |
163 | value: new Date(2010, 0, 1)\r | |
164 | });\r | |
165 | field.setValue(null);\r | |
166 | expect(field.getFormattedValue()).toBe('');\r | |
167 | });\r | |
168 | });\r | |
169 | \r | |
170 | \r | |
171 | }); |