From fcb4a668b6d42b9b1bc366725ad3457241f83168 Mon Sep 17 00:00:00 2001 From: Veljko Date: Fri, 8 Mar 2024 20:43:37 +0100 Subject: [PATCH] Revert checkout block test --- .../tests/shopper/checkout-block.spec.js | 102 +++++++++--------- 1 file changed, 48 insertions(+), 54 deletions(-) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js index 4c07c61a0dd55..3b4397798e86a 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js +++ b/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' ); @@ -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(); @@ -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, @@ -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(); @@ -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 } ) @@ -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' ); @@ -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' ); @@ -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 } ) @@ -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 } ) @@ -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 } ) @@ -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 } ) @@ -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 } ) @@ -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 ); @@ -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 ); @@ -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 } )