]> git.proxmox.com Git - extjs.git/blob - extjs/packages/core/test/specs/direct/RemotingProvider.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / test / specs / direct / RemotingProvider.js
1 describe("Ext.direct.RemotingProvider", function() {
2 var RP = Ext.direct.RemotingProvider,
3 provider,
4
5 api = {
6 actions: {
7 "TestAction": [{
8 len: 1,
9 name: "echo"
10 },{
11 len: 1,
12 name: "directFail"
13 }, {
14 name: 'directForm',
15 formHandler: true
16 }, {
17 len: 1,
18 name: 'directMetaNamed',
19 metadata: {
20 params: [],
21 strict: false
22 }
23 }, {
24 len: 1,
25 name: 'directMetaOrdered',
26 metadata: {
27 len: 2
28 }
29 }, {
30 name: 'directMetaFormNamed',
31 formHandler: true,
32 metadata: {
33 params: [],
34 strict: false
35 }
36 }, {
37 name: 'directMetaFormOrdered',
38 formHandler: true,
39 metadata: {
40 len: 2
41 }
42 }],
43
44 "TestAction.Foo": [{
45 len: 0,
46 name: "foo"
47 }],
48
49 "TestAction.Foo.Bar": [{
50 len: 0,
51 name: "bar"
52 }],
53
54 "TestAction.Foo.Bar.Baz": [{
55 len: 0,
56 name: "baz"
57 }],
58
59 "TestAction.Foo.Qux": [{
60 len: 0,
61 name: "qux"
62 }]
63 },
64
65 namespace: "Direct.foo.bar",
66 type: "remoting",
67 url: "/router",
68 id: "foo"
69 },
70
71 directMethods = {
72 echo: function(value) {
73 return value;
74 },
75
76 directFail: function(value) {
77 return {
78 type: 'exception'
79 };
80 },
81
82 directForm: function(form) {
83 return {
84 success: true,
85 data: form
86 };
87 },
88
89 directMetaNamed: function(data, metadata) {
90 return {
91 data: data,
92 metadata: metadata
93 }
94 },
95
96 directMetaOrdered: function(data, metadata) {
97 return {
98 data: data,
99 metadata: metadata
100 }
101 },
102
103 directMetaFormNamed: function(form, metadata) {
104 return {
105 success: true,
106 data: form,
107 metadata: metadata
108 }
109 },
110
111 directMetaFormOrdered: function(form, metadata) {
112 return {
113 success: true,
114 data: form,
115 metadata: metadata
116 }
117 },
118
119 foo: function() {
120 return 'foo';
121 },
122
123 bar: function() {
124 return 'bar';
125 },
126
127 baz: function() {
128 return 'baz';
129 },
130
131 qux: function() {
132 return 'qux';
133 }
134 };
135
136 // This simulation stub is *asynchronous*
137 function simulateDirectRequest(options) {
138 var callback = options.callback,
139 scope = options.scope,
140 transaction = options.transaction,
141 isForm = options.form !== undefined,
142 isUpload = options.isUpload,
143 arg = {},
144 data, tid, action, method, arg, fn, success,
145 result, response, xhr, opt, metadata;
146
147 if (isForm) {
148 data = options.params;
149 tid = data.extTID;
150 action = data.extAction;
151 method = data.extMethod;
152 metadata = data.extMetadata;
153
154 // Collect the input field values
155 Ext.fly(options.form).select('input').each(function(el, c, idx) {
156 this[el.dom.name] = el.dom.value;
157 }, arg);
158 arg = [arg];
159 }
160 else {
161 data = options.jsonData;
162 tid = data.tid;
163 action = data.action;
164 method = data.method;
165 arg = data.data || [];
166 metadata = data.metadata;
167 }
168
169 fn = directMethods[method];
170
171 // TODO Come up with something less hacky
172 if (/^directMeta/.test(method)) {
173 arg.push(metadata);
174 }
175
176 if (options.timeout === 666) {
177 response = {
178 type: 'exception',
179 tid: tid,
180 message: "Can't connect to the server"
181 };
182
183 success = false;
184 }
185 else {
186 try {
187 result = fn.apply({}, arg);
188 response = {
189 type: 'rpc',
190 tid: tid,
191 action: action,
192 method: method,
193 result: result
194 };
195 }
196 catch (e) {
197 // Direct exception handling here
198 response = {
199 type: 'exception',
200 tid: tid,
201 message: e.toString(),
202 where: 'internal'
203 };
204 }
205
206 // Success only means *communication* success
207 success = true;
208 }
209
210 xhr = {
211 responseText: Ext.encode(response)
212 };
213
214 opt = {
215 transaction: transaction
216 };
217
218 Ext.callback(callback, scope, [opt, success, xhr], 1);
219 }
220
221 beforeEach(function() {
222 provider = new RP(api);
223 });
224
225 afterEach(function() {
226 if (provider) {
227 provider.destroy();
228 }
229
230 Ext.direct.Manager.clearAllMethods();
231
232 provider = null;
233
234 try {
235 delete window.Direct;
236 }
237 catch (e) {
238 window.Direct = undefined;
239 }
240 });
241
242 describe("handles namespaces:", function() {
243 var ns;
244
245 it("creates namespace for itself if passed a string", function() {
246 expect(Direct.foo.bar).toBeDefined();
247 });
248
249 it("doesn't create nested objects until it's connected", function() {
250 expect(Direct.foo.bar).toEqual({});
251 });
252
253 describe("creates nested namespaces after it's connected:", function() {
254 beforeEach(function() {
255 provider.connect();
256 ns = Direct.foo.bar;
257 });
258
259 it("creates TestAction", function() {
260 expect(ns.TestAction).toBeDefined();
261 });
262
263 it("creates TestAction.Foo", function() {
264 expect(ns.TestAction.Foo).toBeDefined();
265 });
266
267 it("creates TestAction.Foo.Bar", function() {
268 expect(ns.TestAction.Foo.Bar).toBeDefined();
269 });
270
271 it("creates TestAction.Foo.Bar.Baz", function() {
272 expect(ns.TestAction.Foo.Bar.Baz).toBeDefined();
273 });
274
275 it("creates TestAction.Foo.Qux", function() {
276 expect(ns.TestAction.Foo.Qux).toBeDefined();
277 });
278 });
279
280 describe("handles nested namespaces the old way:", function() {
281 beforeEach(function() {
282 provider.disableNestedActions = true;
283 provider.connect();
284 ns = Direct.foo.bar;
285 });
286
287 it("creates TestAction", function() {
288 expect(ns.TestAction).toBeDefined();
289 });
290
291 it("creates TestAction.Foo", function() {
292 expect(ns['TestAction.Foo']).toBeDefined();
293 // AND
294 expect(ns.TestAction.Foo).not.toBeDefined();
295 });
296
297 it("creates TestAction.Foo.Bar", function() {
298 expect(ns['TestAction.Foo.Bar']).toBeDefined();
299 });
300
301 it("creates TestAction.Foo.Bar.Baz", function() {
302 expect(ns['TestAction.Foo.Bar.Baz']).toBeDefined();
303 });
304
305 it("creates TestAction.Foo.Qux", function() {
306 expect(ns['TestAction.Foo.Qux']).toBeDefined();
307 });
308 });
309 });
310
311 describe("handles remoting methods:", function() {
312 var ns;
313
314 function checkFn(fn) {
315 expect( Ext.isFunction(fn) ).toBeTruthy();
316 };
317
318 beforeEach(function() {
319 provider.connect();
320 ns = Direct.foo.bar;
321 });
322
323 it("has Foo.foo", function() {
324 checkFn(ns.TestAction.Foo.foo);
325 });
326
327 it("has Foo.Bar.bar", function() {
328 checkFn(ns.TestAction.Foo.Bar.bar);
329 });
330
331 it("has Foo.Bar.Baz.baz", function() {
332 checkFn(ns.TestAction.Foo.Bar.Baz.baz);
333 });
334
335 it("has Foo.Qux.qux", function() {
336 checkFn(ns.TestAction.Foo.Qux.qux);
337 });
338 });
339
340 describe("runs remoting methods:", function() {
341 var ns, echo, options, handler;
342
343 function echoStatus(result, event) {
344 this.echo = event.status;
345 }
346
347 function echoResult(result, event) {
348 if (event.status) {
349 this.echo = result;
350 }
351 }
352
353 function echoFormResult(request, result) {
354 this.echo = result.result;
355 }
356
357 function echoResultAndOptions(result, event, success, options) {
358 if (success) {
359 this.echo = result;
360 this.options = options;
361 }
362 }
363
364 function returnFalse() {
365 return false;
366 }
367
368 function checkEcho() {
369 return Ext.isDefined(this.echo);
370 }
371
372 function checkHandler() {
373 return !!handler.callCount;
374 }
375
376 function waitForEcho(fn, desc, timeout) {
377 fn = fn || checkEcho;
378 desc = desc || 'callback never fired';
379 timeout = timeout != null ? timeout : 100;
380
381 waitsFor(fn, desc, timeout);
382 }
383
384 function expectEcho(want) {
385 runs(function() {
386 expect(this.echo).toEqual(want);
387 });
388 }
389
390 beforeEach(function() {
391 echo = undefined;
392 options = undefined;
393
394 spyOn(Ext.Ajax, 'request').andCallFake(simulateDirectRequest);
395
396 provider.connect();
397 ns = Direct.foo.bar;
398
399 handler = jasmine.createSpy('event handler');
400 });
401
402 afterEach(function() {
403 handler = undefined;
404 });
405
406 describe("handles call mechanics", function() {
407 describe("call batching", function() {
408 afterEach(function() {
409 // Transactions in this suite have no chance of finishing,
410 // so we clean them up manually
411 if (provider.callTask) {
412 provider.callTask.cancel();
413 }
414
415 Ext.direct.Manager.transactions.clear();
416 });
417
418 it("should batch calls within specified enableBuffer timeout", function() {
419 var options, baseTid;
420
421 runs(function() {
422 Ext.Ajax.request.andCallFake(function(opt) {
423 options = opt;
424 });
425
426 baseTid = Ext.direct.Transaction.TRANSACTION_ID;
427
428 ns.TestAction.echo('foo', Ext.emptyFn);
429 ns.TestAction.echo('bar', Ext.emptyFn);
430 });
431
432 waitsFor(function() { return !!options }, 'options never modified', 20);
433
434 runs(function() {
435 expect(options.jsonData).toEqual([{
436 action: 'TestAction',
437 method: 'echo',
438 type: 'rpc',
439 tid: baseTid + 1,
440 data: ['foo']
441 }, {
442 action: 'TestAction',
443 method: 'echo',
444 type: 'rpc',
445 tid: baseTid + 2,
446 data: ['bar']
447 }]);
448 });
449 });
450
451 it("should run calls with specified timeout w/o batching", function() {
452 var options = [],
453 baseTid;
454
455 runs(function() {
456 Ext.Ajax.request.andCallFake(function(opt) {
457 options.push(opt);
458 });
459
460 provider.enableBuffer = 200;
461 baseTid = Ext.direct.Transaction.TRANSACTION_ID;
462
463 ns.TestAction.echo('baz', Ext.emptyFn);
464 ns.TestAction.echo('qux', Ext.emptyFn, this, { timeout: 1 });
465 });
466
467 waitsFor(function() { return !!options }, 'options never modified', 20);
468
469 runs(function() {
470 expect(options.length).toBe(1);
471 // AND
472 expect(options[0].jsonData).toEqual({
473 action: 'TestAction',
474 method: 'echo',
475 type: 'rpc',
476 tid: baseTid + 2,
477 data: ['qux']
478 });
479 });
480 });
481
482 it("should run calls instantly with disableBatching", function() {
483 var options = [],
484 baseTid;
485
486 runs(function() {
487 Ext.Ajax.request.andCallFake(function(opt) {
488 options.push(opt);
489 });
490
491 provider.enableBuffer = 200;
492 baseTid = Ext.direct.Transaction.TRANSACTION_ID;
493
494 ns.TestAction.echo('baz', Ext.emptyFn);
495
496 ns.TestAction.echo.$directCfg.method.disableBatching = true;
497 ns.TestAction.echo('qux', Ext.emptyFn);
498 });
499
500 waitsFor(function() { return !!options }, 'options never modified', 20);
501
502 runs(function() {
503 expect(options.length).toBe(1);
504 // AND
505 expect(options[0].jsonData).toEqual({
506 action: 'TestAction',
507 method: 'echo',
508 type: 'rpc',
509 tid: baseTid + 2,
510 data: ['qux']
511 });
512 });
513 });
514
515 it("should run calls instantly with enableBuffer = false", function() {
516 var option, baseTid;
517
518 Ext.Ajax.request.andCallFake(function(opt) {
519 options = opt;
520 });
521
522 provider.enableBuffer = false;
523 baseTid = Ext.direct.Transaction.TRANSACTION_ID;
524
525 ns.TestAction.echo('fred', Ext.emptyFn);
526
527 expect(options.jsonData).toEqual({
528 action: 'TestAction',
529 method: 'echo',
530 type: 'rpc',
531 tid: baseTid + 1,
532 data: ['fred']
533 });
534 });
535
536 describe("bufferLimit", function() {
537 var options, baseTid;
538
539 beforeEach(function() {
540 options = [];
541
542 Ext.Ajax.request.andCallFake(function(opt) {
543 options.push(opt);
544 });
545
546 provider.enableBuffer = 200;
547 provider.bufferLimit = 3;
548
549 baseTid = Ext.direct.Transaction.TRANSACTION_ID;
550 });
551
552 it("should batch calls up to bufferLimit", function() {
553 runs(function() {
554 ns.TestAction.echo('fee', Ext.emptyFn);
555 ns.TestAction.echo('fie', Ext.emptyFn);
556 ns.TestAction.echo('foe', Ext.emptyFn);
557 ns.TestAction.echo('foo', Ext.emptyFn);
558 });
559
560 waitsFor(function() {
561 return !!options.length;
562 }, 'options never modified', 20);
563
564 runs(function() {
565 expect(options.length).toBe(1);
566
567 expect(options[0].jsonData).toEqual([{
568 action: 'TestAction',
569 method: 'echo',
570 type: 'rpc',
571 tid: baseTid + 1,
572 data: ['fee']
573 }, {
574 action: 'TestAction',
575 method: 'echo',
576 type: 'rpc',
577 tid: baseTid + 2,
578 data: ['fie']
579 }, {
580 action: 'TestAction',
581 method: 'echo',
582 type: 'rpc',
583 tid: baseTid + 3,
584 data: ['foe']
585 }]);
586 });
587 });
588
589 it("should make 2 batched requests for 6 calls", function() {
590 runs(function() {
591 ns.TestAction.echo('frobbe', Ext.emptyFn);
592 ns.TestAction.echo('throbbe', Ext.emptyFn);
593 ns.TestAction.echo('gurgle', Ext.emptyFn);
594 ns.TestAction.echo('bonzo', Ext.emptyFn);
595 ns.TestAction.echo('mymse', Ext.emptyFn);
596 ns.TestAction.echo('splurge', Ext.emptyFn);
597 });
598
599 waitsFor(function() {
600 return !!options.length;
601 }, 'options never modified', 20);
602
603 runs(function() {
604 expect(options.length).toBe(2);
605
606 expect(options[0].jsonData).toEqual([{
607 action: 'TestAction',
608 method: 'echo',
609 type: 'rpc',
610 tid: baseTid + 1,
611 data: ['frobbe']
612 }, {
613 action: 'TestAction',
614 method: 'echo',
615 type: 'rpc',
616 tid: baseTid + 2,
617 data: ['throbbe']
618 }, {
619 action: 'TestAction',
620 method: 'echo',
621 type: 'rpc',
622 tid: baseTid + 3,
623 data: ['gurgle']
624 }]);
625
626 expect(options[1].jsonData).toEqual([{
627 action: 'TestAction',
628 method: 'echo',
629 type: 'rpc',
630 tid: baseTid + 4,
631 data: ['bonzo']
632 }, {
633 action: 'TestAction',
634 method: 'echo',
635 type: 'rpc',
636 tid: baseTid + 5,
637 data: ['mymse']
638 }, {
639 action: 'TestAction',
640 method: 'echo',
641 type: 'rpc',
642 tid: baseTid + 6,
643 data: ['splurge']
644 }]);
645 });
646 });
647
648 it("should make 3 batched requests for 7 calls", function() {
649 runs(function() {
650 ns.TestAction.echo('Grumpy', Ext.emptyFn);
651 ns.TestAction.echo('Sleepy', Ext.emptyFn);
652 ns.TestAction.echo('Dopey', Ext.emptyFn);
653 ns.TestAction.echo('Bashful', Ext.emptyFn);
654 ns.TestAction.echo('Sneezy', Ext.emptyFn);
655 ns.TestAction.echo('Happy', Ext.emptyFn);
656 ns.TestAction.echo('Doc', Ext.emptyFn);
657 });
658
659 waitsFor(function() {
660 return options.length === 3;
661 }, '3 Ajax requests', 300);
662
663 runs(function() {
664 expect(options.length).toBe(3);
665
666 expect(options[0].jsonData).toEqual([{
667 action: 'TestAction',
668 method: 'echo',
669 type: 'rpc',
670 tid: baseTid + 1,
671 data: ['Grumpy']
672 }, {
673 action: 'TestAction',
674 method: 'echo',
675 type: 'rpc',
676 tid: baseTid + 2,
677 data: ['Sleepy']
678 }, {
679 action: 'TestAction',
680 method: 'echo',
681 type: 'rpc',
682 tid: baseTid + 3,
683 data: ['Dopey']
684 }]);
685
686 expect(options[1].jsonData).toEqual([{
687 action: 'TestAction',
688 method: 'echo',
689 type: 'rpc',
690 tid: baseTid + 4,
691 data: ['Bashful']
692 }, {
693 action: 'TestAction',
694 method: 'echo',
695 type: 'rpc',
696 tid: baseTid + 5,
697 data: ['Sneezy']
698 }, {
699 action: 'TestAction',
700 method: 'echo',
701 type: 'rpc',
702 tid: baseTid + 6,
703 data: ['Happy']
704 }]);
705
706 expect(options[2].jsonData).toEqual({
707 action: 'TestAction',
708 method: 'echo',
709 type: 'rpc',
710 tid: baseTid + 7,
711 data: ['Doc']
712 });
713 });
714 });
715 });
716 });
717
718 describe("call related events", function() {
719 it("fires 'beforecall' event", function() {
720 runs(function() {
721 provider.on('beforecall', handler);
722
723 ns.TestAction.echo('fred', Ext.emptyFn);
724 });
725
726 waitsFor(checkHandler, 'event handler never fired', 20);
727
728 runs(function() {
729 expect(handler).toHaveBeenCalled();
730 });
731
732 waits(35);
733 });
734
735 it("fires 'call' event", function() {
736 runs(function() {
737 provider.on('call', handler);
738
739 ns.TestAction.echo('plugh', Ext.emptyFn);
740 });
741
742 waitsFor(checkHandler, 'event handler never fired', 20);
743
744 runs(function() {
745 expect(handler).toHaveBeenCalled();
746 });
747
748 waits(35);
749 });
750
751 it("cancels request when 'beforecall' handler returns false", function() {
752 runs(function() {
753 handler.andCallFake(returnFalse);
754
755 provider.on('beforecall', handler);
756
757 ns.TestAction.echo('mymse', Ext.emptyFn);
758 });
759
760 waitsFor(checkHandler, 'event handler never fired', 200);
761
762 // Additional timeout for callbacks to queue and fire
763 waits(20);
764
765 runs(function() {
766 expect(options).toBeUndefined();
767 });
768
769 waits(35);
770 });
771 });
772 });
773
774 describe("with connection failed", function() {
775 it("retries failed transactions", function() {
776 var proto = Ext.direct.Transaction.prototype;
777
778 runs(function() {
779 spyOn(proto, 'retry').andCallThrough();
780
781 ns.TestAction.echo('foo', Ext.emptyFn, this, { timeout: 666 });
782 });
783
784 waitsFor(function() {
785 return proto.retry.callCount === 1;
786 }, 'transaction.retry() never called', 200);
787
788 runs(function() {
789 expect(proto.retry).toHaveBeenCalled();
790 });
791 });
792
793 it("fires exception when retry count is exceeded", function() {
794 runs(function() {
795 provider.on('data', handler);
796
797 ns.TestAction.echo('bar', Ext.emptyFn, this, { timeout: 666 });
798 });
799
800 waitsFor(checkHandler, 'event handler never fired', 200);
801
802 runs(function() {
803 expect(handler).toHaveBeenCalled();
804 });
805 });
806
807 describe("handles callback:", function() {
808 it("fires 'beforecallback' event", function() {
809 runs(function() {
810 provider.on('beforecallback', handler);
811
812 ns.TestAction.echo('baz', Ext.emptyFn, this, { timeout: 666 });
813 });
814
815 waitsFor(checkHandler, 'event handler never fired', 200);
816
817 runs(function() {
818 expect(handler).toHaveBeenCalled();
819 });
820 });
821
822 it("cancels callback when 'beforecallback' handler returns false", function() {
823 var cb = jasmine.createSpy('callback');
824
825 runs(function() {
826 handler.andCallFake(returnFalse);
827
828 provider.on('beforecallback', handler);
829
830 ns.TestAction.echo('qux', cb, this, { timeout: 666 });
831 });
832
833 waitsFor(checkHandler, 'event handler never fired', 200);
834
835 // Additional timeout for callback to be handled
836 waits(20);
837
838 runs(function() {
839 expect(handler).toHaveBeenCalled();
840 // AND
841 expect(cb).not.toHaveBeenCalled();
842 });
843 });
844
845 it("fires callback when retry count is exceeded", function() {
846 runs(function() {
847 ns.TestAction.echo('plugh', echoStatus, this, { timeout: 666 });
848 });
849
850 waitsFor(checkEcho, 'callback never fired', 200);
851
852 runs(function() {
853 expect(this.echo).toBe(false);
854 });
855 });
856 });
857 });
858
859 describe("successfully connected:", function() {
860 it("fires 'data' event", function() {
861 runs(function() {
862 provider.on('data', handler);
863
864 ns.TestAction.echo('foo', echoResult, this);
865 });
866
867 waitForEcho();
868
869 runs(function() {
870 expect(handler).toHaveBeenCalled();
871 });
872 });
873
874 describe("handles callback:", function() {
875 it("fires 'beforecallback' event", function() {
876 runs(function() {
877 provider.on('beforecallback', handler);
878
879 ns.TestAction.echo('foo', echoResult, this);
880 });
881
882 waitsFor(checkEcho, 'event handler never fired', 100);
883
884 runs(function() {
885 expect(handler).toHaveBeenCalled();
886 });
887 });
888
889 it("cancels callback when 'beforecallback' handler returns false", function() {
890 var cb = jasmine.createSpy('callback');
891
892 runs(function() {
893 handler.andCallFake(returnFalse);
894
895 provider.on('beforecallback', handler);
896
897 ns.TestAction.echo('bar', cb, this);
898 });
899
900 waitsFor(checkHandler, 'event handler never fired', 100);
901
902 // Additional timeout for callback to be handled
903 waits(20);
904
905 runs(function() {
906 expect(handler).toHaveBeenCalled();
907 // AND
908 expect(cb).not.toHaveBeenCalled();
909 });
910 });
911
912 it('runs w/o additional options', function() {
913 runs(function() {
914 ns.TestAction.echo('foo', echoResult, this);
915 });
916
917 waitForEcho();
918
919 expectEcho('foo');
920 });
921
922 it('runs w/ additional options', function() {
923 runs(function() {
924 ns.TestAction.echo('bar', echoResultAndOptions, this, {
925 victory: 'Huzzah!'
926 });
927 });
928
929 waitForEcho();
930
931 runs(function() {
932 expect(this.echo).toEqual('bar');
933 expect(this.options).toBeDefined();
934 expect(this.options.victory).toEqual('Huzzah!');
935 });
936 });
937
938 it('runs in nested namespaces', function() {
939 runs(function() {
940 ns.TestAction.Foo.foo(echoResult, this);
941 });
942
943 waitForEcho();
944
945 expectEcho('foo');
946 });
947
948 it('runs in deeply nested namespaces', function() {
949 runs(function() {
950 ns.TestAction.Foo.Bar.bar(echoResult, this);
951 });
952
953 waitForEcho();
954
955 expectEcho('bar');
956 });
957
958 it('runs in really truly deeply nested namespaces', function() {
959 runs(function() {
960 ns.TestAction.Foo.Bar.Baz.baz(echoResult, this);
961 });
962
963 waitForEcho();
964
965 expectEcho('baz');
966 });
967 });
968
969 describe("metadata", function() {
970 it("will pass named metadata", function() {
971 runs(function() {
972 ns.TestAction.directMetaNamed('foo', echoResult, this, {
973 metadata: {
974 bleh: 'blah'
975 }
976 });
977 });
978
979 waitForEcho();
980
981 expectEcho({ data: 'foo', metadata: { bleh: 'blah' } });
982 });
983
984 it("will pass ordered metadata", function() {
985 runs(function() {
986 ns.TestAction.directMetaOrdered('bar', echoResult, this, {
987 metadata: ['blerg', 'blam', 'frob']
988 });
989 });
990
991 waitForEcho();
992
993 // Metadata len === 2, so 3rd argument should be cut off
994 expectEcho({ data: 'bar', metadata: ['blerg', 'blam'] });
995 });
996 })
997 });
998
999 (Ext.toolkit === 'classic' ? describe : xdescribe)("form calls:", function() {
1000 var form;
1001
1002 function createForm(config) {
1003 config = Ext.apply({
1004 xtype: 'form',
1005 renderTo: document.body,
1006 width: 300,
1007 height: 200,
1008 layout: 'form',
1009
1010 api: {
1011 submit: 'TestAction.directForm'
1012 },
1013
1014 items: [{
1015 xtype: 'hiddenfield',
1016 name: 'hidden_foo',
1017 value: 'hide the sacred foo from infoodels!'
1018 }, {
1019 xtype: 'textfield',
1020 name: 'overt_foo',
1021 value: 'behold the false, deceitful overt foo'
1022 }]
1023 }, config);
1024
1025 form = Ext.widget(config);
1026 }
1027
1028 beforeEach(function() {
1029 createForm();
1030 });
1031
1032 afterEach(function() {
1033 if (form) {
1034 form.destroy();
1035 }
1036 });
1037
1038 describe("submit", function() {
1039 it("should pass field values to direct fn", function() {
1040 runs(function() {
1041 form.submit({
1042 success: echoFormResult,
1043 scope: this
1044 });
1045 });
1046
1047 // Callbacks are a bit slow but 2 sec is enough
1048 waitsFor(checkEcho, 'callback that never fired', 2000);
1049
1050 runs(function() {
1051 expect(this.echo).toEqual({
1052 success: true,
1053 data: {
1054 hidden_foo: 'hide the sacred foo from infoodels!',
1055 overt_foo: 'behold the false, deceitful overt foo'
1056 }
1057 });
1058 });
1059 });
1060
1061 it("should pass extra params to direct fn", function() {
1062 runs(function() {
1063 form.submit({
1064 params: {
1065 simple_foo: 'barf!'
1066 },
1067 success: echoFormResult,
1068 scope: this
1069 });
1070 });
1071
1072 waitsFor(checkEcho, 'callback that never fired', 2000);
1073
1074 runs(function() {
1075 expect(this.echo).toEqual({
1076 success: true,
1077 data: {
1078 hidden_foo: 'hide the sacred foo from infoodels!',
1079 overt_foo: 'behold the false, deceitful overt foo',
1080 simple_foo: 'barf!'
1081 }
1082 });
1083 });
1084 });
1085
1086 it("should pass form baseParams to direct fn", function() {
1087 runs(function() {
1088 form.getForm().baseParams = {
1089 MEGA_FOO: 'ALL YOUR FOO ARE BELONG TO US!'
1090 };
1091
1092 form.submit({
1093 success: echoFormResult,
1094 scope: this
1095 });
1096 });
1097
1098 waitsFor(checkEcho, 'callback that never fired', 2000);
1099
1100 runs(function() {
1101 expect(this.echo).toEqual({
1102 success: true,
1103 data: {
1104 hidden_foo: 'hide the sacred foo from infoodels!',
1105 overt_foo: 'behold the false, deceitful overt foo',
1106 MEGA_FOO: 'ALL YOUR FOO ARE BELONG TO US!'
1107 }
1108 });
1109 });
1110 });
1111
1112 it("should pass named metadata", function() {
1113 runs(function() {
1114 form.getForm().api.submit = 'TestAction.directMetaFormNamed';
1115
1116 form.getForm().metadata = {
1117 foo: 'bargh!'
1118 };
1119
1120 form.submit({
1121 success: echoFormResult,
1122 scope: this
1123 });
1124 });
1125
1126 waitsFor(checkEcho, 'callback that never fired', 2000);
1127
1128 runs(function() {
1129 expect(this.echo).toEqual({
1130 success: true,
1131 data: {
1132 hidden_foo: 'hide the sacred foo from infoodels!',
1133 overt_foo: 'behold the false, deceitful overt foo'
1134 },
1135
1136 // JSONified!
1137 metadata: '{"foo":"bargh!"}'
1138 });
1139 });
1140 });
1141
1142 it("should pass ordered metadata", function() {
1143 runs(function() {
1144 form.getForm().api.submit = 'TestAction.directMetaFormOrdered';
1145
1146 form.getForm().metadata = ['bram', 'blam', 'qux?'];
1147
1148 form.submit({
1149 success: echoFormResult,
1150 scope: this
1151 });
1152 });
1153
1154 waitsFor(checkEcho, 'callback that never fired', 2000);
1155
1156 runs(function() {
1157 expect(this.echo).toEqual({
1158 success: true,
1159 data: {
1160 hidden_foo: 'hide the sacred foo from infoodels!',
1161 overt_foo: 'behold the false, deceitful overt foo'
1162 },
1163
1164 // JSONified!
1165 metadata: '["bram","blam"]'
1166 });
1167 });
1168 });
1169 });
1170 });
1171 });
1172 });