Skip to content

Commit

Permalink
Display page level error and disable checkout button when no availabl…
Browse files Browse the repository at this point in the history
…e payment methods (#2873)

* Added payment method query to checkoutPageFragments.gql.js to fetch all available payment methods while fetching cart data on checkout page

* Added page level error message when no payment method implementations available for available methods

* Adding checkout page test update

* Adding useCheckoutPage talon test

* executed prettier on checkoutPage.spec.js

* executed prettier on useCheckoutPage.spec.js

* Updated unit test

* Corrected test snap to pass the unit test

* Converted "CheckoutPageOperations" to peregrine. Also moved other connected queries to peregrine.

* Fixed useCheckoutPage.spec.js to make it compatible with migrated "CheckoutPageOperations" in useCheckoutPage.js peregrine component

* Prettier-ed useCheckoutPage.spec.js

* Fixed issue with gql client after migration of CheckoutPageOperations to peregrine.

* Fixed issue with gql client after migration of CheckoutPageOperations to peregrine.

* Sorted the new lang definitions while adding

* Used the ternary operator instead of the logical operators

* Changed variable "props" to "defaultProps"

* Removed empty object usage as it was not required anymore.

* Corrected lint error related to array reassignment due to let declaration

* Update packages/peregrine/lib/talons/CheckoutPage/useCheckoutPage.js

Co-authored-by: Stephen <sirugh@users.noreply.github.com>

* Re-add lost query

* Add missing mock in test

Signed-off-by: sirugh <rugh@adobe.com>

* Prettified

* exporting default operations as root properties

* Remove styles

Signed-off-by: sirugh <rugh@adobe.com>

* fix operations mock in tests

Signed-off-by: sirugh <rugh@adobe.com>

* Fix zero total checkout use case. Add tests

* Fixed layout issue with multiple page errors on checkoutPage.

* Updated test snapshots

* Updated test cases snapshots

Co-authored-by: Stephen <sirugh@users.noreply.github.com>
Co-authored-by: sirugh <rugh@adobe.com>
Co-authored-by: Devagouda <40405790+dpatil-magento@users.noreply.github.com>
  • Loading branch information
4 people authored Feb 26, 2021
1 parent 05bb83f commit ec4e97d
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { gql } from '@apollo/client';

import { ItemsReviewFragment } from './itemsReviewFragments.gql';

export const GET_CONFIGURABLE_THUMBNAIL_SOURCE = gql`
query getConfigurableThumbnailSource {
storeConfig {
Expand All @@ -9,6 +11,18 @@ export const GET_CONFIGURABLE_THUMBNAIL_SOURCE = gql`
}
`;

export const LIST_OF_PRODUCTS_IN_CART_QUERY = gql`
query getItemsInCart($cartId: String!) {
cart(cart_id: $cartId) {
id
...ItemsReviewFragment
}
}
${ItemsReviewFragment}
`;

export default {
getConfigurableThumbnailSource: GET_CONFIGURABLE_THUMBNAIL_SOURCE
getConfigurableThumbnailSource: GET_CONFIGURABLE_THUMBNAIL_SOURCE,
getItemsInCart: LIST_OF_PRODUCTS_IN_CART_QUERY
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jest.mock('../../../../context/cart', () => ({

jest.mock('@apollo/client', () => {
return {
...jest.requireActual('@apollo/client'),
useApolloClient: jest.fn(),
useQuery: jest.fn().mockReturnValue({
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`Should return correct shape 1`] = `
Object {
"activeContent": "checkout",
"availablePaymentMethods": null,
"cartItems": Array [],
"checkoutStep": 1,
"customer": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import CheckoutError from '../CheckoutError';

jest.mock('@apollo/client', () => {
return {
...jest.requireActual('@apollo/client'),
useLazyQuery: jest.fn(),
useApolloClient: jest.fn(),
useMutation: jest.fn(),
Expand Down Expand Up @@ -64,9 +65,14 @@ const getCheckoutDetailsQuery = 'getCheckoutDetailsQuery';
const getOrderDetailsQuery = 'getOrderDetailsQuery';
const getCustomerQuery = 'getCustomerQuery';

const props = {
mutations: { createCartMutation, placeOrderMutation },
queries: { getCheckoutDetailsQuery, getOrderDetailsQuery, getCustomerQuery }
const defaultProps = {
operations: {
createCartMutation,
getCheckoutDetailsQuery,
getOrderDetailsQuery,
getCustomerQuery,
placeOrderMutation
}
};

const readQuery = jest.fn().mockReturnValue({ cart: {} });
Expand Down Expand Up @@ -182,7 +188,7 @@ beforeEach(() => {
*/

test('Should return correct shape', () => {
const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps).toMatchSnapshot();
});
Expand All @@ -193,7 +199,7 @@ test('isLoading should be set to true if the checkout details query networkStatu
networkStatus: 4
});

const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

expect(talonProps.isLoading).toBeTruthy();

Expand Down Expand Up @@ -221,7 +227,7 @@ test('isLoading should be set to true if the customer details query is loading',
loading: true
});

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.isLoading).toBeTruthy();
});
Expand All @@ -231,7 +237,7 @@ test('returns cartItems from getOrderDetails query', () => {
getCheckoutDetailsQueryResult.mockReturnValueOnce({
data: { cart: { items: cartItems } }
});
const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.cartItems).toEqual(cartItems);
});
Expand All @@ -247,7 +253,7 @@ test('returned error prop should be error from place order mutation', () => {
}
]);

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.error).toBeInstanceOf(CheckoutError);
});
Expand All @@ -258,7 +264,7 @@ test('should get order details when handlePlaceOrder called', () => {
{ createCart: () => {}, removeCart: () => {} }
]);

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

