Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Display page level error and disable checkout button when no available payment methods #2873

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c07e650
Merge pull request #1 from magento/develop
ankurvr Nov 24, 2020
9b237db
Added payment method query to checkoutPageFragments.gql.js to fetch a…
ankurvr Nov 24, 2020
fb2d1d9
Added page level error message when no payment method implementations…
ankurvr Nov 24, 2020
e1c385d
Adding checkout page test update
ankurvr Nov 25, 2020
e8ff5af
Adding useCheckoutPage talon test
ankurvr Nov 25, 2020
6aff5b5
executed prettier on checkoutPage.spec.js
ankurvr Nov 25, 2020
aefa7a8
executed prettier on useCheckoutPage.spec.js
ankurvr Nov 25, 2020
b21de33
Merge pull request #2 from magento/develop
ankurvr Nov 26, 2020
5965e67
Merge pull request #3 from ankurvr/develop
ankurvr Nov 26, 2020
342e5e7
Updated unit test
ankurvr Nov 26, 2020
717ac9b
Corrected test snap to pass the unit test
ankurvr Nov 26, 2020
08be417
Converted "CheckoutPageOperations" to peregrine. Also moved other con…
ankurvr Nov 26, 2020
395e219
Fixed useCheckoutPage.spec.js to make it compatible with migrated "Ch…
ankurvr Nov 26, 2020
a251e7e
Prettier-ed useCheckoutPage.spec.js
ankurvr Nov 26, 2020
f05b171
Fixed issue with gql client after migration of CheckoutPageOperations…
ankurvr Nov 26, 2020
04cb94b
Fixed issue with gql client after migration of CheckoutPageOperations…
ankurvr Nov 26, 2020
90f943c
Merge pull request #4 from magento/develop
ankurvr Jan 21, 2021
d1cdb4f
Merge branch 'develop' into ankurvr-payment-method-page-error
ankurvr Jan 21, 2021
388c29c
Sorted the new lang definitions while adding
ankurvr Jan 21, 2021
39598f4
Used the ternary operator instead of the logical operators
ankurvr Jan 21, 2021
4c987b7
Changed variable "props" to "defaultProps"
ankurvr Jan 21, 2021
0661e00
Removed empty object usage as it was not required anymore.
ankurvr Jan 21, 2021
1f110eb
Corrected lint error related to array reassignment due to let declara…
ankurvr Jan 27, 2021
0e6f5a5
Merge pull request #6 from magento/develop
ankurvr Jan 27, 2021
00b3091
Merge branch 'develop' into ankurvr-payment-method-page-error
ankurvr Jan 27, 2021
ffeb001
Update packages/peregrine/lib/talons/CheckoutPage/useCheckoutPage.js
ankurvr Jan 27, 2021
111ef66
Re-add lost query
sirugh Jan 27, 2021
9e43e95
Add missing mock in test
sirugh Jan 27, 2021
7b49371
Prettified
ankurvr Jan 28, 2021
fb58229
Merge branch 'develop' into ankurvr-payment-method-page-error
ankurvr Jan 28, 2021
9473a70
Merge branch 'develop' into ankurvr-payment-method-page-error
ankurvr Jan 29, 2021
47d0d84
Merge branch 'develop' into ankurvr-payment-method-page-error
ankurvr Jan 30, 2021
f83d709
Merge branch 'develop' into ankurvr-payment-method-page-error
ankurvr Feb 5, 2021
ce0b03b
exporting default operations as root properties
sirugh Feb 8, 2021
21ab670
Remove styles
sirugh Feb 8, 2021
59f3741
fix operations mock in tests
sirugh Feb 10, 2021
d2688d6
Merge branch 'develop' into ankurvr-payment-method-page-error
ankurvr Feb 11, 2021
e752235
Merge branch 'develop' into ankurvr-payment-method-page-error
dpatil-magento Feb 17, 2021
6420448
Merge branch 'develop' into ankurvr-payment-method-page-error
sirugh Feb 23, 2021
b261791
Fix zero total checkout use case. Add tests
sirugh Feb 23, 2021
00821eb
Merge branch 'develop' into ankurvr-payment-method-page-error
ankurvr Feb 25, 2021
d744966
Merge branch 'develop' into ankurvr-payment-method-page-error
ankurvr Feb 26, 2021
b40cfd8
Fixed layout issue with multiple page errors on checkoutPage.
ankurvr Feb 26, 2021
bc79f6c
Updated test snapshots
ankurvr Feb 26, 2021
a09f4d8
Updated test cases snapshots
ankurvr Feb 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
ankurvr marked this conversation as resolved.
Show resolved Hide resolved
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