Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[feature]: refactor edit steps out of redux and into local checkout state #1338

Merged
merged 11 commits into from
Jul 29, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import actions from '../actions';
import {
beginCheckout,
editOrder,
formatAddress,
getShippingMethods,
resetCheckout,
Expand Down Expand Up @@ -114,26 +113,6 @@ describe('resetCheckout', () => {
});
});

describe('editOrder', () => {
test('editOrder() returns a thunk', () => {
expect(editOrder()).toBeInstanceOf(Function);
});

test('editOrder thunk returns undefined', async () => {
const result = await editOrder()(...thunkArgs);

expect(result).toBeUndefined();
});

test('editOrder thunk dispatches actions', async () => {
const payload = 'PAYLOAD';
await editOrder(payload)(...thunkArgs);

expect(dispatch).toHaveBeenCalledWith(actions.edit(payload));
expect(dispatch).toHaveBeenCalledTimes(1);
});
});

describe('getShippingMethods', () => {
test('getShippingMethods() returns a thunk', () => {
expect(getShippingMethods()).toBeInstanceOf(Function);
Expand Down
9 changes: 2 additions & 7 deletions packages/venia-concept/src/actions/checkout/asyncActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export const resetCheckout = () =>
dispatch(actions.reset());
};

export const editOrder = section =>
async function thunk(dispatch) {
dispatch(actions.edit(section));
};

export const getShippingMethods = () => {
return async function thunk(dispatch, getState) {
const { cart, user } = getState();
Expand Down Expand Up @@ -112,7 +107,7 @@ export const submitBillingAddress = payload =>
desiredBillingAddress = formatAddress(payload, countries);
} catch (error) {
dispatch(actions.billingAddress.reject(error));
return;
throw error;
}
}

Expand Down Expand Up @@ -156,7 +151,7 @@ export const submitShippingAddress = payload =>
invalidAddressMessage: error.message
})
);
return null;
throw error;
}

await saveShippingAddress(address);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders a Payment Form component if editing paymentMethod 1`] = `
<PaymentsForm
cancel={[Function]}
submit={[Function]}
/>
`;

exports[`renders an AddressForm component if editing address 1`] = `
<AddressForm
cancel={[Function]}
submit={[Function]}
/>
`;

exports[`renders an ShippingForm component if editing shippingMethod 1`] = `
<ShippingForm
cancel={[Function]}
submit={[Function]}
/>
`;

exports[`renders an null Editable Form component 1`] = `null`;

exports[`renders billing info CTA if no payment method is entered 1`] = `null`;

exports[`renders empty strings if payment data is not defined 1`] = `null`;

exports[`renders name and street if shipping address is entered 1`] = `null`;

exports[`renders payment method summary if payment method entered 1`] = `null`;

exports[`renders shipping address CTA if no shipping address is entered 1`] = `null`;

exports[`renders shipping method CTA if no shipping method selected 1`] = `null`;

exports[`renders shipping title if shipping method is selected 1`] = `null`;
Loading