From fabb47adc26b56a55ebe439ba7232a33e50c8a96 Mon Sep 17 00:00:00 2001 From: hanna-meda <93833759+hanna-meda@users.noreply.github.com> Date: Mon, 25 Nov 2024 22:31:26 +0200 Subject: [PATCH 1/3] Fixes #173 Adds to clean-up the switch theme via WP CLI --- src/features/performance-hints.feature | 1 - utils/commands.ts | 13 +++++++++++++ utils/page-utils.ts | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/features/performance-hints.feature b/src/features/performance-hints.feature index 392e779..1699617 100644 --- a/src/features/performance-hints.feature +++ b/src/features/performance-hints.feature @@ -20,7 +20,6 @@ Feature: Clear lcp/performance hints data tests Given performance hints data added to DB And switching the theme Then data is removed from the performance hints tables - Then theme 'Twenty Twenty' is activated Scenario: Should clear performance hints of the current URL Given I log out diff --git a/utils/commands.ts b/utils/commands.ts index bc977ee..c3e8335 100644 --- a/utils/commands.ts +++ b/utils/commands.ts @@ -293,6 +293,19 @@ export async function updatePermalinkStructure(structure: string): Promise await wp(`option update permalink_structure ${structure}`); } +/** + * Switch Theme. + * + * @function + * @name switchToDefaultTheme + * @async + * @param {string} theme - The theme to activate. + * @returns {Promise} - A Promise that resolves when the theme is activated. + */ +export async function switchToDefaultTheme(theme: string): Promise { + await wp(`theme activate ${theme}`); +} + /** * Executes a SQL query on the WordPress database using WP-CLI. * diff --git a/utils/page-utils.ts b/utils/page-utils.ts index 86a3889..b006f60 100644 --- a/utils/page-utils.ts +++ b/utils/page-utils.ts @@ -16,7 +16,7 @@ import { ICustomWorld } from '../src/common/custom-world'; import fs from "fs/promises"; import {WP_BASE_URL, WP_PASSWORD, WP_USERNAME} from '../config/wp.config'; -import { uninstallPlugin, updatePermalinkStructure, deactivatePlugin } from "./commands"; +import { uninstallPlugin, updatePermalinkStructure, deactivatePlugin, switchToDefaultTheme } from "./commands"; /** * Utility class for interacting with a Playwright Page instance in WordPress testing. @@ -583,6 +583,9 @@ export class PageUtils { // Reset permalink structure. await updatePermalinkStructure('/%postname%/'); + // Switch to "Twenty Twenty" theme. + await switchToDefaultTheme('twentytwenty'); + // Remove WP Rocket from UI if on local run is explicitly parsed. if ( process.env.npm_config_env !== undefined && process.env.npm_config_env === 'local' ) { // Start the process to remove wp-rocket. From 8b86f2b2f1ceeb618611734b2019f39a3af3fd48 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 26 Nov 2024 13:25:38 +0100 Subject: [PATCH 2/3] Rename old function for switching theme --- src/support/hooks.ts | 2 +- src/support/steps/general.ts | 4 ++-- utils/page-utils.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/support/hooks.ts b/src/support/hooks.ts index 8e12671..c4b0afb 100644 --- a/src/support/hooks.ts +++ b/src/support/hooks.ts @@ -72,7 +72,7 @@ BeforeAll(async function (this: ICustomWorld) { const utils = new PageUtils(page, sections); await utils.auth(); - await utils.switchTheme(theme); + await utils.switchThemeViaUi(theme); await page?.close(); await context?.close(); diff --git a/src/support/steps/general.ts b/src/support/steps/general.ts index 8f20ee8..7a98d73 100644 --- a/src/support/steps/general.ts +++ b/src/support/steps/general.ts @@ -180,7 +180,7 @@ When('I create reference', async function (this:ICustomWorld) { * Executes the step to activate a theme. */ When('theme {string} is activated', async function (this:ICustomWorld, theme) { - await this.utils.switchTheme(theme); + await this.utils.switchThemeViaUi(theme); }); /** @@ -193,7 +193,7 @@ When('theme is activated', async function (this:ICustomWorld) { return; } - await this.utils.switchTheme(theme); + await this.utils.switchThemeViaUi(theme); }); /** diff --git a/utils/page-utils.ts b/utils/page-utils.ts index b006f60..6b455d5 100644 --- a/utils/page-utils.ts +++ b/utils/page-utils.ts @@ -670,7 +670,7 @@ export class PageUtils { * * @return {Promise} */ - public async switchTheme(theme: string): Promise { + public async switchThemeViaUi(theme: string): Promise { await this.visitPage('wp-admin/themes.php'); await this.page.locator('#wp-filter-search-input').fill(theme); // Wait for filtered theme to be displayed. From 985ff540ba141a5f0a4619250b9196cb3a23abfb Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 26 Nov 2024 13:27:20 +0100 Subject: [PATCH 3/3] Changed function name for better code readability --- utils/commands.ts | 4 ++-- utils/page-utils.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/commands.ts b/utils/commands.ts index c3e8335..f19f0d0 100644 --- a/utils/commands.ts +++ b/utils/commands.ts @@ -297,12 +297,12 @@ export async function updatePermalinkStructure(structure: string): Promise * Switch Theme. * * @function - * @name switchToDefaultTheme + * @name switchTheme * @async * @param {string} theme - The theme to activate. * @returns {Promise} - A Promise that resolves when the theme is activated. */ -export async function switchToDefaultTheme(theme: string): Promise { +export async function switchTheme(theme: string): Promise { await wp(`theme activate ${theme}`); } diff --git a/utils/page-utils.ts b/utils/page-utils.ts index 6b455d5..e1f1524 100644 --- a/utils/page-utils.ts +++ b/utils/page-utils.ts @@ -16,7 +16,7 @@ import { ICustomWorld } from '../src/common/custom-world'; import fs from "fs/promises"; import {WP_BASE_URL, WP_PASSWORD, WP_USERNAME} from '../config/wp.config'; -import { uninstallPlugin, updatePermalinkStructure, deactivatePlugin, switchToDefaultTheme } from "./commands"; +import { uninstallPlugin, updatePermalinkStructure, deactivatePlugin, switchTheme } from "./commands"; /** * Utility class for interacting with a Playwright Page instance in WordPress testing. @@ -584,7 +584,7 @@ export class PageUtils { await updatePermalinkStructure('/%postname%/'); // Switch to "Twenty Twenty" theme. - await switchToDefaultTheme('twentytwenty'); + await switchTheme('twentytwenty'); // Remove WP Rocket from UI if on local run is explicitly parsed. if ( process.env.npm_config_env !== undefined && process.env.npm_config_env === 'local' ) {