8
0

restricteddocument.js 2.7 KB

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