From 3a497947fa6813adec9371b73a2abc4120f21331 Mon Sep 17 00:00:00 2001 From: Khadreal Date: Thu, 9 Jan 2025 11:12:22 +0100 Subject: [PATCH 1/2] Add new scenario -- closes: #131 --- src/features/performance-hints.feature | 83 ++++++++++++++------------ src/support/steps/performance-hints.ts | 9 ++- 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/features/performance-hints.feature b/src/features/performance-hints.feature index 16996174..7c4cdd5a 100644 --- a/src/features/performance-hints.feature +++ b/src/features/performance-hints.feature @@ -6,47 +6,54 @@ Feature: Clear lcp/performance hints data tests And plugin is installed 'new_release' And plugin is activated - Scenario: C16387 - Should clear performance hints data when click clear PH in admin bar - Given performance hints data added to DB + Scenario: When I change site homepage to page with links + When I go '/wp-admin/options-reading.php' + And I changed homepage to 'homepage_10urls' When clear performance hints is clicked in admin bar - Then data is removed from the performance hints tables + And I log out + + + #Scenario: C16387 - Should clear performance hints data when click clear PH in admin bar + # Given performance hints data added to DB + # When clear performance hints is clicked in admin bar + # Then data is removed from the performance hints tables - Scenario: C16389 - Should clear performance hints when change permalinks - Given performance hints data added to DB - When permalink structure is changed to '/%postname%' - Then data is removed from the performance hints tables + #Scenario: C16389 - Should clear performance hints when change permalinks + # Given performance hints data added to DB + # When permalink structure is changed to '/%postname%' + # Then data is removed from the performance hints tables - Scenario: C16390 - Should clear performance hints when switch theme - Given performance hints data added to DB - And switching the theme - Then data is removed from the performance hints tables + #Scenario: C16390 - Should clear performance hints when switch theme + # Given performance hints data added to DB + # And switching the theme + # Then data is removed from the performance hints tables - Scenario: Should clear performance hints of the current URL - Given I log out - And I visit beacon driven page 'atf-lrc-1' with browser dimension 1600 x 700 - And I visit beacon driven page 'atf-lrc-2' with browser dimension 1600 x 700 - And data for 'atf-lrc-1' present in the performance hints tables - And data for 'atf-lrc-2' present in the performance hints tables - And I am logged in - And I go to 'atf-lrc-1' - When clear performance hints for this URL is clicked in admin bar - Then data for 'atf-lrc-1' is removed from the performance hints tables - Then data for 'atf-lrc-2' present in the performance hints tables + #Scenario: Should clear performance hints of the current URL + # Given I log out + # And I visit beacon driven page 'atf-lrc-1' with browser dimension 1600 x 700 + # And I visit beacon driven page 'atf-lrc-2' with browser dimension 1600 x 700 + # And data for 'atf-lrc-1' present in the performance hints tables + # And data for 'atf-lrc-2' present in the performance hints tables + # And I am logged in + # And I go to 'atf-lrc-1' + # When clear performance hints for this URL is clicked in admin bar + # Then data for 'atf-lrc-1' is removed from the performance hints tables + # Then data for 'atf-lrc-2' present in the performance hints tables - Scenario: C16388 - Should clear performance hints of the URL when edited - Given I log out - And I visit beacon driven page 'atf-lrc-1' with browser dimension 1600 x 700 - And data for 'atf-lrc-1' present in the performance hints tables - And I am logged in - And I go to 'atf-lrc-1' - When I edit the content of post - Then data for 'atf-lrc-1' is removed from the performance hints tables + #Scenario: C16388 - Should clear performance hints of the URL when edited + # Given I log out + # And I visit beacon driven page 'atf-lrc-1' with browser dimension 1600 x 700 + # And data for 'atf-lrc-1' present in the performance hints tables + # And I am logged in + # And I go to 'atf-lrc-1' + # When I edit the content of post + # Then data for 'atf-lrc-1' is removed from the performance hints tables - Scenario: C16388 - Should clear performance hints of the URL when deleted - Given I log out - And I visit beacon driven page 'atf-lrc-1' with browser dimension 1600 x 700 - And data for 'atf-lrc-1' present in the performance hints tables - And I am logged in - When 'atf-lrc-1' page is deleted - Then data for 'atf-lrc-1' is removed from the performance hints tables - Then untrash and republish 'atf-lrc-1' page \ No newline at end of file + #Scenario: C16388 - Should clear performance hints of the URL when deleted + # Given I log out + # And I visit beacon driven page 'atf-lrc-1' with browser dimension 1600 x 700 + # And data for 'atf-lrc-1' present in the performance hints tables + # And I am logged in + # When 'atf-lrc-1' page is deleted + # Then data for 'atf-lrc-1' is removed from the performance hints tables + # Then untrash and republish 'atf-lrc-1' page \ No newline at end of file diff --git a/src/support/steps/performance-hints.ts b/src/support/steps/performance-hints.ts index 2d1510c6..eaee1c1f 100644 --- a/src/support/steps/performance-hints.ts +++ b/src/support/steps/performance-hints.ts @@ -141,4 +141,11 @@ Then ('untrash and republish {string} page', async function (this: ICustomWorld, const postDataStdout = await getPostDataFromTitle(permalink, 'trash', 'ID,post_title'); const postData = await extractFromStdout(postDataStdout); await updatePostStatus(parseInt(postData[0].ID, 10), 'publish'); -}); \ No newline at end of file +}); + +When('I changed homepage to {string}', async function(this: ICustomWorld, page: string){ + await this.page.locator('input[name="show_on_front"][value="page"]').click(); + await this.page.pause() + await this.page.selectOption('select#page_on_front', { label: 'atf-lrc-2' }); + await this.page.locator('#submit').click(); +}) \ No newline at end of file From 1a0ed74a24ec950ff5607c789bfb1aa4e3a54d3f Mon Sep 17 00:00:00 2001 From: Khadreal Date: Fri, 10 Jan 2025 11:41:10 +0100 Subject: [PATCH 2/2] Add more scenario to test --- src/features/performance-hints.feature | 20 +++++++++---- src/support/steps/performance-hints.ts | 41 ++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/features/performance-hints.feature b/src/features/performance-hints.feature index 7c4cdd5a..3e555744 100644 --- a/src/features/performance-hints.feature +++ b/src/features/performance-hints.feature @@ -1,16 +1,26 @@ -@setup @performancehints +@setup @delaylcp @performancehints Feature: Clear lcp/performance hints data tests Background: Given I am logged in - And plugin is installed 'new_release' - And plugin is activated Scenario: When I change site homepage to page with links When I go '/wp-admin/options-reading.php' - And I changed homepage to 'homepage_10urls' - When clear performance hints is clicked in admin bar + And I changed homepage to 'homepage_10URLs' + Given plugin is installed 'new_release' + And plugin is activated And I log out + When I visit site url + Then homepage and n URLs is added to Database + + Scenario: Shouldn't cause error if no links in home page + Given I am logged in + When I go '/wp-admin/options-reading.php' + And I changed homepage to 'homepage_noURLs' + When clear performance hints is clicked in admin bar + Then I must not see any error in debug.log + And only homepage is added to Database + #Scenario: C16387 - Should clear performance hints data when click clear PH in admin bar diff --git a/src/support/steps/performance-hints.ts b/src/support/steps/performance-hints.ts index eaee1c1f..57188357 100644 --- a/src/support/steps/performance-hints.ts +++ b/src/support/steps/performance-hints.ts @@ -13,6 +13,7 @@ import { WP_BASE_URL } from '../../../config/wp.config'; import { When, Then, Given } from '@cucumber/cucumber'; import { dbQuery, getWPTablePrefix, getPostDataFromTitle, updatePostStatus } from "../../../utils/commands"; import { extractFromStdout, seedData, checkData } from "../../../utils/helpers"; +import {Row} from "../../../utils/types"; /* * Executes step to add hardcoded data to DB: ATF & LRC tables @@ -146,6 +147,42 @@ Then ('untrash and republish {string} page', async function (this: ICustomWorld, When('I changed homepage to {string}', async function(this: ICustomWorld, page: string){ await this.page.locator('input[name="show_on_front"][value="page"]').click(); await this.page.pause() - await this.page.selectOption('select#page_on_front', { label: 'atf-lrc-2' }); + await this.page.selectOption('select#page_on_front', { label: page }); await this.page.locator('#submit').click(); -}) \ No newline at end of file +}) + +Then('homepage and n URLs is added to Database', async function (this: ICustomWorld) { + let sql: string, + result: string, + resultFromStdout: Row[]; + + const tablePrefix: string = await getWPTablePrefix(); + + const links = await this.page.locator('ul li:not(li:has(comment)) a') + .evaluateAll((elements) => { + return elements.map(el => { + const href = el.getAttribute('href') || ''; + try { + const url = new URL(href); + return url.pathname; + } catch { + return href; + } + }); + }); + + for (const link in links) { + sql = `SELECT lcp, viewport + FROM ${tablePrefix}wpr_above_the_fold + WHERE url LIKE "%${link}%" + AND is_mobile = 0`; + result = await dbQuery(sql); + resultFromStdout = await extractFromStdout(result); + + console.log(resultFromStdout) + } +}); + +When('only homepage is added to Database', async function (this: ICustomWorld) { + // +}); \ No newline at end of file