aboutsummaryrefslogtreecommitdiffstats
path: root/src/features
diff options
context:
space:
mode:
authorLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-04-16 13:36:02 +0200
committerLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-04-16 13:36:02 +0200
commit51a2a62e679131a2046b0d3f4a662448466ca86f (patch)
treefa75bbe50684cddce80459d6fc0b278e90005768 /src/features
parentMerge branch 'develop' of https://github.com/meetfranz/franz into develop (diff)
downloadferdium-app-51a2a62e679131a2046b0d3f4a662448466ca86f.tar.gz
ferdium-app-51a2a62e679131a2046b0d3f4a662448466ca86f.tar.zst
ferdium-app-51a2a62e679131a2046b0d3f4a662448466ca86f.zip
fix issues with actions and reactions setup in feature store
Diffstat (limited to 'src/features')
-rw-r--r--src/features/utils/FeatureStore.js10
-rw-r--r--src/features/utils/FeatureStore.test.js90
2 files changed, 94 insertions, 6 deletions
diff --git a/src/features/utils/FeatureStore.js b/src/features/utils/FeatureStore.js
index b6e0fbce3..0bc10e176 100644
--- a/src/features/utils/FeatureStore.js
+++ b/src/features/utils/FeatureStore.js
@@ -1,9 +1,7 @@
1import { union } from 'lodash';
2
3export class FeatureStore { 1export class FeatureStore {
4 _actions = null; 2 _actions = [];
5 3
6 _reactions = null; 4 _reactions = [];
7 5
8 stop() { 6 stop() {
9 this._stopActions(); 7 this._stopActions();
@@ -13,7 +11,7 @@ export class FeatureStore {
13 // ACTIONS 11 // ACTIONS
14 12
15 _registerActions(actions) { 13 _registerActions(actions) {
16 this._actions = union(this._actions, actions); 14 this._actions = actions;
17 this._startActions(); 15 this._startActions();
18 } 16 }
19 17
@@ -28,7 +26,7 @@ export class FeatureStore {
28 // REACTIONS 26 // REACTIONS
29 27
30 _registerReactions(reactions) { 28 _registerReactions(reactions) {
31 this._reactions = union(this._reactions, reactions); 29 this._reactions = reactions;
32 this._startReactions(); 30 this._startReactions();
33 } 31 }
34 32
diff --git a/src/features/utils/FeatureStore.test.js b/src/features/utils/FeatureStore.test.js
new file mode 100644
index 000000000..b618b0a14
--- /dev/null
+++ b/src/features/utils/FeatureStore.test.js
@@ -0,0 +1,90 @@
1import PropTypes from 'prop-types';
2import { observable } from 'mobx';
3import { FeatureStore } from './FeatureStore';
4import { createActionsFromDefinitions } from '../../actions/lib/actions';
5
6const actions = createActionsFromDefinitions({
7 countUp: {},
8}, PropTypes.checkPropTypes);
9
10class TestFeatureStore extends FeatureStore {
11 @observable count = 0;
12
13 reactionInvokedCount = 0;
14
15 start() {
16 this._registerActions([
17 [actions.countUp, this._countUp],
18 ]);
19 this._registerReactions([
20 this._countReaction,
21 ]);
22 }
23
24 _countUp = () => {
25 this.count += 1;
26 };
27
28 _countReaction = () => {
29 this.reactionInvokedCount += 1;
30 }
31}
32
33describe('FeatureStore', () => {
34 let store = null;
35
36 beforeEach(() => {
37 store = new TestFeatureStore();
38 });
39
40 describe('registering actions', () => {
41 it('starts the actions', () => {
42 store.start();
43 actions.countUp();
44 expect(store.count).toBe(1);
45 });
46 it('starts the reactions', () => {
47 store.start();
48 actions.countUp();
49 expect(store.reactionInvokedCount).toBe(1);
50 });
51 });
52
53 describe('stopping the store', () => {
54 it('stops the actions', () => {
55 store.start();
56 actions.countUp();
57 store.stop();
58 actions.countUp();
59 expect(store.count).toBe(1);
60 });
61 it('stops the reactions', () => {
62 store.start();
63 actions.countUp();
64 store.stop();
65 store.count += 1;
66 expect(store.reactionInvokedCount).toBe(1);
67 });
68 });
69
70 describe('toggling the store', () => {
71 it('restarts the actions correctly', () => {
72 store.start();
73 actions.countUp();
74 store.stop();
75 actions.countUp();
76 store.start();
77 actions.countUp();
78 expect(store.count).toBe(2);
79 });
80 it('restarts the reactions correctly', () => {
81 store.start();
82 actions.countUp();
83 store.stop();
84 actions.countUp();
85 store.start();
86 actions.countUp();
87 expect(store.count).toBe(2);
88 });
89 });
90});