/** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor'; import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view'; import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; import StandardEditingModeEditing from '../src/standardeditingmodeediting'; import RestrictedEditingExceptionCommand from '../src/restrictededitingexceptioncommand'; import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; describe( 'StandardEditingModeEditing', () => { let editor, model; testUtils.createSinonSandbox(); beforeEach( async () => { editor = await VirtualTestEditor.create( { plugins: [ Paragraph, StandardEditingModeEditing ] } ); model = editor.model; } ); afterEach( () => { return editor.destroy(); } ); it( 'should be named', () => { expect( StandardEditingModeEditing.pluginName ).to.equal( 'StandardEditingModeEditing' ); } ); it( 'should be loaded', () => { expect( editor.plugins.get( 'StandardEditingModeEditing' ) ).to.be.instanceOf( StandardEditingModeEditing ); } ); it( 'root should have "ck-restricted-editing_mode_standard" class', () => { for ( const root of editor.editing.view.document.roots ) { expect( root.hasClass( 'ck-restricted-editing_mode_standard' ) ).to.be.true; } } ); it( 'should set proper schema rules', () => { expect( model.schema.checkAttribute( [ '$root', '$text' ], 'restrictedEditingException' ) ).to.be.true; expect( model.schema.checkAttribute( [ '$block', '$text' ], 'restrictedEditingException' ) ).to.be.true; expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'restrictedEditingException' ) ).to.be.true; expect( model.schema.checkAttribute( [ '$block' ], 'restrictedEditingException' ) ).to.be.false; } ); it( 'should register the command', () => { const command = editor.commands.get( 'restrictedEditingException' ); expect( command ).to.be.instanceof( RestrictedEditingExceptionCommand ); } ); describe( 'conversion', () => { describe( 'upcast', () => { it( 'should convert to the model attribute', () => { editor.setData( '

foo bar baz

' ); expect( getModelData( model, { withoutSelection: true } ) ) .to.equal( 'foo <$text restrictedEditingException="true">bar baz' ); } ); } ); describe( 'downcast', () => { it( 'should convert the model attribute to a ', () => { const expectedView = '

foo bar baz

'; setModelData( editor.model, 'foo <$text restrictedEditingException="true">bar baz' ); expect( editor.getData() ).to.equal( expectedView ); expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView ); } ); it( 'converted should be outer most element', () => { editor.conversion.for( 'downcast' ).attributeToElement( { model: 'bold', view: 'b' } ); editor.conversion.for( 'downcast' ).attributeToElement( { model: 'italic', view: 'i' } ); const expectedView = '

foo bar baz

'; setModelData( editor.model, '' + '<$text restrictedEditingException="true" bold="true">foo' + '<$text restrictedEditingException="true"> ' + '<$text restrictedEditingException="true" italic="true">bar' + '<$text restrictedEditingException="true"> baz' + '' ); assertEqualMarkup( editor.getData(), expectedView ); assertEqualMarkup( getViewData( editor.editing.view, { withoutSelection: true } ), expectedView ); } ); } ); } ); } );