This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
customevents_test.js
91 lines (65 loc) · 2.18 KB
/
customevents_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
goog.provide('jsaction.testing.CustomEventsTest');
goog.setTestOnly('jsaction.testing.CustomEventsTest');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.recordFunction');
goog.require('jsaction');
goog.require('jsaction.testing.CustomEvents');
var customEvents;
var container;
var origin;
function setUpPage() {
container = document.getElementById('container');
origin = document.getElementById('origin');
}
function setUp() {
customEvents = new jsaction.testing.CustomEvents();
}
function tearDown() {
customEvents.dispose();
}
function testSimpleListen() {
var handlerA = goog.testing.recordFunction();
var handlerB = goog.testing.recordFunction();
customEvents.listen(container, 'custom_a', handlerA);
customEvents.listen(container, 'custom_b', handlerB);
jsaction.fireCustomEvent(origin, 'custom_a');
handlerA.assertCallCount(1);
handlerB.assertCallCount(0);
handlerA.reset();
jsaction.fireCustomEvent(origin, 'custom_b');
handlerA.assertCallCount(0);
handlerB.assertCallCount(1);
}
function testMultiListen() {
var handler1 = goog.testing.recordFunction();
var handler2 = goog.testing.recordFunction();
customEvents.listen(container, 'custom_a', handler1);
customEvents.listen(container, 'custom_a', handler2);
jsaction.fireCustomEvent(origin, 'custom_a');
handler1.assertCallCount(1);
handler2.assertCallCount(1);
}
function testListenWithContextAndData() {
var context = {
expected: 1,
handler: goog.testing.recordFunction(function(actionFlow) {
assertEquals(this.expected, actionFlow.event().detail.data['x']);
})
};
customEvents.listen(container, 'custom_a', context.handler, context);
jsaction.fireCustomEvent(origin, 'custom_a', {'x': 1});
context.handler.assertCallCount(1);
}
function testDispose() {
var handler = goog.testing.recordFunction();
customEvents.listen(container, 'custom_a', handler);
jsaction.fireCustomEvent(origin, 'custom_a');
handler.assertCallCount(1);
handler.reset();
jsaction.fireCustomEvent(origin, 'custom_a');
handler.assertCallCount(1);
handler.reset();
customEvents.dispose();
jsaction.fireCustomEvent(origin, 'custom_a');
handler.assertCallCount(0);
}