Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
primogenial
/
wp-content-20241001222009
/
plugins
/
woocommerce
/
packages
/
woocommerce-blocks
/
assets
/
js
/
data
/
cart
/
test
:
reducers.js
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
/** * External dependencies */ import deepFreeze from 'deep-freeze'; /** * Internal dependencies */ import cartReducer from '../reducers'; import { ACTION_TYPES as types } from '../action-types'; describe( 'cartReducer', () => { const originalState = deepFreeze( { cartData: { coupons: [], items: [], fees: [], itemsCount: 0, itemsWeight: 0, needsShipping: true, totals: {}, }, metaData: {}, errors: [ { code: '100', message: 'Test Error', data: {}, }, ], } ); it( 'sets expected state when a cart is received', () => { const testAction = { type: types.RECEIVE_CART, response: { coupons: [], items: [], fees: [], itemsCount: 0, itemsWeight: 0, needsShipping: true, totals: {}, }, }; const newState = cartReducer( originalState, testAction ); expect( newState ).not.toBe( originalState ); expect( newState.cartData ).toEqual( { coupons: [], items: [], fees: [], itemsCount: 0, itemsWeight: 0, needsShipping: true, totals: {}, } ); } ); it( 'sets expected state when errors are replaced', () => { const testAction = { type: types.REPLACE_ERRORS, error: { code: '101', message: 'Test Error', data: {}, }, }; const newState = cartReducer( originalState, testAction ); expect( newState ).not.toBe( originalState ); expect( newState.errors ).toEqual( [ { code: '101', message: 'Test Error', data: {}, }, ] ); } ); it( 'sets expected state when an error is added', () => { const testAction = { type: types.RECEIVE_ERROR, error: { code: '101', message: 'Test Error', data: {}, }, }; const newState = cartReducer( originalState, testAction ); expect( newState ).not.toBe( originalState ); expect( newState.errors ).toEqual( [ { code: '100', message: 'Test Error', data: {}, }, { code: '101', message: 'Test Error', data: {}, }, ] ); } ); it( 'sets expected state when a coupon is applied', () => { const testAction = { type: types.APPLYING_COUPON, couponCode: 'APPLYME', }; const newState = cartReducer( originalState, testAction ); expect( newState ).not.toBe( originalState ); expect( newState.metaData.applyingCoupon ).toEqual( 'APPLYME' ); } ); it( 'sets expected state when a coupon is removed', () => { const testAction = { type: types.REMOVING_COUPON, couponCode: 'REMOVEME', }; const newState = cartReducer( originalState, testAction ); expect( newState ).not.toBe( originalState ); expect( newState.metaData.removingCoupon ).toEqual( 'REMOVEME' ); } ); } );