Closed Mai-Saad closed 2 months ago
Steps breakdown
Given WPR installed and activated -> We can re-use the existing steps:
Background:
Given I am logged in
And plugin is installed 'new_release'
And plugin is activated
And performance hints data added to DB
: We can create a step that adds some hard-coded rows into the database. It can be done with something like:
let sql: string;
sql =` TRUNCATE TABLE `${tablePrefix}wpr_above_the_fold` `
await dbQuery(sql);
sql = `INSERT INTO ${tablePrefix}wpr_above_the_fold
(a,b,c)
VALUES
(1,2,3),
(4,5,6),
(7,8,9);`
await dbQuery(sql);
(a,b,c) must be the column names of the table, and we can then specify values to add. Deleting the data first will ensure we don't have conflicts on IDs for instance.
We would need to adapt this step when we add other tables for performance hints (for instance the LRC table).
When clear performance hints is clicked in admin bar: Can be inspired by When('I clear cache'
which is already implemented. Note: instead of waitForLoadState, consider using a waitForSelector and identify the banner/message displayed after clearing performance hints.
When click clear performance hints of this URL in page view of URL1: Same as above, we need a variation of the function
then data is removed from the performance hints tables: We can count the rows in a table with:
sql = `SELECT count(*)
FROM ${tablePrefix}wpr_above_the_fold;
result = await dbQuery(sql);
resultFromStdout = await extractFromStdout(result);
I think we might have a race condition with warm-up in some cases. Maybe we will want the count to be <= 2 (homepage might get there quickly).
When switching the theme: can re-use When('theme {string} is activated'
URL visits: can re-use When('I visit site url'
Then data of this URL1 is removed from the performance hints tables: A DB query and checking the result is 0?
sql = `SELECT count(*)
FROM ${tablePrefix}wpr_above_the_fold;
WHERE url = ${the_url}
result = await dbQuery(sql);
resultFromStdout = await extractFromStdout(result);
And the data of URL2 still in the table: Same as above, but checking it is not 0.
Other steps seems like navigation steps that would need custom functions (change permalinks, and When URL page is deleted).
I would suggest to go step by step, eventually with several PRs, one per scenario to begin with?
Effort: M
@jeawhanlee, could you have a look over this grooming? And about change permalinks, where will we add this, shall it be in support/utils or just steps to related feature directly? Thank you.
And about change permalinks, where will we add this, shall it be in support/utils or just steps to related feature directly?
I feel like changing permalinks will be re-used at some point (I think I saw already another E2E issue mentioning this step) so something generic in utils makes sense 👍
And performance hints data added to DB: We can create a step that adds some hard-coded rows into the database. It can be done with something like:
@MathieuLamiot why don't we visit some URLs so it will be added directly to DB?, after clear those URLs will be removed from DB
@Mai-Saad That would work too yes. The risk is that, to be sure data is added, this visit has to be done after clearing the cache and Performance Hints data. So it adds a few steps to the test, while hard-coding data to be added in the DB separates a bit more the different tests and steps. both are fine with me
LGTM
Is your feature request related to a problem? Please describe. Since now we can check the database, we can cover clearing data scenarios in the e2e. Here are some basic scenarios to start with, then we can build on that.
Scenario1: Should clear performance hints data when click clear PH in admin bar Given WPR installed and activated And performance hints data added to DB When clear performance hints is clicked in admin bar then data is removed from the performance hints tables
Scenario2: Should clear performance hints when change permalinks Given WPR installed and activated And performance hints data added to DB When permalinks is changed then data is removed from the performance hints tables
Scenario3: Should clear performance hints when switch theme Given WPR installed and activated And performance hints data added to DB When switching the theme then data is removed from the performance hints tables
Scenario4: Should clear performance hints of the current URL Given WPR installed and activated And URL1 , URL2 are visited And performance hints data added to DB When click clear performance hints of this URL in page view of URL1 then data of this URL1 is removed from the performance hints tables And the data of URL2 still in the table
Scenario5: Should clear performance hints of the URL when edited Given WPR installed and activated And URL is visited And performance hints data added to DB When edit the content of the URL then data of this URL is removed from the performance hints tables
Scenario6: Should clear performance hints of the URL when deleted Given WPR installed and activated And URL is visited And performance hints data added to DB When URL page is deleted then data of this URL is removed from the performance hints tables