/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
test/e2e/specs/editor/blocks/code.spec.js
165 строк
4 KB
Ella
Block editor: render a real default block in place of the default appender (#81231)
12 авг 2026, 03:15
Не верифицирован
12 авг 2026, 03:15
c98049d
Код
Авторство
О чём код?
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); test.describe( 'Code', () => { test.beforeEach( async ( { admin } ) => { await admin.createNewPost(); } ); test( 'can be created by three backticks', async ( { editor, page } ) => { await editor.canvas .locator( 'role=document[name="Add default block"i]' ) .click(); await page.keyboard.type( '```<?php' ); expect( await editor.getBlocks() ).toMatchObject( [ { name: 'core/code', attributes: { content: '<?php', }, }, ] ); } ); test( 'should delete block when backspace in an empty code', async ( { editor, page, } ) => { await editor.insertBlock( { name: 'core/code' } ); await page.keyboard.type( 'a' ); await page.keyboard.press( 'Backspace' ); await page.keyboard.press( 'Backspace' ); // Expect code block to be deleted. expect( await editor.getEditedPostContent() ).toBe( '' ); } ); test( 'should paste plain text', async ( { editor, pageUtils } ) => { await editor.insertBlock( { name: 'core/code' } ); // Test to see if HTML and white space is kept. pageUtils.setClipboardData( { plainText: '<img />\n\t<br>' } ); await pageUtils.pressKeys( 'primary+v' ); expect( await editor.getEditedPostContent() ).toMatchSnapshot(); } ); test.describe( 'Block transforms', () => { test.describe( 'FROM paragraph', () => { test( 'should preserve the content', async ( { editor } ) => { await editor.insertBlock( { name: 'core/paragraph', attributes: { content: 'initial content', }, } ); await editor.transformBlockTo( 'core/code' ); const codeBlock = ( await editor.getBlocks() )[ 0 ]; expect( codeBlock.name ).toBe( 'core/code' ); expect( codeBlock.attributes.content ).toBe( 'initial content' ); } ); test( 'should preserve the metadata name attribute', async ( { editor, } ) => { await editor.insertBlock( { name: 'core/paragraph', attributes: { content: 'initial content', metadata: { name: 'Custom name', }, }, } ); await editor.transformBlockTo( 'core/code' ); const codeBlock = ( await editor.getBlocks() )[ 0 ]; expect( codeBlock.name ).toBe( 'core/code' ); expect( codeBlock.attributes.metadata ).toMatchObject( { name: 'Custom name', } ); } ); } ); test.describe( 'FROM HTML', () => { test( 'should preserve the content', async ( { editor } ) => { // The HTML block's markup lives in its inner content, not in // an attribute, so it can't be seeded via `insertBlock`. await editor.setContent( `<!-- wp:html -->\ninitial content\n<!-- /wp:html -->` ); await editor.canvas .locator( '[data-type="core/html"]' ) .click(); await editor.transformBlockTo( 'core/code' ); const codeBlock = ( await editor.getBlocks() )[ 0 ]; expect( codeBlock.name ).toBe( 'core/code' ); expect( codeBlock.attributes.content ).toBe( 'initial content' ); } ); test( 'should preserve the metadata name attribute', async ( { editor, } ) => { await editor.insertBlock( { name: 'core/html', attributes: { metadata: { name: 'Custom name', }, }, } ); await editor.transformBlockTo( 'core/code' ); const codeBlock = ( await editor.getBlocks() )[ 0 ]; expect( codeBlock.name ).toBe( 'core/code' ); expect( codeBlock.attributes.metadata ).toMatchObject( { name: 'Custom name', } ); } ); } ); test.describe( 'TO paragraph', () => { test( 'should preserve the content', async ( { editor } ) => { await editor.insertBlock( { name: 'core/code', attributes: { content: 'initial content', }, } ); await editor.transformBlockTo( 'core/paragraph' ); const codeBlock = ( await editor.getBlocks() )[ 0 ]; expect( codeBlock.name ).toBe( 'core/paragraph' ); expect( codeBlock.attributes.content ).toBe( 'initial content' ); } ); test( 'should preserve the metadata name attribute', async ( { editor, } ) => { await editor.insertBlock( { name: 'core/code', attributes: { content: 'initial content', metadata: { name: 'Custom name', }, }, } ); await editor.transformBlockTo( 'core/paragraph' ); const codeBlock = ( await editor.getBlocks() )[ 0 ]; expect( codeBlock.name ).toBe( 'core/paragraph' ); expect( codeBlock.attributes.metadata ).toMatchObject( { name: 'Custom name', } ); } ); } ); } ); } );