|
| 1 | +/** |
| 2 | + * WordPress dependencies |
| 3 | + */ |
| 4 | +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); |
| 5 | + |
| 6 | +test.describe( 'Revision Fields Diff Panel', () => { |
| 7 | + test.beforeEach( async ( { admin } ) => { |
| 8 | + await admin.createNewPost(); |
| 9 | + } ); |
| 10 | + |
| 11 | + test( 'should show only the revision footnotes, not the current post footnotes', async ( { |
| 12 | + editor, |
| 13 | + page, |
| 14 | + } ) => { |
| 15 | + // Revision 1: paragraph with footnote "alpha". |
| 16 | + await editor.canvas |
| 17 | + .getByRole( 'button', { name: 'Add default block' } ) |
| 18 | + .click(); |
| 19 | + await page.keyboard.type( 'Paragraph one' ); |
| 20 | + await editor.showBlockToolbar(); |
| 21 | + await editor.clickBlockToolbarButton( 'More' ); |
| 22 | + await page.getByRole( 'menuitem', { name: 'Footnote' } ).click(); |
| 23 | + await page.keyboard.type( 'alpha' ); |
| 24 | + await editor.saveDraft(); |
| 25 | + |
| 26 | + // Revision 2: add a second paragraph with footnote "beta". |
| 27 | + // Insert programmatically to avoid focus issues with footnotes block. |
| 28 | + await page.evaluate( () => { |
| 29 | + const block = window.wp.blocks.createBlock( 'core/paragraph', { |
| 30 | + content: 'Paragraph two', |
| 31 | + } ); |
| 32 | + window.wp.data |
| 33 | + .dispatch( 'core/block-editor' ) |
| 34 | + .insertBlock( block, 1 ); |
| 35 | + } ); |
| 36 | + await editor.canvas |
| 37 | + .getByRole( 'document', { name: 'Block: Paragraph' } ) |
| 38 | + .nth( 1 ) |
| 39 | + .click(); |
| 40 | + await page.keyboard.press( 'End' ); |
| 41 | + await editor.showBlockToolbar(); |
| 42 | + await editor.clickBlockToolbarButton( 'More' ); |
| 43 | + await page.getByRole( 'menuitem', { name: 'Footnote' } ).click(); |
| 44 | + await page.keyboard.type( 'beta' ); |
| 45 | + await editor.saveDraft(); |
| 46 | + |
| 47 | + // Open revisions UI. |
| 48 | + await editor.openDocumentSettingsSidebar(); |
| 49 | + const settingsSidebar = page.getByRole( 'region', { |
| 50 | + name: 'Editor settings', |
| 51 | + } ); |
| 52 | + await settingsSidebar.getByRole( 'tab', { name: 'Post' } ).click(); |
| 53 | + await settingsSidebar |
| 54 | + .getByRole( 'button', { name: '2', exact: true } ) |
| 55 | + .click(); |
| 56 | + await expect( |
| 57 | + page.getByRole( 'button', { name: 'Restore' } ) |
| 58 | + ).toBeVisible(); |
| 59 | + |
| 60 | + // Expand the Meta panel. |
| 61 | + await settingsSidebar.getByRole( 'button', { name: 'Meta' } ).click(); |
| 62 | + |
| 63 | + const footnotesRow = settingsSidebar.locator( |
| 64 | + '.editor-post-panel__row', |
| 65 | + { |
| 66 | + has: page.locator( |
| 67 | + '.editor-post-panel__row-label:text("footnotes")' |
| 68 | + ), |
| 69 | + } |
| 70 | + ); |
| 71 | + const footnotesControl = footnotesRow.locator( |
| 72 | + '.editor-post-panel__row-control' |
| 73 | + ); |
| 74 | + |
| 75 | + // Latest revision (2 footnotes) diffs against rev 1 (1 footnote). |
| 76 | + // Should contain both "alpha" and "beta". |
| 77 | + await expect( footnotesControl ).toContainText( 'alpha' ); |
| 78 | + await expect( footnotesControl ).toContainText( 'beta' ); |
| 79 | + |
| 80 | + // Navigate to oldest revision. |
| 81 | + const slider = page.getByRole( 'slider', { name: 'Revision' } ); |
| 82 | + await slider.focus(); |
| 83 | + await page.keyboard.press( 'Home' ); |
| 84 | + |
| 85 | + // Oldest revision (1 footnote) has no previous revision. |
| 86 | + // Should only contain "alpha", NOT "beta". |
| 87 | + await expect( footnotesControl ).toContainText( 'alpha' ); |
| 88 | + await expect( footnotesControl ).not.toContainText( 'beta' ); |
| 89 | + } ); |
| 90 | +} ); |
0 commit comments