Best JavaScript code snippet using ava
Container.js
Source:Container.js
1describe("Ext.Container", function() {2 var ct;34 afterEach(function() {5 ct = Ext.destroy(ct);6 });78 function makeContainer(cfg) {9 if (Ext.isArray(cfg)) {10 cfg = {11 items: cfg12 };13 }14 ct = new Ext.container.Container(cfg);15 return ct;16 }17 18 describe("add", function() {19 beforeEach(function() {20 makeContainer();21 });22 23 it("should return the item when adding single item", function() {24 var c = ct.add({25 xtype: 'component'26 });27 28 expect(ct.items.getAt(0)).toBe(c);29 });30 31 it("should return the array of added items when passed an array", function() {32 var cs = ct.add([{ xtype: 'component' }]);33 34 expect(Ext.isArray(cs)).toBe(true);35 expect(cs.length).toBe(1);36 expect(ct.items.getAt(0)).toBe(cs[0]);37 });38 39 it("should return the array of added items when adding more than one", function() {40 var cs = ct.add([41 { xtype: 'component' },42 { xtype: 'component' }43 ]);44 45 expect(Ext.isArray(cs)).toBe(true);46 expect(cs.length).toBe(2);47 expect(ct.items.getAt(0)).toBe(cs[0]);48 expect(ct.items.getAt(1)).toBe(cs[1]);49 });50 });51 52 describe("remove", function() {53 var c0, c1;54 55 beforeEach(function() {56 makeContainer({57 items: [{58 // itemIds are reversed to trip the tests59 // if something goes wrong60 xtype: 'component',61 itemId: '1'62 }, {63 xtype: 'component',64 itemId: '0'65 }]66 });67 68 c0 = ct.items.getAt(0);69 c1 = ct.items.getAt(1);70 });71 72 afterEach(function() {73 Ext.destroy(c0, c1);74 c0 = c1 = null;75 });76 77 describe("by instance", function() {78 it("should remove an item", function() {79 ct.remove(c0);80 81 expect(ct.items.getCount()).toBe(1);82 });83 84 it("should return the removed item", function() {85 var ret = ct.remove(c0);86 87 expect(ret).toBe(c0);88 });89 90 it("should destroy the item when asked to", function() {91 var ret = ct.remove(c0, true);92 93 expect(ret.destroyed).toBe(true);94 });95 96 it("should not remove the remaining item", function() {97 var ret = ct.remove(c0);98 99 expect(ct.items.getAt(0)).toBe(c1);100 });101 });102 103 describe("by index", function() {104 it("should remove an item", function() {105 ct.remove(0);106 107 expect(ct.items.getCount()).toBe(1);108 });109 110 it("should return the removed item", function() {111 var ret = ct.remove(0);112 113 expect(ret).toBe(c0);114 });115 116 it("should destroy the item when asked to", function() {117 var ret = ct.remove(0, true);118 119 expect(ret.destroyed).toBe(true);120 });121 122 it("should not remove the remaining item", function() {123 ct.remove(0);124 125 expect(ct.items.getAt(0)).toBe(c1);126 });127 });128 129 describe("by itemId", function() {130 it("should remove an item", function() {131 ct.remove('0');132 133 expect(ct.items.getCount()).toBe(1);134 });135 136 it("should return the removed item", function() {137 var ret = ct.remove('0');138 139 expect(ret).toBe(c1);140 });141 142 it("should destroy the item when asked to", function() {143 var ret = ct.remove('0');144 145 expect(ret.destroyed).toBe(true);146 });147 148 it("should not remove the remaining item", function() {149 ct.remove('0');150 151 expect(ct.items.getAt(0)).toBe(c0);152 });153 });154 });155 156 describe("removeAll", function() {157 var c0, c1;158 159 beforeEach(function() {160 makeContainer({161 items: [{162 xtype: 'component'163 }, {164 xtype: 'component'165 }]166 });167 168 c0 = ct.items.getAt(0);169 c1 = ct.items.getAt(1);170 });171 172 afterEach(function() {173 Ext.destroy(c0, c1);174 c0 = c1 = null;175 });176 177 it("should remove all items", function() {178 ct.removeAll();179 180 expect(ct.items.getCount()).toBe(0);181 });182 183 it("should return the removed items", function() {184 var ret = ct.removeAll();185 186 expect(Ext.isArray(ret)).toBe(true);187 expect(ret.length).toBe(2);188 expect(ret[0]).toBe(c0);189 expect(ret[1]).toBe(c1);190 });191 192 it("should destroy the items when asked", function() {193 var ret = ct.removeAll(true);194 195 expect(ret[0].destroyed).toBe(true);196 expect(ret[1].destroyed).toBe(true);197 });198 199 // TODO removeAll(true, true)200 xit("should remove everything", function() {201 });202 });203 204 describe("removeAt", function() {205 var c0, c1;206 207 beforeEach(function() {208 makeContainer({209 items: [{210 xtype: 'component'211 }, {212 xtype: 'component'213 }]214 });215 216 c0 = ct.items.getAt(0);217 c1 = ct.items.getAt(1);218 });219 220 afterEach(function() {221 Ext.destroy(c0, c1);222 c0 = c1 = null;223 });224 225 it("should remove the item at index", function() {226 ct.removeAt(0);227 228 expect(ct.items.getCount()).toBe(1);229 });230 231 it("should return the removed item", function() {232 var ret = ct.removeAt(0);233 234 expect(ret).toBe(c0);235 });236 237 it("should not remove other items", function() {238 ct.removeAt(0);239 240 expect(ct.items.getAt(0)).toBe(c1);241 });242 });243 244 // TODO Not sure what an inner item is and how to add it? - AT245 xdescribe("removeInnerAt", function() {246 });247248 describe("references", function() {249 describe("static", function() {250 it("should not be a reference holder by default", function() {251 makeContainer({252 items: {253 xtype: 'component',254 reference: 'a'255 }256 }); 257 expect(ct.lookupReference('foo')).toBeNull();258 });259 260 it("should support a direct child", function() {261 makeContainer({262 referenceHolder: true,263 items: {264 xtype: 'component',265 itemId: 'compA',266 reference: 'a'267 }268 });269 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));270 });271 272 it("should support a deep child", function() {273 makeContainer({274 referenceHolder: true,275 items: {276 xtype: 'container',277 items: {278 xtype: 'container',279 items: {280 xtype: 'container',281 items: {282 xtype: 'component',283 itemId: 'compA',284 reference: 'a'285 }286 }287 }288 }289 });290 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));291 });292 293 it("should support children at multiple depths", function() {294 makeContainer({295 referenceHolder: true,296 items: [{297 xtype: 'component',298 itemId: 'compA',299 reference: 'a'300 }, {301 xtype: 'container',302 items: {303 xtype: 'component',304 itemId: 'compB',305 reference: 'b'306 }307 }]308 }); 309 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));310 expect(ct.lookupReference('b')).toBe(ct.down('#compB'));311 });312 313 it("should support multiple children at the same depth", function() {314 makeContainer({315 referenceHolder: true,316 items: [{317 xtype: 'component',318 itemId: 'compA',319 reference: 'a'320 }, {321 xtype: 'component',322 itemId: 'compB',323 reference: 'b'324 }]325 });326 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));327 expect(ct.lookupReference('b')).toBe(ct.down('#compB'));328 });329 330 it("should support multiple children down the some tree", function() {331 makeContainer({332 referenceHolder: true,333 items: [{334 xtype: 'container',335 itemId: 'compA',336 reference: 'a',337 items: {338 xtype: 'container',339 itemId: 'compB',340 reference: 'b',341 items: {342 xtype: 'component',343 itemId: 'compC',344 reference: 'c'345 }346 }347 }]348 });349 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));350 expect(ct.lookupReference('b')).toBe(ct.down('#compB'));351 expect(ct.lookupReference('c')).toBe(ct.down('#compC'));352 });353 354 it("should support a reference holder not being at the root", function() {355 makeContainer({356 items: {357 xtype: 'container',358 items: {359 xtype: 'container',360 itemId: 'ref',361 referenceHolder: true,362 items: {363 xtype: 'container',364 items: {365 xtype: 'component',366 itemId: 'compA',367 reference: 'a'368 }369 }370 }371 }372 }); 373 var ref = ct.down('#ref');374 expect(ref.lookupReference('a')).toBe(ref.down('#compA'));375 });376 377 it("should support multiple ref holders in a tree", function() {378 makeContainer({379 referenceHolder: true,380 items: {381 xtype: 'container',382 itemId: 'compA',383 reference: 'a',384 items: {385 xtype: 'container',386 referenceHolder: true,387 itemId: 'ref',388 items: {389 xtype: 'container',390 items: {391 xtype: 'component',392 itemId: 'compB',393 reference: 'b'394 }395 }396 }397 }398 });399 var ref = ct.down('#ref');400 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));401 expect(ref.lookupReference('b')).toBe(ref.down('#compB'));402 });403 404 it("should hide inner references from outer holders", function() {405 makeContainer({406 referenceHolder: true,407 items: {408 xtype: 'container',409 itemId: 'compA',410 reference: 'a',411 items: {412 xtype: 'container',413 referenceHolder: true,414 itemId: 'ref',415 items: {416 xtype: 'container',417 items: {418 xtype: 'component',419 itemId: 'compB',420 reference: 'b'421 }422 }423 }424 }425 });426 expect(ct.lookupReference('b')).toBeNull();427 });428 429 it("should allow a reference holder to have a reference", function() {430 makeContainer({431 referenceHolder: true,432 items: {433 referenceHolder: true,434 xtype: 'container',435 itemId: 'compA',436 reference: 'a',437 items: {438 xtype: 'container',439 itemId: 'compB',440 reference: 'b'441 }442 }443 });444 445 var inner = ct.down('#compA');446 447 expect(inner.lookupReference('b')).toBe(inner.down('#compB'));448 expect(ct.lookupReference('a')).toBe(inner);449 });450 451 describe("docking", function() {452 it("should get a reference to a direct child", function() {453 makeContainer({454 referenceHolder: true,455 items: {456 docked: 'top',457 xtype: 'component',458 itemId: 'compA',459 reference: 'a'460 }461 });462 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));463 });464 465 it("should get a reference to an indirect child", function() {466 makeContainer({467 referenceHolder: true,468 items: {469 xtype: 'container',470 docked: 'top',471 items: {472 xtype: 'component',473 itemId: 'compA',474 reference: 'a'475 }476 }477 });478 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));479 });480 });481 482 describe("chained references", function() {483 it("should gain a reference to a deep child", function() {484 makeContainer({485 referenceHolder: true,486 items: [{487 xtype: 'container',488 reference: 'parent>',489 items: {490 xtype: 'component',491 itemId: 'compA',492 reference: 'a'493 }494 }]495 });496 expect(ct.lookupReference('parent.a')).toBe(ct.down('#compA'));497 });498 499 it("should strip the > from the parent reference", function() {500 makeContainer({501 referenceHolder: true,502 items: [{503 xtype: 'container',504 reference: 'a>',505 itemId: 'compA',506 items: {507 xtype: 'component',508 reference: 'b'509 }510 }]511 });512 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));513 });514 515 it("should allow the parent to be reference even if there's no children", function() {516 makeContainer({517 referenceHolder: true,518 items: [{519 xtype: 'container',520 reference: 'a>',521 itemId: 'compA'522 }]523 });524 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));525 });526 527 it("should not setup a deep reference if the there's an intervening referenceHolder", function() {528 makeContainer({529 referenceHolder: true,530 items: [{531 xtype: 'container',532 referenceHolder: true,533 reference: 'a>',534 items: {535 xtype: 'component',536 reference: 'b'537 }538 }]539 });540 expect(ct.lookupReference('b')).toBeNull();541 });542 543 it("should allow for a multiple depth reference", function() {544 makeContainer({545 referenceHolder: true,546 items: [{547 xtype: 'container',548 reference: 'a>',549 items: {550 xtype: 'container',551 reference: 'b>',552 items: {553 xtype: 'container',554 reference: 'c>',555 items: {556 xtype: 'container',557 reference: 'd>',558 items: {559 xtype: 'component',560 reference: 'e',561 itemId: 'compE'562 }563 }564 }565 }566 }]567 });568 expect(ct.lookupReference('a.b.c.d.e')).toBe(ct.down('#compE'));569 });570 571 it("should isolate references by parent", function() {572 makeContainer({573 referenceHolder: true,574 items: [{575 xtype: 'container',576 reference: 'parent1>',577 items: {578 xtype: 'component',579 reference: 'child',580 itemId: 'compA'581 }582 }, {583 xtype: 'container',584 reference: 'parent2>',585 items: {586 xtype: 'component',587 reference: 'child',588 itemId: 'compB'589 }590 }]591 });592 expect(ct.lookupReference('parent1.child')).toBe(ct.down('#compA'));593 expect(ct.lookupReference('parent2.child')).toBe(ct.down('#compB'));594 });595 596 it("should allow the reference holder to begin at any depth", function() {597 makeContainer({598 items: [{599 xtype: 'container',600 reference: 'a>',601 items: {602 xtype: 'container',603 reference: 'b>',604 items: {605 xtype: 'container',606 referenceHolder: true,607 reference: 'c>',608 itemId: 'compC',609 items: {610 xtype: 'container',611 reference: 'd>',612 items: {613 xtype: 'component',614 reference: 'e',615 itemId: 'compE'616 }617 }618 }619 }620 }]621 });622 var inner = ct.down('#compC');623 expect(inner.lookupReference('d.e')).toBe(ct.down('#compE'));624 });625 626 it("should allow multiple references in the tree", function() {627 makeContainer({628 referenceHolder: true,629 items: [{630 xtype: 'container',631 reference: 'a>',632 itemId: 'compA',633 items: {634 xtype: 'container',635 reference: 'b>',636 itemId: 'compB',637 items: {638 xtype: 'container',639 referenceHolder: true,640 reference: 'c>',641 itemId: 'compC',642 items: {643 xtype: 'container',644 reference: 'd>',645 itemId: 'compD',646 items: {647 xtype: 'component',648 reference: 'e',649 itemId: 'compE'650 }651 }652 }653 }654 }]655 });656 expect(ct.lookupReference('a.b')).toBe(ct.down('#compB'));657 expect(ct.lookupReference('a.b.c')).toBe(ct.down('#compC'));658 expect(ct.lookupReference('a.b.c.d')).toBeNull();659 expect(ct.lookupReference('a.b.c.d.e')).toBeNull();660 }); 661 662 describe("docking", function() {663 it("should get a reference to an indirect child", function() {664 makeContainer({665 referenceHolder: true,666 items: {667 xtype: 'container',668 docked: 'top',669 reference: 'a>',670 items: {671 xtype: 'component',672 itemId: 'compB',673 reference: 'b'674 }675 }676 });677 expect(ct.lookupReference('a.b')).toBe(ct.down('#compB'));678 });679 });680 });681 });682 683 describe("dynamic", function() {684 describe("adding", function() {685 it("should gain a reference to a direct child", function() {686 makeContainer({687 referenceHolder: true688 });689 ct.add({690 xtype: 'component',691 itemId: 'compA',692 reference: 'a'693 });694 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));695 }); 696 697 it("should gain a reference to an indirect child", function() {698 makeContainer({699 referenceHolder: true700 });701 ct.add({702 xtype: 'container',703 items: {704 xtype: 'component',705 itemId: 'compA',706 reference: 'a'707 }708 });709 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));710 });711 712 it("should gain a reference to a component inside an already constructed container", function() {713 var local = new Ext.container.Container({714 items: {715 xtype: 'component',716 itemId: 'compA',717 reference: 'a'718 }719 }); 720 721 makeContainer({722 referenceHolder: true,723 items: local724 });725 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));726 });727 728 it("should gain a reference to a component added to containers child", function() {729 makeContainer({730 referenceHolder: true,731 items: {732 xtype: 'container'733 }734 }); 735 ct.items.first().add({736 xtype: 'component',737 itemId: 'compA',738 reference: 'a'739 }); 740 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));741 });742 743 describe("chained references", function() {744 it("should gain a reference to an indirect child", function() {745 makeContainer({746 referenceHolder: true747 });748 ct.add({749 xtype: 'container',750 reference: 'parent>',751 items: {752 xtype: 'component',753 itemId: 'compA',754 reference: 'a'755 }756 });757 expect(ct.lookupReference('parent.a')).toBe(ct.down('#compA'));758 });759760 it("should gain a reference to a component inside an already constructed container", function() {761 var local = new Ext.container.Container({762 reference: 'parent>',763 items: {764 xtype: 'component',765 itemId: 'compA',766 reference: 'a'767 }768 }); 769770 makeContainer({771 referenceHolder: true,772 items: local773 });774 expect(ct.lookupReference('parent.a')).toBe(ct.down('#compA'));775 });776777 it("should gain a reference to a component added to containers child", function() {778 makeContainer({779 referenceHolder: true,780 items: {781 xtype: 'container',782 reference: 'parent>'783 }784 }); 785 ct.items.first().add({786 xtype: 'component',787 itemId: 'compA',788 reference: 'a'789 }); 790 expect(ct.lookupReference('parent.a')).toBe(ct.down('#compA'));791 });792 793 describe("docking", function() {794 it("should gain a reference to an indirect child", function() {795 makeContainer({796 referenceHolder: true797 });798 ct.add({799 xtype: 'container',800 docked: 'top',801 reference: 'parent>',802 items: {803 xtype: 'component',804 itemId: 'compA',805 reference: 'a'806 }807 });808 expect(ct.lookupReference('parent.a')).toBe(ct.down('#compA'));809 });810811 it("should gain a reference to a component inside an already constructed container", function() {812 var local = new Ext.container.Container({813 docked: 'top',814 reference: 'parent>',815 items: {816 xtype: 'component',817 itemId: 'compA',818 reference: 'a'819 }820 }); 821822 makeContainer({823 referenceHolder: true,824 items: local825 });826 expect(ct.lookupReference('parent.a')).toBe(ct.down('#compA'));827 });828829 it("should gain a reference to a component added to containers child", function() {830 makeContainer({831 referenceHolder: true,832 items: {833 docked: 'top',834 xtype: 'container',835 itemId: 'docked',836 reference: 'parent>'837 }838 }); 839 ct.down('#docked').add({840 xtype: 'component',841 itemId: 'compA',842 reference: 'a'843 }); 844 expect(ct.lookupReference('parent.a')).toBe(ct.down('#compA'));845 });846 });847 });848 849 describe("docking", function() {850 it("should gain a reference to a direct child", function() {851 makeContainer({852 referenceHolder: true853 });854 ct.add({855 xtype: 'component',856 docked: 'top',857 itemId: 'compA',858 reference: 'a'859 });860 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));861 }); 862 863 it("should gain a reference to an indirect child", function() {864 makeContainer({865 referenceHolder: true866 });867 ct.add({868 xtype: 'container',869 docked: 'top',870 items: {871 xtype: 'component',872 itemId: 'compA',873 reference: 'a'874 }875 });876 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));877 });878 879 it("should gain a reference to a component inside an already constructed container", function() {880 var local = new Ext.container.Container({881 docked: 'top',882 items: {883 xtype: 'component',884 itemId: 'compA',885 reference: 'a'886 }887 }); 888 889 makeContainer({890 referenceHolder: true,891 items: local892 });893 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));894 });895 896 it("should gain a reference to a component added to containers child", function() {897 makeContainer({898 referenceHolder: true,899 items: {900 xtype: 'container',901 docked: 'top',902 itemId: 'docked'903 }904 }); 905 ct.down('#docked').add({906 xtype: 'component',907 itemId: 'compA',908 reference: 'a'909 }); 910 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));911 });912 }); 913 });914 915 describe("removing", function() {916 it("should not have a reference when removing a direct child", function() {917 makeContainer({918 referenceHolder: true,919 items: {920 xtype: 'component',921 reference: 'a'922 }923 }); 924 var c = ct.lookupReference('a');925 c.destroy();926 expect(ct.lookupReference('a')).toBeNull();927 });928 929 it("should not have a reference when removing an indirect child", function() {930 makeContainer({931 referenceHolder: true,932 items: {933 xtype: 'container',934 items: {935 xtype: 'component',936 reference: 'a'937 }938 }939 }); 940 var c = ct.lookupReference('a');941 c.destroy();942 expect(ct.lookupReference('a')).toBeNull();943 });944 945 it("should not have a reference when removing+destroying a container that has references", function() {946 makeContainer({947 referenceHolder: true,948 items: {949 xtype: 'container',950 items: {951 xtype: 'component',952 reference: 'a'953 }954 }955 }); 956 var c = ct.lookupReference('a');957 var removed = ct.remove(0);958 expect(ct.lookupReference('a')).toBeNull();959 removed.destroy();960 });961 962 it("should not have a reference when only removing a container that has references", function() {963 makeContainer({964 id: 'a',965 referenceHolder: true,966 items: {967 id: 'b',968 xtype: 'container',969 items: {970 id: 'c',971 xtype: 'component',972 reference: 'a'973 }974 }975 });976 977 var c = ct.lookupReference('a');978 var removed = ct.remove(0, false);979 expect(ct.lookupReference('a')).toBeNull();980 removed.destroy();981 });982 983 describe("chained references", function() {984 it("should not have a reference when removing an indirect child", function() {985 makeContainer({986 referenceHolder: true,987 items: {988 xtype: 'container',989 reference: 'parent>',990 items: {991 xtype: 'component',992 reference: 'a'993 }994 }995 }); 996 var c = ct.lookupReference('parent.a');997 c.destroy();998 expect(ct.lookupReference('parent.a')).toBeNull();999 });10001001 it("should not have a reference when removing+destroying a container that has references", function() {1002 makeContainer({1003 referenceHolder: true,1004 items: {1005 xtype: 'container',1006 reference: 'parent>',1007 items: {1008 xtype: 'component',1009 reference: 'a'1010 }1011 }1012 }); 1013 var c = ct.lookupReference('parent.a');1014 var removed = ct.remove(0);1015 expect(ct.lookupReference('parent.a')).toBeNull();1016 removed.destroy();1017 });10181019 it("should not have a reference when only removing a container that has references", function() {1020 makeContainer({1021 referenceHolder: true,1022 items: {1023 xtype: 'container',1024 reference: 'parent>',1025 items: {1026 xtype: 'component',1027 reference: 'a'1028 }1029 }1030 }); 1031 var c = ct.lookupReference('parent.a');1032 var removed = ct.remove(0, false);1033 expect(ct.lookupReference('parent.a')).toBeNull();1034 removed.destroy();1035 });1036 1037 describe("docking", function() {1038 it("should not have a reference when removing an indirect child", function() {1039 makeContainer({1040 referenceHolder: true,1041 items: {1042 xtype: 'container',1043 docked: 'top',1044 reference: 'parent>',1045 items: {1046 xtype: 'component',1047 reference: 'a'1048 }1049 }1050 }); 1051 var c = ct.lookupReference('parent.a');1052 c.destroy();1053 expect(ct.lookupReference('parent.a')).toBeNull();1054 });10551056 it("should not have a reference when removing+destroying a container that has references", function() {1057 makeContainer({1058 referenceHolder: true,1059 items: {1060 xtype: 'container',1061 docked: 'top',1062 itemId: 'docked',1063 reference: 'parent>',1064 items: {1065 xtype: 'component',1066 reference: 'a'1067 }1068 }1069 }); 1070 var dock = ct.down('#docked');10711072 ct.remove(dock);1073 expect(ct.lookupReference('parent.a')).toBeNull();1074 });10751076 it("should not have a reference when only removing a container that has references", function() {1077 makeContainer({1078 referenceHolder: true,1079 items: {1080 xtype: 'container',1081 docked: 'top',1082 itemId: 'docked',1083 reference: 'parent>',1084 items: {1085 xtype: 'component',1086 reference: 'a'1087 }1088 }1089 }); 1090 var dock = ct.down('#docked');10911092 var removed = ct.remove(dock, false);1093 expect(ct.lookupReference('parent.a')).toBeNull();1094 removed.destroy();1095 }); 1096 });1097 });1098 1099 describe("docking", function() {1100 it("should not have a reference when removing a direct child", function() {1101 makeContainer({1102 referenceHolder: true,1103 items: {1104 xtype: 'component',1105 docked: 'top',1106 reference: 'a'1107 }1108 }); 1109 var c = ct.lookupReference('a');1110 c.destroy();1111 expect(ct.lookupReference('a')).toBeNull();1112 });1113 1114 it("should not have a reference when removing an indirect child", function() {1115 makeContainer({1116 referenceHolder: true,1117 items: {1118 xtype: 'container',1119 docked: 'top',1120 items: {1121 xtype: 'component',1122 reference: 'a'1123 }1124 }1125 }); 1126 var c = ct.lookupReference('a');1127 c.destroy();1128 expect(ct.lookupReference('a')).toBeNull();1129 });1130 1131 it("should not have a reference when removing+destroying a container that has references", function() {1132 makeContainer({1133 referenceHolder: true,1134 items: {1135 xtype: 'container',1136 docked: 'top',1137 itemId: 'docked',1138 items: {1139 xtype: 'component',1140 reference: 'a'1141 }1142 }1143 }); 1144 var dock = ct.down('#docked');1145 1146 ct.remove(dock);1147 expect(ct.lookupReference('a')).toBeNull();1148 });1149 1150 xit("should not have a reference when only removing a container that has references", function() {1151 makeContainer({1152 referenceHolder: true,1153 dockedItems: {1154 xtype: 'container',1155 docked: 'top',1156 itemId: 'docked',1157 items: {1158 xtype: 'component',1159 reference: 'a'1160 }1161 }1162 });1163 1164 var dock = ct.down('#docked');1165 1166 var removed = ct.remove(dock, false);1167 expect(ct.lookupReference('a')).toBeNull();1168 removed.destroy();1169 }); 1170 });1171 });1172 });11731174 describe("setup", function() {1175 it("should not create references on the rootInheritedState if not requested", function() {1176 var vp = new Ext.viewport.Default({1177 referenceHolder: true1178 });11791180 var temp = new Ext.container.Container({1181 items: {1182 xtype: 'component',1183 reference: 'a'1184 }1185 });11861187 var c = temp.items.first();118811891190 ct = new Ext.container.Container({1191 referenceHolder: true,1192 items: temp1193 });11941195 expect(vp.lookupReference('a')).toBeNull();1196 expect(ct.lookupReference('a')).toBe(c);11971198 vp.destroy();1199 });1200 });1201 });12021203 describe("view controllers", function() {1204 var Controller;1205 beforeEach(function() {1206 Controller = Ext.define('spec.TestController', {1207 extend: 'Ext.app.ViewController',1208 alias: 'controller.test'1209 });1210 });1211 1212 afterEach(function() {1213 Controller = null;1214 Ext.undefine('spec.TestController');1215 Ext.Factory.controller.instance.clearCache();1216 });1217 1218 it("should use a defined controller as a referenceHolder", function() {1219 makeContainer({1220 controller: 'test',1221 items: {1222 xtype: 'component',1223 itemId: 'compA',1224 reference: 'a'1225 }1226 }); 1227 expect(ct.lookupReference('a')).toBe(ct.down('#compA'));1228 }); 1229 });1230 1231 describe("defaultListenerScope", function() {1232 describe("static", function() {1233 it("should fire on a direct parent", function() {1234 makeContainer({1235 defaultListenerScope: true,1236 items: {1237 xtype: 'container',1238 itemId: 'compA',1239 listeners: {1240 custom: 'callFn'1241 }1242 }1243 });1244 ct.callFn = jasmine.createSpy();1245 ct.down('#compA').fireEvent('custom');1246 expect(ct.callFn).toHaveBeenCalled(); 1247 });12481249 it("should fire on an indirect parent", function() {1250 makeContainer({1251 defaultListenerScope: true,1252 items: {1253 xtype: 'container',1254 items: {1255 xtype: 'container',1256 itemId: 'compA',1257 listeners: {1258 custom: 'callFn'1259 }1260 }1261 }1262 });1263 ct.callFn = jasmine.createSpy();1264 ct.down('#compA').fireEvent('custom');1265 expect(ct.callFn).toHaveBeenCalled(); 1266 });12671268 it("should fire children in the same tree", function() {1269 makeContainer({1270 defaultListenerScope: true,1271 items: {1272 xtype: 'container',1273 itemId: 'compA',1274 listeners: {1275 custom: 'callFn'1276 },1277 items: {1278 xtype: 'container',1279 itemId: 'compB',1280 listeners: {1281 custom: 'callFn'1282 }1283 }1284 }1285 });1286 ct.callFn = jasmine.createSpy();1287 ct.down('#compA').fireEvent('custom');1288 ct.down('#compB').fireEvent('custom');1289 expect(ct.callFn.callCount).toBe(2); 1290 });12911292 it("should fire when the ref holder isn't at the root", function() {1293 makeContainer({1294 items: {1295 defaultListenerScope: true,1296 xtype: 'container',1297 itemId: 'compA',1298 items: {1299 xtype: 'container',1300 itemId: 'compB',1301 listeners: {1302 custom: 'callFn'1303 }1304 }1305 }1306 });1307 var c = ct.down('#compA'); 1308 c.callFn = jasmine.createSpy();1309 ct.down('#compB').fireEvent('custom');1310 expect(c.callFn).toHaveBeenCalled(); 1311 });13121313 it("should only fire the event at the closest defaultListenerScope holder", function() {1314 makeContainer({1315 defaultListenerScope: true,1316 items: {1317 defaultListenerScope: true,1318 xtype: 'container',1319 itemId: 'compA',1320 items: {1321 xtype: 'container',1322 itemId: 'compB',1323 listeners: {1324 custom: 'callFn'1325 }1326 }1327 }1328 });1329 var c = ct.down('#compA');1330 ct.callFn = jasmine.createSpy();1331 c.callFn = jasmine.createSpy();13321333 ct.down('#compB').fireEvent('custom');1334 expect(c.callFn).toHaveBeenCalled();1335 expect(ct.callFn).not.toHaveBeenCalled(); 1336 });1337 });1338 1339 describe("dynamic", function() {1340 it("should fire on a direct parent", function() {1341 makeContainer({1342 defaultListenerScope: true1343 });13441345 var c = ct.add({1346 xtype: 'component',1347 listeners: {1348 custom: 'callFn'1349 }1350 });13511352 ct.callFn = jasmine.createSpy();1353 c.fireEvent('custom');1354 expect(ct.callFn).toHaveBeenCalled();1355 });13561357 it("should fire on an indirect parent", function() {1358 makeContainer({1359 defaultListenerScope: true,1360 items: {1361 xtype: 'container'1362 }1363 });13641365 var c = ct.items.first().add({1366 xtype: 'component',1367 listeners: {1368 custom: 'callFn'1369 }1370 });13711372 ct.callFn = jasmine.createSpy();1373 c.fireEvent('custom');1374 expect(ct.callFn).toHaveBeenCalled();1375 });13761377 it("should resolve a new method in a new hierarchy", function() {1378 makeContainer({1379 defaultListenerScope: true,1380 items: {1381 xtype: 'component',1382 itemId: 'compA',1383 listeners: {1384 custom: 'callFn'1385 }1386 }1387 });13881389 var other = new Ext.container.Container({1390 defaultListenerScope: true1391 });13921393 var c = ct.down('#compA');13941395 ct.callFn = jasmine.createSpy();1396 other.callFn = jasmine.createSpy();13971398 c.fireEvent('custom');1399 expect(ct.callFn).toHaveBeenCalled();14001401 other.add(c);1402 ct.callFn.reset();1403 c.fireEvent('custom');14041405 expect(ct.callFn).not.toHaveBeenCalled();1406 expect(other.callFn).toHaveBeenCalled();14071408 other.destroy();1409 });14101411 it("should resolve a new method in the same hierarchy", function() {1412 makeContainer({1413 defaultListenerScope: true,1414 items: {1415 defaultListenerScope: true,1416 xtype: 'container',1417 itemId: 'compA',1418 items: {1419 xtype: 'component',1420 itemId: 'compB',1421 listeners: {1422 custom: 'callFn'1423 }1424 }1425 }1426 });14271428 var inner = ct.down('#compA'),1429 c = ct.down('#compB');14301431 ct.callFn = jasmine.createSpy();1432 inner.callFn = jasmine.createSpy();14331434 c.fireEvent('custom');1435 expect(inner.callFn).toHaveBeenCalled();1436 expect(ct.callFn).not.toHaveBeenCalled();14371438 ct.add(c);1439 inner.callFn.reset();14401441 c.fireEvent('custom');1442 expect(ct.callFn).toHaveBeenCalled();1443 expect(inner.callFn).not.toHaveBeenCalled();1444 });1445 });1446 });1447
...
weixin.js
Source:weixin.js
...64 //è°è¯å¯ç¨åºå®è·¯å¾è°è¯65 // url: 'http://devchongdianviph5.winbons.com/pay'66 },function (res) {67 if (callFn && typeof callFn == 'function')68 callFn(res.data)69 })70 },71 /**72 * 使ç¨è®¾å¤idåä»·æ ¼æ¹æ¡idå»åå°è·åJSç¾ååæ¯ä»ç¾å73 */74 signPay(deviceId,priceId,callFn){75 // console.log('url=',this.getSignURL())76 payAPI.pay({77 deviceId: deviceId,78 priceId:priceId79 }, function (res) {80 setTimeout(() => {81 if (callFn && typeof callFn == 'function')82 callFn(res.data)83 } , 100)84 },()=>{85 Indicator.close()86 })87 },88 /**89 * 使ç¨è®¾å¤idåä»·æ ¼æ¹æ¡idå»åå°è·åJSç¾ååæ¯ä»ç¾å(å
çµå®90 */91 signPayCDB(deviceId,callFn){92 // console.log('url=',this.getSignURL())93 payAPI.payCDB({94 deviceId: deviceId,95 }, function (res) {96 setTimeout(() => {97 if (callFn && typeof callFn == 'function')98 callFn(res.data)99 } , 100)100 },()=>{101 Indicator.close()102 })103 },104 /**105 * 使ç¨é¢æ¯ä»è®¢åidå»åå°è·åJSç¾ååæ¯ä»ç¾å106 */107 signPayPreOrder(prepayOrderId,callFn){108 // console.log('url=',this.getSignURL())109 payAPI.payPreOrder({110 id: prepayOrderId111 }, function (res) {112 setTimeout(() => {113 if (callFn && typeof callFn == 'function')114 callFn(res.data)115 } , 100)116 },()=>{117 Indicator.close()118 })119 },120 /**121 * 使ç¨JSSDKåè¿è¡é
ç½®122 */123 wxConfig(res,params,callFn){124 Object.assign(res,{jsApiList:params})125 console.log('wxConfigJSæ¥å£å表',res)126 wx.config({127 debug: false,128 appId: res.appID, // å¿
å¡«ï¼å
¬ä¼å·çå¯ä¸æ è¯129 timestamp: res.timestamp, // å¿
å¡«ï¼çæç¾åçæ¶é´æ³130 nonceStr: res.nonceStr, // å¿
å¡«ï¼çæç¾åçéæºä¸²131 signature: res.signature,// å¿
å¡«ï¼ç¾åï¼è§éå½1132 jsApiList: res.jsApiList // å¿
å¡«ï¼éè¦ä½¿ç¨çJSæ¥å£å表ï¼ææJSæ¥å£å表è§éå½2133 })134 wx.ready(function () {135 console.log('wx.ready')136 if (callFn && typeof callFn == 'function')137 callFn()138 })139 },140 wxPayConfig(res,callFn){141 wx.config({142 // debug: true,143 appId: res.appId, // å¿
å¡«ï¼å
¬ä¼å·çå¯ä¸æ è¯144 timestamp: res.timestamp, // å¿
å¡«ï¼çæç¾åçæ¶é´æ³145 nonceStr: res.nonceStr, // å¿
å¡«ï¼çæç¾åçéæºä¸²146 signature: res.paySign,// å¿
å¡«ï¼ç¾åï¼è§éå½1147 jsApiList: ['chooseWXPay'] // å¿
å¡«ï¼éè¦ä½¿ç¨çJSæ¥å£å表ï¼ææJSæ¥å£å表è§éå½2148 })149 wx.ready(function () {150 console.log('wx.ready')151 if (callFn && typeof callFn == 'function')152 callFn(res)153 })154 },155 /**156 * 使ç¨JSSDKä»»ä½æ¥å£é½å¿
é¡»å
å«å¨readyéé¢ï¼å¦æéè¦å¯ä»¥æ©å±error()157 */158 wxReady(jsApiList,callFn){159 if (callFn && typeof callFn == 'function')160 this.signJS((cofingres) => this.wxConfig(cofingres, jsApiList, ()=> callFn()))161 },162 wxPayReady(deviceId,priceId,callFn){163 if (callFn && typeof callFn == 'function')164 this.signPay(deviceId,priceId,(cofingres) => this.wxPayConfig(cofingres.payment,(res)=> callFn(res,cofingres.id)))165 },166 wxPayPreOrderReady(prepayOrderId,callFn){167 if (callFn && typeof callFn == 'function')168 this.signPayPreOrder(prepayOrderId,(cofingres) => this.wxPayConfig(cofingres.payment,(res)=> callFn(res,cofingres.id)))169 },170 wxPayReadyCDB(deviceId,callFn){171 if (callFn && typeof callFn == 'function')172 this.signPayCDB(deviceId,(cofingres) => this.wxPayConfig(cofingres.payment,(res)=> callFn(res,cofingres.id)))173 },174 // #endregion175 /* 1.successï¼æ¥å£è°ç¨æåæ¶æ§è¡çåè°å½æ°ã176 2.failï¼æ¥å£è°ç¨å¤±è´¥æ¶æ§è¡çåè°å½æ°ã177 3.completeï¼æ¥å£è°ç¨å®ææ¶æ§è¡çåè°å½æ°ï¼æ 论æåæ失败é½ä¼æ§è¡ã178 4.cancelï¼ç¨æ·ç¹å»åæ¶æ¶çåè°å½æ°ï¼ä»
é¨åæç¨æ·åæ¶æä½çapiæä¼ç¨å°ã179 5.trigger: çå¬Menuä¸çæé®ç¹å»æ¶è§¦åçæ¹æ³ï¼è¯¥æ¹æ³ä»
æ¯æMenuä¸çç¸å
³æ¥å£ã180 å¤æ³¨ï¼ä¸è¦å°è¯å¨triggerä¸ä½¿ç¨ajaxå¼æ¥è¯·æ±ä¿®æ¹æ¬æ¬¡å享çå
容ï¼å 为客æ·ç«¯å享æä½æ¯ä¸ä¸ªåæ¥æä½ï¼è¿æ¶å使ç¨ajaxçåå
ä¼è¿æ²¡æè¿åã181 以ä¸å 个å½æ°é½å¸¦æä¸ä¸ªåæ°ï¼ç±»å为对象ï¼å
¶ä¸é¤äºæ¯ä¸ªæ¥å£æ¬èº«è¿åçæ°æ®ä¹å¤ï¼è¿æä¸ä¸ªéç¨å±æ§errMsgï¼å
¶å¼æ ¼å¼å¦ä¸ï¼182 è°ç¨æåæ¶ï¼"xxx:ok" ï¼å
¶ä¸xxx为è°ç¨çæ¥å£å183 ç¨æ·åæ¶æ¶ï¼"xxx:cancel"ï¼å
¶ä¸xxx为è°ç¨çæ¥å£å184 è°ç¨å¤±è´¥æ¶ï¼å
¶å¼ä¸ºå
·ä½é误信æ¯*/185 // #region wxæä¾çæ¥å£ï¼æææ¥å£é½å¯ä»¥å®ä¹successï¼failï¼completeï¼cancelï¼trigger186 /*187 * å享ç»æåå188 * @param params189 * @param callFn190 */191 wxShare(params, callFn) {192 let jsApiList = [193 'checkJsApi',194 'onMenuShareTimeline',195 'onMenuShareAppMessage'196 ]197 this.wxReady(jsApiList, () => {198 wx.checkJsApi({199 jsApiList: [200 'checkJsApi',201 'onMenuShareTimeline',202 'onMenuShareAppMessage'203 ],204 success: function (res) {205 // ç¹å»æé®æ«æäºç»´ç 206 if (res.checkResult.getLocation == false) {207 MessageBox.alert('ä½ ç微信çæ¬å¤ªä½ï¼ä¸æ¯æ微信JSæ¥å£ï¼è¯·å级å°ææ°ç微信çæ¬ï¼', 'alert');208 return;209 } else {210 wx.onMenuShareTimeline({211 title: params.title, // å享æ é¢212 link: params.link, // // å享é¾æ¥ï¼è¯¥é¾æ¥ååæè·¯å¾å¿
é¡»ä¸å½å页é¢å¯¹åºçå
¬ä¼å·JSå®å
¨ååä¸è´213 desc: params.desc,214 imgUrl: config.wxSignHost + '/static/weika-logo.png', // å享å¾æ 215 success: function () {216 // ç¨æ·ç¡®è®¤å享åæ§è¡çåè°å½æ°217 callFn && callFn()218 },219 cancel: function () {220 // ç¨æ·åæ¶å享åæ§è¡çåè°å½æ°221 MessageBox.alert('åæ¶å享ç»æååï¼', 'alert')222 }223 });224 wx.onMenuShareAppMessage({225 title: params.title, // å享æ é¢226 link: params.link, // å享é¾æ¥,å°å½åç»å½ç¨æ·è½¬ä¸ºpuid,以便äºåå±ä¸çº¿227 desc: params.desc,228 imgUrl: config.wxSignHost + '/static/weika-logo.png', // å享å¾æ 229 success: function () {230 // ç¨æ·ç¡®è®¤å享åæ§è¡çåè°å½æ°231 callFn && callFn()232 },233 cancel: function () {234 // ç¨æ·åæ¶å享åæ§è¡çåè°å½æ°235 }236 });237 wx.error(function (res) {238 // configä¿¡æ¯éªè¯å¤±è´¥ä¼æ§è¡errorå½æ°ï¼å¦ç¾åè¿æ导è´éªè¯å¤±è´¥ï¼å
·ä½é误信æ¯å¯ä»¥æå¼configçdebug模å¼æ¥çï¼239 // ä¹å¯ä»¥å¨è¿åçresåæ°ä¸æ¥çï¼å¯¹äºSPAå¯ä»¥å¨è¿éæ´æ°ç¾åã240 console.log('errrrr ', res)241 MessageBox.alert('share config error MSG: ' + res, 'alert');242 })243 }244 }245 })246 })247 },248 chooseImage(params,callFn) {249 console.log('chooseImage params==',params)250 wx.chooseImage({251 count: params.count,252 scene: params.scene,253 sizeType: params.sizeType, // å¯ä»¥æå®æ¯åå¾è¿æ¯å缩å¾ï¼é»è®¤äºè
é½æ254 sourceType: params.sourceType, // å¯ä»¥æå®æ¥æºæ¯ç¸åè¿æ¯ç¸æºï¼é»è®¤äºè
é½æ255 success: function (res) {256 console.log('chooseImage success')257 if (callFn && typeof callFn == 'function')258 callFn(res)259 }260 })261 },262 uploadImage(res,params,callFn){263 setTimeout(() => {264 Indicator.open()265 wx.uploadImage({266 localId: res.localIds[0], // å¾ççlocalID267 isShowProgressTips: params,268 success: function (uploadData) {269 if (callFn && typeof callFn == 'function')270 callFn(uploadData.serverId)// è¿åå¾ççæå¡å¨ç«¯ID271 }272 })273 }, 100)274 },275 getLocation(type,callback,cancelCallFn){276 wx.getLocation({277 type: type,278 success: function (res) {279 (callback && typeof callback === 'function') && callback(res)280 // var latitude = res.latitude; // 纬度ï¼æµ®ç¹æ°ï¼èå´ä¸º90 ~ -90281 // var longitude = res.longitude; // ç»åº¦ï¼æµ®ç¹æ°ï¼èå´ä¸º180 ~ -180ã282 // var speed = res.speed; // é度ï¼ä»¥ç±³/æ¯ç§è®¡283 // var accuracy = res.accuracy; // ä½ç½®ç²¾åº¦284 },285 fail: function (res) {286 //æªå¼å¯å®ä½åè½287 console.error('ç¨æ·æªå¼å¯å®ä½åè½')288 },289 cancel: function (res) {290 (cancelCallFn && typeof cancelCallFn === 'function') && cancelCallFn()291 //ç¨æ·æç»ææè·åå°çä½ç½®292 console.error('ç¨æ·æç»ææè·åå°çä½ç½®')293 }294 })295 },296 chooseWXPay(payment,prepayOrderId,callFn){297 console.log('payment=',payment)298 wx.chooseWXPay({299 appId: config.appId,300 // appId: payment.appId, // å¿
å¡«ï¼å
¬ä¼å·çå¯ä¸æ è¯301 timestamp: payment.timeStamp, // æ¯ä»ç¾åæ¶é´æ³ï¼æ³¨æ微信jssdkä¸çææ使ç¨timestampå段å为å°åãä½ææ°ççæ¯ä»åå°çæç¾å使ç¨çtimeStampå段åé大åå
¶ä¸çSå符302 nonceStr: payment.nonceStr, // æ¯ä»ç¾åéæºä¸²ï¼ä¸é¿äº 32 ä½303 package: payment.package, // ç»ä¸æ¯ä»æ¥å£è¿åçprepay_idåæ°å¼ï¼æäº¤æ ¼å¼å¦ï¼prepay_id=***ï¼304 signType: payment.signType, // ç¾åæ¹å¼ï¼é»è®¤ä¸º'SHA1'ï¼ä½¿ç¨æ°çæ¯ä»éä¼ å
¥'MD5'305 paySign: payment.paySign, // æ¯ä»ç¾å306 success: function (res) {307 // æ¯ä»æååçåè°å½æ°308 if (res.errMsg == 'chooseWXPay:ok') {309 if (callFn && typeof callFn == 'function')310 callFn(prepayOrderId)311 }312 }, //å¦æä½ æç
§æ£å¸¸çjQueryé»è¾ï¼ä¸é¢å¦æåéé误ï¼ä¸å®æ¯errorï¼é£ä½ 就太天çäºï¼å½ç¶ï¼jssdkææ¡£ä¸ä¹ææå°313 fail: function(res) {314 //æ¥å£è°ç¨å¤±è´¥æ¶æ§è¡çåè°å½æ°ã315 },316 complete: function(res) {317 //æ¥å£è°ç¨å®ææ¶æ§è¡çåè°å½æ°ï¼æ 论æåæ失败æåæ¶é½ä¼æ§è¡ã318 Indicator.close()319 },320 cancel: function(res) {321 //ç¨æ·ç¹å»åæ¶æ¶çåè°å½æ°ï¼ä»
é¨åæç¨æ·åæ¶æä½çapiæä¼ç¨å°ã322 /* payAPI.paymentCancel({323 id: prepayOrderId324 }, function (resData) {325 })*/326 }327 })328 },329 scanQRCode(need=1, callFn){330 wx.scanQRCode({331 needResult : need, // é»è®¤ä¸º0ï¼æ«æç»æç±å¾®ä¿¡å¤çï¼1åç´æ¥è¿åæ«æç»æï¼332 scanType : ["qrCode"], // å¯ä»¥æå®æ«äºç»´ç è¿æ¯ä¸ç»´ç ï¼é»è®¤äºè
é½æ333 success : function(res) {334 // Toast(JSON.stringify(res))335 if(need==1){336 let result = res.resultStr; // å½needResult 为 1 æ¶ï¼æ«ç è¿åçç»æ337 if(result){338 if (callFn && typeof callFn == 'function')339 callFn(result)340 }else{341 Toast('äºç»´ç é®é¢!')342 }343 }else {344 if (callFn && typeof callFn == 'function')345 callFn(result)346 }347 }348 })349 },350 checkJsApi(joggle,callFn){351 wx.checkJsApi({352 jsApiList :joggle,353 success : function(res) {354 if (callFn && typeof callFn == 'function')355 callFn()356 }357 })358 },359 //#endregion360 //#region èªå®ä¹æ¥å£ç±»361 wxUploadImg(serverId, name, callFn){362 wxAPI.wxUploadImg({363 mediaId: serverId,364 name,365 }, function (res) {366 Indicator.close()367 Toast({368 message: 'ä¸ä¼ æå',369 position: 'top'370 })371 if (callFn && typeof callFn == 'function')372 callFn(res.data)373 })374 },375 /**376 * è·åæ¯ä»å®æç订å377 * res.orderId378 */379 paymentReturn(prepayOrderId,callFn){380 payAPI.paymentReturn({381 prepayOrderId: prepayOrderId382 }, function (resData) {383 if (callFn && typeof callFn == 'function')384 callFn(resData.data)385 })386 },387 /**388 * è·åæ¯ä»å®æç订å(å
çµå®)389 * res.orderId390 */391 paymentReturnCDB(prepayOrderId,callFn){392 payAPI.paymentReturnCDB({393 prepayOrderId: prepayOrderId394 }, function (resData) {395 if (callFn && typeof callFn == 'function')396 callFn(prepayOrderId)397 })398 },399 //#endregion400//#region åºç¨ç±»401 /**402 * 微信å¾çä¸ä¼ 并æå¾çä¸ä¼ å°æå¡å¨ä¸403 * @param type ç¸æºåç¸åçéæ©ï¼1-ç¸åï¼2-ç¸æºï¼3-é½æ404 * @param callback405 */406 weixinUploadImg(type, name, callFn) {407 let jsApiList = ['chooseImage', 'uploadImage']408 let chooseImageCofig = {409 count: 1,410 scene: 1,411 sizeType: ['original', 'compressed'], // å¯ä»¥æå®æ¯åå¾è¿æ¯å缩å¾ï¼é»è®¤äºè
é½æ412 }413 //#region å¯ä»¥æå®æ¥æºæ¯ç¸åè¿æ¯ç¸æºï¼é»è®¤äºè
é½æ414 if (type == 1) {415 Object.assign(chooseImageCofig, {sourceType: ['album']})416 } else if (type == 2) {417 Object.assign(chooseImageCofig, {sourceType: ['camera']})418 } else if (type == 3) {419 Object.assign(chooseImageCofig, {sourceType: ['album', 'camera']})420 }421 //#endregion422 if (callFn && typeof callFn == 'function')423 this.wxReady(jsApiList, () => this.chooseImage(chooseImageCofig, (res) => this.uploadImage(res, 0, (serverId) => this.wxUploadImg(serverId, name, (urlres) => callFn(urlres)))))424 },425 /**426 * è·åå°çä½ç½®427 */428 weixinGetLocation(callback,cancelCallFn) {429 let jsApiList = ['getLocation']430 // é»è®¤ä¸ºwgs84çgpsåæ ï¼å¦æè¦è¿åç´æ¥ç»openLocationç¨çç«æåæ ï¼å¯ä¼ å
¥'gcj02'431 this.wxReady(jsApiList, () => this.getLocation('wgs84', (res) => {(callback && typeof callback === 'function') && callback(res)}, () => {(cancelCallFn && typeof cancelCallFn === 'function') && cancelCallFn()}))432 },433 weixinPay(deviceId,priceId,callback){434 this.wxPayReady(deviceId,priceId,(params,prepayOrderId) => this.chooseWXPay(params,prepayOrderId,(id)=>this.paymentReturn(id,(res) => {(callback && typeof callback === 'function') && callback(res)})))435 },436 weixinPayPreOrder(preOrderId,callback){437 this.wxPayPreOrderReady(preOrderId,(params,prepayOrderId) => this.chooseWXPay(params,prepayOrderId,(id)=>this.paymentReturn(id,(res) => {(callback && typeof callback === 'function') && callback(res)})))...
server.js
Source:server.js
...5 6 this.invalidatables = [];7 this.destructiveInvalidatables = [];8 this.cache = {};9 this.setup = this.callFn("setup");10 this.getNodes = this.getFn("graph/nodes", Movie, "nodes");11 this.getEdges = this.getFn("graph/edges", RoleEdge, "edges");12 this.tmdb = {13 search: this.cachedFn(this.thenFn(this.callFn("tmdb/search"), asObject), "tmdbSearch")14 };15 this.clear = this.destructiveFn(this.callFn("clear"));16 this.add = this.destructiveFn(this.callFn("add"));17 this.progress = this.callFn("progress");18 this.abort = this.callFn("abort");19 this.update = this.invalidateFn(this.callFn("update", ["unlabeled", "detailed", "condensed",20 "weighted", "top-actors"]));21 this.filterNodes = this.invalidateFn(22 this.callFilterFn("filter/node", ["movie-filter", "neighborhood-filter"]));23 this.filterEdges = this.invalidateFn(24 this.callFilterFn("filter/edge", ["gender-filter", "same-character-filter",25 "billing-filter", "actor-filter", "type-filter"]));26 this.search = this.cachedFn(this.thenFn(this.callFn("search"), asList), "search");27 this.inverseSearch = this.cachedFn(28 this.thenFn(this.callFn("inverse-search"), asList), "inverseSearch");29 this.synchronkartei = {30 suggest: this.cachedFn(31 this.thenFn(this.callFn("synchronkartei/suggest"), asList), "synchronkarteiSuggest"),32 add: this.destructiveFn(this.callFn("synchronkartei/add")),33 search: this.thenFn(this.callFn("synchronkartei/search"), asList)34 };35 this.details = this.cachedFn(this.callFn("details"), "details");36 this.suggest = this.thenFn(this.callFn("suggest"), asList);37 this.eval = this.callFn("eval");38 this.loadGraph = this.destructiveFn(this.callFn("graph/load"));39 var setupFinished = false;40 defer(function() {41 if (!setupFinished)42 $("#setup-dialog").dialog("open");43 }, 500);44 this.setup().always(function() {45 setupFinished = true;46 }).then(function() {47 $("#setup-dialog").dialog("close");48 }).then(function() {49 return self.update();50 }).then(initialized);51};52Server.prototype = {53 callFn: function(fn, legalValues) {54 var self = this;55 return function(arr) {56 var args = Array.isArray(arr) ? arr : Array.prototype.slice.call(arguments);57 args = args.filter(function(arg) { return arg !== "." && arg !== ".."; });58 assertLegalValues(args, legalValues);59 var url = "/" + fn + "/" + args.join("/");60 if (self.debug) {61 console.log(url);62 return instantPromise();63 } else64 return $.ajax(url).fail(function(xhr) {65 App().reportError(xhr.responseText);66 });67 };68 },69 thenFn: function(fn, cb) {70 return function() {71 return fn.apply(this, arguments).then(cb);72 };73 },74 call: function(fn, legalValues) {75 return this.callFn(fn, legalValues)(Array.prototype.slice.call(arguments, 2));76 },77 callFilterFn: function(fn, legalValues) {78 var self = this;79 return function(filter) {80 legalValues = legalValues || [];81 legalValues.push("or-filter", "and-filter", "not-filter", "all-filter");82 assertLegalForm(filter, legalValues);83 return self.callFn(fn)(JSON.stringify(filter));84 };85 },86 invalidateFn: function(fn) {87 var self = this;88 return function() {89 return fn.apply(this, arguments).then(function() {90 $("#graph").prop("data", "/assets/graph.svg?" + new Date().getTime());91 self.invalidatables.forEach(function(obj) {92 obj.invalidate();93 });94 });95 };96 },97 destructiveFn: function(fn) {98 var self = this;99 return function() {100 return self.invalidateFn(fn).apply(this, arguments).then(function() {101 self.destructiveInvalidatables.forEach(function(obj) {102 obj.invalidate();103 });104 });105 };106 },107 invalidate: function(fn) {108 fn = fn || instantPromise;109 return this.invalidateFn(fn)(Array.prototype.slice.call(arguments, 1));110 },111 shouldInvalidate: function(obj) {112 this.invalidatables.push(obj);113 },114 shouldInvalidateOnDestruction: function(obj) {115 this.destructiveInvalidatables.push(obj);116 },117 saveGraph: function() {118 document.location.href = "/graph/save/";119 },120 exportGraph: function() {121 document.location.href = "/graph/export/";122 },123 getFn: function(fn, klass, cacheProp) {124 var self = this;125 return this.thenFn(this.callFn(fn), function(data) {126 return self.cache[cacheProp] = asList(data).map(klass);127 });128 },129 cachedFn: function(fn, cacheProp) {130 var self = this;131 self.cache[cacheProp] = {};132 return function() {133 var key = JSON.stringify(Array.prototype.slice.call(arguments));134 if (self.cache[cacheProp][key])135 return instantPromise(self.cache[cacheProp][key]);136 else137 return fn.apply(this, arguments).then(function(data) {138 return self.cache[cacheProp][key] = data;139 });...
Using AI Code Generation
1const availableFn = require('./availableFn');2availableFn.callFn();3module.exports = {4 callFn: function() {5 console.log('callFn method');6 }7}8const availableFn = require('./availableFn');9availableFn.callFn();10const availableFn = require('./availableFn');11availableFn.callFn();12module.exports = {13 callFn: function() {14 console.log('callFn method');15 }16}17const availableFn = require('./availableFn');18availableFn.callFn();19const availableFn = require('./availableFn');20availableFn.callFn();21module.exports = {22 callFn: function() {23 console.log('callFn method');24 }25}26const availableFn = require('./availableFn');27availableFn.callFn();28const availableFn = require('./availableFn');29availableFn.callFn();30module.exports = {31 callFn: function() {32 console.log('callFn method');33 }34}35const availableFn = require('./availableFn');36availableFn.callFn();37const availableFn = require('./availableFn');38availableFn.callFn();39module.exports = {40 callFn: function() {41 console.log('callFn method');42 }43}44const availableFn = require('./availableFn');45availableFn.callFn();46const availableFn = require('./availableFn');47availableFn.callFn();
Using AI Code Generation
1const availableFn = require('./availableFn');2const callFn = availableFn.callFn;3callFn('add', 1, 2);4callFn('subtract', 1, 2);5callFn('multiply', 1, 2);6callFn('divide', 1, 2);7const add = require('./add');8const subtract = require('./subtract');9const multiply = require('./multiply');10const divide = require('./divide');11const callFn = (fnName, a, b) => {12 switch (fnName) {13 add(a, b);14 break;15 subtract(a, b);16 break;17 multiply(a, b);18 break;19 divide(a, b);20 break;21 console.log('Invalid function name');22 }23};24module.exports = { callFn };25const add = (a, b) => {26 console.log(`Addition of ${a} and ${b} is ${a + b}`);27};28module.exports = add;29const subtract = (a, b) => {30 console.log(`Subtraction of ${a} and ${b} is ${a - b}`);31};32module.exports = subtract;33const multiply = (a, b) => {34 console.log(`Multiplication of ${a} and ${b} is ${a * b}`);35};36module.exports = multiply;37const divide = (a, b) => {38 console.log(`Division of ${a} and ${b} is ${a / b}`);39};40module.exports = divide;
Using AI Code Generation
1var availableFn = require('./availableFn');2availableFn.callFn();3module.exports.callFn = function(){4 console.log("callFn method of availableFn is called");5};6module.exports = function() {7}8module.exports = {9}10exports.callFn = function() {11}12var availableFn = require('./availableFn');13availableFn.callFn();14module.exports.callFn = function(){15 console.log("callFn method of availableFn is called");16};17module.exports = function() {18}19module.exports = {20}21exports.callFn = function() {22}23var availableFn = require('./availableFn');24availableFn.callFn();
Using AI Code Generation
1const { availableFn } = require('./availableFn');2availableFn.callFn();3const callFn = () => {4 console.log('callFn method called');5};6module.exports = {7};8exports.callFn = () => {9 console.log('callFn method called');10};
Using AI Code Generation
1callFn('add', 1, 2);2function add(a, b) {3 return a + b;4}5module.exports = {6};7We also learned how to export and import functions from different files. For example, we created a file called availableFn.js and exported a function called add from that file. We then imported that
Using AI Code Generation
1var callFn = require('callFn');2callFn('Hello World');3module.exports = function(msg) {4 console.log(msg);5}6module.exports = {7 method1: function() {8 },9 method2: function() {10 }11}12var callFn = require('callFn');13callFn.method1();14callFn.method2();15module.exports = {16 method1: function() {17 }18}19var callFn = require('callFn');20callFn.method1();21module.exports = function(msg) {22 console.log(msg);23}
Using AI Code Generation
1availableFn.callFn("sum", 10, 20, function (err, result) {2 if (err) {3 console.log(err);4 } else {5 console.log(result);6 }7});8availableFn.callFn("mul", 10, 20, function (err, result) {9 if (err) {10 console.log(err);11 } else {12 console.log(result);13 }14});15availableFn.callFn("sub", 10, 20, function (err, result) {16 if (err) {17 console.log(err);18 } else {19 console.log(result);20 }21});22availableFn.callFn("div", 10, 20, function (err, result) {23 if (err) {24 console.log(err);25 } else {26 console.log(result);27 }28});29availableFn.callFn("mod", 10, 20, function (err, result) {30 if (err) {31 console.log(err);32 } else {33 console.log(result);34 }35});36availableFn.callFn("pow", 10, 20, function (err, result) {37 if (err) {38 console.log(err);39 } else {40 console.log(result);41 }42});43availableFn.callFn("sqrt", 10, 20, function (err, result) {44 if (err) {45 console.log(err);46 } else {47 console.log(result);48 }49});50availableFn.callFn("abs", 10, 20, function (err, result) {51 if (err) {52 console.log(err);53 } else {54 console.log(result);55 }56});57availableFn.callFn("log", 10, 20, function (err, result) {58 if (err) {59 console.log(err);60 } else {61 console.log(result);62 }63});64availableFn.callFn("sin", 10, 20, function (err, result) {65 if (err) {66 console.log(err);67 } else {68 console.log(result);69 }70});71availableFn.callFn("cos
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!