Skip to content

Commit

Permalink
Add more scenario to test
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Jan 10, 2025
1 parent 3a49794 commit 1a0ed74
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/features/performance-hints.feature
Original file line number Diff line number Diff line change
@@ -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
Expand Down
41 changes: 39 additions & 2 deletions src/support/steps/performance-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
})
})

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) {
//
});

0 comments on commit 1a0ed74

Please sign in to comment.