/** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ /* globals document, Event */ import View from '@ckeditor/ckeditor5-ui/src/view'; import InlineEditorUI from '../src/inlineeditorui'; import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui'; import InlineEditorUIView from '../src/inlineeditoruiview'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor'; import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; import { assertBinding } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; import { isElement } from 'lodash-es'; describe( 'InlineEditorUI', () => { let editor, view, ui, viewElement; testUtils.createSinonSandbox(); beforeEach( () => { return VirtualInlineTestEditor .create( 'foo', { toolbar: [ 'foo', 'bar' ] } ) .then( newEditor => { editor = newEditor; ui = editor.ui; view = ui.view; viewElement = view.editable.element; } ); } ); afterEach( () => { editor.destroy(); } ); describe( 'constructor()', () => { it( 'extends EditorUI', () => { expect( ui ).to.instanceof( EditorUI ); } ); } ); describe( 'init()', () => { it( 'renders the #view', () => { expect( view.isRendered ).to.be.true; } ); describe( 'panel', () => { it( 'binds view.panel#isVisible to editor.ui#focusTracker', () => { ui.focusTracker.isFocused = false; expect( view.panel.isVisible ).to.be.false; ui.focusTracker.isFocused = true; expect( view.panel.isVisible ).to.be.true; } ); it( 'doesn\'t set the view#viewportTopOffset, if not specified in the config', () => { expect( view.viewportTopOffset ).to.equal( 0 ); } ); it( 'sets view#viewportTopOffset, if specified', () => { return VirtualInlineTestEditor .create( 'foo', { toolbar: { viewportTopOffset: 100 } } ) .then( editor => { const ui = editor.ui; const view = ui.view; expect( view.viewportTopOffset ).to.equal( 100 ); return editor.destroy(); } ); } ); // https://github.com/ckeditor/ckeditor5-editor-inline/issues/4 it( 'pin() is called on editor.ui#update', () => { const spy = sinon.stub( view.panel, 'pin' ); view.panel.show(); editor.ui.fire( 'update' ); sinon.assert.calledOnce( spy ); sinon.assert.calledWithExactly( spy, { target: view.editable.element, positions: sinon.match.array } ); } ); it( 'pin() is not called on editor.ui#update when panel is hidden', () => { const spy = sinon.stub( view.panel, 'pin' ); view.panel.hide(); editor.ui.fire( 'update' ); sinon.assert.notCalled( spy ); } ); } ); describe( 'editable', () => { let editable; beforeEach( () => { editable = editor.editing.view.document.getRoot(); } ); it( 'registers view.editable#element in editor focus tracker', () => { ui.focusTracker.isFocused = false; view.editable.element.dispatchEvent( new Event( 'focus' ) ); expect( ui.focusTracker.isFocused ).to.true; } ); it( 'sets view.editable#name', () => { expect( view.editable.name ).to.equal( editable.rootName ); } ); it( 'binds view.editable#isFocused', () => { assertBinding( view.editable, { isFocused: false }, [ [ ui.focusTracker, { isFocused: true } ] ], { isFocused: true } ); } ); } ); describe( 'placeholder', () => { it( 'sets placeholder from editor.config.placeholder', () => { return VirtualInlineTestEditor .create( 'foo', { extraPlugins: [ Paragraph ], placeholder: 'placeholder-text' } ) .then( newEditor => { const firstChild = newEditor.editing.view.document.getRoot().getChild( 0 ); expect( firstChild.getAttribute( 'data-placeholder' ) ).to.equal( 'placeholder-text' ); return newEditor.destroy(); } ); } ); it( 'sets placeholder from the "placeholder" attribute of a passed