restricteddocumentediting.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  6. import testUtils from './_utils/utils';
  7. import VirtualTestEditor from './_utils/virtualtesteditor';
  8. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  9. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import RestrictedDocument from './../src/restricteddocument';
  11. import RestrictedDocumentCommand from '../src/restricteddocumentcommand';
  12. describe( 'RestrictedDocumentEditing', () => {
  13. let editor, model;
  14. testUtils.createSinonSandbox();
  15. beforeEach( async () => {
  16. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, RestrictedDocument ] } );
  17. model = editor.model;
  18. } );
  19. afterEach( () => {
  20. if ( editor ) {
  21. return editor.destroy();
  22. }
  23. } );
  24. it( 'should be named', () => {
  25. expect( RestrictedDocument.pluginName ).to.equal( 'RestrictedDocument' );
  26. } );
  27. it( 'should be loaded', () => {
  28. expect( editor.plugins.get( 'RestrictedDocument' ) ).to.be.instanceOf( RestrictedDocument );
  29. } );
  30. it( 'should set proper schema rules', () => {
  31. expect( model.schema.checkAttribute( [ '$root', '$text' ], 'nonRestricted' ) ).to.be.true;
  32. expect( model.schema.checkAttribute( [ '$block', '$text' ], 'nonRestricted' ) ).to.be.true;
  33. expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'nonRestricted' ) ).to.be.true;
  34. expect( model.schema.checkAttribute( [ '$block' ], 'nonRestricted' ) ).to.be.false;
  35. } );
  36. it( 'should register command', () => {
  37. const command = editor.commands.get( 'nonRestricted' );
  38. expect( command ).to.be.instanceof( RestrictedDocumentCommand );
  39. } );
  40. describe( 'conversion', () => {
  41. describe( 'upcast', () => {
  42. it( 'should convert <span class="ck-non-restricted"> to model attribute', () => {
  43. editor.setData( '<p>foo <span class="ck-non-restricted">bar</span> baz</p>' );
  44. expect( getModelData( model, { withoutSelection: true } ) )
  45. .to.equal( '<paragraph>foo <$text nonRestricted="true">bar</$text> baz</paragraph>' );
  46. } );
  47. } );
  48. describe( 'downcast', () => {
  49. it( 'should convert model attribute to <span>', () => {
  50. const expectedView = '<p>foo <span class="ck-non-restricted">bar</span> baz</p>';
  51. setModelData( editor.model,
  52. '<paragraph>foo <$text nonRestricted="true">bar</$text> baz</paragraph>'
  53. );
  54. expect( editor.getData() ).to.equal( expectedView );
  55. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
  56. } );
  57. } );
  58. } );
  59. } );