Skip to content

Commit 325a412

Browse files
committed
enable bubling test for DeluxeSignal class
1 parent e87ae1b commit 325a412

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

test/org/osflash/signals/DeluxeSignalWithBubblingEventTest.test.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,52 @@ import { IEvent } from "../../../../src/org/osflash/signals/events/IEvent";
1111
describe("DeluxeSignalWithBubblingEventTest", () => {
1212
let async: AsyncUtil = new AsyncUtil();
1313

14-
let theParent: IBubbleEventHandler;
14+
let theParent: Child;
1515
let theChild: Child;
1616
let theGrandChild: Child;
1717
let cancelTimeout: Function;
18+
let doneFunc: Function;
19+
20+
function onEventBubbled(e: IEvent): boolean {
21+
cancelTimeout();
22+
assert.equal(theGrandChild, e.target, "e.target should be the object that originally dispatched event");
23+
assert.equal(this, e.currentTarget, "e.currentTarget should be the object receiving the bubbled event");
24+
doneFunc();
25+
return false;
26+
}
1827

1928
beforeEach(() => {
20-
theParent = this;
21-
theChild = new Child(this, "theChild");
29+
theParent = new Child(null, "theParent", onEventBubbled);
30+
theChild = new Child(theParent, "theChild");
2231
theGrandChild = new Child(theChild, "theGrandChild");
2332
});
2433

2534
afterEach(() => {
2635
theChild = null;
2736
theGrandChild = null;
2837
cancelTimeout = null;
38+
doneFunc = null;
2939
});
3040

3141
it("parent_child_relationships()", () => {
32-
assert.equal(this, theChild.parent, "theChild's parent is this");
33-
// TODO: find a way to typecheck for interfaces
34-
// assert.isTrue(this instanceof IBubbleEventHandler, "this can handle bubbling events");
42+
assert.equal(theParent, theChild.parent, "theChild's parent is this");
3543
});
3644

37-
it.skip("dispatch_bubbling_event_from_theGrandChild_should_bubble_to_parent_IBubbleHandler()", (done) => {
45+
it("dispatch_bubbling_event_from_theGrandChild_should_bubble_to_parent_IBubbleHandler()", (done) => {
3846
// If cancelTimeout() isn"t called, this test will fail.
39-
cancelTimeout = async.add(null, 10);
47+
cancelTimeout = async.add(null, 1000);
48+
49+
// keep reference for done function
50+
doneFunc = done;
51+
52+
// prepare event
4053
let event: IEvent = new GenericEvent();
4154
event.bubbles = true;
4255

56+
// dispatch event from grand child, expecting that it will arrive on parent
4357
theGrandChild.completed.dispatch(event);
4458
});
4559

46-
function onEventBubbled(e: IEvent): boolean {
47-
cancelTimeout();
48-
assert.equal(theGrandChild, e.target, "e.target should be the object that originally dispatched event");
49-
assert.equal(this, e.currentTarget, "e.currentTarget should be the object receiving the bubbled event");
50-
return false;
51-
}
52-
5360
// TODO: returning after throwing an error is not possible in TS
5461
it.skip("returning_false_from_onEventBubbled_should_stop_bubbling()", () => {
5562
let bubbleHater: BubbleHater = new BubbleHater();
@@ -82,11 +89,13 @@ class Child implements IBubbleEventHandler {
8289
public parent: Object;
8390
public completed: DeluxeSignal;
8491
public name: string;
92+
public listener: Function = null;
8593
public popsBubbles: boolean = false;
8694

87-
constructor(parent: Object = null, name = "") {
95+
constructor(parent: Object = null, name = "", listener = null) {
8896
this.parent = parent;
8997
this.name = name;
98+
this.listener = listener;
9099
this.completed = new DeluxeSignal(this);
91100
}
92101

@@ -95,7 +104,11 @@ class Child implements IBubbleEventHandler {
95104
}
96105

97106
public onEventBubbled(event: IEvent): boolean {
98-
return !this.popsBubbles;
107+
if (this.listener !== null) {
108+
return this.listener(event);
109+
} else {
110+
return !this.popsBubbles;
111+
}
99112
}
100113
}
101114

0 commit comments

Comments
 (0)