restrictedediting.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /* global document */
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  8. import RestrictedEditing from './../src/restrictedediting';
  9. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  11. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  12. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  13. describe( 'RestrictedEditing', () => {
  14. let editor, element;
  15. testUtils.createSinonSandbox();
  16. describe( 'plugin', () => {
  17. beforeEach( async () => {
  18. element = document.createElement( 'div' );
  19. document.body.appendChild( element );
  20. editor = await ClassicTestEditor.create( element, { plugins: [ RestrictedEditing ] } );
  21. } );
  22. afterEach( () => {
  23. element.remove();
  24. return editor.destroy();
  25. } );
  26. it( 'should be named', () => {
  27. expect( RestrictedEditing.pluginName ).to.equal( 'RestrictedEditing' );
  28. } );
  29. it( 'should be loaded', () => {
  30. expect( editor.plugins.get( RestrictedEditing ) ).to.be.instanceOf( RestrictedEditing );
  31. } );
  32. } );
  33. describe( 'conversion', () => {
  34. let model;
  35. beforeEach( async () => {
  36. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, RestrictedEditing ] } );
  37. model = editor.model;
  38. } );
  39. afterEach( () => {
  40. return editor.destroy();
  41. } );
  42. describe( 'downcast', () => {
  43. it( 'should convert model marker to <span>', () => {
  44. setModelData( model, '<paragraph>foo bar baz</paragraph>' );
  45. const paragraph = model.document.getRoot().getChild( 0 );
  46. model.change( writer => {
  47. writer.addMarker( 'restricted-editing-exception:1', {
  48. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  49. usingOperation: true,
  50. affectsData: true
  51. } );
  52. } );
  53. const expectedView = '<p>foo <span class="ck-restricted-editing-exception">bar</span> baz</p>';
  54. expect( editor.getData() ).to.equal( expectedView );
  55. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
  56. } );
  57. } );
  58. } );
  59. } );