Skip to content

Commit

Permalink
Revert checkout block test
Browse files Browse the repository at this point in the history
  • Loading branch information
veljkho committed Mar 8, 2024
1 parent 1ddb491 commit fcb4a66
Showing 1 changed file with 48 additions and 54 deletions.
102 changes: 48 additions & 54 deletions plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js
@@ -1,5 +1,4 @@
const { test, expect } = require( '@playwright/test' );
const { disableWelcomeModal } = require( '../../utils/editor' );
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
const { admin, customer } = require( '../../test-data/data' );
const { setFilterValue, clearFilters } = require( '../../utils/filters' );
Expand All @@ -19,7 +18,7 @@ const singleProductSalePrice = '75.00';
const twoProductPrice = ( singleProductSalePrice * 2 ).toString();
const threeProductPrice = ( singleProductSalePrice * 3 ).toString();

const checkoutBlockPageTitle = `Checkout Block ${ Date.now() }`;
const checkoutBlockPageTitle = 'Checkout Block';
const checkoutBlockPageSlug = checkoutBlockPageTitle
.replace( / /gi, '-' )
.toLowerCase();
Expand All @@ -32,8 +31,6 @@ let guestOrderId1,
shippingZoneId;

test.describe( 'Checkout Block page', () => {
test.use( { storageState: process.env.ADMINSTATE } );

test.beforeAll( async ( { baseURL } ) => {
const api = new wcApi( {
url: baseURL,
Expand Down Expand Up @@ -206,26 +203,38 @@ test.describe( 'Checkout Block page', () => {
} );
} );

test.beforeEach( async ( { context } ) => {
// Shopping cart is very sensitive to cookies, so be explicit
await context.clearCookies();
} );

test( 'can see empty checkout block page', async ( { page } ) => {
// go to create a new page
// create a new page with checkout block
await page.goto( 'wp-admin/post-new.php?post_type=page' );
await page.waitForLoadState( 'networkidle' );
await page.locator( 'input[name="log"]' ).fill( admin.username );
await page.locator( 'input[name="pwd"]' ).fill( admin.password );
await page.locator( 'text=Log In' ).click();

await disableWelcomeModal( { page } );
// Close welcome popup if prompted
try {
await page
.getByLabel( 'Close', { exact: true } )
.click( { timeout: 5000 } );
} catch ( error ) {
console.log( "Welcome modal wasn't present, skipping action." );
}

// fill page title and add checkout block
await page
.getByRole( 'textbox', { name: 'Add title' } )
.fill( checkoutBlockPageTitle );
await page.getByRole( 'textbox', { name: 'Add title' } ).click();
await page.getByLabel( 'Add block' ).click();
await page.getByRole( 'button', { name: 'Add default block' } ).click();
await page
.getByPlaceholder( 'Search', { exact: true } )
.fill( 'checkout' );
await page
.getByRole( 'option', { name: 'Checkout', exact: true } )
.click();

// publish created checkout block page
.getByRole( 'document', {
name: 'Empty block; start writing or type forward slash to choose a block',
} )
.fill( '/checkout' );
await page.keyboard.press( 'Enter' );
await page
.getByRole( 'button', { name: 'Publish', exact: true } )
.click();
Expand All @@ -237,7 +246,7 @@ test.describe( 'Checkout Block page', () => {
page.getByText( `${ checkoutBlockPageTitle } is now live.` )
).toBeVisible();

// go to the page to test empty checkout block
// go to the page to test empty cart block
await page.goto( checkoutBlockPageSlug );
await expect(
page.getByRole( 'heading', { name: checkoutBlockPageTitle } )
Expand All @@ -256,9 +265,7 @@ test.describe( 'Checkout Block page', () => {

test( 'allows customer to choose available payment methods', async ( {
page,
context,
} ) => {
await context.clearCookies();
// this time we're going to add two products to the cart
await addProductsToCart( page, simpleProductName, '2' );

Expand Down Expand Up @@ -292,12 +299,7 @@ test.describe( 'Checkout Block page', () => {
await expect( page.getByLabel( 'Cash on delivery' ) ).toBeChecked();
} );

test( 'allows customer to fill shipping details', async ( {
page,
context,
} ) => {
await context.clearCookies();

test( 'allows customer to fill shipping details', async ( { page } ) => {
// this time we're going to add three products to the cart
await addProductsToCart( page, simpleProductName, '3' );

Expand Down Expand Up @@ -337,10 +339,10 @@ test.describe( 'Checkout Block page', () => {

test( 'allows customer to fill different shipping and billing details', async ( {
page,
context,
} ) => {
await context.clearCookies();
await page.goto( `/shop/?add-to-cart=${ productId }` );
await page.goto( `/shop/?add-to-cart=${ productId }`, {
waitUntil: 'networkidle',
} );
await page.goto( checkoutBlockPageSlug );
await expect(
page.getByRole( 'heading', { name: checkoutBlockPageTitle } )
Expand Down Expand Up @@ -379,7 +381,9 @@ test.describe( 'Checkout Block page', () => {
.toString();

// go again to the checkout to verify details
await page.goto( `/shop/?add-to-cart=${ productId }` );
await page.goto( `/shop/?add-to-cart=${ productId }`, {
waitUntil: 'networkidle',
} );
await page.goto( checkoutBlockPageSlug );
await expect(
page.getByRole( 'heading', { name: checkoutBlockPageTitle } )
Expand Down Expand Up @@ -448,10 +452,10 @@ test.describe( 'Checkout Block page', () => {

test( 'warn when customer is missing required details', async ( {
page,
context,
} ) => {
await context.clearCookies();
await page.goto( `/shop/?add-to-cart=${ productId }` );
await page.goto( `/shop/?add-to-cart=${ productId }`, {
waitUntil: 'networkidle',
} );
await page.goto( checkoutBlockPageSlug );
await expect(
page.getByRole( 'heading', { name: checkoutBlockPageTitle } )
Expand Down Expand Up @@ -481,10 +485,10 @@ test.describe( 'Checkout Block page', () => {

test( 'allows customer to fill shipping details and toggle different billing', async ( {
page,
context,
} ) => {
await context.clearCookies();
await page.goto( `/shop/?add-to-cart=${ productId }` );
await page.goto( `/shop/?add-to-cart=${ productId }`, {
waitUntil: 'networkidle',
} );
await page.goto( checkoutBlockPageSlug );
await expect(
page.getByRole( 'heading', { name: checkoutBlockPageTitle } )
Expand All @@ -508,10 +512,10 @@ test.describe( 'Checkout Block page', () => {

test( 'can choose different shipping types in the checkout', async ( {
page,
context,
} ) => {
await context.clearCookies();
await page.goto( `/shop/?add-to-cart=${ productId }` );
await page.goto( `/shop/?add-to-cart=${ productId }`, {
waitUntil: 'networkidle',
} );
await page.goto( checkoutBlockPageSlug );
await expect(
page.getByRole( 'heading', { name: checkoutBlockPageTitle } )
Expand Down Expand Up @@ -583,11 +587,7 @@ test.describe( 'Checkout Block page', () => {
).toContainText( twoProductPrice );
} );

test( 'allows guest customer to place an order', async ( {
page,
context,
} ) => {
await context.clearCookies();
test( 'allows guest customer to place an order', async ( { page } ) => {
await addProductsToCart( page, simpleProductName, '2' );

await page.goto( checkoutBlockPageSlug );
Expand Down Expand Up @@ -697,11 +697,7 @@ test.describe( 'Checkout Block page', () => {
await clearFilters( page );
} );

test( 'allows existing customer to place an order', async ( {
page,
context,
} ) => {
await context.clearCookies();
test( 'allows existing customer to place an order', async ( { page } ) => {
await addProductsToCart( page, simpleProductName, '2' );

await page.goto( checkoutBlockPageSlug );
Expand Down Expand Up @@ -807,12 +803,10 @@ test.describe( 'Checkout Block page', () => {
);
} );

test( 'can create an account during checkout', async ( {
page,
context,
} ) => {
await context.clearCookies();
await page.goto( `/shop/?add-to-cart=${ productId }` );
test( 'can create an account during checkout', async ( { page } ) => {
await page.goto( `/shop/?add-to-cart=${ productId }`, {
waitUntil: 'networkidle',
} );
await page.goto( checkoutBlockPageSlug );
await expect(
page.getByRole( 'heading', { name: checkoutBlockPageTitle } )
Expand Down

0 comments on commit fcb4a66

Please sign in to comment.