From dd56a3ba6137edc8494ed764eee0ffbbe897ce07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Thu, 15 Feb 2024 08:17:12 +0100 Subject: [PATCH] Clean up block templates after running e2e tests (#44600) * Clean up block templates after running e2e tests * Add changelog entry * Fix linting --- .../tests/e2e/tests/templates/constants.ts | 2 +- .../templates/single-product-template.block_theme.spec.ts | 4 ++++ ...ingle-product-template.block_theme_with_templates.spec.ts | 4 ++++ .../template-customization.block_theme.side_effects.spec.ts | 5 ++--- .../templates/template-customization.block_theme.spec.ts | 4 ++++ ...template-customization.block_theme_with_templates.spec.ts | 4 ++++ .../changelog/44600-fix-44445-clean-up-block-templates | 3 +++ 7 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 plugins/woocommerce/changelog/44600-fix-44445-clean-up-block-templates diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/constants.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/constants.ts index 319ae46d89e..a4fdf860a51 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/constants.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/constants.ts @@ -17,7 +17,7 @@ type TemplateCustomizationTest = { } ) => Promise< void | Response | null >; templateName: string; templatePath: string; - templateType: string; + templateType: 'wp_template' | 'wp_template_part'; fallbackTemplate?: { templateName: string; templatePath: string; 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 index 22c9e59e55b..c3fba7d44ce 100644 --- 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 @@ -4,6 +4,10 @@ import { test, expect } from '@woocommerce/e2e-playwright-utils'; test.describe( 'Single Product template', async () => { + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deleteAllTemplates( 'wp_template' ); + } ); + test( 'shows password form in products protected with password', async ( { page, } ) => { diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/single-product-template.block_theme_with_templates.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/single-product-template.block_theme_with_templates.spec.ts index 7aaae780b70..8ad0976bf0c 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/single-product-template.block_theme_with_templates.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/single-product-template.block_theme_with_templates.spec.ts @@ -15,6 +15,10 @@ const userText = 'Hello World in the Belt template'; const themeTemplateText = 'Single Product Belt template loaded from theme'; test.describe( 'Single Product Template', async () => { + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deleteAllTemplates( 'wp_template' ); + } ); + test( 'loads the theme template for a specific product using the product slug and it can be customized', async ( { admin, editorUtils, diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme.side_effects.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme.side_effects.spec.ts index dc75254461a..05b062040e3 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme.side_effects.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme.side_effects.spec.ts @@ -2,7 +2,6 @@ * 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, @@ -22,8 +21,8 @@ CUSTOMIZABLE_WC_TEMPLATES.forEach( ( testData ) => { const woocommerceTemplateUserText = `Hello World in the WooCommerce ${ testData.templateName } template`; test.describe( `${ testData.templateName } template`, async () => { - test.afterAll( async () => { - await deleteAllTemplates( 'wp_template' ); + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deleteAllTemplates( testData.templateType ); } ); 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 ( { diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme.spec.ts index a8ea27a9866..05a7405e970 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme.spec.ts @@ -15,6 +15,10 @@ CUSTOMIZABLE_WC_TEMPLATES.forEach( ( testData ) => { testData.templateType === 'wp_template' ? 'template' : 'template part'; test.describe( `${ testData.templateName } template`, async () => { + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deleteAllTemplates( testData.templateType ); + } ); + test( 'can be modified and reverted', async ( { admin, frontendUtils, diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme_with_templates.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme_with_templates.spec.ts index 259c4b0404c..ce31f3b4e1d 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme_with_templates.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/template-customization.block_theme_with_templates.spec.ts @@ -19,6 +19,10 @@ CUSTOMIZABLE_WC_TEMPLATES.forEach( ( testData ) => { testData.templateType === 'wp_template' ? 'template' : 'template part'; test.describe( `${ testData.templateName } template`, async () => { + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deleteAllTemplates( testData.templateType ); + } ); + test( "theme template has priority over WooCommerce's and can be modified", async ( { admin, editorUtils, diff --git a/plugins/woocommerce/changelog/44600-fix-44445-clean-up-block-templates b/plugins/woocommerce/changelog/44600-fix-44445-clean-up-block-templates new file mode 100644 index 00000000000..3842d83be7f --- /dev/null +++ b/plugins/woocommerce/changelog/44600-fix-44445-clean-up-block-templates @@ -0,0 +1,3 @@ +Significance: patch +Type: update +Comment: Clean up block templates after running e2e tests.