diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/mini-cart-template-part.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/mini-cart-template-part.block_theme.spec.ts index be777b5382c..e78049f638a 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/mini-cart-template-part.block_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/mini-cart-template-part.block_theme.spec.ts @@ -40,7 +40,7 @@ test.describe( 'Mini-Cart template part', async () => { await editorUtils.saveTemplate(); await page.goto( testData.permalink ); - await page.getByLabel( 'Add to cart' ).first().click(); + await frontendUtils.addToCart(); let block = await frontendUtils.getBlockByName( testData.miniCartBlockName ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/mini-cart-template-part.block_theme_with_templates.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/mini-cart-template-part.block_theme_with_templates.spec.ts index 5678635f3f8..10018cafab4 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/mini-cart-template-part.block_theme_with_templates.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/mini-cart-template-part.block_theme_with_templates.spec.ts @@ -41,7 +41,7 @@ test.describe( 'Mini-Cart template part', async () => { await editorUtils.saveTemplate(); await page.goto( testData.permalink ); - await page.getByLabel( 'Add to cart' ).first().click(); + await frontendUtils.addToCart(); let block = await frontendUtils.getBlockByName( testData.miniCartBlockName ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/product-catalog-template.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/product-catalog-template.block_theme.spec.ts deleted file mode 100644 index 68fff07a5a0..00000000000 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/product-catalog-template.block_theme.spec.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * External dependencies - */ -import { test, expect } from '@woocommerce/e2e-playwright-utils'; - -const permalink = '/shop'; -const templateName = 'Product Catalog'; -const templatePath = 'woocommerce/woocommerce//archive-product'; -const templateType = 'wp_template'; -const userText = 'Hello World in the template'; - -test.describe( 'Product Catalog template', async () => { - test( 'can be modified and reverted', async ( { - admin, - editorUtils, - page, - } ) => { - // Verify the template can be edited. - await admin.visitSiteEditor( { - postId: templatePath, - postType: templateType, - } ); - await editorUtils.enterEditMode(); - await editorUtils.closeWelcomeGuideModal(); - await editorUtils.editor.insertBlock( { - name: 'core/paragraph', - attributes: { content: userText }, - } ); - await editorUtils.saveTemplate(); - await page.goto( permalink ); - await expect( page.getByText( userText ).first() ).toBeVisible(); - - // Verify the edition can be reverted. - await admin.visitAdminPage( - 'site-editor.php', - `path=/${ templateType }/all` - ); - await editorUtils.revertTemplateCustomizations( templateName ); - await page.goto( permalink ); - - await expect( page.getByText( userText ) ).toHaveCount( 0 ); - } ); -} ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/product-search-results-template.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/product-search-results-template.block_theme.spec.ts deleted file mode 100644 index de30ea92b79..00000000000 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/product-search-results-template.block_theme.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -/** - * External dependencies - */ -import { test, expect } from '@woocommerce/e2e-playwright-utils'; - -const permalink = '/?s=shirt&post_type=product'; -const templateName = 'Product Search Results'; -const templatePath = 'woocommerce/woocommerce//product-search-results'; -const templateType = 'wp_template'; -const userText = 'Hello World in the template'; - -test.describe( 'Product Search Results template', async () => { - test( 'can be modified and reverted', async ( { - admin, - editorUtils, - page, - } ) => { - // Verify the template can be edited. - await admin.visitSiteEditor( { - postId: templatePath, - postType: templateType, - } ); - await editorUtils.enterEditMode(); - await editorUtils.closeWelcomeGuideModal(); - await editorUtils.editor.insertBlock( { - name: 'core/paragraph', - attributes: { content: userText }, - } ); - await editorUtils.saveTemplate(); - await page.goto( permalink ); - await expect( page.getByText( userText ).first() ).toBeVisible(); - - // Verify the edition can be reverted. - await admin.visitAdminPage( - 'site-editor.php', - `path=/${ templateType }/all` - ); - await editorUtils.revertTemplateCustomizations( templateName ); - await page.goto( permalink ); - await expect( page.getByText( userText ) ).toHaveCount( 0 ); - } ); -} ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/products-by-attribute-template.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/products-by-attribute-template.block_theme.spec.ts deleted file mode 100644 index 16b73a86712..00000000000 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/products-by-attribute-template.block_theme.spec.ts +++ /dev/null @@ -1,79 +0,0 @@ -/** - * External dependencies - */ -import { test, expect } from '@woocommerce/e2e-playwright-utils'; - -const permalink = '/color/blue'; -const templateName = 'Products by Attribute'; -const templatePath = 'woocommerce/woocommerce//taxonomy-product_attribute'; -const templateType = 'wp_template'; -const userText = 'Hello World in the template'; -const userTextInCatalogTemplate = 'Hello World in the Product Catalog template'; - -test.describe( 'Products by Attribute template', async () => { - test( 'can be modified and reverted', async ( { - admin, - editorUtils, - page, - } ) => { - // Verify the template can be edited. - await admin.visitSiteEditor( { - postId: templatePath, - postType: templateType, - } ); - await editorUtils.enterEditMode(); - await editorUtils.closeWelcomeGuideModal(); - await editorUtils.editor.insertBlock( { - name: 'core/paragraph', - attributes: { content: userText }, - } ); - await editorUtils.saveTemplate(); - await page.goto( permalink ); - await expect( page.getByText( userText ).first() ).toBeVisible(); - - // Verify the edition can be reverted. - await admin.visitAdminPage( - 'site-editor.php', - `path=/${ templateType }/all` - ); - await editorUtils.revertTemplateCustomizations( templateName ); - await page.goto( permalink ); - await expect( page.getByText( userText ) ).toHaveCount( 0 ); - } ); - - test( 'defaults to the Product Catalog template', async ( { - admin, - editorUtils, - page, - } ) => { - // Edit Product Catalog template and verify changes are visible. - await admin.visitSiteEditor( { - postId: 'woocommerce/woocommerce//archive-product', - postType: 'wp_template', - } ); - await editorUtils.enterEditMode(); - await editorUtils.closeWelcomeGuideModal(); - await editorUtils.editor.insertBlock( { - name: 'core/paragraph', - attributes: { - content: userTextInCatalogTemplate, - }, - } ); - await editorUtils.saveTemplate(); - await page.goto( permalink ); - await expect( - page.getByText( userTextInCatalogTemplate ).first() - ).toBeVisible(); - - // Verify the edition can be reverted. - await admin.visitAdminPage( - 'site-editor.php', - `path=/wp_template/all` - ); - await editorUtils.revertTemplateCustomizations( 'Product Catalog' ); - await page.goto( permalink ); - await expect( page.getByText( userTextInCatalogTemplate ) ).toHaveCount( - 0 - ); - } ); -} ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/products-by-category-template.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/products-by-category-template.block_theme.spec.ts deleted file mode 100644 index ee4c3ea339a..00000000000 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/products-by-category-template.block_theme.spec.ts +++ /dev/null @@ -1,79 +0,0 @@ -/** - * External dependencies - */ -import { test, expect } from '@woocommerce/e2e-playwright-utils'; - -const permalink = '/product-category/clothing'; -const templateName = 'Products by Category'; -const templatePath = 'woocommerce/woocommerce//taxonomy-product_cat'; -const templateType = 'wp_template'; -const userText = 'Hello World in the template'; -const userTextInCatalogTemplate = 'Hello World in the Product Catalog template'; - -test.describe( 'Products by Category template', async () => { - test( 'can be modified and reverted', async ( { - admin, - editorUtils, - page, - } ) => { - // Verify the template can be edited. - await admin.visitSiteEditor( { - postId: templatePath, - postType: templateType, - } ); - await editorUtils.enterEditMode(); - await editorUtils.closeWelcomeGuideModal(); - await editorUtils.editor.insertBlock( { - name: 'core/paragraph', - attributes: { content: userText }, - } ); - await editorUtils.saveTemplate(); - await page.goto( permalink ); - await expect( page.getByText( userText ).first() ).toBeVisible(); - - // Verify the edition can be reverted. - await admin.visitAdminPage( - 'site-editor.php', - `path=/${ templateType }/all` - ); - await editorUtils.revertTemplateCustomizations( templateName ); - await page.goto( permalink ); - await expect( page.getByText( userText ) ).toHaveCount( 0 ); - } ); - - test( 'defaults to the Product Catalog template', async ( { - admin, - editorUtils, - page, - } ) => { - // Edit Product Catalog template and verify changes are visible. - await admin.visitSiteEditor( { - postId: 'woocommerce/woocommerce//archive-product', - postType: 'wp_template', - } ); - await editorUtils.enterEditMode(); - await editorUtils.closeWelcomeGuideModal(); - await editorUtils.editor.insertBlock( { - name: 'core/paragraph', - attributes: { - content: userTextInCatalogTemplate, - }, - } ); - await editorUtils.saveTemplate(); - await page.goto( permalink ); - await expect( - page.getByText( userTextInCatalogTemplate ).first() - ).toBeVisible(); - - // Verify the edition can be reverted. - await admin.visitAdminPage( - 'site-editor.php', - `path=/wp_template/all` - ); - await editorUtils.revertTemplateCustomizations( 'Product Catalog' ); - await page.goto( permalink ); - await expect( page.getByText( userTextInCatalogTemplate ) ).toHaveCount( - 0 - ); - } ); -} ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/products-by-tag-template.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/products-by-tag-template.block_theme.spec.ts deleted file mode 100644 index 2dd10bd6f0d..00000000000 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/products-by-tag-template.block_theme.spec.ts +++ /dev/null @@ -1,79 +0,0 @@ -/** - * External dependencies - */ -import { test, expect } from '@woocommerce/e2e-playwright-utils'; - -const permalink = '/product-tag/recommended/'; -const templateName = 'Products by Tag'; -const templatePath = 'woocommerce/woocommerce//taxonomy-product_tag'; -const templateType = 'wp_template'; -const userText = 'Hello World in the template'; -const userTextInCatalogTemplate = 'Hello World in the Product Catalog template'; - -test.describe( 'Products by Tag template', async () => { - test( 'can be modified and reverted', async ( { - admin, - editorUtils, - page, - } ) => { - // Verify the template can be edited. - await admin.visitSiteEditor( { - postId: templatePath, - postType: templateType, - } ); - await editorUtils.enterEditMode(); - await editorUtils.closeWelcomeGuideModal(); - await editorUtils.editor.insertBlock( { - name: 'core/paragraph', - attributes: { content: userText }, - } ); - await editorUtils.saveTemplate(); - await page.goto( permalink ); - await expect( page.getByText( userText ).first() ).toBeVisible(); - - // Verify the edition can be reverted. - await admin.visitAdminPage( - 'site-editor.php', - `path=/${ templateType }/all` - ); - await editorUtils.revertTemplateCustomizations( templateName ); - await page.goto( permalink ); - await expect( page.getByText( userText ) ).toHaveCount( 0 ); - } ); - - test( 'defaults to the Product Catalog template', async ( { - admin, - editorUtils, - page, - } ) => { - // Edit Product Catalog template and verify changes are visible. - await admin.visitSiteEditor( { - postId: 'woocommerce/woocommerce//archive-product', - postType: 'wp_template', - } ); - await editorUtils.enterEditMode(); - await editorUtils.closeWelcomeGuideModal(); - await editorUtils.editor.insertBlock( { - name: 'core/paragraph', - attributes: { - content: userTextInCatalogTemplate, - }, - } ); - await editorUtils.saveTemplate(); - await page.goto( permalink ); - await expect( - page.getByText( userTextInCatalogTemplate ).first() - ).toBeVisible(); - - // Verify the edition can be reverted. - await admin.visitAdminPage( - 'site-editor.php', - `path=/wp_template/all` - ); - await editorUtils.revertTemplateCustomizations( 'Product Catalog' ); - await page.goto( permalink ); - await expect( page.getByText( userTextInCatalogTemplate ) ).toHaveCount( - 0 - ); - } ); -} ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/single-product-template.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/single-product-template.block_theme.spec.ts deleted file mode 100644 index e56d55cd9b2..00000000000 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/single-product-template.block_theme.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -/** - * External dependencies - */ -import { test, expect } from '@woocommerce/e2e-playwright-utils'; - -const permalink = '/product/hoodie'; -const templateName = 'Single Product'; -const templatePath = 'woocommerce/woocommerce//single-product'; -const templateType = 'wp_template'; -const userText = 'Hello World in the template'; - -test.describe( 'Single Product template', async () => { - test( 'can be modified and reverted', async ( { - admin, - editorUtils, - page, - } ) => { - // Verify the template can be edited. - await admin.visitSiteEditor( { - postId: templatePath, - postType: templateType, - } ); - await editorUtils.enterEditMode(); - await editorUtils.closeWelcomeGuideModal(); - await editorUtils.editor.insertBlock( { - name: 'core/paragraph', - attributes: { content: userText }, - } ); - await editorUtils.saveTemplate(); - await page.goto( permalink ); - await expect( page.getByText( userText ).first() ).toBeVisible(); - - // Verify the edition can be reverted. - await admin.visitAdminPage( - 'site-editor.php', - `path=/${ templateType }/all` - ); - await editorUtils.revertTemplateCustomizations( templateName ); - await page.goto( permalink ); - await expect( page.getByText( userText ) ).toHaveCount( 0 ); - } ); -} ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-user-customization.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-user-customization.block_theme.spec.ts new file mode 100644 index 00000000000..82a8dcffb9f --- /dev/null +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-user-customization.block_theme.spec.ts @@ -0,0 +1,133 @@ +/** + * External dependencies + */ +import { test, expect } from '@woocommerce/e2e-playwright-utils'; + +const templateUserCustomizationTests = [ + { + permalink: '/shop', + templateName: 'Product Catalog', + templatePath: 'woocommerce/woocommerce//archive-product', + templateType: 'wp_template', + }, + { + permalink: '/?s=shirt&post_type=product', + templateName: 'Product Search Results', + templatePath: 'woocommerce/woocommerce//product-search-results', + templateType: 'wp_template', + }, + { + permalink: '/color/blue', + templateName: 'Products by Attribute', + templatePath: 'woocommerce/woocommerce//taxonomy-product_attribute', + templateType: 'wp_template', + defaultTemplate: { + templateName: 'Product Catalog', + templatePath: 'woocommerce/woocommerce//archive-product', + }, + }, + { + permalink: '/product-category/clothing', + templateName: 'Products by Category', + templatePath: 'woocommerce/woocommerce//taxonomy-product_cat', + templateType: 'wp_template', + defaultTemplate: { + templateName: 'Product Catalog', + templatePath: 'woocommerce/woocommerce//archive-product', + }, + }, + { + permalink: '/product-tag/recommended/', + templateName: 'Products by Tag', + templatePath: 'woocommerce/woocommerce//taxonomy-product_tag', + templateType: 'wp_template', + defaultTemplate: { + templateName: 'Product Catalog', + templatePath: 'woocommerce/woocommerce//archive-product', + }, + }, + { + permalink: '/product/hoodie', + templateName: 'Single Product', + templatePath: 'woocommerce/woocommerce//single-product', + templateType: 'wp_template', + }, +]; +const userText = 'Hello World in the template'; +const defaultTemplateUserText = 'Hello World in the default template'; + +templateUserCustomizationTests.forEach( ( testData ) => { + test.describe( `${ testData.templateName } template`, async () => { + test( 'can be modified and reverted', async ( { + admin, + editorUtils, + page, + } ) => { + // Verify the template can be edited. + await admin.visitSiteEditor( { + postId: testData.templatePath, + postType: testData.templateType, + } ); + await editorUtils.enterEditMode(); + await editorUtils.closeWelcomeGuideModal(); + await editorUtils.editor.insertBlock( { + name: 'core/paragraph', + attributes: { content: userText }, + } ); + await editorUtils.saveTemplate(); + await page.goto( testData.permalink ); + await expect( page.getByText( userText ).first() ).toBeVisible(); + + // Verify the edition can be reverted. + await admin.visitAdminPage( + 'site-editor.php', + `path=/${ testData.templateType }/all` + ); + await editorUtils.revertTemplateCustomizations( + testData.templateName + ); + await page.goto( testData.permalink ); + await expect( page.getByText( userText ) ).toHaveCount( 0 ); + } ); + + if ( testData.defaultTemplate ) { + test( `defaults to the ${ testData.defaultTemplate.templateName } template`, async ( { + admin, + editorUtils, + page, + } ) => { + // Edit default template and verify changes are visible. + await admin.visitSiteEditor( { + postId: testData.defaultTemplate.templatePath, + postType: testData.templateType, + } ); + await editorUtils.enterEditMode(); + await editorUtils.closeWelcomeGuideModal(); + await editorUtils.editor.insertBlock( { + name: 'core/paragraph', + attributes: { + content: defaultTemplateUserText, + }, + } ); + await editorUtils.saveTemplate(); + await page.goto( testData.permalink ); + await expect( + page.getByText( defaultTemplateUserText ).first() + ).toBeVisible(); + + // Verify the edition can be reverted. + await admin.visitAdminPage( + 'site-editor.php', + `path=/${ testData.templateType }/all` + ); + await editorUtils.revertTemplateCustomizations( + testData.defaultTemplate.templateName + ); + await page.goto( testData.permalink ); + await expect( + page.getByText( defaultTemplateUserText ) + ).toHaveCount( 0 ); + } ); + } + } ); +} ); diff --git a/plugins/woocommerce/changelog/43778-update-block-template-tests-parametized b/plugins/woocommerce/changelog/43778-update-block-template-tests-parametized new file mode 100644 index 00000000000..2021de8a223 --- /dev/null +++ b/plugins/woocommerce/changelog/43778-update-block-template-tests-parametized @@ -0,0 +1,4 @@ +Significance: patch +Type: update +Comment: Convert block templates tests to parametized tests +