Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid duplicate templates appearing on the Site Editor when the WooCo…
…mmerce template and the theme template have been customized by the user (#44000) * Avoid duplicate templates appearing on the Site Editor when the WooCommerce template and the theme template have been customized by the user * Add tests * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Clean up templates after running all tests to increase speed * Fix comment linting * Fix addToCart() util with the classic template * Remove unnecessary condition --------- Co-authored-by: github-actions <github-actions@github.com>
- Loading branch information
Showing
9 changed files
with
324 additions
and
4 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
plugins/woocommerce-blocks/tests/e2e/tests/templates/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { Page, Response } from '@playwright/test'; | ||
import type { FrontendUtils } from '@woocommerce/e2e-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { SIMPLE_VIRTUAL_PRODUCT_NAME } from '../checkout/constants'; | ||
import { CheckoutPage } from '../checkout/checkout.page'; | ||
|
||
type TemplateCustomizationTest = { | ||
visitPage: ( props: { | ||
frontendUtils: FrontendUtils; | ||
page: Page; | ||
} ) => Promise< void | Response | null >; | ||
templateName: string; | ||
templatePath: string; | ||
templateType: string; | ||
defaultTemplate?: { | ||
templateName: string; | ||
templatePath: string; | ||
}; | ||
}; | ||
|
||
export const CUSTOMIZABLE_WC_TEMPLATES: TemplateCustomizationTest[] = [ | ||
{ | ||
visitPage: async ( { frontendUtils } ) => | ||
await frontendUtils.goToShop(), | ||
templateName: 'Product Catalog', | ||
templatePath: 'archive-product', | ||
templateType: 'wp_template', | ||
}, | ||
{ | ||
visitPage: async ( { page } ) => | ||
await page.goto( '/?s=shirt&post_type=product' ), | ||
templateName: 'Product Search Results', | ||
templatePath: 'product-search-results', | ||
templateType: 'wp_template', | ||
}, | ||
{ | ||
visitPage: async ( { page } ) => await page.goto( '/color/blue' ), | ||
templateName: 'Products by Attribute', | ||
templatePath: 'taxonomy-product_attribute', | ||
templateType: 'wp_template', | ||
}, | ||
{ | ||
visitPage: async ( { page } ) => | ||
await page.goto( '/product-category/clothing' ), | ||
templateName: 'Products by Category', | ||
templatePath: 'taxonomy-product_cat', | ||
templateType: 'wp_template', | ||
}, | ||
{ | ||
visitPage: async ( { page } ) => | ||
await page.goto( '/product-tag/recommended/' ), | ||
templateName: 'Products by Tag', | ||
templatePath: 'taxonomy-product_tag', | ||
templateType: 'wp_template', | ||
}, | ||
{ | ||
visitPage: async ( { page } ) => await page.goto( '/product/hoodie' ), | ||
templateName: 'Single Product', | ||
templatePath: 'single-product', | ||
templateType: 'wp_template', | ||
}, | ||
{ | ||
visitPage: async ( { frontendUtils } ) => | ||
await frontendUtils.goToCart(), | ||
templateName: 'Page: Cart', | ||
templatePath: 'page-cart', | ||
templateType: 'wp_template', | ||
}, | ||
{ | ||
visitPage: async ( { frontendUtils } ) => { | ||
await frontendUtils.goToShop(); | ||
await frontendUtils.addToCart(); | ||
await frontendUtils.goToCheckout(); | ||
}, | ||
templateName: 'Page: Checkout', | ||
templatePath: 'page-checkout', | ||
templateType: 'wp_template', | ||
}, | ||
{ | ||
visitPage: async ( { frontendUtils, page } ) => { | ||
const checkoutPage = new CheckoutPage( { page } ); | ||
await frontendUtils.goToShop(); | ||
await frontendUtils.addToCart( SIMPLE_VIRTUAL_PRODUCT_NAME ); | ||
await frontendUtils.goToCheckout(); | ||
await checkoutPage.fillInCheckoutWithTestData(); | ||
await checkoutPage.placeOrder(); | ||
}, | ||
templateName: 'Order Confirmation', | ||
templatePath: 'order-confirmation', | ||
templateType: 'wp_template', | ||
}, | ||
]; | ||
|
||
export const WC_TEMPLATES_SLUG = 'woocommerce/woocommerce'; |
93 changes: 93 additions & 0 deletions
93
...-blocks/tests/e2e/tests/templates/template-customization.block_theme.side_effects.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test, expect } from '@woocommerce/e2e-playwright-utils'; | ||
import { deleteAllTemplates } from '@wordpress/e2e-test-utils'; | ||
import { | ||
BLOCK_THEME_SLUG, | ||
BLOCK_THEME_WITH_TEMPLATES_SLUG, | ||
cli, | ||
} from '@woocommerce/e2e-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { CUSTOMIZABLE_WC_TEMPLATES, WC_TEMPLATES_SLUG } from './constants'; | ||
|
||
const userText = 'Hello World in the template'; | ||
const woocommerceTemplateUserText = 'Hello World in the WooCommerce template'; | ||
|
||
CUSTOMIZABLE_WC_TEMPLATES.forEach( ( testData ) => { | ||
test.describe( `${ testData.templateName } template`, async () => { | ||
test.afterAll( async () => { | ||
await deleteAllTemplates( 'wp_template' ); | ||
} ); | ||
|
||
test( `user-modified ${ testData.templateName } template based on the theme template has priority over the user-modified template based on the default WooCommerce template`, async ( { | ||
admin, | ||
frontendUtils, | ||
editorUtils, | ||
page, | ||
} ) => { | ||
// Edit the WooCommerce default template | ||
await admin.visitSiteEditor( { | ||
postId: `${ WC_TEMPLATES_SLUG }//${ testData.templatePath }`, | ||
postType: testData.templateType, | ||
} ); | ||
await editorUtils.enterEditMode(); | ||
await editorUtils.closeWelcomeGuideModal(); | ||
await editorUtils.editor.insertBlock( { | ||
name: 'core/paragraph', | ||
attributes: { content: woocommerceTemplateUserText }, | ||
} ); | ||
await editorUtils.saveTemplate(); | ||
|
||
await cli( | ||
`npm run wp-env run tests-cli -- wp theme activate ${ BLOCK_THEME_WITH_TEMPLATES_SLUG }` | ||
); | ||
|
||
// Edit the theme template. | ||
await admin.visitSiteEditor( { | ||
postId: `${ BLOCK_THEME_WITH_TEMPLATES_SLUG }//${ testData.templatePath }`, | ||
postType: testData.templateType, | ||
} ); | ||
await editorUtils.enterEditMode(); | ||
await editorUtils.closeWelcomeGuideModal(); | ||
await editorUtils.editor.insertBlock( { | ||
name: 'core/paragraph', | ||
attributes: { content: userText }, | ||
} ); | ||
await editorUtils.saveTemplate(); | ||
|
||
// Verify the template is the one modified by the user based on the theme. | ||
await testData.visitPage( { frontendUtils, page } ); | ||
await expect( page.getByText( userText ).first() ).toBeVisible(); | ||
await expect( | ||
page.getByText( woocommerceTemplateUserText ) | ||
).toHaveCount( 0 ); | ||
|
||
// Revert edition and verify the user-modified WC template is used. | ||
// Note: we need to revert it from the admin (instead of calling | ||
// `deleteAllTemplates()`). This way, we verify there are no | ||
// duplicate templates with the same name. | ||
// See: https://github.com/woocommerce/woocommerce/issues/42220 | ||
await admin.visitAdminPage( | ||
'site-editor.php', | ||
`path=/${ testData.templateType }/all` | ||
); | ||
await editorUtils.revertTemplateCustomizations( | ||
testData.templateName | ||
); | ||
await testData.visitPage( { frontendUtils, page } ); | ||
|
||
await expect( | ||
page.getByText( woocommerceTemplateUserText ).first() | ||
).toBeVisible(); | ||
await expect( page.getByText( userText ) ).toHaveCount( 0 ); | ||
|
||
await cli( | ||
`npm run wp-env run tests-cli -- wp theme activate ${ BLOCK_THEME_SLUG }` | ||
); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...merce-blocks/tests/mocks/theme-with-woo-templates/block-templates/order-confirmation.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!-- wp:template-part {"slug":"header"} /--> | ||
|
||
<!-- wp:paragraph --> | ||
<p>Order Confirmation template loaded from theme</p> | ||
<!-- /wp:paragraph --> | ||
|
||
<!-- wp:group {"tagName":"main","layout":{"inherit":true,"type":"constrained"}} --> | ||
<main class="wp-block-group"><!-- wp:woocommerce/order-confirmation-status {"fontSize":"large"} /--> | ||
|
||
<!-- wp:woocommerce/order-confirmation-summary /--> | ||
|
||
<!-- wp:woocommerce/order-confirmation-totals-wrapper {"align":"wide"} --> | ||
<!-- wp:pattern {"slug":"woocommerce/order-confirmation-totals-heading"} /--> | ||
|
||
<!-- wp:woocommerce/order-confirmation-totals {"lock":{"remove":true}} /--> | ||
<!-- /wp:woocommerce/order-confirmation-totals-wrapper --> | ||
|
||
<!-- wp:woocommerce/order-confirmation-downloads-wrapper {"align":"wide"} --> | ||
<!-- wp:pattern {"slug":"woocommerce/order-confirmation-downloads-heading"} /--> | ||
|
||
<!-- wp:woocommerce/order-confirmation-downloads {"lock":{"remove":true}} /--> | ||
<!-- /wp:woocommerce/order-confirmation-downloads-wrapper --> | ||
|
||
<!-- wp:columns {"align":"wide","className":"woocommerce-order-confirmation-address-wrapper"} --> | ||
<div class="wp-block-columns alignwide woocommerce-order-confirmation-address-wrapper"> | ||
<!-- wp:column --> | ||
<div class="wp-block-column"> | ||
<!-- wp:woocommerce/order-confirmation-shipping-wrapper {"align":"wide"} --> | ||
<!-- wp:pattern {"slug":"woocommerce/order-confirmation-shipping-heading"} /--> | ||
|
||
<!-- wp:woocommerce/order-confirmation-shipping-address {"lock":{"remove":true}} /--> | ||
<!-- /wp:woocommerce/order-confirmation-shipping-wrapper --> | ||
</div> | ||
<!-- /wp:column --> | ||
|
||
<!-- wp:column --> | ||
<div class="wp-block-column"> | ||
<!-- wp:woocommerce/order-confirmation-billing-wrapper {"align":"wide"} --> | ||
<!-- wp:pattern {"slug":"woocommerce/order-confirmation-billing-heading"} /--> | ||
|
||
<!-- wp:woocommerce/order-confirmation-billing-address {"lock":{"remove":true}} /--> | ||
<!-- /wp:woocommerce/order-confirmation-billing-wrapper --> | ||
</div> | ||
<!-- /wp:column --> | ||
</div> | ||
<!-- /wp:columns --> | ||
|
||
<!-- wp:woocommerce/order-confirmation-additional-fields-wrapper {"align":"wide"} --> | ||
<!-- wp:pattern {"slug":"woocommerce/order-confirmation-additional-fields-heading"} /--> | ||
<!-- wp:woocommerce/order-confirmation-additional-fields /--> | ||
<!-- /wp:woocommerce/order-confirmation-additional-fields-wrapper --> | ||
|
||
<!-- wp:woocommerce/order-confirmation-additional-information /--> | ||
</main> | ||
<!-- /wp:group --> | ||
|
||
<!-- wp:template-part {"slug":"footer"} /--> |
13 changes: 13 additions & 0 deletions
13
...ns/woocommerce-blocks/tests/mocks/theme-with-woo-templates/block-templates/page-cart.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- wp:template-part {"slug":"header","tagName":"header"} /--> | ||
<!-- wp:paragraph --> | ||
<p>Page: Cart template loaded from theme</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:woocommerce/page-content-wrapper {"page":"cart"} --> | ||
<!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} --> | ||
<main class="wp-block-group"> | ||
<!-- wp:post-title {"align":"wide", "level":1} /--> | ||
<!-- wp:post-content {"align":"wide"} /--> | ||
</main> | ||
<!-- /wp:group --> | ||
<!-- /wp:woocommerce/page-content-wrapper --> | ||
<!-- wp:template-part {"slug":"footer","tagName":"footer"} /--> |
12 changes: 12 additions & 0 deletions
12
...oocommerce-blocks/tests/mocks/theme-with-woo-templates/block-templates/page-checkout.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!-- wp:template-part {"slug":"checkout-header","theme":"woocommerce/woocommerce","tagName":"header"} /--> | ||
<!-- wp:paragraph --> | ||
<p>Page: Checkout template loaded from theme</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:woocommerce/page-content-wrapper {"page":"checkout"} --> | ||
<!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} --> | ||
<main class="wp-block-group"> | ||
<!-- wp:post-title {"align":"wide", "level":1} /--> | ||
<!-- wp:post-content {"align":"wide"} /--> | ||
</main> | ||
<!-- /wp:group --> | ||
<!-- /wp:woocommerce/page-content-wrapper --> |
4 changes: 4 additions & 0 deletions
4
plugins/woocommerce/changelog/44000-fix-42220-duplicate-templates-when-both-modified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fix | ||
|
||
Avoid duplicate templates appearing on the Site Editor when the WooCommerce template and the theme template have been customized by the user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters