-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple.js
98 lines (86 loc) · 2.16 KB
/
simple.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
import standardReducer from '../src/index'
import { combineReducers } from 'redux'
import reduceReducers from 'reduce-reducers'
describe('Simple', function() {
let reducer
let state
beforeEach(() => {
reducer = reduceReducers(
standardReducer,
(state = { arr: [] }, action) => state,
combineReducers({
partial1(state = { value: 1, foo: 'bar-1' }, action) {
return state
},
partial2(state = { value: 2, foo: 'bar-2' }, action) {
return state
},
})
)
// init
state = {}
state = reducer(state, { type: 'init' })
state.partial1.value.should.equal(1)
state.partial2.value.should.equal(2)
})
it('It works', function() {
// using type = STANDARD_MERGE_STATE_
state = reducer(state, {
type: 'STANDARD_MERGE_STATE_MODIFY_PARTIAL1',
payload: {
partial1: {
value: 'modifyed-1',
},
},
})
// console.log(state)
state.partial1.value.should.equal('modifyed-1')
state.partial1.foo.should.equal('bar-1') // unchanged
// using action.standard
state = reducer(state, {
type: 'MODIFY_PARTIAL_2',
standard: true,
payload: {
partial2: {
value: 'modifyed-2',
},
},
})
state.partial2.value.should.equal('modifyed-2')
state.partial2.foo.should.equal('bar-2') // unchanged
})
it('skip when not ok', function() {
// no action
reducer(state, { foo: 'bar' }).partial2.value.should.equal(2)
// no payload
reducer(state, {
type: 'STANDARD_MERGE_STATE',
}).partial2.value.should.equal(2)
// no payload
reducer(state, {
type: 'ABCD',
standard: true,
}).partial2.value.should.equal(2)
// x - standard
// x - type
reducer(state, {
type: 'ABCD',
standard: false,
payload: {
partial1: {
value: 10,
},
},
}).partial2.value.should.equal(2)
})
it('with array', function() {
state = reducer(state, {
type: 'FETCH_SOME_LIST',
standard: true,
payload: {
arr: [4, 5, 6],
},
})
state.arr.should.match([4, 5, 6])
})
})