From 473a53d54243c6b749a4532112eea4ac8667447f Mon Sep 17 00:00:00 2001 From: Jonathan Lane Date: Thu, 14 Sep 2023 00:10:20 -0700 Subject: [PATCH] Add test to check required fields on checkout (#40099) * Add test to check required fields on checkout * Add changelog --------- Co-authored-by: Jon Lane --- .../changelog/e2e-shopper-checkout | 4 ++ .../e2e-pw/tests/shopper/checkout.spec.js | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 plugins/woocommerce/changelog/e2e-shopper-checkout diff --git a/plugins/woocommerce/changelog/e2e-shopper-checkout b/plugins/woocommerce/changelog/e2e-shopper-checkout new file mode 100644 index 00000000000..43e37f2916f --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-shopper-checkout @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Adds test to check required fields on checkout diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout.spec.js index 75195a3ed48..d06b1f95820 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout.spec.js @@ -178,6 +178,45 @@ test.describe( 'Checkout page', () => { await expect( page.locator( '#billing_email' ) ).toBeEditable(); } ); + test( 'warn when customer is missing required details', async ( { page } ) => { + await page.goto( `/shop/?add-to-cart=${ productId }`, { waitUntil: 'networkidle' } ); + + await page.goto( '/checkout/' ); + + // first try submitting the form with no fields complete + await page.getByRole('button', { name: 'Place order' }).click(); + await expect( page.locator( 'ul.woocommerce-error' ) ).toBeVisible(); + await expect( page.getByText( 'Billing First name is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Billing Last name is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Billing Street address is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Billing Town / City is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Billing ZIP Code is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Billing Phone is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Billing Email address is a required field.' ) ).toBeVisible(); + + // toggle ship to different address, fill out billing info and confirm error shown + await page.getByText('Ship to a different address?').click(); + await page.locator( '#billing_first_name' ).fill( 'Homer' ); + await page.locator( '#billing_last_name' ).fill( 'Simpson' ); + await page + .locator( '#billing_address_1' ) + .fill( '123 Evergreen Terrace' ); + await page.locator( '#billing_city' ).fill( 'Springfield' ); + await page.locator( '#billing_country' ).selectOption( 'US' ); + await page.locator( '#billing_state' ).selectOption( 'OR' ); + await page.locator( '#billing_postcode' ).fill( '97403' ); + await page.locator( '#billing_phone' ).fill( '555 555-5555' ); + await page.locator( '#billing_email' ).fill( customer.email ); + await page.getByRole('button', { name: 'Place order' }).click(); + + await expect( page.locator( 'ul.woocommerce-error' ) ).toBeVisible(); + await expect( page.getByText( 'Shipping First name is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Shipping Last name is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Shipping Street address is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Shipping Town / City is a required field.' ) ).toBeVisible(); + await expect( page.getByText( 'Shipping ZIP Code is a required field.' ) ).toBeVisible(); + } ); + test( 'allows customer to fill shipping details', async ( { page } ) => { for ( let i = 1; i < 3; i++ ) { await page.goto( `/shop/?add-to-cart=${ productId }` );