Skip to content

Commit

Permalink
Added EmptyBlock integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
niegowski committed Jan 22, 2025
1 parent b6ed3d5 commit 890234f
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,22 @@ describe( 'Table cell refresh handler', () => {
expect( getViewForParagraph( table ) ).to.not.equal( previousView );
} );

it( 'should not rename <span> to <p> when setting a selection attribute on <paragraph>', () => {
editor.setData( '<table><tr><td><p>00</p></td></tr></table>' );

const table = root.getChild( 0 );
const previousView = getViewForParagraph( table );

model.change( writer => {
writer.setAttribute( 'selection:bold', true, table.getNodeByPath( [ 0, 0, 0 ] ) );
} );

expect( getViewData( view, { withoutSelection: true } ) ).to.equalMarkup( viewTable( [
[ '<span class="ck-table-bogus-paragraph">00</span>' ]
], { asWidget: true } ) );
expect( getViewForParagraph( table ) ).to.equal( previousView );
} );

it( 'should rename <p> to <span> when removing one of two paragraphs inside table cell', () => {
editor.setData( viewTable( [ [ '<p>00</p><p>foo</p>' ] ] ) );

Expand Down
184 changes: 183 additions & 1 deletion packages/ckeditor5-table/tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
*/

import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor.js';
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';
import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';
import BalloonToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/balloon/balloontoolbar.js';
import ClipboardPipeline from '@ckeditor/ckeditor5-clipboard/src/clipboardpipeline.js';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph.js';
import Heading from '@ckeditor/ckeditor5-heading/src/heading.js';
import EmptyBlock from '@ckeditor/ckeditor5-html-support/src/emptyblock.js';
import global from '@ckeditor/ckeditor5-utils/src/dom/global.js';
import Table from '../src/table.js';
import TableToolbar from '../src/tabletoolbar.js';
Expand Down Expand Up @@ -99,4 +101,184 @@ describe( 'TableContentToolbar integration', () => {
sinon.assert.notCalled( normalPrioritySpy );
} );
} );

describe( 'with the EmptyBlock', () => {
let editor, editorElement;

beforeEach( async () => {
editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );

editor = await ClassicTestEditor.create( editorElement, {
plugins: [ Table, Paragraph, Heading, EmptyBlock ]
} );
} );

afterEach( async () => {
editorElement.remove();
await editor.destroy();
} );

it( 'plain content in table cell', () => {
editor.setData(
'<table>' +
'<tr>' +
'<td>x</td>' +
'</tr>' +
'<tr>' +
'<td>&nbsp;</td>' +
'</tr>' +
'<tr>' +
'<td></td>' +
'</tr>' +
'</table>'
);

expect( getModelData( editor.model, { withoutSelection: true } ) ).to.equal(
'<table>' +
'<tableRow>' +
'<tableCell>' +
'<paragraph>x</paragraph>' +
'</tableCell>' +
'</tableRow>' +
'<tableRow>' +
'<tableCell>' +
'<paragraph></paragraph>' +
'</tableCell>' +
'</tableRow>' +
'<tableRow>' +
'<tableCell htmlEmptyBlock="true">' +
'<paragraph htmlEmptyBlock="true"></paragraph>' +
'</tableCell>' +
'</tableRow>' +
'</table>'
);

expect( editor.getData() ).to.equal(
'<figure class="table">' +
'<table>' +
'<tbody>' +
'<tr>' +
'<td>x</td>' +
'</tr>' +
'<tr>' +
'<td>&nbsp;</td>' +
'</tr>' +
'<tr>' +
'<td></td>' +
'</tr>' +
'</tbody>' +
'</table>' +
'</figure>'
);
} );

it( 'content in paragraph in a table cell', () => {
editor.setData(
'<table>' +
'<tr>' +
'<td><p>x</p></td>' +
'</tr>' +
'<tr>' +
'<td><p>&nbsp;</p></td>' +
'</tr>' +
'<tr>' +
'<td><p></p></td>' +
'</tr>' +
'</table>'
);

expect( getModelData( editor.model, { withoutSelection: true } ) ).to.equal(
'<table>' +
'<tableRow>' +
'<tableCell>' +
'<paragraph>x</paragraph>' +
'</tableCell>' +
'</tableRow>' +
'<tableRow>' +
'<tableCell>' +
'<paragraph></paragraph>' +
'</tableCell>' +
'</tableRow>' +
'<tableRow>' +
'<tableCell>' +
'<paragraph htmlEmptyBlock="true"></paragraph>' +
'</tableCell>' +
'</tableRow>' +
'</table>'
);

expect( editor.getData() ).to.equal(
'<figure class="table">' +
'<table>' +
'<tbody>' +
'<tr>' +
'<td>x</td>' +
'</tr>' +
'<tr>' +
'<td>&nbsp;</td>' +
'</tr>' +
'<tr>' +
'<td></td>' +
'</tr>' +
'</tbody>' +
'</table>' +
'</figure>'
);
} );

it( 'content in heading in a table cell', () => {
editor.setData(
'<table>' +
'<tr>' +
'<td><h2>x</h2></td>' +
'</tr>' +
'<tr>' +
'<td><h2>&nbsp;</h2></td>' +
'</tr>' +
'<tr>' +
'<td><h2></h2></td>' +
'</tr>' +
'</table>'
);

expect( getModelData( editor.model, { withoutSelection: true } ) ).to.equal(
'<table>' +
'<tableRow>' +
'<tableCell>' +
'<heading1>x</heading1>' +
'</tableCell>' +
'</tableRow>' +
'<tableRow>' +
'<tableCell>' +
'<heading1></heading1>' +
'</tableCell>' +
'</tableRow>' +
'<tableRow>' +
'<tableCell>' +
'<heading1 htmlEmptyBlock="true"></heading1>' +
'</tableCell>' +
'</tableRow>' +
'</table>'
);

expect( editor.getData() ).to.equal(
'<figure class="table">' +
'<table>' +
'<tbody>' +
'<tr>' +
'<td><h2>x</h2></td>' +
'</tr>' +
'<tr>' +
'<td><h2>&nbsp;</h2></td>' +
'</tr>' +
'<tr>' +
'<td><h2></h2></td>' +
'</tr>' +
'</tbody>' +
'</table>' +
'</figure>'
);
} );
} );
} );

0 comments on commit 890234f

Please sign in to comment.