/** * @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 VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor'; import ClassicEditorUI from '../src/classiceditorui'; import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; import ClassicEditorUIView from '../src/classiceditoruiview'; 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( 'ClassicEditorUI', () => { let editor, view, ui, viewElement; testUtils.createSinonSandbox(); beforeEach( () => { return VirtualClassicTestEditor .create( '', { toolbar: [ 'foo', 'bar' ] } ) .then( newEditor => { editor = newEditor; ui = editor.ui; view = ui.view; viewElement = view.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( 'stickyPanel', () => { it( 'binds view.stickyToolbar#isActive to editor.focusTracker#isFocused', () => { ui.focusTracker.isFocused = false; expect( view.stickyPanel.isActive ).to.be.false; ui.focusTracker.isFocused = true; expect( view.stickyPanel.isActive ).to.be.true; } ); it( 'sets view.stickyToolbar#limiterElement', () => { expect( view.stickyPanel.limiterElement ).to.equal( view.element ); } ); it( 'doesn\'t set view.stickyToolbar#viewportTopOffset, if not specified in the config', () => { expect( view.stickyPanel.viewportTopOffset ).to.equal( 0 ); } ); it( 'sets view.stickyPanel#viewportTopOffset, when specified in the config', () => { return VirtualClassicTestEditor .create( '', { toolbar: { viewportTopOffset: 100 } } ) .then( editor => { expect( editor.ui.view.stickyPanel.viewportTopOffset ).to.equal( 100 ); return editor.destroy(); } ); } ); } ); describe( 'editable', () => { 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( 'binds view.editable#isFocused', () => { assertBinding( view.editable, { isFocused: false }, [ [ ui.focusTracker, { isFocused: true } ] ], { isFocused: true } ); } ); it( 'set view.editable#name', () => { const editable = editor.editing.view.document.getRoot(); expect( view.editable.name ).to.equal( editable.rootName ); } ); } ); describe( 'placeholder', () => { it( 'sets placeholder from editor.config.placeholder', () => { return VirtualClassicTestEditor .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