diff --git a/scripts/seed-test-content.php b/scripts/seed-test-content.php index c1257c6..1162478 100644 --- a/scripts/seed-test-content.php +++ b/scripts/seed-test-content.php @@ -98,10 +98,35 @@ function chrnx_seed_upsert_post( array $fixture, string $post_type, int $offset } chrnx_seed_editorial_terms(); -$chrnx_seed_pages = chrnx_seed_read_fixture( 'pages.json' ); -$chrnx_seed_posts = chrnx_seed_read_fixture( 'posts.json' ); -$chrnx_seed_page_ids = array(); -$chrnx_seed_post_ids = array(); +$chrnx_seed_pages = chrnx_seed_read_fixture( 'pages.json' ); +$chrnx_seed_posts = chrnx_seed_read_fixture( 'posts.json' ); +$chrnx_seed_page_ids = array(); +$chrnx_seed_post_ids = array(); +$chrnx_seed_keys = array_map( + 'sanitize_key', + array_merge( + array_column( $chrnx_seed_pages, 'fixtureKey' ), + array_column( $chrnx_seed_posts, 'fixtureKey' ) + ) +); +$chrnx_seed_removed = 0; +$chrnx_seed_owned_ids = get_posts( + array( + 'post_type' => array( 'page', 'post' ), + 'post_status' => 'any', + 'posts_per_page' => -1, + 'fields' => 'ids', + 'no_found_rows' => true, + 'meta_key' => '_chrnx_fixture_key', + ) +); +foreach ( $chrnx_seed_owned_ids as $chrnx_seed_owned_id ) { + $chrnx_seed_owned_key = sanitize_key( get_post_meta( $chrnx_seed_owned_id, '_chrnx_fixture_key', true ) ); + if ( preg_match( '/^(?:page|post)-[a-z0-9-]+$/', $chrnx_seed_owned_key ) && ! in_array( $chrnx_seed_owned_key, $chrnx_seed_keys, true ) ) { + wp_delete_post( $chrnx_seed_owned_id, true ); + ++$chrnx_seed_removed; + } +} foreach ( $chrnx_seed_pages as $chrnx_seed_index => $chrnx_seed_page ) { $chrnx_seed_page_id = chrnx_seed_upsert_post( $chrnx_seed_page, 'page', $chrnx_seed_index ); @@ -165,9 +190,10 @@ flush_rewrite_rules( false ); WP_CLI::log( sprintf( - 'CHRNX_FIXTURES pages=%d posts=%d front=%d scenario=%s', + 'CHRNX_FIXTURES pages=%d posts=%d removed=%d front=%d scenario=%s', count( $chrnx_seed_page_ids ), count( $chrnx_seed_post_ids ), + $chrnx_seed_removed, $chrnx_seed_page_ids['home'], $chrnx_seed_scenario ) diff --git a/templates/404.html b/templates/404.html index b263bee..7606439 100644 --- a/templates/404.html +++ b/templates/404.html @@ -5,7 +5,7 @@

Page not found

This address does not lead to a published page. Search the site or return to a known starting point.

- + diff --git a/templates/search.html b/templates/search.html index 91f1c97..b124931 100644 --- a/templates/search.html +++ b/templates/search.html @@ -5,7 +5,7 @@ - + diff --git a/tests/e2e/visual-states.spec.mjs b/tests/e2e/visual-states.spec.mjs index ad395d5..6c29dda 100644 --- a/tests/e2e/visual-states.spec.mjs +++ b/tests/e2e/visual-states.spec.mjs @@ -96,9 +96,16 @@ test( 'long, incomplete, empty, and missing states stay usable', async ( { page } ), ).toBeVisible(); await expect( page.locator( '.chrnx-podcast-meta' ) ).toHaveCount( 0 ); + await expect( page.locator( '.taxonomy-chrnx_topic, .taxonomy-chrnx_language' ) ).toHaveCount( + 0, + ); + await expect( page.getByText( 'Estado de prueba para un episodio sin show' ) ).toHaveCount( 0 ); await page.goto( '/emotion-is-not-a-slider-designing-expressive-systems-that-can-hesitate/' ); await expect( page.locator( 'pre code' ) ).toContainText( 'const state' ); + await expect( page.locator( 'pre code' ) ).toContainText( + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', + ); await expectNoHorizontalOverflow( page ); for ( const [ path, title ] of [ @@ -110,9 +117,6 @@ test( 'long, incomplete, empty, and missing states stay usable', async ( { page '/una-cuerda-rota-tambien-puede-decidir-el-arreglo/', 'Una cuerda rota también puede decidir el arreglo', ], - [ '/nota-local-sin-extracto/', 'Nota local sin extracto' ], - [ '/note-without-topic/', 'Note without a topic' ], - [ '/nota-sin-idioma-asignado/', 'Nota sin idioma asignado' ], ] ) { await page.goto( path ); await expect( page.getByRole( 'heading', { level: 1 } ) ).toContainText( title ); @@ -120,12 +124,6 @@ test( 'long, incomplete, empty, and missing states stay usable', async ( { page } await expect( page.locator( '.chrnx-entry__meta a', { hasText: 'English' } ) ).toHaveCount( 0 ); - await page.goto( '/unbroken-token-overflow-test/' ); - await expect( page.locator( 'pre code' ) ).toContainText( - 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', - ); - await expectNoHorizontalOverflow( page ); - await page.goto( '/journal/?chrnx_topic=..%2F..%2Fcode&chrnx_language%5B%5D=en&s%5B%5D=x' ); await expect( page.locator( 'select[name="chrnx_topic"]' ) ).toHaveValue( '' ); await expect( page.locator( 'select[name="chrnx_language"]' ) ).toHaveValue( '' ); @@ -232,6 +230,23 @@ test( 'site routes preserve heading order, named landmarks, and skip-link keyboa } } ); +test( 'search and not-found recovery navigation landmarks have unique names', async ( { + page, +} ) => { + for ( const [ path, expected ] of [ + [ '/?s=fixture-that-cannot-exist', 'Search recovery navigation' ], + [ '/this-route-does-not-exist/', 'Page not found recovery navigation' ], + ] ) { + await page.goto( path ); + await expect( page.getByRole( 'navigation', { name: expected } ) ).toHaveCount( 1 ); + const names = await page + .locator( 'nav' ) + .evaluateAll( ( nodes ) => nodes.map( ( node ) => node.getAttribute( 'aria-label' ) ) ); + expect( names.every( Boolean ) ).toBeTruthy(); + expect( new Set( names ).size ).toBe( names.length ); + } +} ); + test( 'reduced motion removes card transitions while theme preference remains user-controlled', async ( { page, } ) => { diff --git a/tests/fixtures/posts.json b/tests/fixtures/posts.json index f348ead..c672307 100644 --- a/tests/fixtures/posts.json +++ b/tests/fixtures/posts.json @@ -3,10 +3,11 @@ "fixtureKey": "post-code-primary", "title": "Emotion is not a slider: designing expressive systems that can hesitate", "excerpt": "A working note on modeling emotional state without flattening behavior into a single number.", - "content": "

Expressive software gets interesting when uncertainty is part of the model instead of an error to erase.

const state = observe(world);\nconst choice = agent.respond(state, { uncertainty: true });
", + "content": "

Expressive software gets interesting when uncertainty is part of the model instead of an error to erase.

const state = observe(world);\nconst choice = agent.respond(state, { uncertainty: true });\nABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
", "topic": "code", "language": "en", - "featured": true + "featured": true, + "fixtureState": "unbroken-code" }, { "fixtureKey": "post-research-primary", @@ -61,11 +62,8 @@ { "fixtureKey": "post-podcast-missing-meta", "title": "Conversación pendiente de datos editoriales", - "excerpt": "Estado de prueba para un episodio sin show ni duración asignados.", "content": "

El tema debe seguir siendo claro aunque la ficha editorial todavía esté incompleta.

", - "topic": "podcasts", - "language": "es", - "fixtureState": "missing-podcast-meta" + "fixtureStates": [ "missing-podcast-meta", "missing-excerpt", "missing-topic", "missing-language" ] }, { "fixtureKey": "post-life-fatherhood", @@ -106,42 +104,5 @@ "content": "

La tinta sabía algo que el narrador todavía no.

", "topic": "literature", "language": "es" - }, - { - "fixtureKey": "post-missing-excerpt", - "slug": "nota-local-sin-extracto", - "title": "Nota local sin extracto", - "content": "

Fixture local para comprobar el resumen ausente.

", - "topic": "life", - "language": "es", - "fixtureState": "missing-excerpt" - }, - { - "fixtureKey": "post-missing-topic", - "slug": "note-without-topic", - "title": "Note without a topic", - "excerpt": "A local fixture with no editorial topic.", - "content": "

The theme must not infer a private identity or category.

", - "language": "en", - "fixtureState": "missing-topic" - }, - { - "fixtureKey": "post-missing-language", - "slug": "nota-sin-idioma-asignado", - "title": "Nota sin idioma asignado", - "excerpt": "Fixture local sin taxonomía de idioma.", - "content": "

El contenido permanece legible sin inventar metadatos.

", - "topic": "research", - "fixtureState": "missing-language" - }, - { - "fixtureKey": "post-unbroken-code", - "slug": "unbroken-token-overflow-test", - "title": "Unbroken token overflow test", - "excerpt": "A deliberately hostile local layout fixture.", - "content": "
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
", - "topic": "code", - "language": "en", - "fixtureState": "unbroken-code" } ] diff --git a/tests/smoke/visual-integration.test.mjs b/tests/smoke/visual-integration.test.mjs index 22b02e7..0f2d713 100644 --- a/tests/smoke/visual-integration.test.mjs +++ b/tests/smoke/visual-integration.test.mjs @@ -16,17 +16,18 @@ test( 'local visual fixtures define stable pages and representative editorial st [ 'home', 'journal', 'projects', 'music', 'podcasts', 'about', 'subscribe' ], ); assert.ok( pages.every( ( page ) => page.fixtureKey && page.status === 'publish' ) ); - assert.ok( posts.length >= 10 ); + assert.equal( posts.length, 12 ); assert.ok( posts.some( ( post ) => post.title.length > 100 ) ); assert.ok( posts.some( ( post ) => post.content.includes( 'wp:code' ) ) ); assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-media' ) ); - assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-podcast-meta' ) ); - assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-excerpt' && !( 'excerpt' in post ) ) ); - assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-topic' && !( 'topic' in post ) ) ); - assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-language' && !( 'language' in post ) ) ); + const hasState = ( post, state ) => post.fixtureState === state || post.fixtureStates?.includes( state ); + assert.ok( posts.some( ( post ) => hasState( post, 'missing-podcast-meta' ) ) ); + assert.ok( posts.some( ( post ) => hasState( post, 'missing-excerpt' ) && !( 'excerpt' in post ) ) ); + assert.ok( posts.some( ( post ) => hasState( post, 'missing-topic' ) && !( 'topic' in post ) ) ); + assert.ok( posts.some( ( post ) => hasState( post, 'missing-language' ) && !( 'language' in post ) ) ); assert.ok( posts.some( ( post ) => post.fixtureState === 'unbroken-code' && /[A-Z0-9]{256}/.test( post.content ) ) ); assert.ok( posts.some( ( post ) => /^https:\/\//.test( post.canonicalEpisodeUrl ?? '' ) ) ); - assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-podcast-meta' && !( 'canonicalEpisodeUrl' in post ) ) ); + assert.ok( posts.some( ( post ) => hasState( post, 'missing-podcast-meta' ) && !( 'canonicalEpisodeUrl' in post ) ) ); assert.equal( new Set( posts.map( ( post ) => post.fixtureKey ) ).size, posts.length ); for ( const topic of [ 'code', 'research', 'gaming', 'literature', 'music', 'podcasts', 'life' ] ) { assert.ok( posts.some( ( post ) => post.topic === topic ), `missing ${ topic } fixture` ); @@ -42,12 +43,21 @@ test( 'the seed entrypoint is explicitly local-only and uses a stable fixture ke assert.match( shell, /featured-1/ ); assert.match( shell, /subscribe-unavailable/ ); assert.match( php, /_chrnx_fixture_key/ ); + assert.match( php, /wp_delete_post/ ); assert.match( php, /canonical_episode_url/ ); assert.match( php, /show_on_front/ ); assert.match( php, /page_on_front/ ); assert.match( php, /page_for_posts/ ); } ); +test( 'search and not-found recovery landmarks declare distinct accessible names', () => { + const search = read( 'templates/search.html' ); + const missing = read( 'templates/404.html' ); + assert.match( search, /"ariaLabel":"Search recovery navigation"/ ); + assert.match( missing, /"ariaLabel":"Page not found recovery navigation"/ ); + assert.notEqual( search.match( /"ariaLabel":"([^"]+)"/ )?.[ 1 ], missing.match( /"ariaLabel":"([^"]+)"/ )?.[ 1 ] ); +} ); + test( 'the visual layer is separately enqueued and covers responsive accessible states', () => { const assets = read( 'inc/assets.php' ); const components = read( 'assets/css/components.css' );