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

202 lines
5.1 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';
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( {
...previewCart,
payment_methods: [ 'cod', 'credit-card' ],
} );
} );
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() );
} );
} );