aboutsummaryrefslogtreecommitdiff
path: root/src/web/js/dispatcher/__tests__
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-10-12 22:36:01 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2016-01-26 23:46:32 +0100
commit2c0e17cb977a1e8782799b337df8b1583d019906 (patch)
tree75563e440e9eac14950fa1a71a83e64df20e52d0 /src/web/js/dispatcher/__tests__
parentfixing sqlalchemy resolving warning (diff)
downloadnewspipe-2c0e17cb977a1e8782799b337df8b1583d019906.tar.gz
newspipe-2c0e17cb977a1e8782799b337df8b1583d019906.tar.bz2
newspipe-2c0e17cb977a1e8782799b337df8b1583d019906.zip
bootstraping react
Diffstat (limited to 'src/web/js/dispatcher/__tests__')
-rw-r--r--src/web/js/dispatcher/__tests__/AppDispatcher-test.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/web/js/dispatcher/__tests__/AppDispatcher-test.js b/src/web/js/dispatcher/__tests__/AppDispatcher-test.js
new file mode 100644
index 00000000..d3a35fc5
--- /dev/null
+++ b/src/web/js/dispatcher/__tests__/AppDispatcher-test.js
@@ -0,0 +1,72 @@
+"use strict";
+
+jest.autoMockOff();
+
+describe('AppDispatcher', function() {
+ var AppDispatcher;
+
+ beforeEach(function() {
+ AppDispatcher = require('../AppDispatcher.js');
+ });
+
+ it('sends actions to subscribers', function() {
+ var listener = jest.genMockFunction();
+ AppDispatcher.register(listener);
+
+ var payload = {};
+ AppDispatcher.dispatch(payload);
+ expect(listener.mock.calls.length).toBe(1);
+ expect(listener.mock.calls[0][0]).toBe(payload);
+ });
+
+ it('waits with chained dependencies properly', function() {
+ var payload = {};
+
+ var listener1Done = false;
+ var listener1 = function(pl) {
+ AppDispatcher.waitFor([index2, index4]);
+ // Second, third, and fourth listeners should have now been called
+ expect(listener2Done).toBe(true);
+ expect(listener3Done).toBe(true);
+ expect(listener4Done).toBe(true);
+ listener1Done = true;
+ };
+ var index1 = AppDispatcher.register(listener1);
+
+ var listener2Done = false;
+ var listener2 = function(pl) {
+ AppDispatcher.waitFor([index3]);
+ expect(listener3Done).toBe(true);
+ listener2Done = true;
+ };
+ var index2 = AppDispatcher.register(listener2);
+
+ var listener3Done = false;
+ var listener3 = function(pl) {
+ listener3Done = true;
+ };
+ var index3 = AppDispatcher.register(listener3);
+
+ var listener4Done = false;
+ var listener4 = function(pl) {
+ AppDispatcher.waitFor([index3]);
+ expect(listener3Done).toBe(true);
+ listener4Done = true;
+ };
+ var index4 = AppDispatcher.register(listener4);
+
+ runs(function() {
+ AppDispatcher.dispatch(payload);
+ });
+
+ waitsFor(function() {
+ return listener1Done;
+ }, "Not all subscribers were properly called", 500);
+
+ runs(function() {
+ expect(listener1Done).toBe(true);
+ expect(listener2Done).toBe(true);
+ expect(listener3Done).toBe(true);
+ });
+ });
+});
bgstack15