Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Critical flows: Shopper → Checkout → Can login to existing account an…
Browse files Browse the repository at this point in the history
…d can create an account (#6147)

* Added test cases for user can login and create an account from Checkout block page
  • Loading branch information
Tarun Vijwani authored Apr 21, 2022
1 parent 88a34ea commit a065984
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions tests/e2e/specs/shopper/cart-checkout/account.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* External dependencies
*/
import {
visitBlockPage,
selectBlockByName,
saveOrPublish,
} from '@woocommerce/blocks-test-utils';
import {
merchant,
setCheckbox,
openDocumentSettingsSidebar,
} from '@woocommerce/e2e-utils';
import { switchUserToAdmin, visitAdminPage } from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
*/
import { shopper } from '../../../../utils';
import { SIMPLE_PHYSICAL_PRODUCT_NAME } from '.../../../../utils/constants';

const block = {
name: 'Checkout',
slug: 'woocommerce/checkout',
class: '.wp-block-woocommerce-checkout',
};

if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 ) {
// Skips all the tests if it's a WooCommerce Core process environment.
test.only( 'Skipping Cart & Checkout tests', () => {} );
}

describe( 'Shopper → Checkout → Account', () => {
beforeAll( async () => {
await merchant.openSettings( 'account' );
//Enable create an account at checkout option.
await setCheckbox( '#woocommerce_enable_checkout_login_reminder' );
//Enable login at checkout option.
await setCheckbox(
'#woocommerce_enable_signup_and_login_from_checkout'
);
//Enable guest checkout option.
await setCheckbox( '#woocommerce_enable_guest_checkout' );
await page.click( 'button[name="save"]' );
await page.waitForNavigation( { waitUntil: 'networkidle0' } );
await visitBlockPage( `${ block.name } Block` );
await openDocumentSettingsSidebar();
await selectBlockByName( block.slug );
await selectBlockByName(
'woocommerce/checkout-contact-information-block'
);
//Enable shoppers to sign up at checkout option.
await expect( page ).toClick( 'label', {
text:
'Allow shoppers to sign up for a user account during checkout',
} );
await saveOrPublish();
await shopper.logout();
await shopper.goToShop();
await shopper.addToCartFromShopPage( SIMPLE_PHYSICAL_PRODUCT_NAME );
await shopper.block.goToCheckout();
} );

it( 'user can login to existing account', async () => {
//Get the login link from checkout page.
const loginLink = await page.$eval(
'span.wc-block-components-checkout-step__heading-content a',
( el ) => el.href
);
//Confirm login link is correct.
await expect( loginLink ).toContain(
`${ process.env.WORDPRESS_BASE_URL }/my-account/?redirect_to`
);
await expect( loginLink ).toContain( `checkout` );
} );

it( 'user can can create an account', async () => {
await expect( page ).toClick( 'span', {
text: 'Create an account?',
} );
//Create random email to place an order.
let testEmail = `test${ Math.random() * 10 }@example.com`;
await expect( page ).toFill( `#email`, testEmail );
await shopper.block.fillInCheckoutWithTestData();
await shopper.block.placeOrder();
await expect( page ).toMatch( 'Order received' );
await switchUserToAdmin();
await visitAdminPage( 'users.php' );
//Confirm account is being created with the email.
await expect( page ).toMatch( testEmail );
} );
} );

0 comments on commit a065984

Please sign in to comment.