1
- // @flow strict-local
1
+ /* @flow strict-local */
2
2
import deepFreeze from 'deep-freeze' ;
3
3
4
4
import { NULL_OBJECT } from '../../nullObjects' ;
@@ -13,87 +13,47 @@ describe('draftsReducer', () => {
13
13
14
14
describe ( 'DRAFT_UPDATE' , ( ) => {
15
15
test ( 'add a new draft key drafts' , ( ) => {
16
- const initialState = NULL_OBJECT ;
17
-
18
- const action = deepFreeze ( {
19
- type : DRAFT_UPDATE ,
20
- content : 'Hello' ,
21
- narrow : testNarrow ,
22
- } ) ;
23
-
24
- const expectedState = {
25
- [ testNarrowStr ] : 'Hello' ,
26
- } ;
27
-
28
- const actualState = draftsReducer ( initialState , action ) ;
29
-
30
- expect ( actualState ) . toEqual ( expectedState ) ;
16
+ const prevState = NULL_OBJECT ;
17
+ expect (
18
+ draftsReducer (
19
+ prevState ,
20
+ deepFreeze ( { type : DRAFT_UPDATE , content : 'Hello' , narrow : testNarrow } ) ,
21
+ ) ,
22
+ ) . toEqual ( { [ testNarrowStr ] : 'Hello' } ) ;
31
23
} ) ;
32
24
33
25
test ( 'adding the same draft to drafts does not mutate the state' , ( ) => {
34
- const initialState = deepFreeze ( {
35
- [ testNarrowStr ] : 'Hello' ,
36
- } ) ;
37
-
38
- const action = deepFreeze ( {
39
- type : DRAFT_UPDATE ,
40
- content : 'Hello' ,
41
- narrow : testNarrow ,
42
- } ) ;
43
-
44
- const actualState = draftsReducer ( initialState , action ) ;
45
-
46
- expect ( actualState ) . toBe ( initialState ) ;
26
+ const prevState = deepFreeze ( { [ testNarrowStr ] : 'Hello' } ) ;
27
+ expect (
28
+ draftsReducer (
29
+ prevState ,
30
+ deepFreeze ( { type : DRAFT_UPDATE , content : 'Hello' , narrow : testNarrow } ) ,
31
+ ) ,
32
+ ) . toBe ( prevState ) ;
47
33
} ) ;
48
34
49
35
test ( 'when content is empty remove draft from state' , ( ) => {
50
- const initialState = deepFreeze ( {
51
- [ testNarrowStr ] : 'Hello' ,
52
- } ) ;
53
-
54
- const action = {
55
- type : DRAFT_UPDATE ,
56
- content : '' ,
57
- narrow : testNarrow ,
58
- } ;
59
-
60
- const expectedState = { } ;
61
-
62
- const actualState = draftsReducer ( initialState , action ) ;
63
-
64
- expect ( actualState ) . toEqual ( expectedState ) ;
36
+ const prevState = deepFreeze ( { [ testNarrowStr ] : 'Hello' } ) ;
37
+ expect (
38
+ draftsReducer ( prevState , { type : DRAFT_UPDATE , content : '' , narrow : testNarrow } ) ,
39
+ ) . toEqual ( { } ) ;
65
40
} ) ;
66
41
67
42
test ( 'remove draft when content is white space' , ( ) => {
68
- const initialState = deepFreeze ( {
69
- [ testNarrowStr ] : 'Hello' ,
70
- } ) ;
71
-
72
- const action = {
73
- type : DRAFT_UPDATE ,
74
- content : ' ' ,
75
- narrow : testNarrow ,
76
- } ;
77
-
78
- const expectedState = { } ;
79
-
80
- const actualState = draftsReducer ( initialState , action ) ;
81
-
82
- expect ( actualState ) . toEqual ( expectedState ) ;
43
+ const prevState = deepFreeze ( { [ testNarrowStr ] : 'Hello' } ) ;
44
+ expect (
45
+ draftsReducer ( prevState , { type : DRAFT_UPDATE , content : ' ' , narrow : testNarrow } ) ,
46
+ ) . toEqual ( { } ) ;
83
47
} ) ;
84
48
85
49
test ( 'do not mutate state if there is nothing to remove' , ( ) => {
86
- const initialState = NULL_OBJECT ;
87
-
88
- const action = deepFreeze ( {
89
- type : DRAFT_UPDATE ,
90
- content : '' ,
91
- narrow : testNarrow ,
92
- } ) ;
93
-
94
- const actualState = draftsReducer ( initialState , action ) ;
95
-
96
- expect ( actualState ) . toBe ( initialState ) ;
50
+ const prevState = NULL_OBJECT ;
51
+ expect (
52
+ draftsReducer (
53
+ prevState ,
54
+ deepFreeze ( { type : DRAFT_UPDATE , content : '' , narrow : testNarrow } ) ,
55
+ ) ,
56
+ ) . toBe ( prevState ) ;
97
57
} ) ;
98
58
} ) ;
99
59
} ) ;
0 commit comments