Преглед изворни кода

Tests: Block elements inside list items conversion unit tests.

Krzysztof Krztoń пре 7 година
родитељ
комит
3388ef7458
1 измењених фајлова са 156 додато и 2 уклоњено
  1. 156 2
      packages/ckeditor5-list/tests/listediting.js

+ 156 - 2
packages/ckeditor5-list/tests/listediting.js

@@ -325,8 +325,8 @@ describe( 'ListEditing', () => {
 
 	describe( 'flat lists', () => {
 		describe( 'setting data', () => {
-			function test( testName, string, expectedString = null ) {
-				it( testName, () => {
+			function test( testName, string, expectedString = null, skip = false ) {
+				( skip ? it.skip : it )( testName, () => {
 					editor.setData( string );
 					expect( editor.getData() ).to.equal( expectedString || string );
 				} );
@@ -365,6 +365,160 @@ describe( 'ListEditing', () => {
 
 				expect( getModelData( model, { withoutSelection: true } ) ).to.equal( expectedModelData );
 			} );
+
+			describe( 'block elements inside list items', () => {
+				describe( 'single block', () => {
+					test(
+						'single item',
+						'<ul><li><p>Foo</p></li></ul>',
+						'<p>Foo</p>'
+					);
+					test(
+						'multiple items',
+						'<ul><li><p>Foo</p></li><li><p>Bar</p></li></ul>',
+						'<p>Foo</p><p>Bar</p>'
+					);
+					test(
+						'nested items',
+						'<ul><li><p>Foo</p><ol><li><p>Bar</p></li></ol></li></ul>',
+						'<p>Foo</p><p>Bar</p>'
+					);
+				} );
+
+				describe( 'multiple blocks', () => {
+					test(
+						'single item',
+						'<ul><li><h2>Foo</h2><p>Bar</p></li></ul>',
+						'<p>Foo</p><p>Bar</p>'
+					);
+					test(
+						'multiple items',
+						'<ol><li><p>123</p></li></ol><ul><li><h2>Foo</h2><p>Bar</p></li></ul>',
+						'<p>123</p><p>Foo</p><p>Bar</p>'
+					);
+					test(
+						'nested items #1',
+						'<ol><li><p>123</p><ul><li><h2>Foo</h2><p>Bar</p></li></ul><p>456</p></li></ol>',
+						'<p>123</p><p>Foo</p><p>Bar</p><p>456</p>',
+						true // Skip due to #112 issue.
+					);
+					test(
+						'nested items #2',
+						'<ol><li><p>123</p><p>456</p><ul><li><h2>Foo</h2><p>Bar</p></li></ul></li></ol>',
+						'<p>123</p><p>456</p><p>Foo</p><p>Bar</p>'
+					);
+				} );
+
+				describe( 'inline + block', () => {
+					test(
+						'single item',
+						'<ul><li>Foo<p>Bar</p></li></ul>',
+						'<ul><li>Foo</li></ul><p>Bar</p>'
+					);
+					test(
+						'multiple items',
+						'<ul><li>Foo<p>Bar</p></li><li>Foz<p>Baz</p></li></ul>',
+						'<ul><li>Foo</li></ul><p>Bar</p><ul><li>Foz</li></ul><p>Baz</p>'
+					);
+					test(
+						'split by list items',
+						'<ul><li>Foo</li><li><p>Bar</p></li></ul>',
+						'<ul><li>Foo</li></ul><p>Bar</p>'
+					);
+					test(
+						'nested split by list items',
+						'<ul><li>Foo<ol><li><p>Bar</p></li></ol></li></ul>',
+						'<ul><li>Foo</li></ul><p>Bar</p>'
+					);
+					test(
+						'nested items #1',
+						'<ol><li>Foo<p>Bar</p><ul><li>123<h2>456</h2></li></ul></li></ol>',
+						'<ol><li>Foo</li></ol><p>Bar</p><ul><li>123</li></ul><p>456</p>'
+					);
+					test(
+						'nested items #2',
+						'<ol><li>Foo<p>Bar</p><ul><li>123<h2>456</h2></li></ul></li><li>abc<h2>def</h2></li></ol>',
+						'<ol><li>Foo</li></ol><p>Bar</p><ul><li>123</li></ul><p>456</p><ol><li>abc</li></ol><p>def</p>'
+					);
+				} );
+
+				describe( 'block + inline', () => {
+					test(
+						'single item',
+						'<ul><li><p>Foo</p>Bar</li></ul>',
+						'<p>Foo</p><ul><li>Bar</li></ul>'
+					);
+					test(
+						'multiple items',
+						'<ul><li><p>Foo</p>Bar</li><li><p>Foz</p>Baz</li></ul>',
+						'<p>Foo</p><ul><li>Bar</li></ul><p>Foz</p><ul><li>Baz</li></ul>'
+					);
+					test(
+						'split by list items',
+						'<ul><li><p>Bar</p><li>Foo</li></li></ul>',
+						'<p>Bar</p><ul><li>Foo</li></ul>'
+					);
+					test(
+						'nested split by list items',
+						'<ul><li><p>Bar</p><ol><li>Foo</li></ol></li></ul>',
+						'<p>Bar</p><ol><li>Foo</li></ol>'
+					);
+					test(
+						'nested items #1',
+						'<ol><li><p>Foo</p>Bar<ul><li><h2>123</h2>456</li></ul></li></ol>',
+						'<p>Foo</p><ol><li>Bar</li></ol><p>123</p><ul><li>456</li></ul>'
+					);
+					test(
+						'nested items #2',
+						'<ol><li><p>Foo</p>Bar<ul><li><h2>123</h2>456</li></ul></li><li><h2>abc</h2>def</li></ol>',
+						'<p>Foo</p><ol><li>Bar</li></ol><p>123</p><ul><li>456</li></ul><p>abc</p><ol><li>def</li></ol>'
+					);
+				} );
+
+				describe( 'complex', () => {
+					test(
+						'single item with inline block inline',
+						'<ul><li>Foo<p>Bar</p>Baz</li></ul>',
+						'<ul><li>Foo</li></ul><p>Bar</p><ul><li>Baz</li></ul>'
+					);
+					test(
+						'single item with inline block block',
+						'<ul><li>Text<p>Foo</p><p>Bar</p></li></ul>',
+						'<ul><li>Text</li></ul><p>Foo</p><p>Bar</p>'
+					);
+					test(
+						'single item with block block inline',
+						'<ul><li><p>Foo</p><p>Bar</p>Text</li></ul>',
+						'<p>Foo</p><p>Bar</p><ul><li>Text</li></ul>'
+					);
+					test(
+						'single item with block block block',
+						'<ul><li><p>Foo</p><p>Bar</p><p>Baz</p></li></ul>',
+						'<p>Foo</p><p>Bar</p><p>Baz</p>'
+					);
+					test(
+						'item inline + item block and inline',
+						'<ul><li>Foo</li><li><p>Bar</p>Baz</li></ul>',
+						'<ul><li>Foo</li></ul><p>Bar</p><ul><li>Baz</li></ul>'
+					);
+					test(
+						'item inline and block + item inline',
+						'<ul><li>Foo<p>Bar</p></li><li>Baz</li></ul>',
+						'<ul><li>Foo</li></ul><p>Bar</p><ul><li>Baz</li></ul>'
+					);
+					test(
+						'multiple items inline/block mix',
+						'<ul><li>Text<p>Foo</p></li><li>Bar<p>Baz</p>123</li></ul>',
+						'<ul><li>Text</li></ul><p>Foo</p><ul><li>Bar</li></ul><p>Baz</p><ul><li>123</li></ul>'
+					);
+					test(
+						'nested items',
+						'<ul><li>Foo<p>Bar</p></li><li>Baz<p>123</p>456<ol><li>ABC<p>DEF</p></li><li>GHI</li></ol></li></ul>',
+						'<ul><li>Foo</li></ul><p>Bar</p><ul><li>Baz</li></ul><p>123</p><ul><li>456<ol><li>ABC</li></ol></li></ul>' +
+							'<p>DEF</p><ol><li>GHI</li></ol>'
+					);
+				} );
+			} );
 		} );
 
 		describe( 'position mapping', () => {