63 lines
2.1 KiB
JavaScript
63 lines
2.1 KiB
JavaScript
/* global describe: true, test:true, expect:true */
|
|
import {
|
|
userActivities as userActivitiesReducer,
|
|
initialState,
|
|
} from '~/reducers/userActivities';
|
|
import {
|
|
GET_USER_ACTIVITIES,
|
|
GET_USER_ACTIVITIES_SUCCESS,
|
|
GET_USER_ACTIVITIES_ERROR,
|
|
SET_SHOWN_MEDIA_STATUS,
|
|
LOGOUT_SUCCESS,
|
|
} from '~/store/actionTypes';
|
|
|
|
describe('user activities reducer', () => {
|
|
test('CASE 1: should return initial state', () => {
|
|
expect(userActivitiesReducer(undefined, { type: 'Default' }))
|
|
.toEqual(initialState);
|
|
});
|
|
|
|
test('CASE 2: should return state with meta set to loading when type is GET_USER_ACTIVITIES', () => {
|
|
const expectedState = { ...initialState, meta: { ...initialState.meta, loading: true, error: '' } };
|
|
const stateResult = userActivitiesReducer(initialState, {
|
|
type: GET_USER_ACTIVITIES, payload: {},
|
|
});
|
|
expect(stateResult).toEqual(expectedState);
|
|
});
|
|
|
|
test('CASE 3: should return state with meta set to loading when type is GET_USER_ACTIVITIES_SUCCESS', () => {
|
|
const activities = [{ mediaExchange: {} }];
|
|
const meta = { loading: false, error: '' };
|
|
const stateResult = userActivitiesReducer(initialState, {
|
|
type: GET_USER_ACTIVITIES_SUCCESS, payload: { activities: { activities } },
|
|
});
|
|
expect(stateResult).toHaveProperty('meta', meta);
|
|
});
|
|
|
|
test('CASE 4: should return state with error when type is GET_USER_ACTIVITIES_ERROR', () => {
|
|
const error = new Error('getFriendsError');
|
|
const expectedState = {
|
|
...initialState,
|
|
meta: { ...initialState.meta, error, loading: false },
|
|
};
|
|
const stateResult = userActivitiesReducer(initialState, {
|
|
type: GET_USER_ACTIVITIES_ERROR, payload: { error },
|
|
});
|
|
expect(stateResult).toEqual(expectedState);
|
|
});
|
|
|
|
test('CASE 5: should update isShown state when type is SET_SHOWN_MEDIA_STATUS', (isShown = false) => {
|
|
const stateResult = userActivitiesReducer(initialState, {
|
|
type: SET_SHOWN_MEDIA_STATUS,
|
|
payload: { isShown },
|
|
});
|
|
expect(stateResult).toEqual(initialState);
|
|
});
|
|
|
|
test('CASE 6: should empty the state on LOGOUT_SUCCESS', () => {
|
|
const existingState = {};
|
|
expect(userActivitiesReducer(existingState, { type: LOGOUT_SUCCESS }))
|
|
.toEqual(initialState);
|
|
});
|
|
});
|