act(() => {
talonProps.handlePlaceOrder();
Expand All @@ -284,7 +290,7 @@ test("should place order and cleanup when we have order details and place order
return [jest.fn(), { data: {}, loading: false }];
});

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

await act(async () => {
await talonProps.handlePlaceOrder();
Expand All @@ -308,7 +314,7 @@ test('hasError should be true if place order mutation failed with errors', () =>
}
]);

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.hasError).toBeTruthy();
});
Expand All @@ -321,7 +327,7 @@ describe('isCartEmpty', () => {
loading: false
});

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.isCartEmpty).toBeTruthy();
});
Expand All @@ -337,7 +343,7 @@ describe('isCartEmpty', () => {
loading: false
});

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.isCartEmpty).toBeTruthy();
});
Expand All @@ -353,7 +359,7 @@ describe('isCartEmpty', () => {
loading: false
});

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.isCartEmpty).toBeFalsy();
});
Expand All @@ -362,7 +368,7 @@ describe('isCartEmpty', () => {
test('isGuestCheckout should be negation of isSignedIn from useUserContext', () => {
useUserContext.mockReturnValueOnce([{ isSignedIn: false }]);

const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

expect(talonProps.isGuestCheckout).toBeTruthy();

Expand All @@ -384,7 +390,7 @@ test('orderDetailsData should be data from getOrderDetailsQuery', () => {
}
]);

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.orderDetailsData).toBe(data);
});
Expand All @@ -399,7 +405,7 @@ test('orderDetailsLoading should be loading status of the getOrderDetailsQuery',
}
]);

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.orderDetailsLoading).toBeTruthy();
});
Expand All @@ -420,7 +426,7 @@ test('orderNumber should be the order_number from the place order mutation resul
}
]);

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.orderNumber).toBe('123');
});
Expand All @@ -435,7 +441,7 @@ test('orderNumber should be the null if place order mutation result is falsy', (
}
]);

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.orderNumber).toBeNull();
});
Expand All @@ -450,14 +456,14 @@ test('placeOrderLoading should be loading status of the place order mutation', (
}
]);

const { talonProps } = getTalonProps(props);
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.placeOrderLoading).toBeTruthy();
});

