/** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; import ShiftEnter from '@ckeditor/ckeditor5-enter/src/shiftenter'; import { getData } from '../../../src/dev-utils/model'; // NOTE: // dev utils' setData() loses white spaces so don't use it for tests here!!! // https://github.com/ckeditor/ckeditor5-engine/issues/1428 describe( 'DomConverter – whitespace handling – integration', () => { let editor; // See https://github.com/ckeditor/ckeditor5-engine/issues/822. describe( 'normalizing whitespaces around block boundaries (#822)', () => { beforeEach( () => { return VirtualTestEditor .create( { plugins: [ Paragraph ] } ) .then( newEditor => { editor = newEditor; editor.model.schema.extend( '$text', { allowAttributes: [ 'bold' ] } ); editor.conversion.attributeToElement( { model: 'bold', view: 'b' } ); } ); } ); afterEach( () => { return editor.destroy(); } ); it( 'new line at the end of the content is ignored', () => { editor.setData( '
foo
\n' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
' ); } ); it( 'whitespaces at the end of the content are ignored', () => { editor.setData( 'foo
\n\r\n \t' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
' ); } ); it( 'nbsp at the end of the content is not ignored', () => { editor.setData( 'foo
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
' ); } ); it( 'new line at the beginning of the content is ignored', () => { editor.setData( '\nfoo
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
' ); } ); it( 'whitespaces at the beginning of the content are ignored', () => { editor.setData( '\n\n \tfoo
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
' ); } ); it( 'nbsp at the beginning of the content is not ignored', () => { editor.setData( 'foo
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
' ); } ); it( 'new line between blocks is ignored', () => { editor.setData( 'foo
\nbar
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
bar
' ); } ); it( 'whitespaces between blocks are ignored', () => { editor.setData( 'foo
\n\n \tbar
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
bar
' ); } ); // Controversial result. See https://github.com/ckeditor/ckeditor5-engine/issues/987. it( 'nbsp between blocks is not ignored (between paragraphs)', () => { editor.setData( 'foo
bar
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
bar
' ); } ); it( 'nbsp between blocks is not ignored (different blocks)', () => { editor.model.schema.register( 'block', { inheritAllFrom: '$block' } ); editor.conversion.elementToElement( { model: 'block', view: 'block' } ); editor.setData( 'bar
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( '' + '
bar
' ); } ); it( 'new lines inside blocks are ignored', () => { editor.setData( '\nfoo\n
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
' ); } ); it( 'whitespaces inside blocks are ignored', () => { editor.setData( '\n\n \tfoo\n\n \t
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
' ); } ); it( 'nbsp inside blocks are not ignored', () => { editor.setData( 'foo
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
' ); } ); it( 'single nbsp inside blocks are ignored', () => { editor.setData( '' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( '
foo\n\r\n \t
\nbar
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo
bar
' ); } ); it( 'nbsp between inline elements is not ignored', () => { editor.setData( 'foo bar
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'foo bar
' ); } ); it( 'nbsp before inline element is not ignored', () => { editor.setData( 'bar
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'bar
' ); } ); it( 'nbsp after inline element is not ignored', () => { editor.setData( 'bar
' ); expect( getData( editor.model, { withoutSelection: true } ) ) .to.equal( 'bar
' ); } ); } ); // https://github.com/ckeditor/ckeditor5/issues/1024 describe( 'whitespaces aroundfoo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar
foo
bar