/** * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ import Document from 'ckeditor5-engine/src/model/document'; import isAttributeAllowedInSelection from 'ckeditor5-core/src/command/helpers/isattributeallowedinselection'; import { setData } from 'ckeditor5-engine/src/dev-utils/model'; describe( 'isAttributeAllowedInSelection', () => { const attribute = 'bold'; let document, root; beforeEach( () => { document = new Document(); root = document.createRoot(); document.schema.registerItem( 'p', '$block' ); document.schema.registerItem( 'h1', '$block' ); document.schema.registerItem( 'img', '$inline' ); // Bold text is allowed only in P. document.schema.allow( { name: '$text', attributes: 'bold', inside: 'p' } ); document.schema.allow( { name: 'p', attributes: 'bold', inside: '$root' } ); // Disallow bold on image. document.schema.disallow( { name: 'img', attributes: 'bold', inside: '$root' } ); } ); describe( 'when selection is collapsed', () => { it( 'should return true if characters with the attribute can be placed at caret position', () => { setData( document, '
f[]oo
' ); expect( isAttributeAllowedInSelection( attribute, document.selection, document.schema ) ).to.be.true; } ); it( 'should return false if characters with the attribute cannot be placed at caret position', () => { setData( document, '[foo]
' ); expect( isAttributeAllowedInSelection( attribute, document.selection, document.schema ) ).to.be.true; // Selection spans over characters but also include nodes that can't have attribute. setData( document, 'fo[ob]ar
foobar
foo[]bar