|
| 1 | +/** |
| 2 | + * WordPress dependencies |
| 3 | + */ |
| 4 | +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); |
| 5 | + |
| 6 | +test.describe( 'Page List block', () => { |
| 7 | + test.afterEach( async ( { requestUtils } ) => { |
| 8 | + await requestUtils.deleteAllPages(); |
| 9 | + } ); |
| 10 | + |
| 11 | + test( 'renders HTML formatting and entities in page titles', async ( { |
| 12 | + editor, |
| 13 | + admin, |
| 14 | + requestUtils, |
| 15 | + } ) => { |
| 16 | + // Create a page with both HTML formatting and entities in the title |
| 17 | + await requestUtils.createPage( { |
| 18 | + title: '<strong>Bold &"qwerty"—</strong>', |
| 19 | + status: 'publish', |
| 20 | + } ); |
| 21 | + |
| 22 | + // Insert Page List block directly |
| 23 | + await admin.createNewPost(); |
| 24 | + await editor.insertBlock( { name: 'core/page-list' } ); |
| 25 | + |
| 26 | + // Wait for Page List block to be visible |
| 27 | + const pageListBlock = editor.canvas.getByRole( 'document', { |
| 28 | + name: 'Block: Page List', |
| 29 | + } ); |
| 30 | + |
| 31 | + await expect( pageListBlock ).toBeVisible( { |
| 32 | + // Wait for the Page List block API request to resolve. |
| 33 | + timeout: 10000, |
| 34 | + } ); |
| 35 | + |
| 36 | + // Locate the page list item |
| 37 | + const pageItems = pageListBlock.locator( 'li' ); |
| 38 | + |
| 39 | + // Wait for Page List to load pages |
| 40 | + await pageItems.first().waitFor( { state: 'visible' } ); |
| 41 | + |
| 42 | + // Find the link element - try to find by text content |
| 43 | + const links = pageListBlock.locator( 'a' ); |
| 44 | + const linkCount = await links.count(); |
| 45 | + expect( linkCount ).toBeGreaterThan( 0 ); |
| 46 | + |
| 47 | + // Find the link that contains our test page title |
| 48 | + let link = null; |
| 49 | + for ( let i = 0; i < linkCount; i++ ) { |
| 50 | + const currentLink = links.nth( i ); |
| 51 | + const text = await currentLink.textContent(); |
| 52 | + if ( |
| 53 | + text && |
| 54 | + ( text.includes( 'qwerty' ) || text.includes( 'Bold' ) ) |
| 55 | + ) { |
| 56 | + link = currentLink; |
| 57 | + break; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + expect( link ).not.toBeNull(); |
| 62 | + await expect( link ).toBeVisible(); |
| 63 | + |
| 64 | + // Verify text content shows decoded text (not raw HTML or entity codes) |
| 65 | + const textContent = await link.textContent(); |
| 66 | + expect( textContent ).toContain( 'Bold' ); |
| 67 | + expect( textContent ).toContain( 'qwerty' ); |
| 68 | + // Verify HTML tags are not shown as raw markup |
| 69 | + expect( textContent ).not.toContain( '<strong>' ); |
| 70 | + expect( textContent ).not.toContain( '</strong>' ); |
| 71 | + // Verify entity codes are not shown as raw codes |
| 72 | + expect( textContent ).not.toContain( '&' ); |
| 73 | + expect( textContent ).not.toContain( '"' ); |
| 74 | + expect( textContent ).not.toContain( '—' ); |
| 75 | + |
| 76 | + // Verify HTML is rendered (check for strong tag) |
| 77 | + const strongElement = link.locator( 'css=strong' ); |
| 78 | + await expect( strongElement ).toBeVisible(); |
| 79 | + await expect( strongElement ).toContainText( 'Bold' ); |
| 80 | + await expect( strongElement ).toContainText( 'qwerty' ); |
| 81 | + |
| 82 | + // Verify innerHTML contains the strong tag (not escaped) |
| 83 | + const innerHTML = await link.innerHTML(); |
| 84 | + expect( innerHTML ).toContain( '<strong>' ); |
| 85 | + expect( innerHTML ).toContain( '</strong>' ); |
| 86 | + // Ensure it's not showing raw HTML as text |
| 87 | + expect( innerHTML ).not.toContain( '<strong>' ); |
| 88 | + expect( innerHTML ).not.toContain( '</strong>' ); |
| 89 | + } ); |
| 90 | +} ); |
0 commit comments