]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.form.Panel", function() {\r |
2 | \r | |
3 | var panel;\r | |
4 | \r | |
5 | function createPanel(config) {\r | |
6 | config = config || {};\r | |
7 | panel = new Ext.form.Panel(config);\r | |
8 | }\r | |
9 | \r | |
10 | afterEach(function() {\r | |
11 | if (panel) {\r | |
12 | panel.destroy();\r | |
13 | panel = undefined;\r | |
14 | }\r | |
15 | });\r | |
16 | \r | |
17 | \r | |
18 | \r | |
19 | //========== SPECS: ==========//\r | |
20 | \r | |
21 | describe("creation", function() {\r | |
22 | it("should extend Ext.Panel", function() {\r | |
23 | expect(Ext.form.Panel.superclass).toBe(Ext.Panel.prototype);\r | |
24 | });\r | |
25 | \r | |
26 | it("should be registered with the 'form' xtype", function() {\r | |
27 | var component = Ext.create("Ext.form.Panel", {name: 'test'});\r | |
28 | expect(component instanceof Ext.form.Panel).toBe(true);\r | |
29 | expect(Ext.getClass(component).xtype).toBe("form");\r | |
30 | component.destroy();\r | |
31 | });\r | |
32 | });\r | |
33 | \r | |
34 | \r | |
35 | describe("form property", function() {\r | |
36 | it("should instantiate a Ext.form.Basic as its 'form' property", function() {\r | |
37 | createPanel();\r | |
38 | expect(panel.form instanceof Ext.form.Basic).toBeTruthy();\r | |
39 | });\r | |
40 | \r | |
41 | it("should return the BasicForm when calling the getForm() method", function() {\r | |
42 | createPanel();\r | |
43 | expect(panel.getForm() instanceof Ext.form.Basic).toBeTruthy();\r | |
44 | });\r | |
45 | });\r | |
46 | \r | |
47 | \r | |
48 | describe("default configs", function() {\r | |
49 | var undef,\r | |
50 | expected,\r | |
51 | cfg;\r | |
52 | \r | |
53 | function createTest(name, value) {\r | |
54 | it("should default the '" + cfg + "' config to " + expected[cfg], function() {\r | |
55 | createPanel();\r | |
56 | expect(panel[name]).toBe(value);\r | |
57 | });\r | |
58 | }\r | |
59 | \r | |
60 | expected = {\r | |
61 | hideLabels: undef,\r | |
62 | labelPad: undef,\r | |
63 | labelSeparator: undef,\r | |
64 | labelWidth: undef,\r | |
65 | labelAlign: undef,\r | |
66 | ariaRole: 'presentation',\r | |
67 | bodyAriaRole: 'form'\r | |
68 | };\r | |
69 | \r | |
70 | for (cfg in expected) {\r | |
71 | if (expected.hasOwnProperty(cfg)) {\r | |
72 | createTest.call(this, cfg, expected[cfg]);\r | |
73 | }\r | |
74 | }\r | |
75 | });\r | |
76 | \r | |
77 | \r | |
78 | describe("event relaying", function() {\r | |
79 | function testRelay(eventName) {\r | |
80 | var spy = jasmine.createSpy(eventName + ' handler');\r | |
81 | createPanel();\r | |
82 | panel.on(eventName, spy);\r | |
83 | panel.getForm().fireEvent(eventName);\r | |
84 | expect(spy).toHaveBeenCalled();\r | |
85 | }\r | |
86 | \r | |
87 | it("should relay 'beforeaction' events from the BasicForm", function() {\r | |
88 | testRelay('beforeaction');\r | |
89 | });\r | |
90 | it("should relay 'actionfailed' events from the BasicForm", function() {\r | |
91 | testRelay('actionfailed');\r | |
92 | });\r | |
93 | it("should relay 'actioncomplete' events from the BasicForm", function() {\r | |
94 | testRelay('actioncomplete');\r | |
95 | });\r | |
96 | it("should relay 'validitychange' events from the BasicForm", function() {\r | |
97 | testRelay('validitychange');\r | |
98 | });\r | |
99 | it("should relay 'dirtychange' events from the BasicForm", function() {\r | |
100 | testRelay('dirtychange');\r | |
101 | });\r | |
102 | });\r | |
103 | \r | |
104 | \r | |
105 | describe("destroying", function() {\r | |
106 | it("should call it's form object's destroy method", function() {\r | |
107 | createPanel();\r | |
108 | spyOn(panel.getForm(), 'destroy');\r | |
109 | panel.destroy();\r | |
110 | expect(panel.getForm().destroy).toHaveBeenCalled();\r | |
111 | });\r | |
112 | });\r | |
113 | \r | |
114 | \r | |
115 | describe("fieldDefaults", function() {\r | |
116 | it("should copy properties to a sub-field if those properties are not already configured on the field", function() {\r | |
117 | createPanel({\r | |
118 | fieldDefaults: {\r | |
119 | dummyConfig: 'foo'\r | |
120 | },\r | |
121 | renderTo: Ext.getBody()\r | |
122 | });\r | |
123 | var field = panel.add({xtype: 'textfield', name: 'myfield'});\r | |
124 | expect(field.dummyConfig).toBe('foo');\r | |
125 | });\r | |
126 | \r | |
127 | it("should not copy properties to a sub-field if those properties are already configured on the field", function() {\r | |
128 | createPanel({\r | |
129 | fieldDefaults: {\r | |
130 | dummyConfig: 'foo'\r | |
131 | }\r | |
132 | });\r | |
133 | var field = panel.add({xtype: 'textfield', name: 'myfield', dummyConfig: 'bar'});\r | |
134 | expect(field.dummyConfig).toBe('bar');\r | |
135 | });\r | |
136 | \r | |
137 | it("should copy fieldDefaults deep", function() {\r | |
138 | createPanel({\r | |
139 | renderTo: Ext.getBody(),\r | |
140 | fieldDefaults: {\r | |
141 | dummyConfig: 'foo'\r | |
142 | },\r | |
143 | items: {\r | |
144 | xtype: 'container',\r | |
145 | items: {\r | |
146 | xtype: 'container',\r | |
147 | items: {\r | |
148 | xtype: 'container',\r | |
149 | items: {\r | |
150 | xtype: 'textfield',\r | |
151 | itemId: 'foo'\r | |
152 | }\r | |
153 | }\r | |
154 | }\r | |
155 | }\r | |
156 | });\r | |
157 | var field = panel.down('#foo');\r | |
158 | expect(field.dummyConfig).toBe('foo');\r | |
159 | });\r | |
160 | \r | |
161 | });\r | |
162 | \r | |
163 | \r | |
164 | describe("minButtonWidth config", function() {\r | |
165 | it("should copy to items in the 'buttons' legacy toolbar config", function() {\r | |
166 | var panelCfg = {\r | |
167 | minButtonWidth: 1234,\r | |
168 | buttons: [{\r | |
169 | text: 'foo'\r | |
170 | }]\r | |
171 | };\r | |
172 | createPanel(panelCfg);\r | |
173 | var docked = panel.getDockedItems();\r | |
174 | expect(docked[docked.length - 1].child('button').minWidth).toBe(1234);\r | |
175 | });\r | |
176 | \r | |
177 | it("should not copy to items in the 'buttons' legacy toolbar config with an explicit minWidth", function() {\r | |
178 | var panelCfg = {\r | |
179 | minButtonWidth: 1234,\r | |
180 | buttons: [{\r | |
181 | text: 'foo',\r | |
182 | minWidth: 2345\r | |
183 | }]\r | |
184 | };\r | |
185 | createPanel(panelCfg);\r | |
186 | var docked = panel.getDockedItems();\r | |
187 | expect(docked[docked.length - 1].child('button').minWidth).toBe(2345);\r | |
188 | });\r | |
189 | });\r | |
190 | \r | |
191 | \r | |
192 | describe("load method", function() {\r | |
193 | it("should call the load method of the BasicForm", function() {\r | |
194 | createPanel();\r | |
195 | spyOn(panel.getForm(), 'load');\r | |
196 | panel.load({foo:'bar'});\r | |
197 | expect(panel.getForm().load).toHaveBeenCalledWith({foo:'bar'});\r | |
198 | });\r | |
199 | });\r | |
200 | \r | |
201 | describe("submit method", function() {\r | |
202 | it("should call the submit method of the BasicForm", function() {\r | |
203 | createPanel();\r | |
204 | spyOn(panel.getForm(), 'submit');\r | |
205 | panel.submit({foo:'bar'});\r | |
206 | expect(panel.getForm().submit).toHaveBeenCalledWith({foo:'bar'});\r | |
207 | });\r | |
208 | });\r | |
209 | \r | |
210 | describe("polling", function() {\r | |
211 | it("should call the startPolling method if the 'pollForChanges' config is true", function() {\r | |
212 | createPanel({\r | |
213 | pollForChanges: true,\r | |
214 | startPolling: jasmine.createSpy()\r | |
215 | });\r | |
216 | expect(panel.startPolling).toHaveBeenCalled();\r | |
217 | });\r | |
218 | \r | |
219 | it("should pass the 'pollInterval' config to the startPolling method", function() {\r | |
220 | createPanel({\r | |
221 | pollForChanges: true,\r | |
222 | pollInterval: 12345,\r | |
223 | startPolling: jasmine.createSpy()\r | |
224 | });\r | |
225 | expect(panel.startPolling).toHaveBeenCalledWith(12345);\r | |
226 | });\r | |
227 | \r | |
228 | it("should start running the 'checkChange' method on an interval", function() {\r | |
229 | runs(function() {\r | |
230 | createPanel();\r | |
231 | spyOn(panel, 'checkChange');\r | |
232 | panel.startPolling(1);\r | |
233 | });\r | |
234 | waitsFor(function() {\r | |
235 | return panel.checkChange.callCount > 1;\r | |
236 | }, 'did not start polling');\r | |
237 | });\r | |
238 | });\r | |
239 | \r | |
240 | describe("ARIA", function() {\r | |
241 | beforeEach(function() {\r | |
242 | createPanel({\r | |
243 | renderTo: Ext.getBody()\r | |
244 | });\r | |
245 | });\r | |
246 | \r | |
247 | describe("attributes", function() {\r | |
248 | it("should have form role on the body", function() {\r | |
249 | jasmine.expectAriaAttr(panel.body, 'role', 'form');\r | |
250 | });\r | |
251 | });\r | |
252 | });\r | |
253 | });\r |