Add test to check required fields on checkout (#40099)

* Add test to check required fields on checkout

* Add changelog

---------

Co-authored-by: Jon Lane <jon.lane@automattic.com>
This commit is contained in:
Jonathan Lane 2023-09-14 00:10:20 -07:00 committed by GitHub
parent ef0aacf2d2
commit 473a53d542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Adds test to check required fields on checkout

View File

@ -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 }` );