test: harden Related Stories browser acceptance
This commit is contained in:
3 files changed
+60
-11
No files matched your search
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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*:|<b>\s*(?:Warning|Notice|Fatal error|Parse error|Deprecated)\s*<\/b>\s*:)/i;
|
||||
|
||||
export function containsPhpDiagnostic( responseBody ) {
|
||||
return phpDiagnosticPattern.test( responseBody );
|
||||
}
|
||||
@@ -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',
|
||||
'<b>Warning</b>: Undefined variable $story<br />',
|
||||
'PHP Notice: Undefined index: story',
|
||||
'Notice: Undefined index: story',
|
||||
'<b>Notice</b>: Undefined index: story<br />',
|
||||
'PHP Fatal error: Uncaught Error',
|
||||
'Fatal error: Uncaught Error',
|
||||
'<b>Fatal error</b>: Uncaught Error<br />',
|
||||
'PHP Parse error: unexpected token',
|
||||
'Parse error: unexpected token',
|
||||
'<b>Parse error</b>: unexpected token<br />',
|
||||
'PHP Deprecated: Optional parameter',
|
||||
'Deprecated: Optional parameter',
|
||||
'<b>Deprecated</b>: Optional parameter<br />',
|
||||
] ) {
|
||||
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*\)/ );
|
||||
} );
|
||||
Reference in new issue
Block a user