|
| 1 | +/** |
| 2 | + * WordPress dependencies |
| 3 | + */ |
| 4 | +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); |
| 5 | + |
| 6 | +test.describe( 'Preformatted', () => { |
| 7 | + test.beforeEach( async ( { admin } ) => { |
| 8 | + await admin.createNewPost(); |
| 9 | + } ); |
| 10 | + |
| 11 | + test( 'should preserve character newlines', async ( { editor, page } ) => { |
| 12 | + await editor.insertBlock( { name: 'core/html' } ); |
| 13 | + await page.keyboard.type( '<pre>1' ); |
| 14 | + await page.keyboard.press( 'Enter' ); |
| 15 | + await page.keyboard.type( '2</pre>' ); |
| 16 | + |
| 17 | + expect( await editor.getEditedPostContent() ).toMatchSnapshot(); |
| 18 | + |
| 19 | + await editor.clickBlockOptionsMenuItem( 'Convert to Blocks' ); |
| 20 | + // Once it's edited, it should be saved as BR tags. |
| 21 | + await page.keyboard.type( '0' ); |
| 22 | + await page.keyboard.press( 'Enter' ); |
| 23 | + await editor.clickBlockOptionsMenuItem( 'Edit as HTML' ); |
| 24 | + |
| 25 | + expect( await editor.getEditedPostContent() ).toMatchSnapshot(); |
| 26 | + } ); |
| 27 | + |
| 28 | + test( 'should preserve white space when merging', async ( { |
| 29 | + editor, |
| 30 | + page, |
| 31 | + } ) => { |
| 32 | + await editor.insertBlock( { name: 'core/preformatted' } ); |
| 33 | + await page.keyboard.type( '1' ); |
| 34 | + await page.keyboard.press( 'Enter' ); |
| 35 | + await page.keyboard.type( '2' ); |
| 36 | + await page.keyboard.press( 'Enter' ); |
| 37 | + await editor.insertBlock( { name: 'core/paragraph' } ); |
| 38 | + await page.keyboard.type( '3' ); |
| 39 | + await page.keyboard.press( 'ArrowLeft' ); |
| 40 | + await page.keyboard.press( 'Backspace' ); |
| 41 | + |
| 42 | + expect( await editor.getEditedPostContent() ).toMatchSnapshot(); |
| 43 | + } ); |
| 44 | + |
| 45 | + test( 'should delete block when backspace in an empty preformatted', async ( { |
| 46 | + editor, |
| 47 | + page, |
| 48 | + } ) => { |
| 49 | + await editor.insertBlock( { name: 'core/preformatted' } ); |
| 50 | + |
| 51 | + await page.keyboard.type( 'a' ); |
| 52 | + |
| 53 | + await page.keyboard.press( 'Backspace' ); |
| 54 | + await page.keyboard.press( 'Backspace' ); |
| 55 | + |
| 56 | + // Expect preformatted block to be deleted. |
| 57 | + expect( await editor.getEditedPostContent() ).toBe( '' ); |
| 58 | + } ); |
| 59 | +} ); |
0 commit comments