Procházet zdrojové kódy

Added test to engine.view.Selection.getEditableElement.

Szymon Kupś před 9 roky
rodič
revize
8d6cb8c186
1 změnil soubory, kde provedl 25 přidání a 0 odebrání
  1. 25 0
      packages/ckeditor5-engine/tests/view/selection.js

+ 25 - 0
packages/ckeditor5-engine/tests/view/selection.js

@@ -9,6 +9,7 @@
 
 import Selection from '/ckeditor5/engine/view/selection.js';
 import Range from '/ckeditor5/engine/view/range.js';
+import Document from '/ckeditor5/engine/view/document.js';
 import Element from '/ckeditor5/engine/view/element.js';
 import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
 
@@ -408,4 +409,28 @@ describe( 'Selection', () => {
 			expect( fireSpy.notCalled ).to.be.true;
 		} );
 	} );
+
+	describe( 'getEditableElement', () => {
+		it( 'should return null if no ranges in selection', () => {
+			expect( selection.getEditableElement() ).to.be.null;
+		} );
+
+		it( 'should return null if selection is placed in container that is not EditableElement', () => {
+			selection.addRange( range1 );
+
+			expect( selection.getEditableElement() ).to.be.null;
+		} );
+
+		it( 'should return EditableElement when selection is placed inside', () => {
+			const viewDocument = new Document();
+			const selection = viewDocument.selection;
+			const root = viewDocument.createRoot( 'div' );
+			const element = new Element( 'p' );
+			root.appendChildren( element );
+
+			selection.addRange( Range.createFromParentsAndOffsets( element, 0, element, 0 ) );
+
+			expect( selection.getEditableElement() ).to.equal( root );
+		} );
+	} );
 } );