forked from jeffbski/redux-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify-create-logic.spec.js
116 lines (98 loc) · 3.22 KB
/
notify-create-logic.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import expect from 'expect';
import { NOTIFY_CREATE,
NOTIFY_QUEUE,
NOTIFY_REMOVE,
NOTIFY_DISPLAY_QUEUED,
notifyCreate,
notifyQueue,
notifyRemove,
notifyDisplayQueued } from '../src/notify/actions';
import { MAX_DISPLAY, DISPLAY_TIME,
notifyCreateLogic, notifyRemoveLogic, notifyQueuedLogic,
notifyDisplayQueuedLogic } from '../src/notify/logic';
describe('notifyCreateLogic', () => {
describe('empty current, notifyCreate(), validate', () => {
let action;
let allow;
let reject;
beforeEach((done) => {
const getState = () => ({
notify: {
messages: [],
queue: []
}
});
action = notifyCreate();
allow = expect.createSpy().andCall(() => done());
reject = (action) => done(action); // pass as error to done
notifyCreateLogic.validate({ getState, action }, allow, reject);
});
it('should have called allow with the action', () => {
expect(allow.calls.length).toBe(1);
expect(allow.calls[0].arguments[0]).toEqual(action);
});
});
describe('current = max-1, no queue, notifyCreate(), validate', () => {
let action;
let allow;
let reject;
beforeEach((done) => {
const getState = () => ({
notify: {
messages: (new Array(MAX_DISPLAY - 1)).map((x, idx) => idx),
queue: []
}
});
action = notifyCreate();
allow = expect.createSpy().andCall(() => done());
reject = (action) => done(action); // pass as error to done
notifyCreateLogic.validate({ getState, action }, allow, reject);
});
it('should have called allow with the action', () => {
expect(allow.calls.length).toBe(1);
expect(allow.calls[0].arguments[0]).toEqual(action);
});
});
describe('full current, notifyCreate(), validate', () => {
let action;
let allow;
let reject;
beforeEach((done) => {
const getState = () => ({
notify: {
messages: (new Array(MAX_DISPLAY)).map((x, idx) => idx),
queue: []
}
});
action = notifyCreate();
allow = (action) => done(action); // pass as an error
reject = expect.createSpy().andCall(() => done());
notifyCreateLogic.validate({ getState, action }, allow, reject);
});
it('should have called reject with the queue action', () => {
expect(reject.calls.length).toBe(1);
expect(reject.calls[0].arguments[0]).toEqual(notifyQueue(action.payload));
});
});
describe('empty current but queue, notifyCreate(), validate', () => {
let action;
let allow;
let reject;
beforeEach((done) => {
const getState = () => ({
notify: {
messages: [],
queue: [1]
}
});
action = notifyCreate();
allow = (action) => done(action); // pass as an error
reject = expect.createSpy().andCall(() => done());
notifyCreateLogic.validate({ getState, action }, allow, reject);
});
it('should have called reject with the queue action', () => {
expect(reject.calls.length).toBe(1);
expect(reject.calls[0].arguments[0]).toEqual(notifyQueue(action.payload));
});
});
});