1 | dojo.provide("dojox.wire.tests.programmatic._base"); |
---|
2 | |
---|
3 | dojo.require("dojox.wire._base"); |
---|
4 | |
---|
5 | tests.register("dojox.wire.tests.programmatic._base", [ |
---|
6 | |
---|
7 | function test_create(t){ |
---|
8 | var wire = dojox.wire.create({}); |
---|
9 | t.assertTrue(wire instanceof dojox.wire.Wire); |
---|
10 | |
---|
11 | wire = dojox.wire.create({property: "a"}); |
---|
12 | t.assertTrue(wire instanceof dojox.wire.Wire); |
---|
13 | |
---|
14 | wire = dojox.wire.create({attribute: "a"}); |
---|
15 | t.assertTrue(wire instanceof dojox.wire.DataWire); |
---|
16 | |
---|
17 | wire = dojox.wire.create({path: "a"}); |
---|
18 | t.assertTrue(wire instanceof dojox.wire.XmlWire); |
---|
19 | |
---|
20 | wire = dojox.wire.create({children: "a"}); |
---|
21 | t.assertTrue(wire instanceof dojox.wire.CompositeWire); |
---|
22 | |
---|
23 | wire = dojox.wire.create({columns: "a"}); |
---|
24 | t.assertTrue(wire instanceof dojox.wire.TableAdapter); |
---|
25 | |
---|
26 | wire = dojox.wire.create({nodes: "a"}); |
---|
27 | t.assertTrue(wire instanceof dojox.wire.TreeAdapter); |
---|
28 | |
---|
29 | wire = dojox.wire.create({segments: "a"}); |
---|
30 | t.assertTrue(wire instanceof dojox.wire.TextAdapter); |
---|
31 | |
---|
32 | wire = dojox.wire.create({wireClass: "dojox.wire.DataWire"}); |
---|
33 | t.assertTrue(wire instanceof dojox.wire.DataWire); |
---|
34 | }, |
---|
35 | |
---|
36 | function test_transfer(t){ |
---|
37 | var source = {a: "A"}; |
---|
38 | var target = {}; |
---|
39 | dojox.wire.transfer( |
---|
40 | {object: source, property: "a"}, |
---|
41 | {object: target, property: "a"}); |
---|
42 | t.assertEqual(source.a, target.a); |
---|
43 | }, |
---|
44 | |
---|
45 | function test_connect(t){ |
---|
46 | var trigger = {transfer: function() {}, transferArgument: function() {}}; |
---|
47 | var source = {a: "A"}; |
---|
48 | var target = {}; |
---|
49 | dojox.wire.connect({scope: trigger, event: "transfer"}, |
---|
50 | {object: source, property: "a"}, |
---|
51 | {object: target, property: "a"}); |
---|
52 | trigger.transfer(); |
---|
53 | t.assertEqual(source.a, target.a); |
---|
54 | |
---|
55 | // with argument |
---|
56 | target = {}; |
---|
57 | dojox.wire.connect({scope: trigger, event: "transferArgument"}, |
---|
58 | {property: "[0].a"}, |
---|
59 | {object: target, property: "a"}); |
---|
60 | trigger.transferArgument(source); |
---|
61 | t.assertEqual(source.a, target.a); |
---|
62 | |
---|
63 | // by topic |
---|
64 | target = {}; |
---|
65 | dojox.wire.connect({topic: "transfer"}, |
---|
66 | {object: source, property: "a"}, |
---|
67 | {object: target, property: "a"}); |
---|
68 | dojo.publish("transfer"); |
---|
69 | t.assertEqual(source.a, target.a); |
---|
70 | |
---|
71 | // by topic with argument |
---|
72 | target = {}; |
---|
73 | dojox.wire.connect({topic: "transferArgument"}, |
---|
74 | {property: "[0].a"}, |
---|
75 | {object: target, property: "a"}); |
---|
76 | dojo.publish("transferArgument", [source]); |
---|
77 | t.assertEqual(source.a, target.a); |
---|
78 | }, |
---|
79 | |
---|
80 | function test_disconnect(t){ |
---|
81 | var trigger = {transferDisconnect: function() {}}; |
---|
82 | var source = {a: "A"}; |
---|
83 | var target = {}; |
---|
84 | var connection = dojox.wire.connect({scope: trigger, event: "transferDisconnect"}, |
---|
85 | {object: source, property: "a"}, |
---|
86 | {object: target, property: "a"}); |
---|
87 | trigger.transferDisconnect(); |
---|
88 | t.assertEqual(source.a, target.a); |
---|
89 | delete target.a; |
---|
90 | dojox.wire.disconnect(connection); |
---|
91 | trigger.transferDisconnect(); |
---|
92 | t.assertEqual(undefined, target.a); |
---|
93 | |
---|
94 | // by topic |
---|
95 | target = {}; |
---|
96 | connection = dojox.wire.connect({topic: "transferDisconnect"}, |
---|
97 | {object: source, property: "a"}, |
---|
98 | {object: target, property: "a"}); |
---|
99 | dojo.publish("transferDisconnect"); |
---|
100 | t.assertEqual(source.a, target.a); |
---|
101 | delete target.a; |
---|
102 | dojox.wire.disconnect(connection); |
---|
103 | dojo.publish("transferDisconnect"); |
---|
104 | t.assertEqual(undefined, target.a); |
---|
105 | } |
---|
106 | |
---|
107 | ]); |
---|