Browse Source

Tests: Added getOptimalPosition helper tests to check if it accepts Function or Rect as a Options#target/limiter.

Aleksander Nowodzinski 8 years ago
parent
commit
8c8a14bddf
1 changed files with 39 additions and 0 deletions
  1. 39 0
      packages/ckeditor5-utils/tests/dom/position.js

+ 39 - 0
packages/ckeditor5-utils/tests/dom/position.js

@@ -5,6 +5,7 @@
 
 import global from '../../src/dom/global';
 import { getOptimalPosition } from '../../src/dom/position';
+import Rect from '../../src/dom/rect';
 
 let element, target, limiter;
 
@@ -72,6 +73,20 @@ describe( 'getOptimalPosition()', () => {
 		} );
 	} );
 
+	it( 'should work when the target is a Rect', () => {
+		setElementTargetPlayground();
+
+		assertPosition( {
+			element,
+			target: new Rect( target ),
+			positions: [ attachLeft ]
+		}, {
+			top: 100,
+			left: 80,
+			name: 'left'
+		} );
+	} );
+
 	describe( 'for single position', () => {
 		beforeEach( setElementTargetPlayground );
 
@@ -192,6 +207,30 @@ describe( 'getOptimalPosition()', () => {
 	describe( 'with a limiter', () => {
 		beforeEach( setElementTargetLimiterPlayground );
 
+		it( 'should work when the limiter is a Function', () => {
+			assertPosition( {
+				element, target,
+				limiter: () => limiter,
+				positions: [ attachLeft, attachRight ]
+			}, {
+				top: 100,
+				left: -20,
+				name: 'left'
+			} );
+		} );
+
+		it( 'should work when the limiter is a Rect', () => {
+			assertPosition( {
+				element, target,
+				limiter: new Rect( limiter ),
+				positions: [ attachLeft, attachRight ]
+			}, {
+				top: 100,
+				left: -20,
+				name: 'left'
+			} );
+		} );
+
 		it( 'should return coordinates (#1)', () => {
 			assertPosition( {
 				element, target, limiter,