|
2 | 2 |
|
3 | 3 | import {expect} from 'src/external/chai.js' |
4 | 4 | import Bindings from "src/client/bindings.js" |
| 5 | +import Connection from "src/components/halo/Connection.js" |
5 | 6 |
|
6 | 7 | /*MD # [Bindings](edit://src/client/bindings.js) Test |
7 | 8 |
|
@@ -37,3 +38,94 @@ describe('Bindings', function() { |
37 | 38 | }); |
38 | 39 | }) |
39 | 40 | }); |
| 41 | + |
| 42 | + |
| 43 | +// The Halo based Connections |
| 44 | + |
| 45 | +describe('Connections', function() { |
| 46 | + |
| 47 | + describe('connect', function() { |
| 48 | + it('connects event with property', async function() { |
| 49 | + var a = <div>A</div> |
| 50 | + var b = <div>B</div> |
| 51 | + var connection = new Connection(a, "click", b, "foo", true) |
| 52 | + connection.activate(); |
| 53 | + await lively.sleep(0) // it seems to take time... |
| 54 | + |
| 55 | + a.dispatchEvent(new Event("click")) |
| 56 | + |
| 57 | + await lively.sleep(0) // it seems to take time... |
| 58 | + |
| 59 | + expect(b.foo).to.not.be.undefined(); |
| 60 | + }); |
| 61 | + |
| 62 | + it('connects event with function', async function() { |
| 63 | + var a = <div>A</div> |
| 64 | + var b = <div>B</div> |
| 65 | + b.func = function(v) { this.bar = v} |
| 66 | + |
| 67 | + var connection = new Connection(a, "click", b, "func", true) |
| 68 | + |
| 69 | + connection.activate(); |
| 70 | + await lively.sleep(0) // it seems to take time... |
| 71 | + |
| 72 | + a.dispatchEvent(new Event("click")) |
| 73 | + |
| 74 | + await lively.sleep(0) // it seems to take time... |
| 75 | + |
| 76 | + expect(b.bar).to.not.be.undefined(); |
| 77 | + }); |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + it('connects property with property', async function() { |
| 82 | + var a = <div>A</div> |
| 83 | + var b = <div>B</div> |
| 84 | + var connection = new Connection(a, "foo", b, "bar") |
| 85 | + connection.activate(); |
| 86 | + await lively.sleep(0) // it seems to take time... |
| 87 | + |
| 88 | + a.foo = "hello" |
| 89 | + |
| 90 | + await lively.sleep(0) // it seems to take time... |
| 91 | + |
| 92 | + expect(b.bar).to.equal("hello"); |
| 93 | + }); |
| 94 | + |
| 95 | + it('connects property with function', async function() { |
| 96 | + var a = <div>A</div> |
| 97 | + var b = <div>B</div> |
| 98 | + b.func = function(v) { this.bar = v} |
| 99 | + |
| 100 | + var connection = new Connection(a, "foo", b, "func") |
| 101 | + |
| 102 | + connection.activate(); |
| 103 | + await lively.sleep(0) // it seems to take time... |
| 104 | + |
| 105 | + a.foo = "hello" |
| 106 | + |
| 107 | + await lively.sleep(0) // it seems to take time... |
| 108 | + |
| 109 | + expect(b.bar).to.equal("hello"); |
| 110 | + }); |
| 111 | + |
| 112 | + |
| 113 | + it('connects style attribute with style attribute', async function() { |
| 114 | + var a = <div>A</div> |
| 115 | + var b = <div>B</div> |
| 116 | + |
| 117 | + var connection = new Connection(a, "style.width", b, "style.width") |
| 118 | + connection.activate(); |
| 119 | + |
| 120 | + await lively.sleep(0) // it seems to take time... |
| 121 | + |
| 122 | + a.style.width = "50px" |
| 123 | + |
| 124 | + await lively.sleep(0) // it seems to take time... |
| 125 | + |
| 126 | + expect(b.style.width).to.equal("50px"); |
| 127 | + }); |
| 128 | + }) |
| 129 | +}); |
| 130 | + |
| 131 | + |
0 commit comments