141 lines
4.8 KiB
JavaScript
141 lines
4.8 KiB
JavaScript
/* global describe: true, test:true, expect:true */
|
|
import {
|
|
shareExtension as shareExtReducer,
|
|
initialState,
|
|
} from '~/reducers/shareExtension';
|
|
import {
|
|
SET_SHARE_EXT,
|
|
DEFAULT_SHARE_EXT,
|
|
LOGOUT_SUCCESS,
|
|
GET_SHARE_EXT_DATA,
|
|
GET_SHARE_EXT_DATA_SUCCESS,
|
|
GET_SHARE_EXT_DATA_ERROR,
|
|
} from '~/store/actionTypes';
|
|
|
|
describe('shareExtension reducer', () => {
|
|
test('CASE 1: should return initial state', () => {
|
|
expect(shareExtReducer(undefined, { type: 'Default' }))
|
|
.toEqual(initialState);
|
|
});
|
|
|
|
test('CASE 2: should empty the state on LOGOUT_SUCCESS', () => {
|
|
expect(shareExtReducer({}, { type: LOGOUT_SUCCESS }))
|
|
.toEqual(initialState);
|
|
});
|
|
|
|
test('CASE 3: should return share extension on DEFAULT_SHARE_EXT', () => {
|
|
const expectedState = { ...initialState };
|
|
expect(shareExtReducer(undefined, { type: DEFAULT_SHARE_EXT, payload: { } }))
|
|
.toEqual(expectedState);
|
|
});
|
|
|
|
test('CASE 4: should return share extension on SET_SHARE_EXT', () => {
|
|
const albumId = 123;
|
|
const shareExtension = { albumId };
|
|
const expectedState = { ...initialState, ...shareExtension };
|
|
expect(shareExtReducer(initialState, { type: SET_SHARE_EXT, payload: { albumId } }))
|
|
.toEqual(expectedState);
|
|
});
|
|
test('CASE 5: should return share extension on GET_SHARE_EXT_DATA', () => {
|
|
const shareExtension = { images: [], meta: { loading: true, error: '' } };
|
|
const expectedState = { ...initialState, ...shareExtension };
|
|
expect(shareExtReducer(initialState, { type: GET_SHARE_EXT_DATA, payload: { props1: '', props2: [] } }))
|
|
.toEqual(expectedState);
|
|
});
|
|
|
|
test('CASE 6: should return share extension on GET_SHARE_EXT_DATA_SUCCESS', () => {
|
|
const images = [
|
|
{
|
|
meta: { loading: false, error: '' },
|
|
fullFilePath: '/data/user/0/com.creedon.Nixplay.qa/cache/IMG_8246.JPG',
|
|
uri: 'file:///data/user/0/com.creedon.Nixplay.qa/cache/IMG_8246.JPG',
|
|
type: 'jpg',
|
|
fileSize: '27209639',
|
|
caption: '',
|
|
mime: 'jpg',
|
|
fileName: 'IMG_8246.JPG',
|
|
id: 'id1',
|
|
},
|
|
{
|
|
meta: { loading: false, error: '' },
|
|
fullFilePath: '/data/user/0/com.creedon.Nixplay.qa/cache/IMG_8244.JPG',
|
|
uri: 'file:///data/user/0/com.creedon.Nixplay.qa/cache/IMG_8244.JPG',
|
|
type: 'jpg',
|
|
fileSize: '54096296',
|
|
caption: '',
|
|
mime: 'jpg',
|
|
fileName: 'IMG_8244.JPG',
|
|
id: 'id2',
|
|
}];
|
|
const shareExtension = { images, meta: { loading: false, error: '' } };
|
|
const expectedState = { ...initialState, ...shareExtension };
|
|
expect(shareExtReducer(initialState, { type: GET_SHARE_EXT_DATA_SUCCESS, payload: { images } }))
|
|
.toEqual(expectedState);
|
|
});
|
|
|
|
test('CASE 7: should return share extension on GET_SHARE_EXT_DATA_ERROR', () => {
|
|
const shareExtension = { images: [], meta: { loading: false, error: 'error' } };
|
|
const expectedState = { ...initialState, ...shareExtension };
|
|
expect(shareExtReducer(initialState, { type: GET_SHARE_EXT_DATA_ERROR, payload: { error: 'error' } }))
|
|
.toEqual(expectedState);
|
|
});
|
|
|
|
test('CASE 8: should return update caption share extension on GET_SHARE_EXT_DATA_SUCCESS SET_SHARE_EXT', () => {
|
|
const images = [
|
|
{
|
|
meta: { loading: false, error: '' },
|
|
fullFilePath: '/data/user/0/com.creedon.Nixplay.qa/cache/IMG_8246.JPG',
|
|
uri: 'file:///data/user/0/com.creedon.Nixplay.qa/cache/IMG_8246.JPG',
|
|
type: 'jpg',
|
|
fileSize: '27209639',
|
|
caption: '',
|
|
mime: 'jpg',
|
|
fileName: 'IMG_8246.JPG',
|
|
id: 'id1',
|
|
},
|
|
{
|
|
meta: { loading: false, error: '' },
|
|
fullFilePath: '/data/user/0/com.creedon.Nixplay.qa/cache/IMG_8244.JPG',
|
|
uri: 'file:///data/user/0/com.creedon.Nixplay.qa/cache/IMG_8244.JPG',
|
|
type: 'jpg',
|
|
fileSize: '54096296',
|
|
caption: '',
|
|
mime: 'jpg',
|
|
fileName: 'IMG_8244.JPG',
|
|
id: 'id2',
|
|
}];
|
|
const shareExtension = { images, meta: { loading: false, error: '' } };
|
|
const expectedState = { ...initialState, ...shareExtension };
|
|
expect(shareExtReducer(initialState, { type: GET_SHARE_EXT_DATA_SUCCESS, payload: { images } }))
|
|
.toEqual(expectedState);
|
|
|
|
|
|
const images2 = [
|
|
{
|
|
meta: { loading: false, error: '' },
|
|
fullFilePath: '/data/user/0/com.creedon.Nixplay.qa/cache/IMG_8246.JPG',
|
|
uri: 'file:///data/user/0/com.creedon.Nixplay.qa/cache/IMG_8246.JPG',
|
|
type: 'jpg',
|
|
fileSize: '27209639',
|
|
caption: 'caption1',
|
|
mime: 'jpg',
|
|
fileName: 'IMG_8246.JPG',
|
|
id: 'id1',
|
|
},
|
|
{
|
|
meta: { loading: false, error: '' },
|
|
fullFilePath: '/data/user/0/com.creedon.Nixplay.qa/cache/IMG_8244.JPG',
|
|
uri: 'file:///data/user/0/com.creedon.Nixplay.qa/cache/IMG_8244.JPG',
|
|
type: 'jpg',
|
|
fileSize: '54096296',
|
|
caption: 'caption2',
|
|
mime: 'jpg',
|
|
fileName: 'IMG_8244.JPG',
|
|
id: 'id2',
|
|
}];
|
|
const expectedState2 = { ...initialState, ...shareExtension, images: images2 };
|
|
expect(shareExtReducer(initialState, { type: SET_SHARE_EXT, payload: { images: images2 } }))
|
|
.toEqual(expectedState2);
|
|
});
|
|
});
|