Skip to content

Commit 21be74d

Browse files
committed
drafts tests [nfc]: Tighten up code style a bit
1 parent d259170 commit 21be74d

File tree

1 file changed

+30
-70
lines changed

1 file changed

+30
-70
lines changed
Lines changed: 30 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @flow strict-local
1+
/* @flow strict-local */
22
import deepFreeze from 'deep-freeze';
33

44
import { NULL_OBJECT } from '../../nullObjects';
@@ -13,87 +13,47 @@ describe('draftsReducer', () => {
1313

1414
describe('DRAFT_UPDATE', () => {
1515
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' });
3123
});
3224

3325
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);
4733
});
4834

4935
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({});
6540
});
6641

6742
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({});
8347
});
8448

8549
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);
9757
});
9858
});
9959
});

0 commit comments

Comments
 (0)