Selaa lähdekoodia

Tests: Prefer parse() method or direct params instead of mode.change() calls.

Maciej Gołaszewski 7 vuotta sitten
vanhempi
commit
e2e9e87190

+ 2 - 2
packages/ckeditor5-engine/tests/conversion/downcast-selection-converters.js

@@ -541,7 +541,7 @@ describe( 'downcast-selection-converters', () => {
 
 		it( 'should add a class to the selected table cell', () => {
 			test(
-				// table tr#0 |td#0, table tr#0 td#0|
+				// table tr#0 td#0 [foo, table tr#0 td#0 bar]
 				[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 3 ] ],
 				'<table><tr><td>foo</td></tr><tr><td>bar</td></tr></table>',
 				'<table><tr><td class="selected">foo</td></tr><tr><td>bar</td></tr></table>'
@@ -550,7 +550,7 @@ describe( 'downcast-selection-converters', () => {
 
 		it( 'should not be used if selection contains more than just a table cell', () => {
 			test(
-				// table tr td#1, table tr#2
+				// table tr td#1 f{oo bar, table tr#2 bar]
 				[ [ 0, 0, 0, 1 ], [ 0, 0, 1, 3 ] ],
 				'<table><tr><td>foo</td><td>bar</td></tr></table>',
 				'[<table><tr><td>foo</td><td>bar</td></tr></table>]'

+ 14 - 4
packages/ckeditor5-engine/tests/model/schema.js

@@ -988,7 +988,12 @@ describe( 'Schema', () => {
 			schema.extend( 'article', { isLimit: true } );
 			schema.extend( 'section', { isLimit: true } );
 
-			setData( model, '<div><section><article><paragraph>foo[]bar</paragraph></article></section></div>' );
+			const data = '<div><section><article><paragraph>foobar</paragraph></article></section></div>';
+			const parsedModel = parse( data, model.schema, { context: [ root.name ] } );
+
+			model.change( writer => {
+				writer.insert( parsedModel, root );
+			} );
 
 			const article = root.getNodeByPath( [ 0, 0, 0 ] );
 
@@ -999,7 +1004,12 @@ describe( 'Schema', () => {
 			schema.extend( 'article', { isLimit: true } );
 			schema.extend( 'section', { isLimit: true } );
 
-			setData( model, '<div><section><article><paragraph>foo[]bar</paragraph></article></section></div>' );
+			const data = '<div><section><article><paragraph>foobar</paragraph></article></section></div>';
+			const parsedModel = parse( data, model.schema, { context: [ root.name ] } );
+
+			model.change( writer => {
+				writer.insert( parsedModel, root );
+			} );
 
 			const article = root.getNodeByPath( [ 0, 0, 0 ] );
 
@@ -1124,11 +1134,11 @@ describe( 'Schema', () => {
 			} );
 
 			// Parse data string to model.
-			const parsedResult = parse( '[<p>foo<img />bar</p>]', model.schema, { context: [ root.name ] } );
+			const parsedModel = parse( '<p>foo<img />bar</p>', model.schema, { context: [ root.name ] } );
 
 			// Set parsed model data to prevent selection post-fixer from running.
 			model.change( writer => {
-				writer.insert( parsedResult.model, root );
+				writer.insert( parsedModel, root );
 			} );
 
 			ranges = [ Range.createOn( root.getChild( 0 ) ) ];

+ 19 - 25
packages/ckeditor5-engine/tests/model/utils/deletecontent.js

@@ -608,7 +608,7 @@ describe( 'DataController utils', () => {
 			it( 'creates a paragraph when text is not allowed (custom selection)', () => {
 				setData(
 					model,
-					'[<paragraph>x</paragraph>]<paragraph>yyy</paragraph><paragraph>z</paragraph>',
+					'<paragraph>[x]</paragraph><paragraph>yyy</paragraph><paragraph>z</paragraph>',
 					{ rootName: 'bodyRoot' }
 				);
 
@@ -640,45 +640,39 @@ describe( 'DataController utils', () => {
 			it( 'creates paragraph when text is not allowed (heading selected)', () => {
 				setData(
 					model,
-					'<paragraph>x</paragraph>[<heading1>yyy</heading1>]<paragraph>z</paragraph>',
+					'<paragraph>x</paragraph><heading1>yyy</heading1><paragraph>z</paragraph>',
 					{ rootName: 'bodyRoot' }
 				);
 
-				model.change( writer => {
-					// Set selection to[<heading1>yyy</heading1>] in change() block due to selection post-fixer.
-					const range = new Range(
-						new Position( doc.getRoot( 'bodyRoot' ), [ 1 ] ),
-						new Position( doc.getRoot( 'bodyRoot' ), [ 2 ] )
-					);
-					writer.setSelection( range );
+				// [<heading1>yyy</heading1>]
+				const range = new Range(
+					new Position( doc.getRoot( 'bodyRoot' ), [ 1 ] ),
+					new Position( doc.getRoot( 'bodyRoot' ), [ 2 ] )
+				);
 
-					deleteContent( model, doc.selection );
-				} );
+				deleteContent( model, new Selection( range ) );
 
-				expect( getData( model, { rootName: 'bodyRoot' } ) )
-					.to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>z</paragraph>' );
+				expect( getData( model, { rootName: 'bodyRoot', withoutSelection: true } ) )
+					.to.equal( '<paragraph>x</paragraph><paragraph></paragraph><paragraph>z</paragraph>' );
 			} );
 
 			it( 'creates paragraph when text is not allowed (two blocks selected)', () => {
 				setData(
 					model,
-					'<paragraph>x</paragraph>[<heading1>yyy</heading1><paragraph>yyy</paragraph>]<paragraph>z</paragraph>',
+					'<paragraph>x</paragraph><heading1>yyy</heading1><paragraph>yyy</paragraph><paragraph>z</paragraph>',
 					{ rootName: 'bodyRoot' }
 				);
 
-				model.change( writer => {
-					// Set selection to[<heading1>yyy</heading1><paragraph>yyy</paragraph>] in change() block due to selection post-fixer.
-					const range = new Range(
-						new Position( doc.getRoot( 'bodyRoot' ), [ 1 ] ),
-						new Position( doc.getRoot( 'bodyRoot' ), [ 3 ] )
-					);
-					writer.setSelection( range );
+				// [<heading1>yyy</heading1><paragraph>yyy</paragraph>]
+				const range = new Range(
+					new Position( doc.getRoot( 'bodyRoot' ), [ 1 ] ),
+					new Position( doc.getRoot( 'bodyRoot' ), [ 3 ] )
+				);
 
-					deleteContent( model, doc.selection );
-				} );
+				deleteContent( model, range );
 
-				expect( getData( model, { rootName: 'bodyRoot' } ) )
-					.to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>z</paragraph>' );
+				expect( getData( model, { rootName: 'bodyRoot', withoutSelection: true } ) )
+					.to.equal( '<paragraph>x</paragraph><paragraph></paragraph><paragraph>z</paragraph>' );
 			} );
 
 			it( 'creates paragraph when text is not allowed (all content selected)', () => {