woocommerce/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js

202 lines
5.2 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
import { act, render, screen, waitFor } from '@testing-library/react';
import { previewCart } from '@woocommerce/resource-previews';
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
import * as wpDataFunctions from '@wordpress/data';
import { CART_STORE_KEY, PAYMENT_STORE_KEY } from '@woocommerce/block-data';
import { default as fetchMock } from 'jest-fetch-mock';
import {
registerPaymentMethod,
__experimentalDeRegisterPaymentMethod,
} from '@woocommerce/blocks-registry';
import userEvent from '@testing-library/user-event';
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
import { dispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import PaymentMethods from '../payment-methods';
Feature: Data Store Migration - Payments (https://github.com/woocommerce/woocommerce-blocks/pull/6619) * Move paymentMethodDataProvider into a data store (https://github.com/woocommerce/woocommerce-blocks/pull/6208) * Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type * Add default state for PaymentMethod data store * Add preliminary action types * Add preliminary action dispatchers * Create payment method data store * Add preliminary reducers for payment method data store * Add preliminary selectors for payment method data store * Add reducers/actions for registering payment methods * Export payment method data store key * Add test for payment method data reducers * Add shouldSavePaymentMethod selector * Add store key as constant * Add more action types for registering and initializing payment methods * Get active payment method from data store instead of from context * Add registered methods to default state of payment method data store * Dispatch name of registered payment method to payment method data store * Remove setShouldSavePayment from payment method dispatcher and types * Get payment methods from registry instead of payment context * Add available payment methods to store * Add function to check whether payment methods are allowed to be used * Add selector to check if payments are initialised * Remove resolvers and add controls to payment method data store * Change type of payment requirements to string[] * Turn addRegistered and addRegisteredExpress into generators This is so we can check each payment method's validity before adding it to the list of available payment methods * Add action type for setting express payments as initialized * Only select from available methods in payment method options * Remove argument from addRegisteredPaymentMethod in payment method registry * Rename folder and store name to not contain the word data * Add selectors for express payment methods and their initialisation * Delete controls again in favour of thunks * Rename payment-method-data to payment-methdods * Create new setDefaultPaymentMethod function This will set the payment method when the cart loads. * Add CustomerPaymentMethodConfiguration type * Make getAvailableExpressPaymentMethods return correct data * Check express methods and normal methods when cart changes * Add action for setting active express payment methods * Handle express methods in checkPaymentMethodCanPay * Hide express payments area if none are available * Add selector for paymentMethodData * Add customer data to default state and add selector for it * Add setPaymentStatus action and reducer case * Set the default payment method when one isn't selected * Correct types on getCustomerPaymentMethods * Set status in data store alongside context status * Comment out active gateway selection - remove later * Set status in express payment methods in data store * Use correct key in payment method data context * Directly check payment methods from the list in blocks-registry * Add semicolon to import statement * Fix payment method data state call * Get paymentMethodData from store not context * Fix linting issues Co-authored-by: Saad Tarhi <saad.trh@gmail.com> Co-authored-by: Alex Florisca <alex.florisca@automattic.com> * Rebase on the update/checkout-data-store branch & Fix failed payments (https://github.com/woocommerce/woocommerce-blocks/pull/6587) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type * Add default state for PaymentMethod data store * Add preliminary action types * Add preliminary action dispatchers * Create payment method data store * Add preliminary reducers for payment method data store * Add preliminary selectors for payment method data store * Add reducers/actions for registering payment methods * Export payment method data store key * Add test for payment method data reducers * Add shouldSavePaymentMethod selector * Add store key as constant * Add more action types for registering and initializing payment methods * Get active payment method from data store instead of from context * Add registered methods to default state of payment method data store * Dispatch name of registered payment method to payment method data store * Remove setShouldSavePayment from payment method dispatcher and types * Get payment methods from registry instead of payment context * Add available payment methods to store * Add function to check whether payment methods are allowed to be used * Add selector to check if payments are initialised * Remove resolvers and add controls to payment method data store * Change type of payment requirements to string[] * Turn addRegistered and addRegisteredExpress into generators This is so we can check each payment method's validity before adding it to the list of available payment methods * Add action type for setting express payments as initialized * Only select from available methods in payment method options * Remove argument from addRegisteredPaymentMethod in payment method registry * Rename folder and store name to not contain the word data * Add selectors for express payment methods and their initialisation * Delete controls again in favour of thunks * Rename payment-method-data to payment-methdods * Create new setDefaultPaymentMethod function This will set the payment method when the cart loads. * Add CustomerPaymentMethodConfiguration type * Make getAvailableExpressPaymentMethods return correct data * Check express methods and normal methods when cart changes * Add action for setting active express payment methods * Handle express methods in checkPaymentMethodCanPay * Hide express payments area if none are available * Add selector for paymentMethodData * Add customer data to default state and add selector for it * Add setPaymentStatus action and reducer case * Set the default payment method when one isn't selected * Correct types on getCustomerPaymentMethods * Set status in data store alongside context status * Comment out active gateway selection - remove later * Set status in express payment methods in data store * Directly check payment methods from the list in blocks-registry * Add semicolon to import statement * Fix payment method data state call * Get paymentMethodData from store not context * Add addPaymentMethodData action/reducer case * Update payment method on payment success * Add 'getCurrentStatus' selector * Remove the temporary solution For getting payment method data into the data store * Prevent the 'success' context action from being dispatched * Update the "setPaymentStatus" data store action Accept status as an object instead of string * Fix the "currentStatus" reducer state update value * Get payment data into data store * Set the correct payment status to data store * Get the success status of payment from data store * Use store data in the payment dispatchers Replace the React useReducers action in the payment dispatchers file with the payment method data store * Get payment status from data store * Use data store for the payment error status * Use payment data store failed status * Use payment data store for the isFinished status Co-authored-by: Alex Florisca <alex.florisca@automattic.com> Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com> * Fix merge conflict error * Set & get the provider's state from our data store instead of React's useReducer (https://github.com/woocommerce/woocommerce-blocks/pull/6588) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type * Add default state for PaymentMethod data store * Add preliminary action types * Add preliminary action dispatchers * Create payment method data store * Add preliminary reducers for payment method data store * Add preliminary selectors for payment method data store * Add reducers/actions for registering payment methods * Export payment method data store key * Add test for payment method data reducers * Add shouldSavePaymentMethod selector * Add store key as constant * Add more action types for registering and initializing payment methods * Get active payment method from data store instead of from context * Add registered methods to default state of payment method data store * Dispatch name of registered payment method to payment method data store * Remove setShouldSavePayment from payment method dispatcher and types * Get payment methods from registry instead of payment context * Add available payment methods to store * Add function to check whether payment methods are allowed to be used * Add selector to check if payments are initialised * Remove resolvers and add controls to payment method data store * Change type of payment requirements to string[] * Turn addRegistered and addRegisteredExpress into generators This is so we can check each payment method's validity before adding it to the list of available payment methods * Add action type for setting express payments as initialized * Only select from available methods in payment method options * Remove argument from addRegisteredPaymentMethod in payment method registry * Rename folder and store name to not contain the word data * Add selectors for express payment methods and their initialisation * Delete controls again in favour of thunks * Rename payment-method-data to payment-methdods * Create new setDefaultPaymentMethod function This will set the payment method when the cart loads. * Add CustomerPaymentMethodConfiguration type * Make getAvailableExpressPaymentMethods return correct data * Check express methods and normal methods when cart changes * Add action for setting active express payment methods * Handle express methods in checkPaymentMethodCanPay * Hide express payments area if none are available * Add selector for paymentMethodData * Add customer data to default state and add selector for it * Add setPaymentStatus action and reducer case * Set the default payment method when one isn't selected * Correct types on getCustomerPaymentMethods * Set status in data store alongside context status * Comment out active gateway selection - remove later * Set status in express payment methods in data store * Directly check payment methods from the list in blocks-registry * Add semicolon to import statement * Fix payment method data state call * Get paymentMethodData from store not context * Add addPaymentMethodData action/reducer case * Update payment method on payment success * Add 'getCurrentStatus' selector * Remove the temporary solution For getting payment method data into the data store * Prevent the 'success' context action from being dispatched * Update the "setPaymentStatus" data store action Accept status as an object instead of string * Fix the "currentStatus" reducer state update value * Get payment data into data store * Set the correct payment status to data store * Get the success status of payment from data store * Use store data in the payment dispatchers Replace the React useReducers action in the payment dispatchers file with the payment method data store * Get payment status from data store * Use data store for the payment error status * Use payment data store failed status * Use payment data store for the isFinished status * Update the setPaymentStatus argument * Set up setRegisteredPaymentMethods in data store * Use the data store version of the registeredPaymentMethods * Fix the default state type of the registeredPaymentMethods * Set up setRegisteredExpressPaymentMethod in data store * Use the data version of the registred express payment methods * Set the correct action type for removing payment methods * Fix default state express payment methods type * Use the store data version of activePaymentMethod * Use setActivePaymentMethod in the dispatchers file And refactor code * Update payment status arguments for express payment methods * Use paymentMethodData from the data store * Use payment method's errorMessage from data store * Update paymentMethods list in data store reducer * Replace remaining payment context data with data store * Clean up payment method context file Co-authored-by: Alex Florisca <alex.florisca@automattic.com> Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com> * Get payment method data directly from the data store instead of the usePaymentMethodDataContext hook (https://github.com/woocommerce/woocommerce-blocks/pull/6589) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type * Add default state for PaymentMethod data store * Add preliminary action types * Add preliminary action dispatchers * Create payment method data store * Add preliminary reducers for payment method data store * Add preliminary selectors for payment method data store * Add reducers/actions for registering payment methods * Export payment method data store key * Add test for payment method data reducers * Add shouldSavePaymentMethod selector * Add store key as constant * Add more action types for registering and initializing payment methods * Get active payment method from data store instead of from context * Add registered methods to default state of payment method data store * Dispatch name of registered payment method to payment method data store * Remove setShouldSavePayment from payment method dispatcher and types * Get payment methods from registry instead of payment context * Add available payment methods to store * Add function to check whether payment methods are allowed to be used * Add selector to check if payments are initialised * Remove resolvers and add controls to payment method data store * Change type of payment requirements to string[] * Turn addRegistered and addRegisteredExpress into generators This is so we can check each payment method's validity before adding it to the list of available payment methods * Add action type for setting express payments as initialized * Only select from available methods in payment method options * Remove argument from addRegisteredPaymentMethod in payment method registry * Rename folder and store name to not contain the word data * Add selectors for express payment methods and their initialisation * Delete controls again in favour of thunks * Rename payment-method-data to payment-methdods * Create new setDefaultPaymentMethod function This will set the payment method when the cart loads. * Add CustomerPaymentMethodConfiguration type * Make getAvailableExpressPaymentMethods return correct data * Check express methods and normal methods when cart changes * Add action for setting active express payment methods * Handle express methods in checkPaymentMethodCanPay * Hide express payments area if none are available * Add selector for paymentMethodData * Add customer data to default state and add selector for it * Add setPaymentStatus action and reducer case * Set the default payment method when one isn't selected * Correct types on getCustomerPaymentMethods * Set status in data store alongside context status * Comment out active gateway selection - remove later * Set status in express payment methods in data store * Directly check payment methods from the list in blocks-registry * Add semicolon to import statement * Fix payment method data state call * Get paymentMethodData from store not context * Add addPaymentMethodData action/reducer case * Update payment method on payment success * Add 'getCurrentStatus' selector * Remove the temporary solution For getting payment method data into the data store * Prevent the 'success' context action from being dispatched * Update the "setPaymentStatus" data store action Accept status as an object instead of string * Fix the "currentStatus" reducer state update value * Get payment data into data store * Set the correct payment status to data store * Get the success status of payment from data store * Use store data in the payment dispatchers Replace the React useReducers action in the payment dispatchers file with the payment method data store * Get payment status from data store * Use data store for the payment error status * Use payment data store failed status * Use payment data store for the isFinished status * Update the setPaymentStatus argument * Set up setRegisteredPaymentMethods in data store * Use the data store version of the registeredPaymentMethods * Fix the default state type of the registeredPaymentMethods * Set up setRegisteredExpressPaymentMethod in data store * Use the data version of the registred express payment methods * Set the correct action type for removing payment methods * Fix default state express payment methods type * Use the store data version of activePaymentMethod * Use setActivePaymentMethod in the dispatchers file And refactor code * Update payment status arguments for express payment methods * Use paymentMethodData from the data store * Use payment method's errorMessage from data store * Update paymentMethods list in data store reducer * Replace remaining payment context data with data store * Clean up payment method context file * Get payment method state from data store in the checkout submit hook * Copy types.ts file into the payment data store folder * Fix isExpressPaymentMethodActive selector * Move the entire currentStatus into the data store * Replace the payment context state with the data store * Fix getActiveSavedToken & clean up the context file * Use the accutrate name of the "createErrorNotice" * Update the payment method data store key import * Diable unused state from the context Co-authored-by: Alex Florisca <alex.florisca@automattic.com> Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com> * Refactor the payment method data store & context (https://github.com/woocommerce/woocommerce-blocks/pull/6607) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type * Add default state for PaymentMethod data store * Add preliminary action types * Add preliminary action dispatchers * Create payment method data store * Add preliminary reducers for payment method data store * Add preliminary selectors for payment method data store * Add reducers/actions for registering payment methods * Export payment method data store key * Add test for payment method data reducers * Add shouldSavePaymentMethod selector * Add store key as constant * Add more action types for registering and initializing payment methods * Get active payment method from data store instead of from context * Add registered methods to default state of payment method data store * Dispatch name of registered payment method to payment method data store * Remove setShouldSavePayment from payment method dispatcher and types * Get payment methods from registry instead of payment context * Add available payment methods to store * Add function to check whether payment methods are allowed to be used * Add selector to check if payments are initialised * Remove resolvers and add controls to payment method data store * Change type of payment requirements to string[] * Turn addRegistered and addRegisteredExpress into generators This is so we can check each payment method's validity before adding it to the list of available payment methods * Add action type for setting express payments as initialized * Only select from available methods in payment method options * Remove argument from addRegisteredPaymentMethod in payment method registry * Rename folder and store name to not contain the word data * Add selectors for express payment methods and their initialisation * Delete controls again in favour of thunks * Rename payment-method-data to payment-methdods * Create new setDefaultPaymentMethod function This will set the payment method when the cart loads. * Add CustomerPaymentMethodConfiguration type * Make getAvailableExpressPaymentMethods return correct data * Check express methods and normal methods when cart changes * Add action for setting active express payment methods * Handle express methods in checkPaymentMethodCanPay * Hide express payments area if none are available * Add selector for paymentMethodData * Add customer data to default state and add selector for it * Add setPaymentStatus action and reducer case * Set the default payment method when one isn't selected * Correct types on getCustomerPaymentMethods * Set status in data store alongside context status * Comment out active gateway selection - remove later * Set status in express payment methods in data store * Directly check payment methods from the list in blocks-registry * Add semicolon to import statement * Fix payment method data state call * Get paymentMethodData from store not context * Add addPaymentMethodData action/reducer case * Update payment method on payment success * Add 'getCurrentStatus' selector * Remove the temporary solution For getting payment method data into the data store * Prevent the 'success' context action from being dispatched * Update the "setPaymentStatus" data store action Accept status as an object instead of string * Fix the "currentStatus" reducer state update value * Get payment data into data store * Set the correct payment status to data store * Get the success status of payment from data store * Use store data in the payment dispatchers Replace the React useReducers action in the payment dispatchers file with the payment method data store * Get payment status from data store * Use data store for the payment error status * Use payment data store failed status * Use payment data store for the isFinished status * Update the setPaymentStatus argument * Set up setRegisteredPaymentMethods in data store * Use the data store version of the registeredPaymentMethods * Fix the default state type of the registeredPaymentMethods * Set up setRegisteredExpressPaymentMethod in data store * Use the data version of the registred express payment methods * Set the correct action type for removing payment methods * Fix default state express payment methods type * Use the store data version of activePaymentMethod * Use setActivePaymentMethod in the dispatchers file And refactor code * Update payment status arguments for express payment methods * Use paymentMethodData from the data store * Use payment method's errorMessage from data store * Update paymentMethods list in data store reducer * Replace remaining payment context data with data store * Clean up payment method context file * Get payment method state from data store in the checkout submit hook * Copy types.ts file into the payment data store folder * Fix isExpressPaymentMethodActive selector * Move the entire currentStatus into the data store * Replace the payment context state with the data store * Fix getActiveSavedToken & clean up the context file * Use the accutrate name of the "createErrorNotice" * Update the payment method data store key import * Diable unused state from the context * Get enabled customer payment methods using data store selector * Remove remaining useReducer action from the dispatchers file * Update types and remove unused vars * Remove the payment method dispatchers hook * Refactor & clean up (remove unused files) * Remove commented line from payment methods types * Move event emitter into thunks Co-authored-by: Alex Florisca <alex.florisca@automattic.com> Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com> * Remove checkout-state after merge conflicts * Fix linting errors * Move types to types.ts * Move default states into respective store folders * Fix types and add comment * Move setExpressPaymentError to payment-methods store * fix express payment methods not showing up * Check if payment method is active from the state * Add comments * Remove commented out code in payment method data context * Display an error in the check-payment-methods directly from data store * Remove use-emit-response hook and move utils in event-emit/utils.ts * Use correct action property to remove payment methods * Fix formatting * Only try to initialize payment methods when cart is done loading * Add function to order payment methods from server * Add payment methods in the correct order * Prevent adding registered payment methods before cart is ready * Ensure payment methods get removed from state when deregistered * Reorder setting default payment methods to add customer methods first * Get customer methods from store not context * Remove error from payment-method state and associated selectors * Remove use-payment-method-registration and update the payment method state to remove the duplicated registeredPaymentMethods * Remove errorMessage from payment-methods store * Rename customerPaymentMethods -> savedPaymentMethods * Order payment methods when validating * Refactor payment-methods.js * Fix "Payment methods not set in editor" woocommerce/woocommerce-blocks#6655 bug We never get to load the payment methods object in the editor mode because there are no cart totals to load. * Initialize payment methods when available payments are loaded * Remove duplicate code * Fix data store state mutation anti-pattern A Redux rule is to never mutate the state in a reducer to avoid any unexpected results * Set availablePaymentMethods to the paymentMethods object Instead of its keys. We can get the keys using "Object.keys". * Use the available ordered payment methods The `getPaymentMethods` & `getExpressPaymentMethods` may include unordored & unavailable payment methods. * Get the correct value from the emit event response Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Saad Tarhi <saad.trh@gmail.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2022-07-08 05:53:24 +00:00
import { defaultCartState } from '../../../../data/cart/default-state';
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
jest.mock( '../saved-payment-method-options', () => ( { onChange } ) => {
return (
<>
<span>Saved payment method options</span>
<button onClick={ () => onChange( '0' ) }>Select saved</button>
</>
);
} );
jest.mock(
'@woocommerce/base-components/radio-control-accordion',
() =>
( { onChange } ) =>
(
<>
<span>Payment method options</span>
<button onClick={ () => onChange( 'credit-card' ) }>
Select new payment
</button>
</>
)
);
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
const originalSelect = jest.requireActual( '@wordpress/data' ).select;
const selectMock = jest
.spyOn( wpDataFunctions, 'select' )
.mockImplementation( ( storeName ) => {
const originalStore = originalSelect( storeName );
if ( storeName === PAYMENT_STORE_KEY ) {
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
return {
...originalStore,
getState: () => {
const originalState = originalStore.getState();
return {
...originalState,
savedPaymentMethods: {},
availablePaymentMethods: {},
paymentMethodsInitialized: true,
};
},
};
}
return originalStore;
} );
const registerMockPaymentMethods = () => {
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
[ 'cod', 'credit-card' ].forEach( ( name ) => {
registerPaymentMethod( {
name,
label: name,
content: <div>A payment method</div>,
edit: <div>A payment method</div>,
icons: null,
canMakePayment: () => true,
supports: {
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
showSavedCards: true,
showSaveOption: true,
features: [ 'products' ],
},
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
ariaLabel: name,
} );
} );
dispatch( PAYMENT_STORE_KEY ).__internalUpdateAvailablePaymentMethods();
};
const resetMockPaymentMethods = () => {
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
[ 'cod', 'credit-card' ].forEach( ( name ) => {
__experimentalDeRegisterPaymentMethod( name );
} );
};
describe( 'PaymentMethods', () => {
beforeEach( () => {
fetchMock.mockResponse( ( req ) => {
if ( req.url.match( /wc\/store\/v1\/cart/ ) ) {
return Promise.resolve( JSON.stringify( previewCart ) );
}
return Promise.resolve( '' );
} );
// need to clear the store resolution state between tests.
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
wpDataFunctions
.dispatch( CART_STORE_KEY )
.invalidateResolutionForStore();
wpDataFunctions
.dispatch( CART_STORE_KEY )
.receiveCart( defaultCartState.cartData );
} );
afterEach( () => {
fetchMock.resetMocks();
} );
test( 'should show no payment methods component when there are no payment methods', async () => {
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
render( <PaymentMethods /> );
await waitFor( () => {
const noPaymentMethods = screen.queryAllByText(
/no payment methods available/
);
// We might get more than one match because the `speak()` function
// creates an extra `div` with the notice contents used for a11y.
expect( noPaymentMethods.length ).toBeGreaterThanOrEqual( 1 );
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
// Reset the mock back to how it was because we don't need it anymore after this test.
selectMock.mockRestore();
} );
} );
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
test( 'selecting new payment method', async () => {
const ShowActivePaymentMethod = () => {
const { activePaymentMethod, activeSavedToken } =
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
wpDataFunctions.useSelect( ( select ) => {
const store = select( PAYMENT_STORE_KEY );
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
return {
activePaymentMethod: store.getActivePaymentMethod(),
activeSavedToken: store.getActiveSavedToken(),
};
} );
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
return (
<>
<div>
{ 'Active Payment Method: ' + activePaymentMethod }
</div>
<div>{ 'Active Saved Token: ' + activeSavedToken }</div>
</>
);
};
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
act( () => {
registerMockPaymentMethods();
} );
// Wait for the payment methods to finish loading before rendering.
await waitFor( () => {
expect(
wpDataFunctions
.select( PAYMENT_STORE_KEY )
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
.getActivePaymentMethod()
).toBe( 'cod' );
} );
render(
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
<>
<PaymentMethods />
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
<ShowActivePaymentMethod />
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
</>
);
await waitFor( () => {
const savedPaymentMethodOptions = screen.queryByText(
/Saved payment method options/
);
expect( savedPaymentMethodOptions ).not.toBeNull();
} );
await waitFor( () => {
const paymentMethodOptions = screen.queryByText(
/Payment method options/
);
expect( paymentMethodOptions ).not.toBeNull();
} );
await waitFor( () => {
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
const savedToken = screen.queryByText(
/Active Payment Method: credit-card/
);
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
expect( savedToken ).toBeNull();
} );
userEvent.click( screen.getByText( 'Select new payment' ) );
await waitFor( () => {
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
const activePaymentMethod = screen.queryByText(
/Active Payment Method: credit-card/
);
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
expect( activePaymentMethod ).not.toBeNull();
} );
Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439) * Add left vertical bar to payments methods step. * Remove horizontal borders around order notes. * Add class to order notes component. We need it to traget that element with CSS. * Update padding on order notes checkbox to match desing. * Remove full stop to match the design. * Add label for not saved payment methods option. * Remove use new payment radio. * Always show new ayment methods selector * Remove editor context for now. * Add accordion component skeleton. * Small component refactor. * Use accordion for new payment options. * Fix jsdoc. * Add styling. * Add input styling. * Hide label if we don't have saved methods. * Cleanup. * Cleanup and styling. * Add target class to aid with alignment. * Update use new payments label styling. * Update Place Order button location. * add full stop to payment method copy * ensure that there is always a (default) selected payment method: - using `activePaymentMethod` from context - this ensures there is a default selected on initial render - and handles any dynamic changes to available payment methods - e.g. COD disappearing when change shipping option - remove unused / redundant selectedMethod prop - context is best * use tab-based payment UI for 2 or fewer payment methods: - move saved payment state to payment context; it's shared state needed by both PaymentMethodOptions and SavedPaymentMethodOptions - show previous tabs UI if: - customer has no saved payment methods (cards) - store has 2 or fewer payment methods available - when initialising SavedPaymentMethodOptions, only select one if the user hasn't selected a real payment method - this ensures radio buttons switch correctly between saved card => `Use another` - remove various props and local state that is no longer required (🤞🏻) * experimental - styling tweaks for single payment tab (remove "tab" UI) * Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)" This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4. * Add single payment method UI. * Adjust single method styling. * Add outline and margin to two methods version. * Fix gap for order notes on/off option. * Update Order button spacing CSS. * Reuse computed values. * Remove tabs and single payment option. * We no longer need this test as the UI was changed. * Fix payment methods labels height. * Simplify. * Remove not needed import. * Typecheck an option. * Refactor code. * Rename. * Rename. * Update typdefs. * Remove border for add order notes. * Correct spacing for radio-button and label. * Add simple test. Switch to payment method. * Update style. Co-authored-by: Rua Haszard <rua.haszard@automattic.com> Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 04:51:47 +00:00
Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669) * Mock getCartTotals * Change test to use data store instead of context * Move payment method context test to data store selectors * Change description of test suite * Bump commit to trigger tests * Fix path in test * update package lock * Set correct state payment method reducer tests/use correct actions * Get saved payment methods from store not context * Mock stores and update tests to allow switching payment methods * Update tests to get onSubmit from checkoutEventsContext * Remove cartTotalsLoaded check from payment method initialize check * Make PaymentMethods test wait until payments initialized * initialize payment method data store when cart is loaded * Remove unneeded actions and add initializePaymentMethodDataStore * Remove check for cart totals loaded in checkPaymentMethods * Remove updateAvilablePaymentMethods from registry * Remove unneeded mock * Remove unused import * Rename imports to fix eslint errors * Remove unused imports * Remove return false from checkPaymentMethods * Remove unnecessary setPaymentMethodsInitialized call * Add todo comment to track refactoring opportunity * Remove savedpayment methods from payment method context and rename it * Rename payment method data context to payment method events context * Add tests for setDefaultPaymentMethods * Optimize the availablePaymentMethods state data Store only the "name" attribute for now. * Get list of payment methods from the registry instead of the store We are using this hook to get some React elements in the payment method object. So, we are getting the raw data directly from the registry instead of the store. * Fix payment state not loading on the Checkout edit page * Handle checkout edit page case * Fix infinite loop error on C&C Blocks * Include @wordpress/redux-routine in transformIgnorePatterns jest config Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-22 13:56:44 +00:00
act( () => resetMockPaymentMethods() );
} );
} );