describe('setShippingInformationDone', () => {
test('should set the checkoutStep to SHIPPING_METHOD if current checkoutStep is SHIPPING_ADDRESS', () => {
const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

talonProps.setCheckoutStep(CHECKOUT_STEP.SHIPPING_ADDRESS);

Expand All @@ -473,7 +479,7 @@ describe('setShippingInformationDone', () => {
});

test('should not set the checkoutStep to SHIPPING_METHOD if current checkoutStep is not SHIPPING_ADDRESS', () => {
const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

talonProps.setCheckoutStep(CHECKOUT_STEP.PAYMENT);

Expand All @@ -491,7 +497,7 @@ describe('setShippingInformationDone', () => {

describe('setShippingMethodDone', () => {
test('should set the checkoutStep to PAYMENT if current checkoutStep is SHIPPING_METHOD', () => {
const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

talonProps.setCheckoutStep(CHECKOUT_STEP.SHIPPING_METHOD);

Expand All @@ -507,7 +513,7 @@ describe('setShippingMethodDone', () => {
});

test('should not set the checkoutStep to PAYMENT if current checkoutStep is not SHIPPING_METHOD', () => {
const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

talonProps.setCheckoutStep(CHECKOUT_STEP.REVIEW);

Expand All @@ -525,7 +531,7 @@ describe('setShippingMethodDone', () => {

describe('setPaymentInformationDone', () => {
test('should set the checkoutStep to REVIEW if current checkoutStep is PAYMENT', () => {
const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

talonProps.setCheckoutStep(CHECKOUT_STEP.PAYMENT);

Expand All @@ -541,7 +547,7 @@ describe('setPaymentInformationDone', () => {
});

test('should not set the checkoutStep to REVIEW if current checkoutStep is not PAYMENT', () => {
const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

talonProps.setCheckoutStep(CHECKOUT_STEP.SHIPPING_METHOD);

Expand All @@ -558,7 +564,7 @@ describe('setPaymentInformationDone', () => {
});

test('handleReviewOrder should set reviewOrderButtonClicked to true', () => {
const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

expect(talonProps.reviewOrderButtonClicked).toBeFalsy();

Expand All @@ -570,7 +576,7 @@ test('handleReviewOrder should set reviewOrderButtonClicked to true', () => {
});

test('resetReviewOrderButtonClicked should set reviewOrderButtonClicked to false', () => {
const { talonProps, update } = getTalonProps(props);
const { talonProps, update } = getTalonProps(defaultProps);

expect(talonProps.reviewOrderButtonClicked).toBeFalsy();

Expand All @@ -588,7 +594,7 @@ test('resetReviewOrderButtonClicked should set reviewOrderButtonClicked to false
});

test('toggles addressBook content', () => {
const { talonProps: initialProps, update } = getTalonProps(props);
const { talonProps: initialProps, update } = getTalonProps(defaultProps);

initialProps.toggleAddressBookContent();
const step1Props = update();
Expand All @@ -602,7 +608,7 @@ test('toggles addressBook content', () => {
});

test('toggles signIn content', () => {
const { talonProps: initialProps, update } = getTalonProps(props);
const { talonProps: initialProps, update } = getTalonProps(defaultProps);

initialProps.toggleSignInContent();
const step1Props = update();
Expand All @@ -616,7 +622,7 @@ test('toggles signIn content', () => {
});

test('resets active content to checkout on sign in', () => {
const { talonProps: initialProps, update } = getTalonProps(props);
const { talonProps: initialProps, update } = getTalonProps(defaultProps);

initialProps.toggleSignInContent();
const step1Props = update();
Expand All @@ -628,3 +634,9 @@ test('resets active content to checkout on sign in', () => {

expect(step2Props.activeContent).toBe('checkout');
});

test('check availablePaymentMethods, if not implemented then show page level message', () => {
const { talonProps } = getTalonProps(defaultProps);

expect(talonProps.availablePaymentMethods).toBeNull();
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,9 @@ export const GET_CUSTOMER = gql`
`;

export default {
mutations: {
createCartMutation: CREATE_CART,
placeOrderMutation: PLACE_ORDER
},
queries: {
getCheckoutDetailsQuery: GET_CHECKOUT_DETAILS,
getCustomerQuery: GET_CUSTOMER,
getOrderDetailsQuery: GET_ORDER_DETAILS
}
createCartMutation: CREATE_CART,
getCheckoutDetailsQuery: GET_CHECKOUT_DETAILS,
getCustomerQuery: GET_CUSTOMER,
getOrderDetailsQuery: GET_ORDER_DETAILS,
placeOrderMutation: PLACE_ORDER
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ export const CheckoutPageFragment = gql`
}
# If total quantity is falsy we render empty.
total_quantity
available_payment_methods {
code
}
}
`;
Loading

0 comments on commit ec4e97d

Please sign in to comment.