restrictededitingexceptionediting.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  6. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  7. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  8. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. import RestrictedEditingExceptionEditing from '../src/restrictededitingexceptionediting';
  11. import RestrictedEditingExceptionCommand from '../src/restrictededitingexceptioncommand';
  12. describe( 'RestrictedEditingExceptionEditing', () => {
  13. let editor, model;
  14. testUtils.createSinonSandbox();
  15. beforeEach( async () => {
  16. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, RestrictedEditingExceptionEditing ] } );
  17. model = editor.model;
  18. } );
  19. afterEach( () => {
  20. return editor.destroy();
  21. } );
  22. it( 'should be named', () => {
  23. expect( RestrictedEditingExceptionEditing.pluginName ).to.equal( 'RestrictedEditingExceptionEditing' );
  24. } );
  25. it( 'should be loaded', () => {
  26. expect( editor.plugins.get( 'RestrictedEditingExceptionEditing' ) ).to.be.instanceOf( RestrictedEditingExceptionEditing );
  27. } );
  28. it( 'should set proper schema rules', () => {
  29. expect( model.schema.checkAttribute( [ '$root', '$text' ], 'restrictedEditingException' ) ).to.be.true;
  30. expect( model.schema.checkAttribute( [ '$block', '$text' ], 'restrictedEditingException' ) ).to.be.true;
  31. expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'restrictedEditingException' ) ).to.be.true;
  32. expect( model.schema.checkAttribute( [ '$block' ], 'restrictedEditingException' ) ).to.be.false;
  33. } );
  34. it( 'should register command', () => {
  35. const command = editor.commands.get( 'nonRestricted' );
  36. expect( command ).to.be.instanceof( RestrictedEditingExceptionCommand );
  37. } );
  38. describe( 'conversion', () => {
  39. describe( 'upcast', () => {
  40. it( 'should convert <span class="ck-restricted-editing-exception"> to model attribute', () => {
  41. editor.setData( '<p>foo <span class="ck-restricted-editing-exception">bar</span> baz</p>' );
  42. expect( getModelData( model, { withoutSelection: true } ) )
  43. .to.equal( '<paragraph>foo <$text restrictedEditingException="true">bar</$text> baz</paragraph>' );
  44. } );
  45. } );
  46. describe( 'downcast', () => {
  47. it( 'should convert model attribute to <span>', () => {
  48. const expectedView = '<p>foo <span class="ck-restricted-editing-exception">bar</span> baz</p>';
  49. setModelData( editor.model,
  50. '<paragraph>foo <$text restrictedEditingException="true">bar</$text> baz</paragraph>'
  51. );
  52. expect( editor.getData() ).to.equal( expectedView );
  53. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
  54. } );
  55. } );
  56. } );
  57. } );