diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-16 13:36:02 +0200 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-16 13:36:02 +0200 |
commit | 51a2a62e679131a2046b0d3f4a662448466ca86f (patch) | |
tree | fa75bbe50684cddce80459d6fc0b278e90005768 /src/features/utils/FeatureStore.test.js | |
parent | Merge branch 'develop' of https://github.com/meetfranz/franz into develop (diff) | |
download | ferdium-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/utils/FeatureStore.test.js')
-rw-r--r-- | src/features/utils/FeatureStore.test.js | 90 |
1 files changed, 90 insertions, 0 deletions
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 @@ | |||
1 | import PropTypes from 'prop-types'; | ||
2 | import { observable } from 'mobx'; | ||
3 | import { FeatureStore } from './FeatureStore'; | ||
4 | import { createActionsFromDefinitions } from '../../actions/lib/actions'; | ||
5 | |||
6 | const actions = createActionsFromDefinitions({ | ||
7 | countUp: {}, | ||
8 | }, PropTypes.checkPropTypes); | ||
9 | |||
10 | class 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 | |||
33 | describe('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 | }); | ||