aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/utils/FeatureStore.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/utils/FeatureStore.test.js')
-rw-r--r--src/features/utils/FeatureStore.test.js90
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 @@
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});