completion
This commit is contained in:
121
ioneapps-maagapp-ee31119a522d/__tests__/reducers/photoPrint.js
Normal file
121
ioneapps-maagapp-ee31119a522d/__tests__/reducers/photoPrint.js
Normal file
@@ -0,0 +1,121 @@
|
||||
/* global describe: true, test:true, expect:true */
|
||||
import { photoPrint as photoPrintReducer, initialState } from '~/reducers/photoPrint';
|
||||
import {
|
||||
PLACE_PHOTO_PRINT_ORDER,
|
||||
PLACE_PHOTO_PRINT_ORDER_SUCCESS,
|
||||
PLACE_PHOTO_PRINT_ORDER_ERROR,
|
||||
SET_PHOTOS_TO_QUEUE,
|
||||
SET_PHOTOS_TO_QUEUE_SUCCESS,
|
||||
SET_PHOTOS_TO_QUEUE_ERROR,
|
||||
REMOVE_PHOTO_FROM_QUEUE,
|
||||
REMOVE_PHOTO_FROM_QUEUE_SUCCESS,
|
||||
REMOVE_PHOTO_FROM_QUEUE_ERROR,
|
||||
} from '~/store/actionTypes';
|
||||
|
||||
describe('photoPrint reducer', () => {
|
||||
test('CASE 1: should return initial state', () => {
|
||||
expect(photoPrintReducer(undefined, { type: 'Default' }))
|
||||
.toEqual(initialState);
|
||||
});
|
||||
test('CASE 2: should return state with loading when type is PLACE_PHOTO_PRINT_ORDER, SET_PHOTOS_TO_QUEUE or REMOVE_PHOTO_FROM_QUEUE', () => {
|
||||
const expectedState = { ...initialState, meta: { ...initialState.meta, loading: true } };
|
||||
expect(photoPrintReducer(initialState, { type: PLACE_PHOTO_PRINT_ORDER })).toEqual(expectedState);
|
||||
expect(photoPrintReducer(initialState, { type: SET_PHOTOS_TO_QUEUE })).toEqual(expectedState);
|
||||
expect(photoPrintReducer(initialState, { type: REMOVE_PHOTO_FROM_QUEUE })).toEqual(expectedState);
|
||||
});
|
||||
|
||||
test('CASE 4: should return correct state when type is PLACE_PHOTO_PRINT_ORDER_SUCCESS', () => {
|
||||
const expectedState = { ...initialState, meta: { ...initialState.meta, loading: false }, orderNumbers: ['1234567'] };
|
||||
expect(photoPrintReducer(
|
||||
initialState,
|
||||
{
|
||||
type: PLACE_PHOTO_PRINT_ORDER_SUCCESS,
|
||||
payload: {
|
||||
orderNumber: '1234567',
|
||||
},
|
||||
},
|
||||
)).toEqual(expectedState);
|
||||
});
|
||||
|
||||
test('CASE 5: should return correct state when type is REMOVE_PHOTO_FROM_QUEUE_SUCCESS', () => {
|
||||
const images = ['image1', 'image2', 'image3'];
|
||||
const expectedState = {
|
||||
...initialState,
|
||||
images,
|
||||
count: 3,
|
||||
meta: {
|
||||
...initialState.meta,
|
||||
loading: false,
|
||||
},
|
||||
};
|
||||
expect(photoPrintReducer(
|
||||
initialState,
|
||||
{
|
||||
type: REMOVE_PHOTO_FROM_QUEUE_SUCCESS,
|
||||
payload: {
|
||||
images,
|
||||
},
|
||||
},
|
||||
)).toEqual(expectedState);
|
||||
});
|
||||
|
||||
test('CASE 6: should return correct state when type is SET_PHOTOS_TO_QUEUE_SUCCESS', () => {
|
||||
const images = ['image1', 'image2', 'image3'];
|
||||
const expectedState = {
|
||||
...initialState,
|
||||
images,
|
||||
count:
|
||||
3,
|
||||
meta:
|
||||
{
|
||||
...initialState.meta,
|
||||
loading:
|
||||
false,
|
||||
},
|
||||
};
|
||||
expect(photoPrintReducer(
|
||||
initialState,
|
||||
{
|
||||
type: SET_PHOTOS_TO_QUEUE_SUCCESS,
|
||||
payload: {
|
||||
images,
|
||||
},
|
||||
},
|
||||
)).toEqual(expectedState);
|
||||
});
|
||||
|
||||
|
||||
test('CASE 7: should return error state when type is PLACE_PHOTO_PRINT_ORDER_ERROR', () => {
|
||||
const error = new Error('Error');
|
||||
const expectedState = { ...initialState, meta: { ...initialState.meta, loading: false, error } };
|
||||
expect(photoPrintReducer(
|
||||
initialState,
|
||||
{
|
||||
type: PLACE_PHOTO_PRINT_ORDER_ERROR,
|
||||
payload: { error },
|
||||
},
|
||||
)).toEqual(expectedState);
|
||||
});
|
||||
test('CASE 8: should return error state when type is SET_PHOTOS_TO_QUEUE_ERROR', () => {
|
||||
const error = new Error('Error');
|
||||
const expectedState = { ...initialState, meta: { ...initialState.meta, loading: false, error } };
|
||||
expect(photoPrintReducer(
|
||||
initialState,
|
||||
{
|
||||
type: SET_PHOTOS_TO_QUEUE_ERROR,
|
||||
payload: { error },
|
||||
},
|
||||
)).toEqual(expectedState);
|
||||
});
|
||||
test('CASE 9: should return error state when type is REMOVE_PHOTO_FROM_QUEUE_ERROR', () => {
|
||||
const error = new Error('Error');
|
||||
const expectedState = { ...initialState, meta: { ...initialState.meta, loading: false, error } };
|
||||
expect(photoPrintReducer(
|
||||
initialState,
|
||||
{
|
||||
type: REMOVE_PHOTO_FROM_QUEUE_ERROR,
|
||||
payload: { error },
|
||||
},
|
||||
)).toEqual(expectedState);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user