Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improve E2E checkout tests #7664

Merged
merged 19 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mdmoore marked this conversation as resolved.
Show resolved Hide resolved
];
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' );
mdmoore marked this conversation as resolved.
Show resolved Hide resolved
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();
mdmoore marked this conversation as resolved.
Show resolved Hide resolved
} );

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.' );
mdmoore marked this conversation as resolved.
Show resolved Hide resolved
} );

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
Loading