Decode fees name so special characters are rendered correctly (https://github.com/woocommerce/woocommerce-blocks/pull/3721)
* Decode fees name so special characters are rendered correctly * Decode fees at hook level * Fix several tests * Remove unnecessary check
This commit is contained in:
parent
65d98cef7d
commit
6ec197007f
|
@ -130,7 +130,7 @@ describe( 'Testing Payment Method Data Context Provider', () => {
|
||||||
} );
|
} );
|
||||||
// need to clear the store resolution state between tests.
|
// need to clear the store resolution state between tests.
|
||||||
await dispatch( storeKey ).invalidateResolutionForStore();
|
await dispatch( storeKey ).invalidateResolutionForStore();
|
||||||
await dispatch( storeKey ).receiveCart( defaultCartState );
|
await dispatch( storeKey ).receiveCart( defaultCartState.cartData );
|
||||||
} );
|
} );
|
||||||
afterEach( async () => {
|
afterEach( async () => {
|
||||||
resetMockPaymentMethods();
|
resetMockPaymentMethods();
|
||||||
|
|
|
@ -29,6 +29,7 @@ describe( 'useStoreCart', () => {
|
||||||
const previewCartData = {
|
const previewCartData = {
|
||||||
cartCoupons: previewCart.coupons,
|
cartCoupons: previewCart.coupons,
|
||||||
cartItems: previewCart.items,
|
cartItems: previewCart.items,
|
||||||
|
cartFees: previewCart.fees,
|
||||||
cartItemsCount: previewCart.items_count,
|
cartItemsCount: previewCart.items_count,
|
||||||
cartItemsWeight: previewCart.items_weight,
|
cartItemsWeight: previewCart.items_weight,
|
||||||
cartNeedsPayment: previewCart.needs_payment,
|
cartNeedsPayment: previewCart.needs_payment,
|
||||||
|
@ -37,7 +38,6 @@ describe( 'useStoreCart', () => {
|
||||||
cartIsLoading: false,
|
cartIsLoading: false,
|
||||||
cartItemErrors: [],
|
cartItemErrors: [],
|
||||||
cartErrors: [],
|
cartErrors: [],
|
||||||
cartFees: [],
|
|
||||||
billingAddress: {
|
billingAddress: {
|
||||||
first_name: '',
|
first_name: '',
|
||||||
last_name: '',
|
last_name: '',
|
||||||
|
@ -75,6 +75,7 @@ describe( 'useStoreCart', () => {
|
||||||
const mockCartData = {
|
const mockCartData = {
|
||||||
coupons: [],
|
coupons: [],
|
||||||
items: mockCartItems,
|
items: mockCartItems,
|
||||||
|
fees: [],
|
||||||
itemsCount: 1,
|
itemsCount: 1,
|
||||||
itemsWeight: 10,
|
itemsWeight: 10,
|
||||||
needsPayment: true,
|
needsPayment: true,
|
||||||
|
@ -83,6 +84,8 @@ describe( 'useStoreCart', () => {
|
||||||
shippingAddress: mockShippingAddress,
|
shippingAddress: mockShippingAddress,
|
||||||
shippingRates: [],
|
shippingRates: [],
|
||||||
hasCalculatedShipping: true,
|
hasCalculatedShipping: true,
|
||||||
|
extensions: {},
|
||||||
|
errors: [],
|
||||||
};
|
};
|
||||||
const mockCartTotals = {
|
const mockCartTotals = {
|
||||||
currency_code: 'USD',
|
currency_code: 'USD',
|
||||||
|
|
|
@ -27,8 +27,8 @@ const defaultBillingAddress = {
|
||||||
phone: '',
|
phone: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const decodeAddress = ( address ) =>
|
const decodeValues = ( object ) =>
|
||||||
mapValues( address, ( value ) => decodeEntities( value ) );
|
mapValues( object, ( value ) => decodeEntities( value ) );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
|
@ -53,6 +53,7 @@ export const defaultCartData = {
|
||||||
cartHasCalculatedShipping: false,
|
cartHasCalculatedShipping: false,
|
||||||
paymentRequirements: [],
|
paymentRequirements: [],
|
||||||
receiveCart: () => {},
|
receiveCart: () => {},
|
||||||
|
extensions: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,14 +116,17 @@ export const useStoreCart = ( options = { shouldSelect: true } ) => {
|
||||||
);
|
);
|
||||||
const shippingRatesLoading = store.isCustomerDataUpdating();
|
const shippingRatesLoading = store.isCustomerDataUpdating();
|
||||||
const { receiveCart } = dispatch( storeKey );
|
const { receiveCart } = dispatch( storeKey );
|
||||||
const billingAddress = decodeAddress( cartData.billingAddress );
|
const billingAddress = decodeValues( cartData.billingAddress );
|
||||||
const shippingAddress = cartData.needsShipping
|
const shippingAddress = cartData.needsShipping
|
||||||
? decodeAddress( cartData.shippingAddress )
|
? decodeValues( cartData.shippingAddress )
|
||||||
: billingAddress;
|
: billingAddress;
|
||||||
|
const cartFees = cartData.fees.map( ( fee ) =>
|
||||||
|
decodeValues( fee )
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
cartCoupons: cartData.coupons,
|
cartCoupons: cartData.coupons,
|
||||||
cartItems: cartData.items || [],
|
cartItems: cartData.items || [],
|
||||||
cartFees: cartData.fees || [],
|
cartFees,
|
||||||
cartItemsCount: cartData.itemsCount,
|
cartItemsCount: cartData.itemsCount,
|
||||||
cartItemsWeight: cartData.itemsWeight,
|
cartItemsWeight: cartData.itemsWeight,
|
||||||
cartNeedsPayment: cartData.needsPayment,
|
cartNeedsPayment: cartData.needsPayment,
|
||||||
|
|
|
@ -20,7 +20,7 @@ describe( 'Testing cart', () => {
|
||||||
} );
|
} );
|
||||||
// need to clear the store resolution state between tests.
|
// need to clear the store resolution state between tests.
|
||||||
await dispatch( storeKey ).invalidateResolutionForStore();
|
await dispatch( storeKey ).invalidateResolutionForStore();
|
||||||
await dispatch( storeKey ).receiveCart( defaultCartState );
|
await dispatch( storeKey ).receiveCart( defaultCartState.cartData );
|
||||||
} );
|
} );
|
||||||
afterEach( () => {
|
afterEach( () => {
|
||||||
fetchMock.resetMocks();
|
fetchMock.resetMocks();
|
||||||
|
@ -44,7 +44,9 @@ describe( 'Testing cart', () => {
|
||||||
it( 'renders empty cart if there are no items in the cart', async () => {
|
it( 'renders empty cart if there are no items in the cart', async () => {
|
||||||
fetchMock.mockResponse( ( req ) => {
|
fetchMock.mockResponse( ( req ) => {
|
||||||
if ( req.url.match( /wc\/store\/cart/ ) ) {
|
if ( req.url.match( /wc\/store\/cart/ ) ) {
|
||||||
return Promise.resolve( JSON.stringify( defaultCartState ) );
|
return Promise.resolve(
|
||||||
|
JSON.stringify( defaultCartState.cartData )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
render(
|
render(
|
||||||
|
|
|
@ -14,6 +14,7 @@ describe( 'cartReducer', () => {
|
||||||
cartData: {
|
cartData: {
|
||||||
coupons: [],
|
coupons: [],
|
||||||
items: [],
|
items: [],
|
||||||
|
fees: [],
|
||||||
itemsCount: 0,
|
itemsCount: 0,
|
||||||
itemsWeight: 0,
|
itemsWeight: 0,
|
||||||
needsShipping: true,
|
needsShipping: true,
|
||||||
|
@ -34,6 +35,7 @@ describe( 'cartReducer', () => {
|
||||||
response: {
|
response: {
|
||||||
coupons: [],
|
coupons: [],
|
||||||
items: [],
|
items: [],
|
||||||
|
fees: [],
|
||||||
itemsCount: 0,
|
itemsCount: 0,
|
||||||
itemsWeight: 0,
|
itemsWeight: 0,
|
||||||
needsShipping: true,
|
needsShipping: true,
|
||||||
|
@ -45,6 +47,7 @@ describe( 'cartReducer', () => {
|
||||||
expect( newState.cartData ).toEqual( {
|
expect( newState.cartData ).toEqual( {
|
||||||
coupons: [],
|
coupons: [],
|
||||||
items: [],
|
items: [],
|
||||||
|
fees: [],
|
||||||
itemsCount: 0,
|
itemsCount: 0,
|
||||||
itemsWeight: 0,
|
itemsWeight: 0,
|
||||||
needsShipping: true,
|
needsShipping: true,
|
||||||
|
|
|
@ -20,6 +20,7 @@ describe( 'getCartData', () => {
|
||||||
const { value } = fulfillment.next( {
|
const { value } = fulfillment.next( {
|
||||||
coupons: [],
|
coupons: [],
|
||||||
items: [],
|
items: [],
|
||||||
|
fees: [],
|
||||||
itemsCount: 0,
|
itemsCount: 0,
|
||||||
itemsWeight: 0,
|
itemsWeight: 0,
|
||||||
needsShipping: true,
|
needsShipping: true,
|
||||||
|
@ -29,6 +30,7 @@ describe( 'getCartData', () => {
|
||||||
receiveCart( {
|
receiveCart( {
|
||||||
coupons: [],
|
coupons: [],
|
||||||
items: [],
|
items: [],
|
||||||
|
fees: [],
|
||||||
itemsCount: 0,
|
itemsCount: 0,
|
||||||
itemsWeight: 0,
|
itemsWeight: 0,
|
||||||
needsShipping: true,
|
needsShipping: true,
|
||||||
|
|
|
@ -16,6 +16,7 @@ export const defaultCartState = {
|
||||||
country: '',
|
country: '',
|
||||||
},
|
},
|
||||||
items: [],
|
items: [],
|
||||||
|
fees: [],
|
||||||
itemsCount: 0,
|
itemsCount: 0,
|
||||||
itemsWeight: 0,
|
itemsWeight: 0,
|
||||||
needsShipping: true,
|
needsShipping: true,
|
||||||
|
|
Loading…
Reference in New Issue