/* global describe: true, test:true, expect:true */ import { user } from '~/reducers/user'; import { SUBMIT_LOGIN_SUCCESS, LOGOUT_SUCCESS, } from '~/store/actionTypes'; describe('user reducer', () => { test('CASE 1: should return initial state', () => { const expectedState = { checkUserStorage: false, showLanguageChangedDialog: false, enableLanguageDiscrepancyPopup: false, displayUploadDialogue: true, showStorageFull: false, showLanguageDiscrepancy: false, meta: { loading: false, error: '' }, isFullStoragePopup: false, todo: { avatar: { avatarChanged: true, tutorialDismissed: false, }, }, }; expect(user(undefined, {})) .toEqual(expectedState); }); test('CASE 2: should return correct state when actionType is `SUBMIT_LOGIN_SUCCESS`', () => { const expectedState = { token: 'token', username: 'username', email: 'email@email.com', firstName: 'first', lastName: 'last', checkUserStorage: true, meta: { loading: false, error: '' }, isFullStoragePopup: false, todo: { avatar: { avatarChanged: true, tutorialDismissed: false, }, }, }; expect(user({}, { type: SUBMIT_LOGIN_SUCCESS, payload: { user: expectedState } })) .toEqual(expectedState); }); test('CASE 3: should return correct state when actionType is `LOGOUT_SUCCESS`', () => { const enableLanguageDiscrepancyPopup = false; const expectedState = { checkUserStorage: false, displayUploadDialogue: true, showLanguageChangedDialog: false, enableLanguageDiscrepancyPopup, showStorageFull: false, showLanguageDiscrepancy: false, meta: { loading: false, error: '' }, isFullStoragePopup: false, todo: { avatar: { avatarChanged: true, tutorialDismissed: false, }, }, }; expect(user({ enableLanguageDiscrepancyPopup }, { type: LOGOUT_SUCCESS, payload: { user: expectedState } })) .toEqual(expectedState); }); });