Skip to content

Commit

Permalink
[e2e] External - Expand WPCOM suite, part 2 (woocommerce#51414)
Browse files Browse the repository at this point in the history
* Add /merchant tests to the WPCOM suite

* Skip "can manually add a variation" on WPCOM

* Skip "Coupon management" - API returns 500 on delete

* Resolve `wp-block-woocommerce-checkout-order-summary-block` on the first element

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
Stojdza and github-actions authored Sep 17, 2024
1 parent 861bc09 commit acc313a
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 177 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

Expand the e2e suite we're running on WPCOM part #2.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ config = {
'**/admin-tasks/**/*.spec.js',
'**/shopper/**/*.spec.js',
'**/api-tests/**/*.test.js',
'**/merchant/products/add-variable-product/**/*.spec.js',
'**/merchant/command-palette.spec.js',
'**/merchant/create-cart-block.spec.js',
'**/merchant/create-checkout-block.spec.js',
'**/merchant/create-coupon.spec.js',
'**/merchant/create-order.spec.js',
'**/merchant/create-page.spec.js',
'**/merchant/create-post.spec.js',
],
grepInvert: /@skip-on-default-wpcom/,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ test.describe(
.locator( 'legend' )
).toBeVisible();
await expect(
page.locator(
'.wp-block-woocommerce-checkout-order-summary-block'
)
page
.locator(
'.wp-block-woocommerce-checkout-order-summary-block'
)
.first()
).toBeVisible();
await expect(
page.locator( '.wc-block-components-address-form' ).first()
Expand Down
182 changes: 95 additions & 87 deletions plugins/woocommerce/tests/e2e-pw/tests/merchant/create-coupon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,102 +39,110 @@ const test = baseTest.extend( {
},
} );

test.describe( 'Coupon management', { tag: '@services' }, () => {
for ( const couponType of Object.keys( couponData ) ) {
test( `can create new ${ couponType } coupon`, async ( {
page,
coupon,
} ) => {
await test.step( 'add new coupon', async () => {
await page.goto(
'wp-admin/post-new.php?post_type=shop_coupon'
);
await page
.getByLabel( 'Coupon code' )
.fill( couponData[ couponType ].code );
await page
.getByPlaceholder( 'Description (optional)' )
.fill( couponData[ couponType ].description );
await page
.getByPlaceholder( '0' )
.fill( couponData[ couponType ].amount );

// set expiry date if it was provided
if ( couponData[ couponType ].expiryDate ) {
test.describe(
'Coupon management',
{ tag: [ '@services', '@skip-on-default-wpcom' ] },
() => {
for ( const couponType of Object.keys( couponData ) ) {
test( `can create new ${ couponType } coupon`, async ( {
page,
coupon,
} ) => {
await test.step( 'add new coupon', async () => {
await page.goto(
'wp-admin/post-new.php?post_type=shop_coupon'
);
await page
.getByPlaceholder( 'yyyy-mm-dd' )
.fill( couponData[ couponType ].expiryDate );
}

// be explicit about whether free shipping is allowed
if ( couponData[ couponType ].freeShipping ) {
await page.getByLabel( 'Allow free shipping' ).check();
} else {
await page.getByLabel( 'Allow free shipping' ).uncheck();
}
} );
.getByLabel( 'Coupon code' )
.fill( couponData[ couponType ].code );
await page
.getByPlaceholder( 'Description (optional)' )
.fill( couponData[ couponType ].description );
await page
.getByPlaceholder( '0' )
.fill( couponData[ couponType ].amount );

// publish the coupon and retrieve the id
await test.step( 'publish the coupon', async () => {
await expect(
page.getByRole( 'link', { name: 'Move to Trash' } )
).toBeVisible();
await page
.getByRole( 'button', { name: 'Publish', exact: true } )
.click();
await expect(
page.getByText( 'Coupon updated.' )
).toBeVisible();
coupon.id = page.url().match( /(?<=post=)\d+/ )[ 0 ];
expect( coupon.id ).toBeDefined();
} );
// set expiry date if it was provided
if ( couponData[ couponType ].expiryDate ) {
await page
.getByPlaceholder( 'yyyy-mm-dd' )
.fill( couponData[ couponType ].expiryDate );
}

// verify the creation of the coupon and details
await test.step( 'verify coupon creation', async () => {
await page.goto( 'wp-admin/edit.php?post_type=shop_coupon' );
await expect(
page.getByRole( 'cell', {
name: couponData[ couponType ].code,
} )
).toBeVisible();
await expect(
page.getByRole( 'cell', {
name: couponData[ couponType ].description,
} )
).toBeVisible();
await expect(
page.getByRole( 'cell', {
name: couponData[ couponType ].amount,
exact: true,
} )
).toBeVisible();
} );
// be explicit about whether free shipping is allowed
if ( couponData[ couponType ].freeShipping ) {
await page.getByLabel( 'Allow free shipping' ).check();
} else {
await page
.getByLabel( 'Allow free shipping' )
.uncheck();
}
} );

// check expiry date if it was set
if ( couponData[ couponType ].expiryDate ) {
await test.step( 'verify coupon expiry date', async () => {
// publish the coupon and retrieve the id
await test.step( 'publish the coupon', async () => {
await expect(
page.getByRole( 'link', { name: 'Move to Trash' } )
).toBeVisible();
await page
.getByText( couponData[ couponType ].code )
.last()
.getByRole( 'button', { name: 'Publish', exact: true } )
.click();
await expect(
page.getByPlaceholder( 'yyyy-mm-dd' )
).toHaveValue( couponData[ couponType ].expiryDate );
page.getByText( 'Coupon updated.' )
).toBeVisible();
coupon.id = page.url().match( /(?<=post=)\d+/ )[ 0 ];
expect( coupon.id ).toBeDefined();
} );
}

// if it was a free shipping coupon check that
if ( couponData[ couponType ].freeShipping ) {
await test.step( 'verify free shipping', async () => {
await page
.getByText( couponData[ couponType ].code )
.last()
.click();
// verify the creation of the coupon and details
await test.step( 'verify coupon creation', async () => {
await page.goto(
'wp-admin/edit.php?post_type=shop_coupon'
);
await expect(
page.getByRole( 'cell', {
name: couponData[ couponType ].code,
} )
).toBeVisible();
await expect(
page.getByLabel( 'Allow free shipping' )
).toBeChecked();
page.getByRole( 'cell', {
name: couponData[ couponType ].description,
} )
).toBeVisible();
await expect(
page.getByRole( 'cell', {
name: couponData[ couponType ].amount,
exact: true,
} )
).toBeVisible();
} );
}
} );

// check expiry date if it was set
if ( couponData[ couponType ].expiryDate ) {
await test.step( 'verify coupon expiry date', async () => {
await page
.getByText( couponData[ couponType ].code )
.last()
.click();
await expect(
page.getByPlaceholder( 'yyyy-mm-dd' )
).toHaveValue( couponData[ couponType ].expiryDate );
} );
}

// if it was a free shipping coupon check that
if ( couponData[ couponType ].freeShipping ) {
await test.step( 'verify free shipping', async () => {
await page
.getByText( couponData[ couponType ].code )
.last()
.click();
await expect(
page.getByLabel( 'Allow free shipping' )
).toBeChecked();
} );
}
} );
}
}
} );
);
Loading

0 comments on commit acc313a

Please sign in to comment.