Przeglądaj źródła

Fixed view tests.

Maciej Bukowski 6 lat temu
rodzic
commit
81a8cb1ee0

+ 32 - 30
packages/ckeditor5-engine/src/view/downcastwriter.js

@@ -1094,7 +1094,7 @@ export default class DowncastWriter {
 			// <p><span class="bar">abc</span></p>  -->  <p><span class="foo bar">abc</span></p>
 			//
 			if ( isAttribute && this._wrapAttributeElement( wrapElement, child ) ) {
-				wrapPositions.push(	new Position( parent, i ) );
+				wrapPositions.push( new Position( parent, i ) );
 			}
 			//
 			// Wrap the child if it is not an attribute element or if it is an attribute element that should be inside
@@ -1114,7 +1114,7 @@ export default class DowncastWriter {
 				parent._insertChild( i, newAttribute );
 				this._addToClonedElementsGroup( newAttribute );
 
-				wrapPositions.push(	new Position( parent, i ) );
+				wrapPositions.push( new Position( parent, i ) );
 			}
 			//
 			// If other nested attribute is found and it wasn't wrapped (see above), continue wrapping inside it.
@@ -1572,40 +1572,41 @@ export default class DowncastWriter {
 			const newPosition = new Position( positionParent.parent, positionParent.index + 1 );
 
 			return this._breakAttributes( newPosition, forceSplitText );
-		} else
-		// <p>foo<b><u>{}bar</u></b></p>
-		// <p>foo<b>[]<u>bar</u></b></p>
-		// <p>foo{}<b><u>bar</u></b></p>
-		if ( positionOffset === 0 ) {
-			const newPosition = new Position( positionParent.parent, positionParent.index );
+		} else {
+			// <p>foo<b><u>{}bar</u></b></p>
+			// <p>foo<b>[]<u>bar</u></b></p>
+			// <p>foo{}<b><u>bar</u></b></p>
+			if ( positionOffset === 0 ) {
+				const newPosition = new Position( positionParent.parent, positionParent.index );
 
-			return this._breakAttributes( newPosition, forceSplitText );
-		}
-		// <p>foo<b><u>b{}ar</u></b></p>
-		// <p>foo<b><u>b[]ar</u></b></p>
-		// <p>foo<b><u>b</u>[]<u>ar</u></b></p>
-		// <p>foo<b><u>b</u></b>[]<b><u>ar</u></b></p>
-		else {
-			const offsetAfter = positionParent.index + 1;
+				return this._breakAttributes( newPosition, forceSplitText );
+			}
+			// <p>foo<b><u>b{}ar</u></b></p>
+			// <p>foo<b><u>b[]ar</u></b></p>
+			// <p>foo<b><u>b</u>[]<u>ar</u></b></p>
+			// <p>foo<b><u>b</u></b>[]<b><u>ar</u></b></p>
+			else {
+				const offsetAfter = positionParent.index + 1;
 
-			// Break element.
-			const clonedNode = positionParent._clone();
+				// Break element.
+				const clonedNode = positionParent._clone();
 
-			// Insert cloned node to position's parent node.
-			positionParent.parent._insertChild( offsetAfter, clonedNode );
-			this._addToClonedElementsGroup( clonedNode );
+				// Insert cloned node to position's parent node.
+				positionParent.parent._insertChild( offsetAfter, clonedNode );
+				this._addToClonedElementsGroup( clonedNode );
 
-			// Get nodes to move.
-			const count = positionParent.childCount - positionOffset;
-			const nodesToMove = positionParent._removeChildren( positionOffset, count );
+				// Get nodes to move.
+				const count = positionParent.childCount - positionOffset;
+				const nodesToMove = positionParent._removeChildren( positionOffset, count );
 
-			// Move nodes to cloned node.
-			clonedNode._appendChild( nodesToMove );
+				// Move nodes to cloned node.
+				clonedNode._appendChild( nodesToMove );
 
-			// Create new position to work on.
-			const newPosition = new Position( positionParent.parent, offsetAfter );
+				// Create new position to work on.
+				const newPosition = new Position( positionParent.parent, offsetAfter );
 
-			return this._breakAttributes( newPosition, forceSplitText );
+				return this._breakAttributes( newPosition, forceSplitText );
+			}
 		}
 	}
 
@@ -1842,7 +1843,7 @@ function validateNodesToInsert( nodes, errorContext ) {
 		}
 
 		if ( !node.is( 'text' ) ) {
-			validateNodesToInsert( node.getChildren() );
+			validateNodesToInsert( node.getChildren(), errorContext );
 		}
 	}
 }
@@ -1875,6 +1876,7 @@ function validateRangeContainer( range, errorContext ) {
 		 *
 		 * @error view-writer-invalid-range-container
 		 */
+
 		throw new CKEditorError( 'view-writer-invalid-range-container', errorContext );
 	}
 }

+ 1 - 1
packages/ckeditor5-engine/src/view/position.js

@@ -342,7 +342,7 @@ export default class Position {
 				throw new CKEditorError(
 					'view-createPositionAt-offset-required: ' +
 					'View#createPositionAt() requires the offset when the first parameter is a view item.',
-					this
+					node
 				);
 			}
 

+ 1 - 1
packages/ckeditor5-engine/src/view/treewalker.js

@@ -51,7 +51,7 @@ export default class TreeWalker {
 		if ( options.direction && options.direction != 'forward' && options.direction != 'backward' ) {
 			throw new CKEditorError(
 				'view-tree-walker-unknown-direction: Only `backward` and `forward` direction allowed.',
-				this,
+				options.startPosition,
 				{ direction: options.direction }
 			);
 		}

+ 3 - 1
packages/ckeditor5-engine/tests/model/position.js

@@ -131,7 +131,9 @@ describe( 'Position', () => {
 	describe( 'static creators', () => {
 		describe( '_createAt()', () => {
 			it( 'should throw if no offset is passed', () => {
-				expectToThrowCKEditorError( () => Position._createAt( ul ), /model-createPositionAt-offset-required/, model );
+				expectToThrowCKEditorError( () => {
+					Position._createAt( ul );
+				}, /model-createPositionAt-offset-required/, model );
 			} );
 
 			it( 'should create positions from positions', () => {

+ 2 - 2
packages/ckeditor5-engine/tests/view/downcastwriter/remove.js

@@ -39,7 +39,7 @@ describe( 'DowncastWriter', () => {
 
 		beforeEach( () => {
 			document = new Document();
-			writer = new DowncastWriter();
+			writer = new DowncastWriter( document );
 		} );
 
 		it( 'should throw when range placed in two containers', () => {
@@ -205,7 +205,7 @@ describe( 'DowncastWriter', () => {
 
 			expectToThrowCKEditorError( () => {
 				writer.remove( el );
-			}, 'view-position-before-root', document );
+			}, 'view-position-before-root' );
 		} );
 	} );
 } );

+ 3 - 1
packages/ckeditor5-engine/tests/view/position.js

@@ -382,7 +382,9 @@ describe( 'Position', () => {
 			it( 'should throw if no offset is passed', () => {
 				const element = new Element( 'p' );
 
-				expectToThrowCKEditorError( () => Position._createAt( element ), /view-createPositionAt-offset-required/, element );
+				expectToThrowCKEditorError( () => {
+					Position._createAt( element );
+				}, /view-createPositionAt-offset-required/ );
 			} );
 
 			it( 'should create positions from positions', () => {