| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* globals document, Event */
- /* bender-tags: editor, browser-only */
- import ClassicEditorUIView from '/ckeditor5/editor-classic/classiceditoruiview.js';
- import ClassicTestEditor from '/tests/core/_utils/classictesteditor.js';
- import ButtonView from '/ckeditor5/ui/button/buttonview.js';
- import StickyToolbarView from '/ckeditor5/ui/toolbar/sticky/stickytoolbarview.js';
- import InlineEditableUIView from '/ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
- import testUtils from '/tests/utils/_utils/utils.js';
- describe( 'ClassicEditorUI', () => {
- let editorElement, editor, editable, view;
- beforeEach( () => {
- editorElement = document.createElement( 'div' );
- document.body.appendChild( editorElement );
- editor = new ClassicTestEditor( editorElement, {
- toolbar: [ 'foo', 'bar' ]
- } );
- editable = editor.editing.view.createRoot( document.createElement( 'div' ) );
- editor.ui = view = new ClassicEditorUIView( editor, editor.locale );
- function createButton( locale ) {
- return new ButtonView( locale );
- }
- view.featureComponents.add( 'foo', createButton );
- view.featureComponents.add( 'bar', createButton );
- } );
- describe( 'constructor', () => {
- describe( 'toolbar', () => {
- it( 'creates toolbar', () => {
- expect( view.toolbar ).to.be.instanceof( StickyToolbarView );
- } );
- it( 'binds view.toolbar#isFocused to editor#focusTracker', () => {
- editor.focusTracker.isFocused = false;
- expect( view.toolbar.isActive ).to.false;
- editor.focusTracker.isFocused = true;
- expect( view.toolbar.isActive ).to.true;
- } );
- } );
- describe( 'editable', () => {
- it( 'creates view#editable', () => {
- expect( view.editable ).to.be.instanceof( InlineEditableUIView );
- } );
- it( 'registers editable#element in editor focus tracker', () => {
- return view.init()
- .then( () => {
- editor.focusTracker.isFocused = false;
- view.editable.element.dispatchEvent( new Event( 'focus' ) );
- expect( editor.focusTracker.isFocused ).to.true;
- } );
- } );
- it( 'sets view.editable#name', () => {
- expect( view.editable.name ).to.equal( editable.rootName );
- } );
- it( 'binds view.editable#isFocused', () => {
- testUtils.assertBinding(
- view.editable,
- { isFocused: false },
- [
- [ editable, { isFocused: true } ]
- ],
- { isFocused: true }
- );
- } );
- it( 'binds view.editable#isReadOnly', () => {
- testUtils.assertBinding(
- view.editable,
- { isReadOnly: false },
- [
- [ editable, { isReadOnly: true } ]
- ],
- { isReadOnly: true }
- );
- } );
- } );
- } );
- describe( 'editableElement', () => {
- it( 'returns editable\'s view element', () => {
- document.body.appendChild( view.element );
- return view.init()
- .then( () => {
- expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
- } );
- } );
- } );
- describe( 'init', () => {
- it( 'returns a promise', () => {
- document.body.appendChild( view.element );
- expect( view.init() ).to.be.instanceof( Promise );
- } );
- it( 'sets view.toolbar#limiterElement', ( done ) => {
- view.init().then( () => {
- expect( view.toolbar.limiterElement ).to.equal( view.element );
- done();
- } );
- } );
- } );
- } );
|