From 2dd54dce607da436930223922c44b2c64669c0ee Mon Sep 17 00:00:00 2001 From: Peter Petrov Date: Wed, 3 Apr 2024 11:26:21 +0300 Subject: [PATCH 1/4] Update Boost's CLI to include support for image guide module --- projects/plugins/boost/app/lib/class-cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/boost/app/lib/class-cli.php b/projects/plugins/boost/app/lib/class-cli.php index 720c325398f02..506ee1238baf8 100644 --- a/projects/plugins/boost/app/lib/class-cli.php +++ b/projects/plugins/boost/app/lib/class-cli.php @@ -24,7 +24,7 @@ class CLI { */ private $jetpack_boost; - const MAKE_E2E_TESTS_WORK_MODULES = array( 'critical_css', 'render_blocking_js' ); + const MAKE_E2E_TESTS_WORK_MODULES = array( 'critical_css', 'render_blocking_js', 'image_guide' ); /** * CLI constructor. From e7c3746e0ffac58de63dd274ac2547bb8e2ed7f1 Mon Sep 17 00:00:00 2001 From: Peter Petrov Date: Wed, 3 Apr 2024 12:26:40 +0300 Subject: [PATCH 2/4] Add e2e tests for image guide --- .../assets/src/js/features/module/module.tsx | 2 +- .../boost/tests/e2e/lib/env/prerequisites.js | 16 ++++++ .../e2e/lib/pages/frontend/FirstPostPage.js | 24 +++++++++ .../boost/tests/e2e/lib/pages/index.js | 1 + .../e2e-appended-image/assets/e2e-image.png | Bin 0 -> 2727 bytes .../e2e-appended-image/e2e-appended-image.php | 21 ++++++++ .../e2e/specs/image-guide/image-guide.test.js | 50 ++++++++++++++++++ .../docker/jetpack-docker-config-default.yml | 1 + 8 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 projects/plugins/boost/tests/e2e/lib/pages/frontend/FirstPostPage.js create mode 100644 projects/plugins/boost/tests/e2e/plugins/e2e-appended-image/assets/e2e-image.png create mode 100644 projects/plugins/boost/tests/e2e/plugins/e2e-appended-image/e2e-appended-image.php create mode 100644 projects/plugins/boost/tests/e2e/specs/image-guide/image-guide.test.js diff --git a/projects/plugins/boost/app/assets/src/js/features/module/module.tsx b/projects/plugins/boost/app/assets/src/js/features/module/module.tsx index 71d5c97434124..eaf40d209dde2 100644 --- a/projects/plugins/boost/app/assets/src/js/features/module/module.tsx +++ b/projects/plugins/boost/app/assets/src/js/features/module/module.tsx @@ -58,7 +58,7 @@ const Module = ( { } return ( -
+
{ toggle && ( ensureTestPosts( state.testPostTitles ), clean: () => ensureCleanState( state.clean ), mockSpeedScore: () => ensureMockSpeedScoreState( state.mockSpeedScore ), + appendImage: () => ensureAppendedImage( state.appendImage ), }; logger.prerequisites( JSON.stringify( state, null, 2 ) ); @@ -93,6 +99,16 @@ export async function ensureMockSpeedScoreState( mockSpeedScore ) { } } +export async function ensureAppendedImage( append ) { + if ( append ) { + logger.prerequisites( 'Appending image' ); + await execWpCommand( 'plugin activate e2e-appended-image/e2e-appended-image.php' ); + } else { + logger.prerequisites( 'Removing appended image' ); + await execWpCommand( 'plugin deactivate e2e-appended-image/e2e-appended-image.php' ); + } +} + export async function activateModules( modules ) { for ( const module of modules ) { logger.prerequisites( `Activating module ${ module }` ); diff --git a/projects/plugins/boost/tests/e2e/lib/pages/frontend/FirstPostPage.js b/projects/plugins/boost/tests/e2e/lib/pages/frontend/FirstPostPage.js new file mode 100644 index 0000000000000..3ccd30133b6dc --- /dev/null +++ b/projects/plugins/boost/tests/e2e/lib/pages/frontend/FirstPostPage.js @@ -0,0 +1,24 @@ +import WpPage from 'jetpack-e2e-commons/pages/wp-page.js'; +import { resolveSiteUrl } from 'jetpack-e2e-commons/helpers/utils-helper.js'; + +export default class FirstPostPage extends WpPage { + constructor( page ) { + const url = `${ resolveSiteUrl() }/?p=1`; + super( page, { url } ); + } + + async isImageGuideScriptPresent() { + const selector = '#jetpack-boost-guide-js'; + return ( await this.page.locator( selector ).count() ) > 0; + } + + async isImageGuideAdminBarItemPresent() { + const selector = '#wp-toolbar #jetpack-boost-guide-bar'; + return ( await this.page.locator( selector ).count() ) > 0; + } + + async isImageGuideUIPresent() { + const selector = '.jetpack-boost-guide > .guide'; + return this.waitForElementToBeVisible( selector, 5 * 1000 ); + } +} diff --git a/projects/plugins/boost/tests/e2e/lib/pages/index.js b/projects/plugins/boost/tests/e2e/lib/pages/index.js index 589048da796ce..474734695266c 100644 --- a/projects/plugins/boost/tests/e2e/lib/pages/index.js +++ b/projects/plugins/boost/tests/e2e/lib/pages/index.js @@ -1 +1,2 @@ export { default as JetpackBoostPage } from './wp-admin/JetpackBoostPage.js'; +export { default as FirstPostPage } from './frontend/FirstPostPage.js'; diff --git a/projects/plugins/boost/tests/e2e/plugins/e2e-appended-image/assets/e2e-image.png b/projects/plugins/boost/tests/e2e/plugins/e2e-appended-image/assets/e2e-image.png new file mode 100644 index 0000000000000000000000000000000000000000..94ec9a10839b4de1898f18b1261fa836d4894922 GIT binary patch literal 2727 zcmbtWcTm&W7LJqvp^72Wt8`F$78b;)KmdVI{Ymo&NHY)wVR2C*5TzIeM1rBCsI-8g z2_ixgr7c|`AZ<||(pA7vS9sBR|Gb%D?ykf3<7}& zTBFZ8K_DCe1ac^ymy;c_SpHnjHfYQ_7mJ>rp7iwe$B!RZRaJF#bkOPa!otFgjEv08 z%#xCl^78V!y1Kl)JTjS_m6i48&6}>Su7-vNDwX>B_3NCRoF`A7G&MEV)YJs>%-n}S zV3O8nQ7+fUSLpF<0SLb6d)d)4jvw3q4dCX?sh`ZwgZjfRuKx*R4Gl8JKJvUpIGq+9 z@eta|!9j41wPhk5S(zzg>oG5OrNKoR>ka+;LiUAAN-kI{E?uyx(630X&fNn>TfS%$ z!j3JdXWLikV^gbh3VtDcnJp!=y^2%`zP1>CFZ+^_Y}XDo__Emz<9xS3rnDbBoK}_h zlkh>!tWi_NNf&Bm2SovQ~>&61D|2S9dvGneO=fTeXjAMaAEGtDM5>|{}^_BiC zoYpFQPrPCB+^c&Gw6Vi?k%{SGpUk|tw6T!TY9VuV<7my+qZQ4d4rPCXJGj~JN}HUF zS4wfFP~0_(6Q4*^0y*~2u-XU*)%K?W>nwxrjnTv2PV!dX&RT&Co>5=Y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D23uDXXP*sTUfeQ<8w-`q8Ahc(Gx-rCS7;=guxZQ05kWcD&YU=*8vB zr#IyNI7N?3QB*81`9nQ=rb8=SJm?O2Mr=-k*rgdfZ)-sGyqnaR*G>_7Q;*i0CF|-R z&pn56E;Qse>o2{`;~QJ~Ztxz%w@JdO-rU%j zyQ%YM$`{>Im9DaTu{?JJiuI-WvcKbrgs4k-M61Pb4{9`VV_z?Tx}TDU`MIPy5rOQN zf0(jqY(gf?g#F$+FJz)t2y?aFstJWr+5_;09@(%zx!g)b2N!q3ar$K)w8G~F@^=0g zJQyaPQnZikD?br$*weKTX_^)oA#Qraa~)I;{Wdw#ig*Aa>Z^H}aD&y)Nqe9-pPrV6 zn0c)y2U4_?(m%SQu)lR_wK9e(JDeJ+G;8z}CSam$6F(QZ9i0?`u zJt7CPjQDB%tV@;MO83~s(UrK^k5O^{|0t@sQ7OtK)EYhui0q~u{{sos+hk5_PBzgc zXIbNyTCztL2Swh8kK)X7_qH~LrZd*gjA##l(~f3)OIs;sU0 zE2#7C-j!ih&%c;O3(sTkH!hf`

'; + } + return $content; + } +); diff --git a/projects/plugins/boost/tests/e2e/specs/image-guide/image-guide.test.js b/projects/plugins/boost/tests/e2e/specs/image-guide/image-guide.test.js new file mode 100644 index 0000000000000..767a7260c0a77 --- /dev/null +++ b/projects/plugins/boost/tests/e2e/specs/image-guide/image-guide.test.js @@ -0,0 +1,50 @@ +import { test, expect } from 'jetpack-e2e-commons/fixtures/base-test.js'; +import { boostPrerequisitesBuilder } from '../../lib/env/prerequisites.js'; +import { FirstPostPage } from '../../lib/pages/index.js'; +import playwrightConfig from 'jetpack-e2e-commons/playwright.config.mjs'; + +test.describe( 'Image CDN', () => { + let page; + + test.beforeAll( async ( { browser } ) => { + page = await browser.newPage( playwrightConfig.use ); + await boostPrerequisitesBuilder( page ).withCleanEnv( true ).withConnection( true ).build(); + } ); + + test.afterAll( async () => {} ); + + test( 'Image Guide functionality shouldn`t be active when the module is inactive', async () => { + await boostPrerequisitesBuilder( page ).withInactiveModules( [ 'image_guide' ] ).build(); + const firstPostPage = await FirstPostPage.visit( page ); + + expect( + await firstPostPage.isImageGuideScriptPresent(), + 'Image Guide script shouldn`t be present' + ).toBeFalsy(); + } ); + + test( 'Image Guide functionality should be active when the module is active', async () => { + await boostPrerequisitesBuilder( page ) + .withActiveModules( [ 'image_guide' ] ) + .withAppendedImage( true ) + .build(); + const firstPostPage = await FirstPostPage.visit( page ); + + expect( + await firstPostPage.isImageGuideScriptPresent(), + 'Image Guide script should be present' + ).toBeTruthy(); + + expect( + await firstPostPage.isImageGuideAdminBarItemPresent(), + 'Image Guide admin bar item should be present' + ).toBeTruthy(); + + console.log( await firstPostPage.isImageGuideUIPresent() ); + + expect( + await firstPostPage.isImageGuideUIPresent(), + 'Image Guide UI item should be present' + ).toBeTruthy(); + } ); +} ); diff --git a/tools/docker/jetpack-docker-config-default.yml b/tools/docker/jetpack-docker-config-default.yml index 63ac16823faa9..723e425b689e2 100644 --- a/tools/docker/jetpack-docker-config-default.yml +++ b/tools/docker/jetpack-docker-config-default.yml @@ -61,6 +61,7 @@ e2e: tools/e2e-commons/plugins/e2e-plugin-updater.php: /var/www/html/wp-content/plugins/e2e-plugin-updater.php tools/e2e-commons/plugins/e2e-plan-data-interceptor.php: /var/www/html/wp-content/plugins/e2e-plan-data-interceptor.php tools/e2e-commons/plugins/e2e-waf-data-interceptor.php: /var/www/html/wp-content/plugins/e2e-waf-data-interceptor.php + projects/plugins/boost/tests/e2e/plugins/e2e-appended-image/: /var/www/html/wp-content/plugins/e2e-appended-image/ projects/plugins/boost/tests/e2e/plugins/e2e-mock-speed-score-api.php: /var/www/html/wp-content/plugins/e2e-mock-speed-score-api.php tools/e2e-commons/plugins/e2e-search-test-helper.php: /var/www/html/wp-content/plugins/e2e-search-test-helper.php tools/e2e-commons/plugins/e2e-wpcom-request-interceptor.php: /var/www/html/wp-content/plugins/e2e-wpcom-request-interceptor.php From af356b9048119e55cca76e3f6e9c397a44440ad2 Mon Sep 17 00:00:00 2001 From: Peter Petrov Date: Wed, 3 Apr 2024 12:27:26 +0300 Subject: [PATCH 3/4] Add Boost's image guide test configuration to e2e test matrix --- .github/files/e2e-tests/e2e-matrix.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 2f9ef1cd249fb..2fe2e44f53220 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -58,6 +58,14 @@ const projects = [ suite: '', buildGroup: 'jetpack-boost', }, + { + project: 'Jetpack Boost - Image Guide', + path: 'projects/plugins/boost/tests/e2e', + testArgs: [ 'specs/image-guide', '--retries=1' ], + targets: [ 'plugins/boost' ], + suite: '', + buildGroup: 'jetpack-boost', + }, { project: 'Search', path: 'projects/plugins/search/tests/e2e', From 5a084e2e5ce74c80a40dfbeb882fbc1be25e7f76 Mon Sep 17 00:00:00 2001 From: Peter Petrov Date: Wed, 3 Apr 2024 12:28:00 +0300 Subject: [PATCH 4/4] add changelog --- projects/plugins/boost/changelog/add-e2e-tests-image-guide | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 projects/plugins/boost/changelog/add-e2e-tests-image-guide diff --git a/projects/plugins/boost/changelog/add-e2e-tests-image-guide b/projects/plugins/boost/changelog/add-e2e-tests-image-guide new file mode 100644 index 0000000000000..91dd7af1a7f00 --- /dev/null +++ b/projects/plugins/boost/changelog/add-e2e-tests-image-guide @@ -0,0 +1,5 @@ +Significance: patch +Type: added +Comment: Add e2e tests for Image Guide module. + +