Skip to content

Commit

Permalink
Adds Imagify steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Miraeld committed Sep 18, 2024
1 parent aceccd2 commit 73e6d87
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 11 deletions.
13 changes: 12 additions & 1 deletion config/wp.config.sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ const WP_ADMIN_USER = {

} as const;

/**
* The default Imagify settings informations
*
* @constant
* @type {{ API_KEY: string }}
*/
const IMAGIFY_INFOS = {
API_KEY: ''
} as const;

/**
* Extracted environment variables related to WordPress configuration.
* Uses default values if environment variables are not set.
Expand Down Expand Up @@ -124,5 +134,6 @@ export {
WP_SSH_ADDRESS,
WP_SSH_KEY,
WP_SSH_ROOT_DIR,
SCENARIO_URLS
SCENARIO_URLS,
IMAGIFY_INFOS
};
23 changes: 13 additions & 10 deletions src/features/ll-lcp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ Feature: Lazyload with LCP
When I go to 'wp-admin/options-general.php?page=wprocket#dashboard'
And I save settings 'media' 'lazyloadCssBgImg'

Scenario: Should Exclude LCP/ATF from Lazyload
Given I visit page '[TEMPLATE]' with browser dimension 1600 x 700
When I clear cache
Then lcp image markup is not written to LL format
And ATF image markup is not written to LL format
# Scenario: Should Exclude LCP/ATF from Lazyload
# Given I visit page '[TEMPLATE]' with browser dimension 1600 x 700
# When I clear cache
# Then lcp image markup is not written to LL format
# And ATF image markup is not written to LL format

Scenario: Should exclude next-gen lcp/atf from LL
Given plugin is installed 'imagify'
And display next-gen is enabled on imagify # Create this step
And page with images having next-gen avif, webp, avif/webp, no next gen is visited # I didn't get that
And plugin is activated
And I go to 'wp-admin/options-general.php?page=imagify'
And I save imagify API key
And display next-gen is enabled on imagify
# And page with images having next-gen avif, webp, avif/webp, no next gen is visited # I didn't get that
When I clear cache
And I visit the page '[TEMPLATE]' with dimension 1600 x 700
Then lcp image markup is not written to LL format
And ATF image markup is not written to LL format
# And I visit the page '[TEMPLATE]' with dimension 1600 x 700
# Then lcp image markup is not written to LL format
# And ATF image markup is not written to LL format
35 changes: 35 additions & 0 deletions src/support/steps/imagify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect } from "@playwright/test";
import { ICustomWorld } from "../../common/custom-world";

import { Given, When, Then } from '@cucumber/cucumber';
import { IMAGIFY_INFOS } from "../../../config/wp.config";
import { WP_BASE_URL } from '../../../config/wp.config';
import { createReference, compareReference } from "../../../utils/helpers";
import type { Section } from "../../../utils/types";
import { Page } from '@playwright/test';
import {
deactivatePlugin, installRemotePlugin,
} from "../../../utils/commands";

Given('I save imagify API key', async function (this: ICustomWorld) {
// Check if the API key input field exists on the page
const apiKeyInput = await this.page.$('input#api_key');

if (apiKeyInput) {
// Fill the API key input field with the API key from the config
await this.page.fill('input#api_key', IMAGIFY_INFOS.API_KEY);

// Click the submit button to save the changes
await this.page.click('div.submit.imagify-clearfix input#submit');
}
});
Given('display next-gen is enabled on imagify', async function (this: ICustomWorld) {
// Go to Imagify setting page
await this.utils.gotoImagify();

// Check the 'Display images in Next-Gen format on the site' checkbox
await this.page.click('label[for="imagify_display_nextgen"]');

// Click the submit button to save the changes
await this.page.click('input#submit');
});
9 changes: 9 additions & 0 deletions utils/page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ export class PageUtils {
await this.page.goto(WP_BASE_URL + '/wp-admin/options-general.php?page=wprocket#dashboard');
}

/**
* Navigates to Imagify settings page.
*
* @return {Promise<void>}
*/
public gotoImagify = async (): Promise<void> => {
await this.page.goto(WP_BASE_URL + '/wp-admin/options-general.php?page=imagify');
}

/**
* Navigates to new post on Wordpress.
*
Expand Down

0 comments on commit 73e6d87

Please sign in to comment.