35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
/* global describe: true, test:true, expect:true */
|
|
import { settings as settingsReducer, initialState } from '~/reducers/settings';
|
|
import {
|
|
GET_SETTINGS_SUCCESS,
|
|
SET_SETTINGS_SUCCESS,
|
|
LOGOUT_SUCCESS,
|
|
} from '~/store/actionTypes';
|
|
|
|
describe('settings reducer', () => {
|
|
test('CASE 1: should return initial state', () => {
|
|
expect(settingsReducer(undefined, { type: 'Default' }))
|
|
.toEqual(initialState);
|
|
});
|
|
|
|
test('CASE 2: should empty the state on LOGOUT_SUCCESS', () => {
|
|
expect(settingsReducer({ languageCode: 'en' }, { type: LOGOUT_SUCCESS }))
|
|
.toEqual(initialState);
|
|
});
|
|
|
|
test('CASE 3: should return settings on GET_SETTINGS_SUCCESS', () => {
|
|
const settings = { autoAcceptFriend: true, defaultPlaylistId: 123 };
|
|
const expectedState = { ...initialState, ...settings };
|
|
expect(settingsReducer(undefined, { type: GET_SETTINGS_SUCCESS, payload: { settings } }))
|
|
.toEqual(expectedState);
|
|
});
|
|
|
|
test('CASE 3: should return settings on SET_SETTINGS_SUCCESS', () => {
|
|
const settings = { defaultPlaylistId: 123 };
|
|
const existingState = { autoAcceptFriend: false, defaultPlaylistId: -1 };
|
|
const expectedState = { ...existingState, ...settings };
|
|
expect(settingsReducer(existingState, { type: SET_SETTINGS_SUCCESS, payload: { settings } }))
|
|
.toEqual(expectedState);
|
|
});
|
|
});
|