/** * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ import BlockQuoteEditing from '../src/blockquoteediting.js'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph.js'; import ListEditing from '@ckeditor/ckeditor5-list/src/list/listediting.js'; import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting.js'; import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor.js'; import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js'; import BlockQuoteCommand from '../src/blockquotecommand.js'; describe( 'BlockQuoteEditing', () => { let editor, model; beforeEach( () => { return VirtualTestEditor .create( { plugins: [ BlockQuoteEditing, Paragraph, BoldEditing ] } ) .then( newEditor => { editor = newEditor; model = editor.model; } ); } ); afterEach( () => { return editor.destroy(); } ); it( 'should have pluginName', () => { expect( BlockQuoteEditing.pluginName ).to.equal( 'BlockQuoteEditing' ); } ); it( 'adds a blockQuote command', () => { expect( editor.commands.get( 'blockQuote' ) ).to.be.instanceOf( BlockQuoteCommand ); } ); it( 'allows for blockQuote in the $root', () => { expect( model.schema.checkChild( [ '$root' ], 'blockQuote' ) ).to.be.true; } ); it( 'allows for $block in blockQuote', () => { expect( model.schema.checkChild( [ '$root', 'blockQuote' ], '$block' ) ).to.be.true; expect( model.schema.checkChild( [ '$root', 'blockQuote' ], 'paragraph' ) ).to.be.true; } ); it( 'allows for blockQuote in blockQuote', () => { expect( model.schema.checkChild( [ '$root', 'blockQuote' ], 'blockQuote' ) ).to.be.true; } ); it( 'does not break when checking an unregisterd item', () => { expect( model.schema.checkChild( [ '$root', 'blockQuote' ], 'foo' ) ).to.be.false; } ); it( 'inherits attributes from $container', () => { model.schema.extend( '$container', { allowAttributes: 'foo' } ); expect( model.schema.checkAttribute( 'blockQuote', 'foo' ) ).to.be.true; } ); it( 'adds converters to the data pipeline', () => { const data = '
'; editor.setData( data ); expect( getModelData( model ) ).to.equal( 'x
' ); expect( editor.getData() ).to.equal( data ); } ); it( 'adds a converter to the view pipeline', () => { setModelData( model, '[]x
' ); expect( editor.getData() ).to.equal( 'x
' ); } ); it( 'allows list items inside blockQuote', () => { return VirtualTestEditor .create( { plugins: [ BlockQuoteEditing, Paragraph, ListEditing ] } ) .then( editor => { editor.setData( 'x
' ); expect( editor.getData() ).to.equal( '
- xx
' ); return editor.destroy(); } ); } ); it( 'should remove empty blockQuote elements', () => { setModelData( model, '
- xx
Foo
' ); } ); it( 'should remove blockQuotes which became empty', () => { setModelData( model, '' ); model.change( writer => { const root = model.document.getRoot(); const bq = root.getChild( 0 ); writer.remove( writer.createRangeIn( bq ) ); } ); expect( editor.getData( { trim: 'none' } ) ).to.equal( 'Foo
' ); // Autoparagraphed. } ); it( 'should not unwrap a blockQuote if it was inserted into another blockQuote', () => { setModelData( model, '
' ); model.change( writer => { const root = model.document.getRoot(); const bq = writer.createElement( 'blockQuote' ); const p = writer.createElement( 'paragraph' ); writer.insertText( 'Bar', p, 0 ); //Foo
Bar
. writer.insert( p, bq, 0 ); //. writer.insert( bq, root.getChild( 0 ), 1 ); // Insert afterBar
Foo
. } ); expect( editor.getData() ).to.equal( '' ); } ); it( 'should not unwrap nested blockQuote if it was wrapped into another blockQuote', () => { setModelData( model, 'Foo
Bar
Foo
' ); } ); it( 'postfixer should do nothing on attribute change', () => { // This is strictly a 100% CC test. setModelData( model, 'Foo
Bar
' ); model.change( writer => { const root = model.document.getRoot(); const p = root.getChild( 0 ).getChild( 0 ); writer.setAttribute( 'bold', true, writer.createRangeIn( p ) ); } ); expect( editor.getData() ).to.equal( 'Foo
' ); } ); describe( 'nested blockQuote forbidden by custom rule', () => { // Nested block quotes are supported since https://github.com/ckeditor/ckeditor5/issues/9210, so let's check // if the editor will not blow up in case nested block quotes are forbidden by custom scheme rule. beforeEach( () => { model.schema.addChildCheck( ( ctx, childDef ) => { if ( ctx.endsWith( 'blockQuote' ) && childDef.name == 'blockQuote' ) { return false; } } ); } ); it( 'should unwrap a blockQuote if it was inserted into another blockQuote', () => { setModelData( model, 'Foo
' ); model.change( writer => { const root = model.document.getRoot(); const bq = writer.createElement( 'blockQuote' ); const p = writer.createElement( 'paragraph' ); writer.insertText( 'Bar', p, 0 ); //Foo
Bar
. writer.insert( p, bq, 0 ); //. writer.insert( bq, root.getChild( 0 ), 1 ); // Insert afterBar
Foo
. } ); expect( editor.getData() ).to.equal( '' ); } ); it( 'should unwrap nested blockQuote if it was wrapped into another blockQuote', () => { setModelData( model, 'Foo
Bar
Foo
' ); } ); } ); } );Foo
Bar