diff --git a/tests/plugins/autocomplete/view.js b/tests/plugins/autocomplete/view.js index 477f74a5fa3..f7f430e49b5 100644 --- a/tests/plugins/autocomplete/view.js +++ b/tests/plugins/autocomplete/view.js @@ -158,226 +158,6 @@ assert.isTrue( spy.calledOnce ); }, - 'test position not enough space between the caret and bottom viewport (classic)': function() { - // +---------------------------------------------+ - // | | - // | editor viewport | - // | +--------------+ | - // | | | | - // | | view | | - // | | | | - // | +--------------+ | - // | █ - caret position | - // | | - // +---------------------------------------------+ - var view = createPositionedView( this.editors.classic, { - caretRect: { top: 400, bottom: 410, left: 100 }, - editorViewportRect: { top: 0, bottom: 500 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '300px', view.element.getStyle( 'top' ), 'View is displayed above the caret' ); - assert.areEqual( '100px', view.element.getStyle( 'left' ) ); - }, - - 'test position not enough space between the caret and bottom viewport - edge case (classic)': function() { - // +---------------------------------------------+ - // | | - // | | - // | editor viewport | - // | +--------------+ | - // | | | | - // | | view | | - // | | | | - // | +--------------+ | - // +-----█---------------------------------------+ - // - caret position 1px above the viewport's bottom position - var view = createPositionedView( this.editors.classic, { - caretRect: { top: 199, bottom: 209, left: 100 }, - editorViewportRect: { top: 0, bottom: 200 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '99px', view.element.getStyle( 'top' ), 'View is displayed above the caret' ); - assert.areEqual( '100px', view.element.getStyle( 'left' ) ); - }, - - 'test enough space under and above the caret (classic)': function() { - // +---------------------------------------------+ - // | editor viewport | - // | | - // | | - // | | - // | █ - caret position | - // | +--------------+ | - // | | view | | - // | +--------------+ | - // | | - // | | - // +---------------------------------------------+ - var view = createPositionedView( this.editors.classic, { - caretRect: { top: 100, bottom: 110, left: 50 }, - editorViewportRect: { top: 0, bottom: 500 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '110px', view.element.getStyle( 'top' ), 'View is displayed below the caret' ); - assert.areEqual( '50px', view.element.getStyle( 'left' ) ); - }, - - 'test enough space under the caret - edge case (classic)': function() { - // - caret top position on a par with viewport's top - // +-----█---------------------------------------+ - // | +--------------+ | - // | | view | | - // | +--------------+ | - // | | - // | | - // | editor viewport | - // +---------------------------------------------+ - var view = createPositionedView( this.editors.classic, { - caretRect: { top: 0, bottom: 10, left: 50 }, - editorViewportRect: { top: 0, bottom: 200 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '10px', view.element.getStyle( 'top' ), 'View is displayed below the caret' ); - assert.areEqual( '50px', view.element.getStyle( 'left' ) ); - }, - - 'test view position below viewport (classic)': function() { - // +---------------------------------------------+ - // | editor viewport | - // | | - // | +--------------+ | - // | | | | - // | | view | | - // | | | | - // +-----+==============+------------------------+ - // | | - // | █ - caret position | - // | | - // +---------------------------------------------+ - var view = createPositionedView( this.editors.classic, { - caretRect: { top: 400, bottom: 410, left: 100 }, - editorViewportRect: { top: 0, bottom: 300 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '200px', view.element.getStyle( 'top' ), 'View is displayed above the caret' ); - assert.areEqual( '100px', view.element.getStyle( 'left' ) ); - }, - - 'test view position above viewport (classic)': function() { - // +---------------------------------------------+ - // | | - // | █ - caret position | - // | | - // +-----+==============+------------------------+ - // | | | | - // | | view | | - // | | | | - // | +--------------+ | - // | | - // | editor viewport | - // +---------------------------------------------+ - var view = createPositionedView( this.editors.classic, { - caretRect: { top: 100, bottom: 110, left: 50 }, - editorViewportRect: { top: 200, bottom: 500 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '200px', view.element.getStyle( 'top' ), 'View is displayed below the caret' ); - assert.areEqual( '50px', view.element.getStyle( 'left' ) ); - }, - - 'test enough space under and above the caret (inline)': function() { - // +---------------------------------------------+ - // | editor viewport | - // | | - // | | - // | | - // | █ - caret position | - // | +--------------+ | - // | | view | | - // | +--------------+ | - // | | - // | | - // +---------------------------------------------+ - var view = createPositionedView( this.editors.inline, { - caretRect: { top: 100, bottom: 110, left: 50 }, - editorViewportRect: { top: 0, bottom: 500 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '110px', view.element.getStyle( 'top' ), 'View is displayed below the caret' ); - assert.areEqual( '50px', view.element.getStyle( 'left' ) ); - }, - - 'test position not enough space between the caret and bottom viewport (inline)': function() { - // +---------------------------------------------+ - // | | - // | editor viewport | - // | +--------------+ | - // | | | | - // | | view | | - // | | | | - // | +--------------+ | - // | █ - caret position | - // | | - // +---------------------------------------------+ - var view = createPositionedView( this.editors.inline, { - caretRect: { top: 400, bottom: 410, left: 100 }, - editorViewportRect: { top: 0, bottom: 500 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '300px', view.element.getStyle( 'top' ), 'View is displayed above the caret' ); - assert.areEqual( '100px', view.element.getStyle( 'left' ) ); - }, - - 'test position not enough space between the caret and bottom viewport - edge case (inline)': function() { - // +---------------------------------------------+ - // | | - // | | - // | editor viewport | - // | +--------------+ | - // | | | | - // | | view | | - // | | | | - // | +--------------+ | - // +-----█---------------------------------------+ - // - caret position 1px above the viewport's bottom position - var view = createPositionedView( this.editors.inline, { - caretRect: { top: 199, bottom: 209, left: 100 }, - editorViewportRect: { top: 0, bottom: 200 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '99px', view.element.getStyle( 'top' ), 'View is displayed above the caret' ); - assert.areEqual( '100px', view.element.getStyle( 'left' ) ); - }, - - 'test enough space under the caret - edge case (inline)': function() { - // - caret top position on a par with viewport's top - // +-----█---------------------------------------+ - // | +--------------+ | - // | | view | | - // | +--------------+ | - // | | - // | | - // | editor viewport | - // +---------------------------------------------+ - var view = createPositionedView( this.editors.inline, { - caretRect: { top: 0, bottom: 10, left: 50 }, - editorViewportRect: { top: 0, bottom: 200 }, - viewPanelHeight: 100 - } ); - - assert.areEqual( '10px', view.element.getStyle( 'top' ), 'View is displayed below the caret' ); - assert.areEqual( '50px', view.element.getStyle( 'left' ) ); - }, - 'test attach': function() { var editor = this.editors.classic, view = new CKEDITOR.plugins.autocomplete.view( editor ), @@ -397,21 +177,6 @@ } ); - function createPositionedView( editor, config ) { - var view = new CKEDITOR.plugins.autocomplete.view( editor ), - getClientRectStub = sinon.stub( CKEDITOR.dom.element.prototype, 'getClientRect' ).returns( config.editorViewportRect ); - - view.append(); - - sinon.stub( view.element, 'getSize' ).returns( config.viewPanelHeight ); - - view.setPosition( config.caretRect ); - - getClientRectStub.restore(); - - return view; - } - function assertViewElement( editor, element ) { var zIndex = editor.config.baseFloatZIndex - 3, expectedHtml = ''; diff --git a/tests/plugins/autocomplete/viewposition.js b/tests/plugins/autocomplete/viewposition.js new file mode 100644 index 00000000000..8f030dbae79 --- /dev/null +++ b/tests/plugins/autocomplete/viewposition.js @@ -0,0 +1,174 @@ +/* bender-tags: editor */ +/* bender-ckeditor-plugins: autocomplete, caretposition */ + +( function() { + 'use strict'; + + bender.editors = { + classic: {}, + + inline: { + creator: 'inline' + }, + + divarea: { + extraPlugins: 'divarea' + } + }; + + var tests = { + 'test position not enough space between the caret and bottom viewport': function( editor ) { + // +---------------------------------------------+ + // | | + // | editor viewport | + // | +--------------+ | + // | | | | + // | | view | | + // | | | | + // | +--------------+ | + // | █ - caret position | + // | | + // +---------------------------------------------+ + var view = createPositionedView( editor, { + caretRect: { top: 400, bottom: 410, left: 100 }, + editorViewportRect: { top: 0, bottom: 500 }, + viewPanelHeight: 100 + } ); + + assert.areEqual( '300px', view.element.getStyle( 'top' ), 'View is displayed above the caret' ); + assert.areEqual( '100px', view.element.getStyle( 'left' ) ); + }, + + 'test position not enough space between the caret and bottom viewport - edge case': function( editor ) { + // +---------------------------------------------+ + // | | + // | | + // | editor viewport | + // | +--------------+ | + // | | | | + // | | view | | + // | | | | + // | +--------------+ | + // +-----█---------------------------------------+ + // - caret position 1px above the viewport's bottom position + var view = createPositionedView( editor, { + caretRect: { top: 199, bottom: 209, left: 100 }, + editorViewportRect: { top: 0, bottom: 200 }, + viewPanelHeight: 100 + } ); + + assert.areEqual( '99px', view.element.getStyle( 'top' ), 'View is displayed above the caret' ); + assert.areEqual( '100px', view.element.getStyle( 'left' ) ); + }, + + 'test enough space under and above the caret': function( editor ) { + // +---------------------------------------------+ + // | editor viewport | + // | | + // | | + // | | + // | █ - caret position | + // | +--------------+ | + // | | view | | + // | +--------------+ | + // | | + // | | + // +---------------------------------------------+ + var view = createPositionedView( editor, { + caretRect: { top: 100, bottom: 110, left: 50 }, + editorViewportRect: { top: 0, bottom: 500 }, + viewPanelHeight: 100 + } ); + + assert.areEqual( '110px', view.element.getStyle( 'top' ), 'View is displayed below the caret' ); + assert.areEqual( '50px', view.element.getStyle( 'left' ) ); + }, + + 'test enough space under the caret - edge case': function( editor ) { + // - caret top position on a par with viewport's top + // +-----█---------------------------------------+ + // | +--------------+ | + // | | view | | + // | +--------------+ | + // | | + // | | + // | editor viewport | + // +---------------------------------------------+ + var view = createPositionedView( editor, { + caretRect: { top: 0, bottom: 10, left: 50 }, + editorViewportRect: { top: 0, bottom: 200 }, + viewPanelHeight: 100 + } ); + + assert.areEqual( '10px', view.element.getStyle( 'top' ), 'View is displayed below the caret' ); + assert.areEqual( '50px', view.element.getStyle( 'left' ) ); + }, + + 'test view position below viewport': function( editor ) { + // +---------------------------------------------+ + // | editor viewport | + // | | + // | +--------------+ | + // | | | | + // | | view | | + // | | | | + // +-----+==============+------------------------+ + // | | + // | █ - caret position | + // | | + // +---------------------------------------------+ + var view = createPositionedView( editor, { + caretRect: { top: 400, bottom: 410, left: 100 }, + editorViewportRect: { top: 0, bottom: 300 }, + viewPanelHeight: 100 + } ); + + assert.areEqual( '200px', view.element.getStyle( 'top' ), 'View is displayed above the caret' ); + assert.areEqual( '100px', view.element.getStyle( 'left' ) ); + }, + + 'test view position above viewport': function( editor ) { + // +---------------------------------------------+ + // | | + // | █ - caret position | + // | | + // +-----+==============+------------------------+ + // | | | | + // | | view | | + // | | | | + // | +--------------+ | + // | | + // | editor viewport | + // +---------------------------------------------+ + var view = createPositionedView( editor, { + caretRect: { top: 100, bottom: 110, left: 50 }, + editorViewportRect: { top: 200, bottom: 500 }, + viewPanelHeight: 100 + } ); + + assert.areEqual( '200px', view.element.getStyle( 'top' ), 'View is displayed below the caret' ); + assert.areEqual( '50px', view.element.getStyle( 'left' ) ); + } + + }; + + tests = bender.tools.createTestsForEditors( CKEDITOR.tools.objectKeys( bender.editors ), tests ); + + bender.test( tests ); + + function createPositionedView( editor, config ) { + var view = new CKEDITOR.plugins.autocomplete.view( editor ), + getClientRectStub = sinon.stub( CKEDITOR.dom.element.prototype, 'getClientRect' ).returns( config.editorViewportRect ); + + view.append(); + + sinon.stub( view.element, 'getSize' ).returns( config.viewPanelHeight ); + + view.setPosition( config.caretRect ); + + getClientRectStub.restore(); + + return view; + } + +} )();