Przeglądaj źródła

Added more tests for checking whether "Schema#checkMerge()" works with the position.

Kamil Piechaczek 7 lat temu
rodzic
commit
be5f7e316e
1 zmienionych plików z 36 dodań i 0 usunięć
  1. 36 0
      packages/ckeditor5-engine/tests/model/schema.js

+ 36 - 0
packages/ckeditor5-engine/tests/model/schema.js

@@ -730,6 +730,24 @@ describe( 'Schema', () => {
 			} ).to.throw( CKEditorError, /^schema-check-merge-no-element-before:/ );
 		} );
 
+		it( 'throws an error if the node before the position is not the element', () => {
+			const listItem = new Element( 'listItem', null, [
+				new Text( 'foo' )
+			] );
+
+			// eslint-disable-next-line no-new
+			new Element( '$root', null, [
+				new Text( 'bar' ),
+				listItem
+			] );
+
+			const position = Position.createBefore( listItem );
+
+			expect( () => {
+				expect( schema.checkMerge( position ) );
+			} ).to.throw( CKEditorError, /^schema-check-merge-no-element-before:/ );
+		} );
+
 		it( 'throws an error if there is no element after the position', () => {
 			const listItem = new Element( 'listItem', null, [
 				new Text( 'foo' )
@@ -747,6 +765,24 @@ describe( 'Schema', () => {
 			} ).to.throw( CKEditorError, /^schema-check-merge-no-element-after:/ );
 		} );
 
+		it( 'throws an error if the node after the position is not the element', () => {
+			const listItem = new Element( 'listItem', null, [
+				new Text( 'foo' )
+			] );
+
+			// eslint-disable-next-line no-new
+			new Element( '$root', null, [
+				listItem,
+				new Text( 'bar' )
+			] );
+
+			const position = Position.createBefore( listItem );
+
+			expect( () => {
+				expect( schema.checkMerge( position ) );
+			} ).to.throw( CKEditorError, /^schema-check-merge-no-element-before:/ );
+		} );
+
 		// This is an invalid case by definition – the baseElement should not contain disallowed elements
 		// in the first place. However, the check is focused on the elementToMerge's children so let's make sure
 		// that only them counts.