From 52099a7ca125b0cbe4e9d4b70f34cc48e5de35be Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Wed, 12 Aug 2026 22:05:39 -0500 Subject: [PATCH] test: harden Related Stories browser acceptance --- tests/e2e/related-stories.spec.mjs | 17 +++---- tests/e2e/response-diagnostics.mjs | 6 +++ ...elated-stories-browser-acceptance.test.mjs | 48 +++++++++++++++++++ 3 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 tests/e2e/response-diagnostics.mjs create mode 100644 tests/smoke/related-stories-browser-acceptance.test.mjs diff --git a/tests/e2e/related-stories.spec.mjs b/tests/e2e/related-stories.spec.mjs index 0a80c36..e5708dc 100644 --- a/tests/e2e/related-stories.spec.mjs +++ b/tests/e2e/related-stories.spec.mjs @@ -1,6 +1,8 @@ import { expect, test } from '@playwright/test'; import { injectAxe } from 'axe-playwright'; +import { containsPhpDiagnostic } from './response-diagnostics.mjs'; + async function logIn( page ) { await page.goto( '/wp-login.php' ); await page.locator( '#user_login' ).fill( 'admin' ); @@ -50,15 +52,8 @@ function tabShortcut( browserName, reverse = false ) { async function scrollRailNatively( page, track, browserName ) { await track.hover(); if ( browserName === 'webkit' ) { - await track.evaluate( ( element ) => { - const card = element.querySelector( '.chrnx-related-card' ); - const style = window.getComputedStyle( element ); - const gap = Number.parseFloat( style.columnGap || style.gap ) || 0; - element.scrollBy( { - left: card.getBoundingClientRect().width + gap, - behavior: 'auto', - } ); - } ); + await track.focus(); + await page.keyboard.press( 'ArrowRight' ); return; } await page.mouse.wheel( 240, 0 ); @@ -506,7 +501,7 @@ test( 'interaction buttons move exactly one card and update both disabled edges' await expect( next ).toBeEnabled(); } ); -test( 'interaction native horizontal wheel scrolling remains available', async ( { +test( 'interaction native horizontal scrolling remains available through real user input', async ( { page, browserName, } ) => { @@ -679,7 +674,7 @@ test( 'permalink every rendered related card reaches a same-origin published HTT await page.locator( `#related-stories-5-grid a[href="${ href }"]` ).click(); const response = await responsePromise; expect( response.status() ).toBe( 200 ); - expect( await response.text() ).not.toMatch( /PHP (?:Warning|Notice)|Fatal error/i ); + expect( containsPhpDiagnostic( await response.text() ) ).toBe( false ); await expect( page.locator( 'body' ) ).toHaveClass( /single-post/ ); await expect( page.getByRole( 'heading', { level: 1 } ) ).toBeVisible(); } diff --git a/tests/e2e/response-diagnostics.mjs b/tests/e2e/response-diagnostics.mjs new file mode 100644 index 0000000..549c06d --- /dev/null +++ b/tests/e2e/response-diagnostics.mjs @@ -0,0 +1,6 @@ +export const phpDiagnosticPattern = + /(?:PHP\s+(?:Warning|Notice|Fatal error|Parse error|Deprecated)\b|(?:Warning|Notice|Fatal error|Parse error|Deprecated)\s*:|\s*(?:Warning|Notice|Fatal error|Parse error|Deprecated)\s*<\/b>\s*:)/i; + +export function containsPhpDiagnostic( responseBody ) { + return phpDiagnosticPattern.test( responseBody ); +} diff --git a/tests/smoke/related-stories-browser-acceptance.test.mjs b/tests/smoke/related-stories-browser-acceptance.test.mjs new file mode 100644 index 0000000..f767c33 --- /dev/null +++ b/tests/smoke/related-stories-browser-acceptance.test.mjs @@ -0,0 +1,48 @@ +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import test from 'node:test'; + +import { containsPhpDiagnostic } from '../e2e/response-diagnostics.mjs'; + +test( 'response diagnostics catch plain and display_errors PHP failures without normal prose', () => { + for ( const diagnostic of [ + 'PHP Warning: Undefined variable $story', + 'Warning: Undefined variable $story', + 'Warning: Undefined variable $story
', + 'PHP Notice: Undefined index: story', + 'Notice: Undefined index: story', + 'Notice: Undefined index: story
', + 'PHP Fatal error: Uncaught Error', + 'Fatal error: Uncaught Error', + 'Fatal error: Uncaught Error
', + 'PHP Parse error: unexpected token', + 'Parse error: unexpected token', + 'Parse error: unexpected token
', + 'PHP Deprecated: Optional parameter', + 'Deprecated: Optional parameter', + 'Deprecated: Optional parameter
', + ] ) { + assert.equal( containsPhpDiagnostic( diagnostic ), true, diagnostic ); + } + + for ( const prose of [ + 'Warning signs can make a story more useful.', + 'A notice board hangs beside the door.', + 'The album Deprecated Futures is available now.', + 'Fatal Error is the title of a fictional game.', + 'Parse errors carefully when reviewing a compiler.', + ] ) { + assert.equal( containsPhpDiagnostic( prose ), false, prose ); + } +} ); + +test( 'WebKit native scroll uses a focused rail and a real keyboard gesture', async () => { + const source = await readFile( 'tests/e2e/related-stories.spec.mjs', 'utf8' ); + const helper = source.match( + /async function scrollRailNatively[\s\S]*?\n}\n\ntest\.describe\.serial/, + )?.[ 0 ]; + + assert.ok( helper, 'native scroll helper must remain inspectable' ); + assert.doesNotMatch( helper, /track\.evaluate|\.scrollBy\s*\(/ ); + assert.match( helper, /track\.focus\(\)[\s\S]*keyboard\.press\(\s*['"]ArrowRight['"]\s*\)/ ); +} );