Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("Entries submitted from a form", () => {
const text = $el.text().trim();
expect(text).to.be.oneOf([
"Upgrade to Pro.",
"Get 60% Off Pro!"
"Get 60% Off Pro!"
]);
})

Expand Down
1 change: 1 addition & 0 deletions tests/cypress/e2e/Form Templates/FormTemplates.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ describe("Form Templates page", () => {
cy.login();
cy.visit('/wp-admin/admin.php?page=formidable-form-templates');
cy.viewport(1280, 720);

});

it("should validate page content", () => {
Expand Down
7 changes: 4 additions & 3 deletions tests/cypress/e2e/Forms/formPageDataValidation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ describe("Forms page", () => {
const text = $el.text().trim();
const href = $el.attr('href');

if (href && (text.includes('upgrading to PRO') || text.includes( 'Get 60% Off Pro!' ) || text.match(/GET \d+% OFF|SAVE \d+%/))) {
if (href && (text.includes('upgrading to PRO') || text.match('Get 60% Off Pro!') || text.match(/GET \d+% OFF|SAVE \d+%/))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Harden banner detection with a single case-insensitive regex

Switching to match() is fine, but the current combination is brittle due to case/wording variants. A single case-insensitive regex keeps intent while reducing flakiness.

Apply this diff:

-                if (href && (text.includes('upgrading to PRO') || text.match('Get 60% Off Pro!') || text.match(/GET \d+% OFF|SAVE \d+%/))) {
+                if (href && /(?:upgrad(?:e|ing) to pro)|get \d+% off(?: pro!)?|save \d+%/i.test(text)) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (href && (text.includes('upgrading to PRO') || text.match('Get 60% Off Pro!') || text.match(/GET \d+% OFF|SAVE \d+%/))) {
if (href && /(?:upgrad(?:e|ing) to pro)|get \d+% off(?: pro!)?|save \d+%/i.test(text)) {
🤖 Prompt for AI Agents
In tests/cypress/e2e/Forms/formPageDataValidation.cy.js around line 21, the
banner detection uses multiple brittle case-sensitive checks; replace them with
a single case-insensitive regex and a null-safe test. Update the condition to
ensure text exists then test it with a regex that matches variants like
"upgrading to pro", "get X% off" (optionally "pro") or "save X%" (for example
use a pattern such as /(?:upgrading to pro|get \d+% off(?: pro)?|save \d+%)/i)
so the check is robust to casing and wording variants.

cy.origin('https://formidableforms.com', { args: { href } }, ({ href }) => {
cy.visit(href);
cy.get('h1').should(($h1) => {
const headingText = $h1.text();
expect([
'The Only WordPress Form Maker & Application Builder Plugin',
'Upgrade Today to Unlock the Full Power of Formidable Forms'
'Upgrade Today to Unlock the Full Power of Formidable Forms',
'The Most Advanced WordPress Form builder'
]).to.include(headingText);
});
Comment on lines 24 to 31
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make heading check trim- and case-insensitive to avoid brittle failures

The external page H1 may have minor case/copy tweaks or whitespace. Normalize and check against allowed variants case-insensitively.

Apply this diff:

-                        cy.get('h1').should(($h1) => {
-                            const headingText = $h1.text();
-                            expect([
-                                'The Only WordPress Form Maker & Application Builder Plugin',
-                                'Upgrade Today to Unlock the Full Power of Formidable Forms',
-                                'The Most Advanced WordPress Form builder'
-                            ]).to.include(headingText);
-                        });
+                        cy.get('h1').should(($h1) => {
+                            const headingText = $h1.text().trim();
+                            const allowedHeadings = [
+                                'The Only WordPress Form Maker & Application Builder Plugin',
+                                'Upgrade Today to Unlock the Full Power of Formidable Forms',
+                                'The Most Advanced WordPress Form Builder'
+                            ];
+                            expect(allowedHeadings.map(h => h.toLowerCase())).to.include(headingText.toLowerCase());
+                        });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cy.get('h1').should(($h1) => {
const headingText = $h1.text();
expect([
'The Only WordPress Form Maker & Application Builder Plugin',
'Upgrade Today to Unlock the Full Power of Formidable Forms'
'Upgrade Today to Unlock the Full Power of Formidable Forms',
'The Most Advanced WordPress Form builder'
]).to.include(headingText);
});
cy.get('h1').should(($h1) => {
const headingText = $h1.text().trim();
const allowedHeadings = [
'The Only WordPress Form Maker & Application Builder Plugin',
'Upgrade Today to Unlock the Full Power of Formidable Forms',
'The Most Advanced WordPress Form Builder'
];
expect(
allowedHeadings
.map(h => h.toLowerCase())
.includes(headingText.toLowerCase())
).to.be.true;
});
🤖 Prompt for AI Agents
In tests/cypress/e2e/Forms/formPageDataValidation.cy.js around lines 24 to 31,
the H1 assertion is brittle because it compares raw text; change it to normalize
the heading by trimming whitespace and converting to lower-case, and compare
against a list of allowed variants that are also lower-cased; update the
assertion to call headingText.trim().toLowerCase() and assert inclusion in
allowedVariants.map(v => v.toLowerCase()) so the check becomes both trim- and
case-insensitive.

});
} else {
throw new Error(`Unexpected banner text or missing href: "${text}"`);
throw new Error(`Unexpected banner text or missing href: "${text}"`);
}
});

Expand Down
Loading