-
Notifications
You must be signed in to change notification settings - Fork 221
e2e tests for cart and checkout templates #9939
Changes from 17 commits
ae73afe
047a42b
f79b42b
f001917
8186549
f88c03b
e861c1c
dbc2171
efb2b52
89ac75c
97ef316
e37bbd4
0f9893c
12c7119
314b844
1ae9926
790b53f
87f9259
98d88cd
df350d1
2cdad1e
7de932e
4fbdbbe
6623b3c
9587ed4
45b2949
d51966e
8e8856a
0ae69cd
1b02c07
41f1f8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test, expect } from '@woocommerce/e2e-playwright-utils'; | ||
import { cli } from '@woocommerce/e2e-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { goToShop, addToCart } from '../../utils'; | ||
|
||
test.describe( | ||
'Tests permalink settings for the cart and checkout templates', | ||
async () => { | ||
test.afterAll( async () => { | ||
await cli( | ||
'npm run wp-env run tests-cli "wp option update woocommerce_cart_page_endpoint cart"' | ||
); | ||
await cli( | ||
'npm run wp-env run tests-cli "wp option update woocommerce_checkout_page_endpoint checkout"' | ||
); | ||
} ); | ||
|
||
test.describe( 'Settings page', () => { | ||
test( 'Load advanced settings', async ( { page } ) => { | ||
await page.goto( | ||
'/wp-admin/admin.php?page=wc-settings&tab=advanced' | ||
); | ||
const title = page | ||
.locator( 'div.wrap.woocommerce > form > h2' ) | ||
.first(); | ||
await expect( title ).toHaveText( 'Page setup' ); | ||
} ); | ||
test( 'Permlink settings exist', async ( { page } ) => { | ||
await page.goto( | ||
'/wp-admin/admin.php?page=wc-settings&tab=advanced' | ||
); | ||
const cartInput = page.locator( | ||
'tr:has-text("Cart page "):has-text("cart template") input' | ||
); | ||
const checkoutInput = page.locator( | ||
'tr:has-text("Checkout page "):has-text("checkout template") input' | ||
); | ||
|
||
await expect( cartInput ).toBeVisible(); | ||
await expect( checkoutInput ).toBeVisible(); | ||
} ); | ||
} ); | ||
|
||
test.describe( 'Frontend templates are updated', () => { | ||
test.beforeEach( async ( { page } ) => { | ||
await goToShop( page ); | ||
await addToCart( page ); | ||
} ); | ||
|
||
test( 'Changing cart permalink works', async ( { page } ) => { | ||
await page.goto( | ||
'/wp-admin/admin.php?page=wc-settings&tab=advanced' | ||
); | ||
const cartInput = page.locator( | ||
'tr:has-text("Cart page "):has-text("cart template") input' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting that I would love to revisit this and use the provided locators in future. For now this is OK to get tests working. |
||
); | ||
cartInput.fill( 'updated-cart-permalink' ); | ||
await page.click( 'button[name="save"]' ); | ||
await page.waitForLoadState( 'networkidle' ); | ||
|
||
// Visit the updated page. | ||
await page.goto( '/updated-cart-permalink' ); | ||
const cartText = await page.getByText( 'Proceed to checkout' ); | ||
expect( cartText ).toBeVisible(); | ||
} ); | ||
|
||
test( 'Changing checkout permalink works', async ( { page } ) => { | ||
await page.goto( | ||
'/wp-admin/admin.php?page=wc-settings&tab=advanced' | ||
); | ||
const checkoutInput = page.locator( | ||
'tr:has-text("Checkout page "):has-text("checkout template") input' | ||
); | ||
checkoutInput.fill( 'updated-checkout-permalink' ); | ||
await page.click( 'button[name="save"]' ); | ||
await page.waitForLoadState( 'networkidle' ); | ||
|
||
// Visit the updated page. | ||
await page.goto( '/updated-checkout-permalink' ); | ||
const cartText = await page.getByText( 'Place Order' ); | ||
expect( cartText ).toBeVisible(); | ||
} ); | ||
} ); | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test, expect } from '@woocommerce/e2e-playwright-utils'; | ||
|
||
const permalink = '/cart'; | ||
const templatePath = 'woocommerce/woocommerce//cart'; | ||
const templateType = 'wp_template'; | ||
|
||
test.describe( 'Test the cart template', async () => { | ||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.deleteAllTemplates( 'wp_template' ); | ||
await requestUtils.deleteAllTemplates( 'wp_template_part' ); | ||
} ); | ||
|
||
test( 'Template can be opened in the site editor', async ( { page } ) => { | ||
await page.goto( '/wp-admin/site-editor.php' ); | ||
await page.click( 'text=Templates' ); | ||
await page.click( 'text=Cart' ); | ||
await page.getByRole( 'button', { name: /Edit/i } ).click(); | ||
|
||
await expect( | ||
page | ||
.frameLocator( 'iFrame' ) | ||
.locator( 'button:has-text("Proceed to checkout")' ) | ||
.first() | ||
).toBeVisible(); | ||
} ); | ||
|
||
test( 'Template can be modified', async ( { page, admin, editor } ) => { | ||
await admin.visitSiteEditor( { | ||
postId: templatePath, | ||
postType: templateType, | ||
} ); | ||
await editor.canvas.click( 'body' ); | ||
await editor.canvas.waitForLoadState( 'networkidle' ); | ||
await editor.insertBlock( { | ||
name: 'core/paragraph', | ||
attributes: { content: 'Hello World' }, | ||
} ); | ||
await editor.saveSiteEditorEntities(); | ||
await page.goto( permalink ); | ||
|
||
await expect( page.getByText( 'Hello World' ).first() ).toBeVisible(); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test, expect } from '@woocommerce/e2e-playwright-utils'; | ||
|
||
const permalink = '/checkout'; | ||
const templatePath = 'woocommerce/woocommerce//checkout-header'; | ||
const templateType = 'wp_template_part'; | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.deleteAllTemplates( 'wp_template' ); | ||
await requestUtils.deleteAllTemplates( 'wp_template_part' ); | ||
} ); | ||
|
||
test.describe( 'Test the checkout header template part', async () => { | ||
test( 'Template can be opened in the site editor', async ( { page } ) => { | ||
await page.goto( '/wp-admin/site-editor.php' ); | ||
await page.click( 'text=Template Parts' ); | ||
await page.click( 'text=Checkout Header' ); | ||
|
||
const editButton = page.getByRole( 'button', { name: /Edit/i } ); | ||
await expect( editButton ).toBeVisible(); | ||
} ); | ||
|
||
test( 'Template can be modified', async ( { page, admin, editor } ) => { | ||
await admin.visitSiteEditor( { | ||
postId: templatePath, | ||
postType: templateType, | ||
} ); | ||
await editor.canvas.click( 'body' ); | ||
await editor.canvas.waitForLoadState( 'networkidle' ); | ||
await editor.insertBlock( { | ||
name: 'core/paragraph', | ||
attributes: { content: 'Hello World' }, | ||
} ); | ||
await editor.saveSiteEditorEntities(); | ||
|
||
await page.goto( permalink ); | ||
|
||
await expect( page.getByText( 'Hello World' ).first() ).toBeVisible(); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test, expect } from '@woocommerce/e2e-playwright-utils'; | ||
|
||
const permalink = '/checkout'; | ||
const templatePath = 'woocommerce/woocommerce//checkout'; | ||
const templateType = 'wp_template'; | ||
|
||
test.describe( 'Test the checkout template', async () => { | ||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.deleteAllTemplates( 'wp_template' ); | ||
await requestUtils.deleteAllTemplates( 'wp_template_part' ); | ||
} ); | ||
|
||
test( 'Template can be opened in the site editor', async ( { page } ) => { | ||
await page.goto( '/wp-admin/site-editor.php' ); | ||
await page.click( 'text=Templates' ); | ||
await page.click( 'text=Checkout' ); | ||
await page.getByRole( 'button', { name: /Edit/i } ).click(); | ||
|
||
await expect( | ||
page | ||
.frameLocator( 'iFrame' ) | ||
.locator( 'button:has-text("Place order")' ) | ||
.first() | ||
).toBeVisible(); | ||
} ); | ||
|
||
test( 'Template can be modified', async ( { page, admin, editor } ) => { | ||
await admin.visitSiteEditor( { | ||
postId: templatePath, | ||
postType: templateType, | ||
} ); | ||
await editor.canvas.click( 'body' ); | ||
await editor.canvas.waitForLoadState( 'networkidle' ); | ||
await editor.insertBlock( { | ||
name: 'core/paragraph', | ||
attributes: { content: 'Hello World' }, | ||
} ); | ||
await editor.saveSiteEditorEntities(); | ||
await page.goto( permalink ); | ||
|
||
await expect( page.getByText( 'Hello World' ).first() ).toBeVisible(); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test, expect } from '@woocommerce/e2e-playwright-utils'; | ||
|
||
const permalink = '/checkout/order-received'; | ||
const templatePath = 'woocommerce/woocommerce//order-confirmation'; | ||
const templateType = 'wp_template'; | ||
|
||
test.describe( 'Test the order confirmation template', async () => { | ||
test( 'Template can be opened in the site editor', async ( { page } ) => { | ||
await page.goto( '/wp-admin/site-editor.php' ); | ||
await page.click( 'text=Templates' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We could do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It says "discouraged"—is that the same thing? I've copied usage from other tests and the global-setup file. I'd rather leave it as I'm just trying to get new tests added rather than update our playwright implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah you're right, sorry I misread it as deprecated, I'm so used to seeing that in yellow boxes in documentation 🙈 I am ok with it being left like this for now if updating it is going to delay this PR being merged. I would like to revisit at some point though. |
||
await page.click( 'text=Order confirmation' ); | ||
await page.getByRole( 'button', { name: /Edit/i } ).click(); | ||
|
||
await expect( | ||
page | ||
.frameLocator( 'iFrame' ) | ||
.locator( | ||
'p:has-text("Thank you. Your order has been received.")' | ||
) | ||
.first() | ||
).toBeVisible(); | ||
} ); | ||
|
||
test( 'Template can be modified', async ( { page, admin, editor } ) => { | ||
await admin.visitSiteEditor( { | ||
postId: templatePath, | ||
postType: templateType, | ||
} ); | ||
await editor.canvas.click( 'body' ); | ||
await editor.canvas.waitForLoadState( 'networkidle' ); | ||
await editor.insertBlock( { | ||
name: 'core/paragraph', | ||
attributes: { content: 'Hello World' }, | ||
} ); | ||
await editor.saveSiteEditorEntities(); | ||
await page.goto( permalink ); | ||
|
||
await expect( page.getByText( 'Hello World' ).first() ).toBeVisible(); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Page } from '@playwright/test'; | ||
|
||
export const addToCart = async ( page: Page ) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing actionable here, but I just pointing out that we could probably add product name as an arg here too. Thinking about when we're on the shop page and we call this, it would fail because of multiple add to cart buttons, so if we add a product name we could call by the button's label:
|
||
await page.click( 'text=Add to cart' ); | ||
await page.waitForLoadState( 'networkidle' ); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Page } from '@playwright/test'; | ||
|
||
// Navigate to the shop page. | ||
export const goToShop = ( page: Page ) => { | ||
page.goto( '/shop', { | ||
waitUntil: 'networkidle', | ||
} ); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './get-block-by-name'; | ||
export * from './go-to-shop'; | ||
export * from './add-to-cart'; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug!
getByText
returns arrays