| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- /**
- * @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 Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
- import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
- import TableEditing from '../../src/tableediting';
- import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
- import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
- describe( 'Table cell paragraph post-fixer', () => {
- let editor, model, root;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- plugins: [ TableEditing, Paragraph, UndoEditing ]
- } )
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- root = model.document.getRoot();
- } );
- } );
- afterEach( () => {
- editor.destroy();
- } );
- it( 'should add a paragraph to an empty table cell (on table insert)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- assertEqualMarkup( getModelData( model, { withoutSelection: true } ),
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should add a paragraph to an empty table cell (on row insert)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- // Insert table row with one table cell
- model.change( writer => {
- writer.insertElement( 'tableRow', writer.createPositionAfter( root.getNodeByPath( [ 0, 0 ] ) ) );
- writer.insertElement( 'tableCell', writer.createPositionAt( root.getNodeByPath( [ 0, 1 ] ), 0 ) );
- } );
- assertEqualMarkup( getModelData( model, { withoutSelection: true } ),
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should add a paragraph to an empty table cell (on table cell insert)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- // Insert table row with one table cell
- model.change( writer => {
- writer.insertElement( 'tableCell', writer.createPositionAt( root.getNodeByPath( [ 0, 0 ] ), 'end' ) );
- } );
- assertEqualMarkup( getModelData( model, { withoutSelection: true } ),
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should add a paragraph to an empty table cell (after remove)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>foo</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- // Remove paragraph from table cell.
- model.change( writer => {
- writer.remove( writer.createRangeIn( root.getNodeByPath( [ 0, 0, 0 ] ) ) );
- } );
- assertEqualMarkup( getModelData( model, { withoutSelection: true } ),
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should wrap in paragraph $text nodes placed directly in tableCell (on table cell modification) ', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- // Remove paragraph from table cell & insert: $text<paragraph>$text</paragraph>$text.
- model.change( writer => {
- writer.remove( writer.createRangeIn( root.getNodeByPath( [ 0, 0, 0 ] ) ) );
- const paragraph = writer.createElement( 'paragraph' );
- writer.insertText( 'foo', root.getNodeByPath( [ 0, 0, 0 ] ) );
- writer.insert( paragraph, root.getNodeByPath( [ 0, 0, 0 ] ), 'end' );
- writer.insertText( 'bar', paragraph );
- writer.insertText( 'baz', root.getNodeByPath( [ 0, 0, 0 ] ), 'end' );
- } );
- assertEqualMarkup( getModelData( model, { withoutSelection: true } ),
- '<table>' +
- '<tableRow>' +
- '<tableCell>' +
- '<paragraph>foo</paragraph>' +
- '<paragraph>bar</paragraph>' +
- '<paragraph>baz</paragraph>' +
- '</tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should wrap in paragraph $text nodes placed directly in tableCell (on inserting table cell)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- // Insert new tableCell with $text.
- model.change( writer => {
- const tableCell = writer.createElement( 'tableCell' );
- writer.insertText( 'foo', tableCell );
- writer.insert( tableCell, writer.createPositionAt( root.getNodeByPath( [ 0, 0 ] ), 'end' ) );
- } );
- assertEqualMarkup( getModelData( model, { withoutSelection: true } ),
- '<table>' +
- '<tableRow>' +
- '<tableCell>' +
- '<paragraph></paragraph>' +
- '</tableCell>' +
- '<tableCell>' +
- '<paragraph>foo</paragraph>' +
- '</tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should wrap in paragraph $text nodes placed directly in tableCell (on inserting table rows)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph></paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- // Insert new tableRow with tableCell with $text.
- model.change( writer => {
- const tableRow = writer.createElement( 'tableRow' );
- const tableCell = writer.createElement( 'tableCell' );
- writer.insertText( 'foo', tableCell );
- writer.insert( tableCell, tableRow );
- writer.insert( tableRow, writer.createPositionAt( root.getNodeByPath( [ 0 ] ), 'end' ) );
- } );
- assertEqualMarkup( getModelData( model, { withoutSelection: true } ),
- '<table>' +
- '<tableRow>' +
- '<tableCell>' +
- '<paragraph></paragraph>' +
- '</tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell>' +
- '<paragraph>foo</paragraph>' +
- '</tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- } );
|