Skip to content

Commit

Permalink
Correctly scope guest user test
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Mar 15, 2024
1 parent 871fa7e commit 8249c2e
Showing 1 changed file with 74 additions and 71 deletions.
Expand Up @@ -470,8 +470,7 @@ test.describe( 'Checkout Form Errors (guest user)', () => {
test.describe( 'Billing Address Form', () => {
const blockSelectorInEditor = blockData.selectors.editor.block as string;

// To make sure the company field is visible in the billing address form, we need to enable it in the editor.
test.beforeEach( async ( { editor, admin, editorUtils } ) => {
test( 'Enable company field', async ( { editor, admin, editorUtils } ) => {
await admin.visitSiteEditor( {
postId: 'woocommerce/woocommerce//page-checkout',
postType: 'wp_template',
Expand Down Expand Up @@ -522,78 +521,82 @@ test.describe( 'Billing Address Form', () => {
phone: '',
};

test( 'Ensure billing is empty and shipping address is filled', async ( {
frontendUtils,
page,
checkoutPageObject,
} ) => {
await frontendUtils.emptyCart();
await frontendUtils.goToShop();
await frontendUtils.addToCart( SIMPLE_PHYSICAL_PRODUCT_NAME );
await frontendUtils.goToCheckout();
await checkoutPageObject.fillShippingDetails( shippingTestData );
await page.getByLabel( 'Use same address for billing' ).uncheck();
test.describe( 'Guest user', () => {
test.use( { storageState: guestFile } );

// Check shipping fields are filled.
for ( const [ key, value ] of Object.entries( shippingTestData ) ) {
// eslint-disable-next-line playwright/no-conditional-in-test
switch ( key ) {
case 'firstname':
await expect(
page.locator( '#shipping-first_name' )
).toHaveValue( value );
break;
case 'lastname':
await expect(
page.locator( '#shipping-last_name' )
).toHaveValue( value );
break;
case 'country':
await expect(
page.locator( '#shipping-country input' )
).toHaveValue( value );
break;
case 'addressfirstline':
await expect(
page.locator( '#shipping-address_1' )
).toHaveValue( value );
break;
case 'addresssecondline':
await expect(
page.locator( '#shipping-address_2' )
).toHaveValue( value );
break;
case 'state':
await expect(
page.locator( '#shipping-state input' )
).toHaveValue( value );
break;
default:
await expect(
page.locator( `#shipping-${ key }` )
).toHaveValue( value );
test( 'Ensure billing is empty and shipping address is filled', async ( {
frontendUtils,
page,
checkoutPageObject,
} ) => {
await frontendUtils.emptyCart();
await frontendUtils.goToShop();
await frontendUtils.addToCart( SIMPLE_PHYSICAL_PRODUCT_NAME );
await frontendUtils.goToCheckout();
await checkoutPageObject.fillShippingDetails( shippingTestData );
await page.getByLabel( 'Use same address for billing' ).uncheck();

// Check shipping fields are filled.
for ( const [ key, value ] of Object.entries( shippingTestData ) ) {
// eslint-disable-next-line playwright/no-conditional-in-test
switch ( key ) {
case 'firstname':
await expect(
page.locator( '#shipping-first_name' )
).toHaveValue( value );
break;
case 'lastname':
await expect(
page.locator( '#shipping-last_name' )
).toHaveValue( value );
break;
case 'country':
await expect(
page.locator( '#shipping-country input' )
).toHaveValue( value );
break;
case 'addressfirstline':
await expect(
page.locator( '#shipping-address_1' )
).toHaveValue( value );
break;
case 'addresssecondline':
await expect(
page.locator( '#shipping-address_2' )
).toHaveValue( value );
break;
case 'state':
await expect(
page.locator( '#shipping-state input' )
).toHaveValue( value );
break;
default:
await expect(
page.locator( `#shipping-${ key }` )
).toHaveValue( value );
}
}
}

// Check billing fields are empty.
for ( const [ key, value ] of Object.entries( billingTestData ) ) {
// eslint-disable-next-line playwright/no-conditional-in-test
switch ( key ) {
case 'country':
await expect(
page.locator( '#billing-country input' )
).toHaveValue( value );
break;
case 'state':
await expect(
page.locator( '#billing-state input' )
).toHaveValue( value );
break;
default:
await expect(
page.locator( `#billing-${ key }` )
).toHaveValue( value );
// Check billing fields are empty.
for ( const [ key, value ] of Object.entries( billingTestData ) ) {
// eslint-disable-next-line playwright/no-conditional-in-test
switch ( key ) {
case 'country':
await expect(
page.locator( '#billing-country input' )
).toHaveValue( value );
break;
case 'state':
await expect(
page.locator( '#billing-state input' )
).toHaveValue( value );
break;
default:
await expect(
page.locator( `#billing-${ key }` )
).toHaveValue( value );
}
}
}
} );
} );
} );

0 comments on commit 8249c2e

Please sign in to comment.