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

added function for changing permalink. created performance-hints file… #136

Merged
merged 24 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
02e3ab9
added function for changing permalink. created performance-hints file…
hanna-meda Aug 23, 2024
4868e94
changed 'assert' with 'expect' after review. added @hints tag under p…
hanna-meda Aug 26, 2024
0d0256c
added 4 more scenarios with corresponding steps. refactored some parts
hanna-meda Sep 5, 2024
ebffb21
added one more final step on 3rd scenario. made changes based on late…
hanna-meda Sep 12, 2024
4878d82
improved method that inserts hardcoded data in DB
hanna-meda Sep 13, 2024
1b5656b
Updated step definitions and fixed lints
jeawhanlee Sep 18, 2024
bfc1b98
Added new general step definitions
jeawhanlee Sep 18, 2024
fb1bb62
Added new wp cli command support
jeawhanlee Sep 18, 2024
8b5807e
Updated the way we log out and use wp cli for wp rocket cleanup with …
jeawhanlee Sep 18, 2024
4553c1b
Introduced new helper plugin for disabling saas visit and changed som…
jeawhanlee Sep 18, 2024
28680b5
Remove helper plugin dependency
jeawhanlee Sep 18, 2024
f312c17
Check for seeded data existence
jeawhanlee Sep 18, 2024
ea5e0ea
Add new wp cli commands to get post data by title and update post status
jeawhanlee Sep 19, 2024
5d267bd
Bypass UI and use new commands
jeawhanlee Sep 19, 2024
70267a3
Updated step
jeawhanlee Sep 19, 2024
ff22ddb
Wait for page load to complete
jeawhanlee Sep 19, 2024
e115505
Added new helper to seed data in DB
jeawhanlee Sep 19, 2024
e9fb1ac
Used new helper and removed function with duplicate functionality
jeawhanlee Sep 19, 2024
55f01f5
Merge branch 'develop' into performance-hints
jeawhanlee Sep 19, 2024
ec77a58
Updated helper function to seed data and added new helper to check da…
jeawhanlee Sep 20, 2024
9aa0043
Removed logs from command
jeawhanlee Sep 20, 2024
30286fd
Updated to use new helpers
jeawhanlee Sep 20, 2024
972437a
Removed unused module
jeawhanlee Sep 20, 2024
a857ff4
Removed waitForLoadState function
jeawhanlee Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/features/performance-hints.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@setup
Feature: Clear lcp/performance hints data tests

Background:
Given I am logged in
And plugin is installed 'new_release'
And plugin is activated

Scenario: C16387 - Should clear performance hints data when click clear PH in admin bar
And performance hints data added to DB
jeawhanlee marked this conversation as resolved.
Show resolved Hide resolved
When clear performance hints is clicked in admin bar
Then data is removed from the performance hints tables

@hints
jeawhanlee marked this conversation as resolved.
Show resolved Hide resolved
Scenario: C16389 Should clear performance hints when change permalinks
And performance hints data added to DB
jeawhanlee marked this conversation as resolved.
Show resolved Hide resolved
When permalink is changed
Then data is removed from the performance hints tables
89 changes: 89 additions & 0 deletions src/support/steps/performance-hints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @fileoverview
* This module contains Cucumber step definitions using Playwright for asserting performance hints data clearing from DB,
* both ATF and LRC tables
*
* @requires {@link ../../common/custom-world}
* @requires {@link @playwright/test}
* @requires {@link @cucumber/cucumber}
*/

import { ICustomWorld } from "../../common/custom-world";
import { When, Then } from '@cucumber/cucumber';
import { dbQuery, getWPTablePrefix } from "../../../utils/commands";
import { extractFromStdout } from "../../../utils/helpers";

import {WP_BASE_URL} from "../../../config/wp.config";

import assert from "assert";
jeawhanlee marked this conversation as resolved.
Show resolved Hide resolved


function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

When('performance hints data added to DB', async function (this: ICustomWorld) {
const tablePrefix = await getWPTablePrefix();
jeawhanlee marked this conversation as resolved.
Show resolved Hide resolved
const tableName = `${tablePrefix}wpr_above_the_fold`;

// Truncate the table
await dbQuery(`TRUNCATE TABLE ${tableName}`);

// Define the data to be inserted
const expectedData = [
{ url: `${WP_BASE_URL}/a`, is_mobile: 0, status: 'completed' },
{ url: `${WP_BASE_URL}/b`, is_mobile: 0, status: 'completed' },
{ url: `${WP_BASE_URL}/c`, is_mobile: 0, status: 'completed' }
];

// Insert new rows into the table
const insertSql = `
INSERT INTO ${tableName} (url, is_mobile, status)
VALUES
('${WP_BASE_URL}/a', 0, 'completed'),
('${WP_BASE_URL}/b', 0, 'completed'),
('${WP_BASE_URL}/c', 0, 'completed')
`;
await dbQuery(insertSql);

// Fetch and log the data to verify
const selectSql = `SELECT * FROM ${tableName}`;
const resultFromStdout = await dbQuery(selectSql);

// Log the fetched data
console.log('Data in the table:', resultFromStdout);

// Assert that the actual data matches the expected data
// assert.deepStrictEqual(resultFromStdout, expectedData, 'The data in the table does not match the expected data');

});

When('clear performance hints is clicked in admin bar', async function (this: ICustomWorld) {
await this.page.locator('#wp-admin-bar-wp-rocket').hover();
await this.page.waitForSelector('#wp-admin-bar-clean-saas', { state: 'visible' });
await this.page.locator('#wp-admin-bar-clean-saas').click();
await this.page.waitForSelector('div.notice.notice-success', { state: 'visible' });
});

Then('data is removed from the performance hints tables', async function (this: ICustomWorld) {
const tablePrefix = await getWPTablePrefix();
const tableName = `${tablePrefix}wpr_above_the_fold`;

// Fetch and log the data to verify
const selectSql = `SELECT * FROM ${tableName}`;
const result = await dbQuery(selectSql);

// Extract result from stdout and log it
const resultFromStdout = await extractFromStdout(result);
if (resultFromStdout.length === 0) {
console.log('Data is removed from the table as expected.');
} else {
console.log('Data in the table:', resultFromStdout);
assert.fail('Data still exists in the table, but it was expected to be removed.');
}

});

When('permalink is changed', async function (this: ICustomWorld) {
await this.utils.permalinkChanged();
});
16 changes: 16 additions & 0 deletions utils/page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ export class PageUtils {
await this.page.locator('text=Preview in new tab').click();
}

/**
* Changes permalink custom structure to have ending slash.
*
* @return {Promise<void>}
*/
public permalinkChanged = async (): Promise<void> => {
await this.page.goto(WP_BASE_URL + '/wp-admin/options-permalink.php');
await this.page.locator('#permalink_structure').fill('/%postname%/');

// Save changes.
await this.page.locator('#submit').click();

// Assert permalink structure successfully changed.
await expect(this.page.locator('#setting-error-settings_updated')).toContainText('Permalink structure updated.');
}

/**
* Peforms a WPR menu dropdown action.
*
Expand Down