Skip to content

Commit

Permalink
[e2e] External - Expand WPCOM suite, part 4 (woocommerce#51424)
Browse files Browse the repository at this point in the history
* Skip `can remove a coupon` - error 500

* Make elements more specific

* Skip two tests from order-emails.spec.js

* Skip `WooCommerce Page Load`

* Expand WPCOM suite

* Change hardcoded email address

* Unskip tests in order-emails.spec.js

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

* ESLint updates

* Check different locator for Marketing channels

* Skip "can receive completed email" for now

---------

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
Stojdza and github-actions authored Oct 2, 2024
1 parent 6b5dbbc commit 9c514b3
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 154 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 #4.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ config = {
'**/merchant/settings-woo-com.spec.js',
'**/merchant/users-create.spec.js',
'**/merchant/users-manage.spec.js',
'**/merchant/order-coupon.spec.js',
'**/merchant/order-edit.spec.js',
'**/merchant/order-emails.spec.js',
'**/merchant/order-refund.spec.js',
'**/merchant/order-search.spec.js',
'**/merchant/order-status-filter.spec.js',
'**/merchant/page-loads.spec.js',
'**/merchant/product-create-simple.spec.js',
'**/merchant/product-delete.spec.js',
'**/merchant/product-edit.spec.js',
],
grepInvert: /@skip-on-default-wpcom/,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,40 +119,50 @@ test.describe(
).toBeVisible();
} );

test( 'can remove a coupon', async ( { page } ) => {
await page.goto(
`/wp-admin/admin.php?page=wc-orders&action=edit&id=${ orderId }`
);
// assert that there is a coupon on the order
await expect(
page
.locator( '#woocommerce-order-items li' )
.filter( { hasText: couponCode } )
).toBeVisible();
await expect(
page.getByRole( 'cell', { name: 'Coupon(s)' } )
).toBeVisible();
await expect(
page.getByRole( 'cell', { name: `- $${ couponAmount }.00` } )
).toBeVisible();
await expect(
page.getByRole( 'cell', {
name: `$${ discountedPrice }`,
exact: true,
} )
).toBeVisible();
// remove the coupon
await page.locator( 'a.remove-coupon' ).dispatchEvent( 'click' ); // have to use dispatchEvent because nothing visible to click on
test(
'can remove a coupon',
{ tag: [ '@skip-on-default-wpcom' ] },
async ( { page } ) => {
await page.goto(
`/wp-admin/admin.php?page=wc-orders&action=edit&id=${ orderId }`
);
// assert that there is a coupon on the order
await expect(
page
.locator( '#woocommerce-order-items li' )
.filter( { hasText: couponCode } )
).toBeVisible();
await expect(
page.getByRole( 'cell', { name: 'Coupon(s)' } )
).toBeVisible();
await expect(
page.getByRole( 'cell', {
name: `- $${ couponAmount }.00`,
} )
).toBeVisible();
await expect(
page.getByRole( 'cell', {
name: `$${ discountedPrice }`,
exact: true,
} )
).toBeVisible();
// remove the coupon
await page
.locator( 'a.remove-coupon' )
.dispatchEvent( 'click' ); // have to use dispatchEvent because nothing visible to click on

// make sure the coupon was removed
await expect(
page.locator( '.wc_coupon_list li', { hasText: couponCode } )
).toBeHidden();
await expect(
page
.getByRole( 'cell', { name: `$${ productPrice }` } )
.nth( 1 )
).toBeVisible();
} );
// make sure the coupon was removed
await expect(
page.locator( '.wc_coupon_list li', {
hasText: couponCode,
} )
).toBeHidden();
await expect(
page
.getByRole( 'cell', { name: `$${ productPrice }` } )
.nth( 1 )
).toBeVisible();
}
);
}
);
181 changes: 89 additions & 92 deletions plugins/woocommerce/tests/e2e-pw/tests/merchant/order-emails.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,63 @@ test.describe(
} );
} );

test( 'can receive new order email', async ( { page, baseURL } ) => {
// New order emails are sent automatically when we create a simple order. Verify that we get these.
// Need to create a new order for this test because we clear logs before each run.
const api = new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc/v3',
} );
await api
.post( 'orders', {
status: 'processing',
billing: customerBilling,
} )
.then( ( response ) => {
newOrderId = response.data.id;
} );
// search to narrow it down to just the messages we want
await page.goto(
`/wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent(
customerBilling.email
) }`
);
await expect(
page.locator( 'td.column-receiver >> nth=1' )
).toContainText( admin.email );
await expect(
page.locator( 'td.column-subject >> nth=1' )
).toContainText( `[${ storeName }]: New order #${ newOrderId }` );

// look at order email contents
await page
.getByRole( 'button', { name: 'View log' } )
.last()
.click();

await expect(
page.getByText( `Receiver ${ admin.email }` )
).toBeVisible();
await expect(
page.getByText( 'Subject [WooCommerce Core E2E' )
).toBeVisible();
await page.getByRole( 'link', { name: 'json' } ).click();
await expect(
page.locator( '#wp-mail-logging-modal-content-body-content' )
).toContainText( 'You’ve received the following order from :' );
} );

test(
'can receive new order email',
{ tag: '@skip-on-default-pressable' },
'can receive completed email',
{ tag: '@skip-on-default-wpcom' },
async ( { page, baseURL } ) => {
// New order emails are sent automatically when we create a simple order. Verify that we get these.
// Need to create a new order for this test because we clear logs before each run.
// Completed order emails are sent automatically when an order's payment is completed.
// Verify that the email is sent, and that the content is the expected one
const emailContent =
'#wp-mail-logging-modal-content-body-content';
const emailContentJson = '#wp-mail-logging-modal-format-json';
const api = new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
Expand All @@ -85,111 +136,57 @@ test.describe(
} );
await api
.post( 'orders', {
status: 'processing',
status: 'completed',
billing: customerBilling,
} )
.then( ( response ) => {
newOrderId = response.data.id;
completedOrderId = response.data.id;
} );
// search to narrow it down to just the messages we want
// Search to narrow it down to just the messages we want
await page.goto(
`/wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent(
`wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent(
customerBilling.email
) }`
);
await expect(
page.locator( 'td.column-receiver >> nth=1' )
).toContainText( admin.email );
await expect(
page.locator( 'td.column-subject >> nth=1' )
).toContainText(
`[${ storeName }]: New order #${ newOrderId }`
await page.selectOption(
'select[name="search[place]"]',
'subject'
);
await page.fill( 'input[name="search[term]"]', 'complete' );
await page.click( 'input#search-submit' );

// look at order email contents
await page
.getByRole( 'button', { name: 'View log' } )
.last()
.click();

await expect(
page.getByText( 'Receiver wordpress@example.com' )
).toBeVisible();
await expect(
page.getByText( 'Subject [WooCommerce Core E2E' )
).toBeVisible();
await page.getByRole( 'link', { name: 'json' } ).click();
// Verify that the email has been sent
await expect(
page.locator(
'#wp-mail-logging-modal-content-body-content'
page.getByText(
`Your ${ storeName } order is now complete`
)
).toContainText(
'You’ve received the following order from :'
);
}
);

test( 'can receive completed email', async ( { page, baseURL } ) => {
// Completed order emails are sent automatically when an order's payment is completed.
// Verify that the email is sent, and that the content is the expected one
const emailContent = '#wp-mail-logging-modal-content-body-content';
const emailContentJson = '#wp-mail-logging-modal-format-json';
const api = new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc/v3',
} );
await api
.post( 'orders', {
status: 'completed',
billing: customerBilling,
} )
.then( ( response ) => {
completedOrderId = response.data.id;
} );
// Search to narrow it down to just the messages we want
await page.goto(
`wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent(
customerBilling.email
) }`
);
await page.selectOption(
'select[name="search[place]"]',
'subject'
);
await page.fill( 'input[name="search[term]"]', 'complete' );
await page.click( 'input#search-submit' );

// Verify that the email has been sent
await expect(
page.getByText( `Your ${ storeName } order is now complete` )
).toBeVisible();
).toBeVisible();

// Enter email log and select to view the content in JSON
await page.click( 'button[title^="View log"]' );
await page.locator( emailContentJson ).click();
// Enter email log and select to view the content in JSON
await page.click( 'button[title^="View log"]' );
await page.locator( emailContentJson ).click();

// Verify that the message includes an order processing confirmation
await expect( page.locator( emailContent ) ).toContainText(
'We have finished processing your order.'
);
// Verify that the message includes an order processing confirmation
await expect( page.locator( emailContent ) ).toContainText(
'We have finished processing your order.'
);

// Verify that the email address is the correct one
await expect( page.locator( emailContent ) ).toContainText(
customerBilling.email
);
// Verify that the email address is the correct one
await expect( page.locator( emailContent ) ).toContainText(
customerBilling.email
);

// Verify that the email contains the order ID
await expect( page.locator( emailContent ) ).toContainText(
`[Order #${ completedOrderId.toString() }]`
);
// Verify that the email contains the order ID
await expect( page.locator( emailContent ) ).toContainText(
`[Order #${ completedOrderId.toString() }]`
);

// Verify that the email contains a "Thanks" note
await expect( page.locator( emailContent ) ).toContainText(
'Thanks for shopping with us'
);
} );
// Verify that the email contains a "Thanks" note
await expect( page.locator( emailContent ) ).toContainText(
'Thanks for shopping with us'
);
}
);

test( 'can receive cancelled order email', async ( {
page,
Expand Down
46 changes: 24 additions & 22 deletions plugins/woocommerce/tests/e2e-pw/tests/merchant/page-loads.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ const wcPages = [
{
name: 'Overview',
heading: 'Overview',
element: '.woocommerce-marketing-card-header-description',
text: 'Start by adding a channel to your store',
element: '.woocommerce-marketing-channels-card',
text: 'Channels',
},
{
name: 'Coupons',
Expand Down Expand Up @@ -201,29 +201,31 @@ for ( const currentPage of wcPages ) {
} );

for ( let i = 0; i < currentPage.subpages.length; i++ ) {
test( `Can load ${ currentPage.subpages[ i ].name }`, async ( {
page,
} ) => {
await page
.locator(
`li.wp-menu-open > ul.wp-submenu > li a:text-is("${ currentPage.subpages[ i ].name }")`
)
.click();
test(
`Can load ${ currentPage.subpages[ i ].name }`,
{ tag: '@skip-on-default-wpcom' },
async ( { page } ) => {
await page
.locator(
`li.wp-menu-open > ul.wp-submenu > li a:text-is("${ currentPage.subpages[ i ].name }")`
)
.click();

await expect(
page.locator( 'h1.components-text' )
).toContainText( currentPage.subpages[ i ].heading );
await expect(
page.locator( 'h1.components-text' )
).toContainText( currentPage.subpages[ i ].heading );

await expect(
page
.locator( currentPage.subpages[ i ].element )
.first()
).toBeVisible();
await expect(
page
.locator( currentPage.subpages[ i ].element )
.first()
).toBeVisible();

await expect(
page.locator( currentPage.subpages[ i ].element )
).toContainText( currentPage.subpages[ i ].text );
} );
await expect(
page.locator( currentPage.subpages[ i ].element )
).toContainText( currentPage.subpages[ i ].text );
}
);
}
}
);
Expand Down
Loading

0 comments on commit 9c514b3

Please sign in to comment.