Files
Maagap/ioneapps-maagapp-ee31119a522d/__tests__/reducers/user.js
2025-08-06 13:49:11 +08:00

74 lines
1.9 KiB
JavaScript

/* 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);
});
});