8
0

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