Skip to content

Commit ca8cdd9

Browse files
committed
settings tests [nfc]: Tighten code style a bit
1 parent 6ab521b commit ca8cdd9

File tree

1 file changed

+53
-81
lines changed

1 file changed

+53
-81
lines changed

src/settings/__tests__/settingsReducer-test.js

Lines changed: 53 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ describe('settingsReducer', () => {
2424
onlineNotification: false,
2525
streamNotification: false,
2626
});
27-
28-
const action = eg.mkActionRegisterComplete({
29-
enable_offline_push_notifications: true,
30-
enable_online_push_notifications: true,
31-
enable_stream_push_notifications: true,
32-
user_settings: undefined,
33-
});
34-
35-
const actualState = settingsReducer(prevState, action);
36-
37-
expect(actualState).toMatchObject({
27+
expect(
28+
settingsReducer(
29+
prevState,
30+
eg.mkActionRegisterComplete({
31+
enable_offline_push_notifications: true,
32+
enable_online_push_notifications: true,
33+
enable_stream_push_notifications: true,
34+
user_settings: undefined,
35+
}),
36+
),
37+
).toMatchObject({
3838
offlineNotification: true,
3939
onlineNotification: true,
4040
streamNotification: true,
@@ -77,87 +77,59 @@ describe('settingsReducer', () => {
7777

7878
describe('SET_GLOBAL_SETTINGS', () => {
7979
test('changes value of a key', () => {
80-
const action = deepFreeze({
81-
type: SET_GLOBAL_SETTINGS,
82-
update: { theme: 'night' },
83-
});
84-
85-
const expectedState = {
86-
...baseState,
87-
theme: 'night',
88-
};
89-
90-
const actualState = settingsReducer(baseState, action);
91-
92-
expect(actualState).toEqual(expectedState);
80+
expect(
81+
settingsReducer(
82+
baseState,
83+
deepFreeze({ type: SET_GLOBAL_SETTINGS, update: { theme: 'night' } }),
84+
),
85+
).toEqual({ ...baseState, theme: 'night' });
9386
});
9487
});
9588

9689
describe('EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS', () => {
9790
test('changes offline notification setting', () => {
98-
const prevState = deepFreeze({
99-
...baseState,
100-
offlineNotification: false,
101-
});
102-
const action = deepFreeze({
103-
type: EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,
104-
id: 0,
105-
notification_name: 'enable_offline_push_notifications',
106-
setting: true,
107-
});
108-
109-
const expectedState = {
110-
...baseState,
111-
offlineNotification: true,
112-
};
113-
114-
const actualState = settingsReducer(prevState, action);
115-
116-
expect(actualState).toEqual(expectedState);
91+
const prevState = deepFreeze({ ...baseState, offlineNotification: false });
92+
expect(
93+
settingsReducer(
94+
prevState,
95+
deepFreeze({
96+
type: EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,
97+
id: 0,
98+
notification_name: 'enable_offline_push_notifications',
99+
setting: true,
100+
}),
101+
),
102+
).toEqual({ ...baseState, offlineNotification: true });
117103
});
118104

119105
test('changes online notification setting', () => {
120-
const prevState = deepFreeze({
121-
...baseState,
122-
onlineNotification: false,
123-
});
124-
const action = deepFreeze({
125-
type: EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,
126-
id: 0,
127-
notification_name: 'enable_online_push_notifications',
128-
setting: true,
129-
});
130-
131-
const expectedState = {
132-
...baseState,
133-
onlineNotification: true,
134-
};
135-
136-
const actualState = settingsReducer(prevState, action);
137-
138-
expect(actualState).toEqual(expectedState);
106+
const prevState = deepFreeze({ ...baseState, onlineNotification: false });
107+
expect(
108+
settingsReducer(
109+
prevState,
110+
deepFreeze({
111+
type: EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,
112+
id: 0,
113+
notification_name: 'enable_online_push_notifications',
114+
setting: true,
115+
}),
116+
),
117+
).toEqual({ ...baseState, onlineNotification: true });
139118
});
140119

141120
test('changes stream notification setting', () => {
142-
const prevState = deepFreeze({
143-
...baseState,
144-
streamNotification: false,
145-
});
146-
const action = deepFreeze({
147-
type: EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,
148-
id: 0,
149-
notification_name: 'enable_stream_push_notifications',
150-
setting: true,
151-
});
152-
153-
const expectedState = {
154-
...baseState,
155-
streamNotification: true,
156-
};
157-
158-
const actualState = settingsReducer(prevState, action);
159-
160-
expect(actualState).toEqual(expectedState);
121+
const prevState = deepFreeze({ ...baseState, streamNotification: false });
122+
expect(
123+
settingsReducer(
124+
prevState,
125+
deepFreeze({
126+
type: EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,
127+
id: 0,
128+
notification_name: 'enable_stream_push_notifications',
129+
setting: true,
130+
}),
131+
),
132+
).toEqual({ ...baseState, streamNotification: true });
161133
});
162134
});
163135

0 commit comments

Comments
 (0)