From f53495e5968142d56f2d564121470daa4f23331a Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 12 Apr 2024 15:33:45 +0300 Subject: [PATCH 1/2] Add e2e test for activating themes in site editor --- .../specs/site-editor/activate-theme.spec.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/e2e/specs/site-editor/activate-theme.spec.js diff --git a/test/e2e/specs/site-editor/activate-theme.spec.js b/test/e2e/specs/site-editor/activate-theme.spec.js new file mode 100644 index 0000000000000..675a3a35e3f57 --- /dev/null +++ b/test/e2e/specs/site-editor/activate-theme.spec.js @@ -0,0 +1,46 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +async function activateTheme( { page } ) { + await page.getByRole( 'button', { name: 'Activate Emptytheme' } ).click(); + await page.getByRole( 'button', { name: 'Activate', exact: true } ).click(); + await expect( + page.getByRole( 'button', { name: 'Dismiss this notice' } ) + ).toContainText( 'Site updated' ); +} + +test.describe( 'Activate theme', () => { + test.beforeEach( async ( { admin, page } ) => { + await admin.visitAdminPage( 'themes.php' ); + await page.getByLabel( 'Live Preview Emptytheme' ).click(); + } ); + test.afterEach( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyone' ); + } ); + test( 'activate block theme when live previewing from sidebar save button', async ( { + admin, + page, + } ) => { + await activateTheme( { page } ); + await admin.visitAdminPage( 'themes.php' ); + await expect( page.getByLabel( 'Customize Emptytheme' ) ).toBeVisible(); + } ); + test( 'activate block theme when live previewing in edit mode', async ( { + editor, + admin, + page, + } ) => { + // Wait for the loading to complete. + await expect( page.locator( '.edit-site-canvas-loader' ) ).toHaveCount( + 0 + ); + await editor.canvas.locator( 'body' ).click(); + // Close the welcome guide. + await page.getByRole( 'button', { name: 'Get started' } ).click(); + await activateTheme( { page } ); + await admin.visitAdminPage( 'themes.php' ); + await expect( page.getByLabel( 'Customize Emptytheme' ) ).toBeVisible(); + } ); +} ); From 1a1e1108ed44a8e95fc3b1719b415e39d9f63bb2 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 12 Apr 2024 16:30:03 +0300 Subject: [PATCH 2/2] update test --- .../specs/site-editor/activate-theme.spec.js | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/test/e2e/specs/site-editor/activate-theme.spec.js b/test/e2e/specs/site-editor/activate-theme.spec.js index 675a3a35e3f57..a5fb4b3be0b73 100644 --- a/test/e2e/specs/site-editor/activate-theme.spec.js +++ b/test/e2e/specs/site-editor/activate-theme.spec.js @@ -3,14 +3,6 @@ */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -async function activateTheme( { page } ) { - await page.getByRole( 'button', { name: 'Activate Emptytheme' } ).click(); - await page.getByRole( 'button', { name: 'Activate', exact: true } ).click(); - await expect( - page.getByRole( 'button', { name: 'Dismiss this notice' } ) - ).toContainText( 'Site updated' ); -} - test.describe( 'Activate theme', () => { test.beforeEach( async ( { admin, page } ) => { await admin.visitAdminPage( 'themes.php' ); @@ -23,7 +15,15 @@ test.describe( 'Activate theme', () => { admin, page, } ) => { - await activateTheme( { page } ); + await page + .getByRole( 'button', { name: 'Activate Emptytheme' } ) + .click(); + await page + .getByRole( 'button', { name: 'Activate', exact: true } ) + .click(); + await expect( + page.getByRole( 'button', { name: 'Dismiss this notice' } ) + ).toContainText( 'Site updated' ); await admin.visitAdminPage( 'themes.php' ); await expect( page.getByLabel( 'Customize Emptytheme' ) ).toBeVisible(); } ); @@ -37,9 +37,16 @@ test.describe( 'Activate theme', () => { 0 ); await editor.canvas.locator( 'body' ).click(); - // Close the welcome guide. - await page.getByRole( 'button', { name: 'Get started' } ).click(); - await activateTheme( { page } ); + await page + .getByRole( 'region', { name: 'Editor top bar' } ) + .getByRole( 'button', { name: 'Activate Emptytheme' } ) + .click(); + await page + .getByRole( 'button', { name: 'Activate', exact: true } ) + .click(); + await expect( + page.getByRole( 'button', { name: 'Dismiss this notice' } ) + ).toContainText( 'Site updated' ); await admin.visitAdminPage( 'themes.php' ); await expect( page.getByLabel( 'Customize Emptytheme' ) ).toBeVisible(); } );