Skip to content

Commit

Permalink
Add tests for empty paragraphs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Comandeer committed Dec 1, 2020
1 parent 92cc32e commit b4d9be7
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/core/editable/enterdiv.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var tests = {
'test insert two divs wrapped in another div': testInsertHtml( '<div><div>foo</div><div>bar</div></div>' )
};

tests = CKEDITOR.tools.object.merge( tests, generateEmptyParagraphsTests() );
tests = bender.tools.createTestsForEditors( CKEDITOR.tools.object.keys( bender.editors ), tests );

// (#2751, #4301)
Expand Down Expand Up @@ -84,3 +85,48 @@ function testInsertHtml( htmlString ) {
} );
};
}

function generateEmptyParagraphsTests() {
var tags = [
'p',
'div',
'address',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'center',
'pre'
],
contents = [
'<br>',
'&nbsp;',
'\u00A0',
'&#160;'
];

return CKEDITOR.tools.array.reduce( tags, function( tests, tag ) {
var tagTests = CKEDITOR.tools.array.reduce( contents, function( tests, content ) {
var test = {};

test[ 'empty paragraph test: ' + tag + ' with ' + CKEDITOR.tools.htmlEncode( content ) ] = function( editor ) {
var html = '<div>foo</div><div>bar</div>';

editor.editable().setHtml( generateEmptyParagraph( tag, content ) );
editor.insertHtml( html );

assert.areSame( html, editor.getData() );
};

return CKEDITOR.tools.object.merge( tests, test );
}, {} );

return CKEDITOR.tools.object.merge( tests, tagTests );
}, {} );

function generateEmptyParagraph( tag, content ) {
return '<' + tag + '>' + content + '</' + tag + '>';
}
}

0 comments on commit b4d9be7

Please sign in to comment.