Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear lcp/performance hints data tests #126

Closed
Mai-Saad opened this issue Jul 23, 2024 · 6 comments · Fixed by #136
Closed

Clear lcp/performance hints data tests #126

Mai-Saad opened this issue Jul 23, 2024 · 6 comments · Fixed by #136
Assignees
Labels
effort: [M] 3-5 days of estimated development time

Comments

@Mai-Saad
Copy link
Contributor

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

@MathieuLamiot
Copy link
Contributor

MathieuLamiot commented Aug 14, 2024

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

@MathieuLamiot MathieuLamiot added the effort: [M] 3-5 days of estimated development time label Aug 14, 2024
@hanna-meda
Copy link
Contributor

@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.

@MathieuLamiot
Copy link
Contributor

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 👍

@Mai-Saad
Copy link
Contributor Author

Mai-Saad commented Aug 19, 2024

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

@MathieuLamiot
Copy link
Contributor

@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

@jeawhanlee
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: [M] 3-5 days of estimated development time
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants