diff --git a/changelog/deferred-intent b/changelog/deferred-intent new file mode 100644 index 00000000000..ef5442b5f17 --- /dev/null +++ b/changelog/deferred-intent @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Improve E2E checkout tests diff --git a/tests/e2e/specs/upe-split/shopper/shopper-deferred-intent-creation-upe-enabled.spec.js b/tests/e2e/specs/upe-split/shopper/shopper-deferred-intent-creation-upe-enabled.spec.js index 1e9a6a27956..e1062f6d1ca 100644 --- a/tests/e2e/specs/upe-split/shopper/shopper-deferred-intent-creation-upe-enabled.spec.js +++ b/tests/e2e/specs/upe-split/shopper/shopper-deferred-intent-creation-upe-enabled.spec.js @@ -18,13 +18,10 @@ import { uiUnblocked } from '@woocommerce/e2e-utils/build/page-utils'; const { shopper, merchant } = require( '@woocommerce/e2e-utils' ); const UPE_METHOD_CHECKBOXES = [ - '#inspector-checkbox-control-5', // bancontact - '#inspector-checkbox-control-6', // eps '#inspector-checkbox-control-7', // giropay - '#inspector-checkbox-control-8', // ideal - '#inspector-checkbox-control-9', // sofort ]; const card = config.get( 'cards.basic' ); +const card2 = config.get( 'cards.basic2' ); const MIN_WAIT_TIME_BETWEEN_PAYMENT_METHODS = 20000; describe( 'Enabled UPE with deferred intent creation', () => { @@ -33,11 +30,9 @@ describe( 'Enabled UPE with deferred intent creation', () => { await merchantWCP.enablePaymentMethod( UPE_METHOD_CHECKBOXES ); await merchant.logout(); await shopper.login(); - await shopperWCP.changeAccountCurrencyTo( 'EUR' ); } ); afterAll( async () => { - await shopperWCP.changeAccountCurrencyTo( 'USD' ); await shopperWCP.logout(); await merchant.login(); await merchantWCP.disablePaymentMethod( UPE_METHOD_CHECKBOXES ); @@ -46,6 +41,7 @@ describe( 'Enabled UPE with deferred intent creation', () => { describe( 'Enabled UPE with deferred intent creation', () => { it( 'should successfully place order with Giropay', async () => { + await shopperWCP.goToShopWithCurrency( 'EUR' ); await setupProductCheckout( config.get( 'addresses.customer.billing' ) ); @@ -115,10 +111,23 @@ describe( 'Enabled UPE with deferred intent creation', () => { await shopperWCP.deleteSavedPaymentMethod( card.label ); await expect( page ).toMatch( 'Payment method deleted' ); } ); + + it( 'should not allow guest user to save the card', async () => { + await shopperWCP.logout(); + await setupProductCheckout( + config.get( 'addresses.customer.billing' ) + ); + + await expect( page ).not.toMatchElement( + 'input#wc-woocommerce_payments-new-payment-method' + ); + await shopper.login(); + } ); } ); describe( 'My Account', () => { let timeAdded; + it( 'should add the card as a new payment method', async () => { await shopperWCP.goToPaymentMethods(); await shopperWCP.addNewPaymentMethod( 'basic', card ); @@ -134,14 +143,43 @@ describe( 'Enabled UPE with deferred intent creation', () => { await expect( page ).toMatch( `${ card.expires.month }/${ card.expires.year }` ); + await waitTwentySecondsSinceLastCardAdded(); + } ); + + it( 'should be able to set payment method as default', async () => { + await shopperWCP.goToPaymentMethods(); + await shopperWCP.addNewPaymentMethod( 'basic2', card2 ); + // Take note of the time when we added this card + timeAdded = Date.now(); + + // Verify that the card was added + await expect( page ).not.toMatch( + 'You cannot add a new payment method so soon after the previous one. Please wait for 20 seconds.' + ); + await expect( page ).toMatch( 'Payment method successfully added' ); + await expect( page ).toMatch( + `${ card2.expires.month }/${ card2.expires.year }` + ); + await shopperWCP.setDefaultPaymentMethod( card2.label ); + // Verify that the card was set as default + await expect( page ).toMatch( + 'This payment method was successfully set as your default.' + ); } ); - it( 'should be able to delete the card', async () => { + it( 'should be able to delete cards', async () => { await shopperWCP.deleteSavedPaymentMethod( card.label ); await expect( page ).toMatch( 'Payment method deleted.' ); + + await shopperWCP.deleteSavedPaymentMethod( card2.label ); + await expect( page ).toMatch( 'Payment method deleted.' ); } ); afterAll( async () => { + await waitTwentySecondsSinceLastCardAdded(); + } ); + + async function waitTwentySecondsSinceLastCardAdded() { // Make sure that at least 20s had already elapsed since the last card was added. // Otherwise, you will get the error message, // "You cannot add a new payment method so soon after the previous one." @@ -153,6 +191,6 @@ describe( 'Enabled UPE with deferred intent creation', () => { : 0; await new Promise( ( r ) => setTimeout( r, remainingWaitTime ) ); - } ); + } } ); } ); diff --git a/tests/e2e/utils/flows.js b/tests/e2e/utils/flows.js index 0a2d8a8e7f8..aa18cd328a7 100644 --- a/tests/e2e/utils/flows.js +++ b/tests/e2e/utils/flows.js @@ -129,6 +129,14 @@ export const shopperWCP = { await expect( page ).toClick( 'label', { text: label } ); }, + setDefaultPaymentMethod: async ( label ) => { + const [ paymentMethodRow ] = await page.$x( + `//tr[contains(., '${ label }')]` + ); + await expect( paymentMethodRow ).toClick( '.button.default' ); + await page.waitForNavigation( { waitUntil: 'networkidle0' } ); + }, + toggleCreateAccount: async () => { await expect( page ).toClick( '#createaccount' ); },