]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/test/specs/data/proxy/Proxy.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / test / specs / data / proxy / Proxy.js
CommitLineData
6527f429
DM
1describe("Ext.data.proxy.Proxy", function() {\r
2 var proxy,\r
3 Proxy = Ext.data.proxy.Proxy,\r
4 AlienModelName = 'spec.Alien',\r
5 AlienModelConfig = {\r
6 extend: 'Ext.data.Model',\r
7 fields: [\r
8 {name: 'name', type: 'string'},\r
9 {name: 'age', type: 'int'},\r
10 {name: 'planet', type: 'string'}\r
11 ]\r
12 },\r
13 AlienModel, HumanModel,\r
14 HumanModelName = 'spec.Human',\r
15 HumanModelConfig = {\r
16 extend: 'Ext.data.Model',\r
17 fields: [\r
18 {name: 'name', type: 'string'},\r
19 {name: 'age', type: 'int'},\r
20 {name: 'planet', type: 'string', defaultValue: 'Earth'}\r
21 ]\r
22 };\r
23\r
24 beforeEach(function() {\r
25 Ext.ClassManager.enableNamespaceParseCache = false; \r
26 proxy = new Proxy({});\r
27 \r
28 AlienModel = Ext.define(AlienModelName, AlienModelConfig);\r
29 HumanModel = Ext.define(HumanModelName, HumanModelConfig);\r
30\r
31 });\r
32 \r
33 afterEach(function(){\r
34 Ext.ClassManager.enableNamespaceParseCache = true; \r
35 Ext.data.Model.schema.clear();\r
36 Ext.undefine('spec.Alien');\r
37 Ext.undefine('spec.Human');\r
38 \r
39 if (proxy) {\r
40 proxy.destroy();\r
41 }\r
42 \r
43 proxy = null;\r
44 });\r
45 \r
46\r
47 it("should mixin Ext.mixins.Observable", function() {\r
48 expect(proxy.mixins.observable).toEqual(Ext.mixin.Observable.prototype);\r
49 });\r
50\r
51 describe("instantiation", function() {\r
52 it("should default the batch order to create/update/destroy", function() {\r
53 expect(proxy.getBatchOrder()).toBe('create,update,destroy');\r
54 });\r
55 });\r
56\r
57 describe("methods", function() {\r
58 describe("getModel", function() {\r
59 it ("should return the proxy model", function() {\r
60 proxy.setModel(AlienModel);\r
61 expect(proxy.getModel()).toEqual(AlienModel);\r
62 });\r
63 });\r
64\r
65 describe("setModel", function() {\r
66 it('should have a model equal to AlienModel', function(){\r
67 proxy.setModel(AlienModel);\r
68 expect(proxy.getModel()).toEqual(AlienModel);\r
69 });\r
70\r
71 describe("if the Reader has already been instantiated", function() {\r
72 beforeEach(function() {\r
73 proxy.setReader(new Ext.data.reader.Reader({\r
74 model: null\r
75 }));\r
76\r
77 spyOn(proxy.getReader(), 'setModel').andReturn(true);\r
78 });\r
79\r
80 it("should set the Reader's Model", function() {\r
81 proxy.setModel(AlienModel);\r
82\r
83 expect(proxy.getReader().setModel).toHaveBeenCalledWith(AlienModel);\r
84 });\r
85 });\r
86 });\r
87\r
88 describe("batch", function() {\r
89 var spy,\r
90 batchOperations = {\r
91 create : [AlienModel, HumanModel],\r
92 update : [AlienModel]\r
93 },\r
94 batchListeners = {\r
95 complete: {\r
96 fn : Ext.emptyFn,\r
97 scope : this\r
98 }\r
99 };\r
100\r
101 it('should run Ext.data.Batch.prototype.add 2 times', function() {\r
102 spy = spyOn(Ext.data.Batch.prototype, 'add').andCallThrough();\r
103 proxy.batch(batchOperations, batchListeners); \r
104 expect(spy.callCount).toEqual(2);\r
105 });\r
106\r
107 it('should run Ext.data.Batch.prototype.start 1 times', function(){\r
108 spy = spyOn(Ext.data.Batch.prototype, 'start').andCallThrough();\r
109 proxy.batch(batchOperations, batchListeners); \r
110 expect(spy.callCount).toEqual(1);\r
111 });\r
112 });\r
113 });\r
114\r
115 describe("metachange event", function () {\r
116 var wasCalled = false,\r
117 successData = {\r
118 success: true,\r
119 data: [\r
120 {name: 'alex'},\r
121 {name: 'ben'},\r
122 {name: 'don'},\r
123 {name: 'evan'},\r
124 {name: 'nige'},\r
125 {name: 'phil'}\r
126 ],\r
127 metaData: {\r
128 root: 'data',\r
129 fields: ['occupation']\r
130 }\r
131 },\r
132 args, proxyArg, metaArg;\r
133\r
134 beforeEach(function () {\r
135 proxy = new Proxy({\r
136 listeners: {\r
137 metachange: function (proxy, meta) {\r
138 wasCalled = true;\r
139 args = arguments;\r
140 proxyArg = proxy;\r
141 metaArg = meta;\r
142 }\r
143 }\r
144 });\r
145\r
146 proxy.getReader().readRecords(successData);\r
147 });\r
148\r
149 afterEach(function () {\r
150 wasCalled = false;\r
151 args = proxyArg = metaArg = null;\r
152 });\r
153\r
154 it("should call the listener", function () {\r
155 expect(wasCalled).toBe(true);\r
156 });\r
157\r
158 it("should return the proxy", function () {\r
159 expect(proxyArg).toBe(proxy);\r
160 });\r
161\r
162 it("should return the meta data", function () {\r
163 expect(metaArg).toEqual(successData.metaData);\r
164 });\r
165\r
166 it("should return the proxy as the first arg", function () {\r
167 expect(args[0]).toBe(proxy);\r
168 });\r
169\r
170 it("should return the meta data as the second arg", function () {\r
171 expect(args[1]).toBe(metaArg);\r
172 });\r
173 });\r
174 \r
175 describe("pending operations", function() {\r
176 var op1, op2;\r
177 \r
178 beforeEach(function() {\r
179 op1 = new Ext.data.operation.Operation();\r
180 op2 = new Ext.data.operation.Operation();\r
181 \r
182 spyOn(op1, 'abort');\r
183 spyOn(op2, 'abort');\r
184 \r
185 proxy.pendingOperations[op1._internalId] = op1;\r
186 proxy.pendingOperations[op2._internalId] = op2;\r
187 });\r
188 \r
189 afterEach(function() {\r
190 op1 = op2 = proxy = null;\r
191 });\r
192 \r
193 describe("aborting", function() {\r
194 beforeEach(function() {\r
195 op1.execute();\r
196 proxy.destroy();\r
197 });\r
198 \r
199 it("should abort running operations", function() {\r
200 expect(op1.abort).toHaveBeenCalled();\r
201 });\r
202 \r
203 it("should not abort non-running operations", function() {\r
204 expect(op2.abort).not.toHaveBeenCalled();\r
205 });\r
206 });\r
207 \r
208 describe("cleanup", function() {\r
209 beforeEach(function() {\r
210 proxy.destroy();\r
211 });\r
212 \r
213 it("should null pendingOperations", function() {\r
214 expect(proxy.pendingOperations).toBe(null);\r
215 });\r
216 });\r
217 });\r
218});\r