4ea7a668b86910c12aa67df30a019633f4bf2169.svn-base 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. if (!dojo._hasResource["dojox.wire.tests.programmatic._base"]) { // _hasResource
  2. // checks
  3. // added by
  4. // build. Do
  5. // not use
  6. // _hasResource
  7. // directly
  8. // in your
  9. // code.
  10. dojo._hasResource["dojox.wire.tests.programmatic._base"] = true;
  11. dojo.provide("dojox.wire.tests.programmatic._base");
  12. dojo.require("dojox.wire._base");
  13. tests.register("dojox.wire.tests.programmatic._base", [
  14. function test_create(t) {
  15. var wire = dojox.wire.create({});
  16. t.assertTrue(wire instanceof dojox.wire.Wire);
  17. wire = dojox.wire.create({
  18. property : "a"
  19. });
  20. t.assertTrue(wire instanceof dojox.wire.Wire);
  21. wire = dojox.wire.create({
  22. attribute : "a"
  23. });
  24. t.assertTrue(wire instanceof dojox.wire.DataWire);
  25. wire = dojox.wire.create({
  26. path : "a"
  27. });
  28. t.assertTrue(wire instanceof dojox.wire.XmlWire);
  29. wire = dojox.wire.create({
  30. children : "a"
  31. });
  32. t.assertTrue(wire instanceof dojox.wire.CompositeWire);
  33. wire = dojox.wire.create({
  34. columns : "a"
  35. });
  36. t.assertTrue(wire instanceof dojox.wire.TableAdapter);
  37. wire = dojox.wire.create({
  38. nodes : "a"
  39. });
  40. t.assertTrue(wire instanceof dojox.wire.TreeAdapter);
  41. wire = dojox.wire.create({
  42. segments : "a"
  43. });
  44. t.assertTrue(wire instanceof dojox.wire.TextAdapter);
  45. wire = dojox.wire.create({
  46. wireClass : "dojox.wire.DataWire"
  47. });
  48. t.assertTrue(wire instanceof dojox.wire.DataWire);
  49. },
  50. function test_transfer(t) {
  51. var source = {
  52. a : "A"
  53. };
  54. var target = {};
  55. dojox.wire.transfer({
  56. object : source,
  57. property : "a"
  58. }, {
  59. object : target,
  60. property : "a"
  61. });
  62. t.assertEqual(source.a, target.a);
  63. },
  64. function test_connect(t) {
  65. var trigger = {
  66. transfer : function() {
  67. },
  68. transferArgument : function() {
  69. }
  70. };
  71. var source = {
  72. a : "A"
  73. };
  74. var target = {};
  75. dojox.wire.connect({
  76. scope : trigger,
  77. event : "transfer"
  78. }, {
  79. object : source,
  80. property : "a"
  81. }, {
  82. object : target,
  83. property : "a"
  84. });
  85. trigger.transfer();
  86. t.assertEqual(source.a, target.a);
  87. // with argument
  88. target = {};
  89. dojox.wire.connect({
  90. scope : trigger,
  91. event : "transferArgument"
  92. }, {
  93. property : "[0].a"
  94. }, {
  95. object : target,
  96. property : "a"
  97. });
  98. trigger.transferArgument(source);
  99. t.assertEqual(source.a, target.a);
  100. // by topic
  101. target = {};
  102. dojox.wire.connect({
  103. topic : "transfer"
  104. }, {
  105. object : source,
  106. property : "a"
  107. }, {
  108. object : target,
  109. property : "a"
  110. });
  111. dojo.publish("transfer");
  112. t.assertEqual(source.a, target.a);
  113. // by topic with argument
  114. target = {};
  115. dojox.wire.connect({
  116. topic : "transferArgument"
  117. }, {
  118. property : "[0].a"
  119. }, {
  120. object : target,
  121. property : "a"
  122. });
  123. dojo.publish("transferArgument", [source]);
  124. t.assertEqual(source.a, target.a);
  125. },
  126. function test_disconnect(t) {
  127. var trigger = {
  128. transferDisconnect : function() {
  129. }
  130. };
  131. var source = {
  132. a : "A"
  133. };
  134. var target = {};
  135. var connection = dojox.wire.connect({
  136. scope : trigger,
  137. event : "transferDisconnect"
  138. }, {
  139. object : source,
  140. property : "a"
  141. }, {
  142. object : target,
  143. property : "a"
  144. });
  145. trigger.transferDisconnect();
  146. t.assertEqual(source.a, target.a);
  147. delete target.a;
  148. dojox.wire.disconnect(connection);
  149. trigger.transferDisconnect();
  150. t.assertEqual(undefined, target.a);
  151. // by topic
  152. target = {};
  153. connection = dojox.wire.connect({
  154. topic : "transferDisconnect"
  155. }, {
  156. object : source,
  157. property : "a"
  158. }, {
  159. object : target,
  160. property : "a"
  161. });
  162. dojo.publish("transferDisconnect");
  163. t.assertEqual(source.a, target.a);
  164. delete target.a;
  165. dojox.wire.disconnect(connection);
  166. dojo.publish("transferDisconnect");
  167. t.assertEqual(undefined, target.a);
  168. }
  169. ]);
  170. }