diff options
author | 2022-06-26 01:26:19 +0200 | |
---|---|---|
committer | 2022-06-25 23:26:19 +0000 | |
commit | 465b5772763ccb8d4970d4c55e30a518abb7be3e (patch) | |
tree | e929e34910dbf6a3958cdc4de77dc1dcae93e7b0 /test/features/utils/FeatureStore.test.js | |
parent | chore: add more strict types in electron directory (#367) (diff) | |
download | ferdium-app-465b5772763ccb8d4970d4c55e30a518abb7be3e.tar.gz ferdium-app-465b5772763ccb8d4970d4c55e30a518abb7be3e.tar.zst ferdium-app-465b5772763ccb8d4970d4c55e30a518abb7be3e.zip |
chore: moved tests to ./test directory (#366)
* chore: allow coverage to be generated from non-tested files
Diffstat (limited to 'test/features/utils/FeatureStore.test.js')
-rw-r--r-- | test/features/utils/FeatureStore.test.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/test/features/utils/FeatureStore.test.js b/test/features/utils/FeatureStore.test.js new file mode 100644 index 000000000..d8d85bec1 --- /dev/null +++ b/test/features/utils/FeatureStore.test.js | |||
@@ -0,0 +1,93 @@ | |||
1 | import PropTypes from 'prop-types'; | ||
2 | import { observable } from 'mobx'; | ||
3 | import { FeatureStore } from '../../../src/features/utils/FeatureStore'; | ||
4 | import { createActionsFromDefinitions } from '../../../src/actions/lib/actions'; | ||
5 | import { createActionBindings } from '../../../src/features/utils/ActionBinding'; | ||
6 | import { createReactions } from '../../../src/stores/lib/Reaction'; | ||
7 | |||
8 | const actions = createActionsFromDefinitions( | ||
9 | { | ||
10 | countUp: {}, | ||
11 | }, | ||
12 | PropTypes.checkPropTypes, | ||
13 | ); | ||
14 | |||
15 | class TestFeatureStore extends FeatureStore { | ||
16 | @observable count = 0; | ||
17 | |||
18 | reactionInvokedCount = 0; | ||
19 | |||
20 | start() { | ||
21 | this._registerActions( | ||
22 | createActionBindings([[actions.countUp, this._countUp]]), | ||
23 | ); | ||
24 | this._registerReactions(createReactions([this._countReaction])); | ||
25 | } | ||
26 | |||
27 | _countUp = () => { | ||
28 | this.count += 1; | ||
29 | }; | ||
30 | |||
31 | _countReaction = () => { | ||
32 | this.reactionInvokedCount += 1; | ||
33 | }; | ||
34 | } | ||
35 | |||
36 | describe('FeatureStore', () => { | ||
37 | let store = null; | ||
38 | |||
39 | beforeEach(() => { | ||
40 | store = new TestFeatureStore(); | ||
41 | }); | ||
42 | |||
43 | describe('registering actions', () => { | ||
44 | it('starts the actions', () => { | ||
45 | store.start(); | ||
46 | actions.countUp(); | ||
47 | expect(store.count).toBe(1); | ||
48 | }); | ||
49 | it('starts the reactions', () => { | ||
50 | store.start(); | ||
51 | actions.countUp(); | ||
52 | expect(store.reactionInvokedCount).toBe(1); | ||
53 | }); | ||
54 | }); | ||
55 | |||
56 | describe('stopping the store', () => { | ||
57 | it('stops the actions', () => { | ||
58 | store.start(); | ||
59 | actions.countUp(); | ||
60 | store.stop(); | ||
61 | actions.countUp(); | ||
62 | expect(store.count).toBe(1); | ||
63 | }); | ||
64 | it('stops the reactions', () => { | ||
65 | store.start(); | ||
66 | actions.countUp(); | ||
67 | store.stop(); | ||
68 | store.count += 1; | ||
69 | expect(store.reactionInvokedCount).toBe(1); | ||
70 | }); | ||
71 | }); | ||
72 | |||
73 | describe('toggling the store', () => { | ||
74 | it('restarts the actions correctly', () => { | ||
75 | store.start(); | ||
76 | actions.countUp(); | ||
77 | store.stop(); | ||
78 | actions.countUp(); | ||
79 | store.start(); | ||
80 | actions.countUp(); | ||
81 | expect(store.count).toBe(2); | ||
82 | }); | ||
83 | it('restarts the reactions correctly', () => { | ||
84 | store.start(); | ||
85 | actions.countUp(); | ||
86 | store.stop(); | ||
87 | actions.countUp(); | ||
88 | store.start(); | ||
89 | actions.countUp(); | ||
90 | expect(store.count).toBe(2); | ||
91 | }); | ||
92 | }); | ||
93 | }); | ||