OLD | NEW |
| (Empty) |
1 (function() | |
2 { | |
3 module("Filter notifier", {setup: prepareFilterComponents, teardown: restoreFi
lterComponents}); | |
4 | |
5 let triggeredListeners = []; | |
6 let listeners = [ | |
7 (action, item) => triggeredListeners.push(["listener1", action, item]), | |
8 (action, item) => triggeredListeners.push(["listener2", action, item]), | |
9 (action, item) => triggeredListeners.push(["listener3", action, item]) | |
10 ]; | |
11 | |
12 function compareListeners(test, list) | |
13 { | |
14 let result1 = triggeredListeners = []; | |
15 FilterNotifier.triggerListeners("foo", {bar: true}); | |
16 | |
17 let result2 = triggeredListeners = []; | |
18 for (let observer of list) | |
19 observer("foo", {bar: true}); | |
20 | |
21 deepEqual(result1, result2, test); | |
22 } | |
23 | |
24 test("Adding/removing listeners", function() | |
25 { | |
26 let [listener1, listener2, listener3] = listeners; | |
27 | |
28 compareListeners("No listeners", []); | |
29 | |
30 FilterNotifier.addListener(listener1); | |
31 compareListeners("addListener(listener1)", [listener1]); | |
32 | |
33 FilterNotifier.addListener(listener1); | |
34 compareListeners("addListener(listener1) again", [listener1]); | |
35 | |
36 FilterNotifier.addListener(listener2); | |
37 compareListeners("addListener(listener2)", [listener1, listener2]); | |
38 | |
39 FilterNotifier.removeListener(listener1); | |
40 compareListeners("removeListener(listener1)", [listener2]); | |
41 | |
42 FilterNotifier.removeListener(listener1); | |
43 compareListeners("removeListener(listener1) again", [listener2]); | |
44 | |
45 FilterNotifier.addListener(listener3); | |
46 compareListeners("addListener(listener3)", [listener2, listener3]); | |
47 | |
48 FilterNotifier.addListener(listener1); | |
49 compareListeners("addListener(listener1)", [listener2, listener3, listener1]
); | |
50 | |
51 FilterNotifier.removeListener(listener3); | |
52 compareListeners("removeListener(listener3)", [listener2, listener1]); | |
53 | |
54 FilterNotifier.removeListener(listener1); | |
55 compareListeners("removeListener(listener1)", [listener2]); | |
56 | |
57 FilterNotifier.removeListener(listener2); | |
58 compareListeners("removeListener(listener2)", []); | |
59 }); | |
60 | |
61 test("Removing listeners while being called", function() | |
62 { | |
63 let listener1 = function() | |
64 { | |
65 listeners[0].apply(this, arguments); | |
66 FilterNotifier.removeListener(listener1); | |
67 }; | |
68 let listener2 = listeners[1]; | |
69 FilterNotifier.addListener(listener1); | |
70 FilterNotifier.addListener(listener2); | |
71 | |
72 compareListeners("Initial call", [listener1, listener2]); | |
73 compareListeners("Subsequent calls", [listener2]); | |
74 }); | |
75 })(); | |
OLD | NEW |