Skip to content

Commit

Permalink
Merge branch 'develop' into add/334-test-mode-notice-order-details
Browse files Browse the repository at this point in the history
  • Loading branch information
htdat committed Dec 14, 2023
2 parents 6e9975f + e5bca8d commit fc35450
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelog/deferred-intent
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Improve E2E checkout tests
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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 );
Expand All @@ -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' )
);
Expand Down Expand Up @@ -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 );
Expand All @@ -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."
Expand All @@ -153,6 +191,6 @@ describe( 'Enabled UPE with deferred intent creation', () => {
: 0;

await new Promise( ( r ) => setTimeout( r, remainingWaitTime ) );
} );
}
} );
} );
8 changes: 8 additions & 0 deletions tests/e2e/utils/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
},
Expand Down

0 comments on commit fc35450

Please sign in to comment.