From b8df34659cc8fe34ee35fa36ca4ba7999d68d7e8 Mon Sep 17 00:00:00 2001 From: Bart Kalisz Date: Wed, 10 Apr 2024 10:38:55 +0200 Subject: [PATCH] Blocks E2E: Ensure legacy template slugs are supported (#46269) --- .../legacy-templates.block_theme.spec.ts | 108 ++++++++++++++++++ .../e2e-ensure-legacy-template-name-support | 4 + 2 files changed, 112 insertions(+) create mode 100644 plugins/woocommerce-blocks/tests/e2e/tests/templates/legacy-templates.block_theme.spec.ts create mode 100644 plugins/woocommerce/changelog/e2e-ensure-legacy-template-name-support diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/legacy-templates.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/legacy-templates.block_theme.spec.ts new file mode 100644 index 00000000000..c860cca2268 --- /dev/null +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/legacy-templates.block_theme.spec.ts @@ -0,0 +1,108 @@ +/** + * External dependencies + */ +import { test, expect } from '@woocommerce/e2e-playwright-utils'; +import { cli } from '@woocommerce/e2e-utils'; + +test.describe( 'Legacy templates', async () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.deleteAllTemplates( 'wp_template' ); + } ); + + test.afterEach( async ( { requestUtils } ) => { + await requestUtils.deleteAllTemplates( 'wp_template' ); + } ); + + test( 'woocommerce//* slug is supported', async ( { + admin, + page, + editor, + } ) => { + const template = { + id: 'single-product', + name: 'Single Product', + customText: 'This is a customized template.', + frontendPath: '/product/hoodie/', + }; + + await test.step( 'Customize existing template to create DB entry', async () => { + await admin.visitSiteEditor( { + postId: `woocommerce/woocommerce//${ template.id }`, + postType: 'wp_template', + canvas: 'edit', + } ); + + const title = editor.canvas.getByText( 'Title' ); + + await title.click(); + await title.press( 'Enter' ); + + const emptyBlock = editor.canvas + .getByLabel( 'Empty block' ) + .first(); + + await emptyBlock.fill( template.customText ); + await page.keyboard.press( 'Escape' ); + + await expect( + editor.canvas.getByText( template.customText ) + ).toBeVisible(); + + await editor.saveSiteEditorEntities(); + } ); + + await test.step( 'Update created term to legacy format in the DB', async () => { + const cliOutput = await cli( + `npm run wp-env run tests-cli -- \ + wp term update wp_theme woocommerce-woocommerce \ + --by="slug" \ + --name="woocommerce" \ + --slug="woocommerce"` + ); + + expect( cliOutput.stdout ).toContain( 'Success: Term updated.' ); + } ); + + await test.step( 'Verify the template can be edited via a legacy ID ', async () => { + await admin.visitSiteEditor( { + postId: `woocommerce//${ template.id }`, + postType: 'wp_template', + canvas: 'edit', + } ); + + await expect( + editor.canvas.getByText( template.customText ) + ).toBeVisible(); + } ); + + await test.step( 'Verify the template is listed in the Site Editor UI', async () => { + await admin.visitSiteEditor( { + path: '/wp_template/all', + } ); + + await page.getByPlaceholder( 'Search' ).fill( template.name ); + + await expect( + page.getByRole( 'link', { name: template.name } ) + ).toBeVisible(); + } ); + + await test.step( 'Verify the template loads correctly in the frontend', async () => { + await page.goto( template.frontendPath ); + + await expect( page.getByText( template.customText ) ).toBeVisible(); + } ); + + await test.step( 'Revert term update', async () => { + const cliOutput = await cli( + `npm run wp-env run tests-cli -- \ + wp term update wp_theme woocommerce \ + --by="slug" \ + --name="woocommerce/woocommerce" \ + --slug="woocommerce-woocommerce"` + ); + + expect( cliOutput.stdout ).toContain( 'Success: Term updated.' ); + } ); + } ); +} ); diff --git a/plugins/woocommerce/changelog/e2e-ensure-legacy-template-name-support b/plugins/woocommerce/changelog/e2e-ensure-legacy-template-name-support new file mode 100644 index 00000000000..e33ce408a96 --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-ensure-legacy-template-name-support @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Blocks E2E: Ensure legacy template names are supported