formatengine.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import FormatEngine from '/ckeditor5/format/formatengine.js';
  7. import Editor from '/ckeditor5/editor.js';
  8. import StandardCreator from '/ckeditor5/creator/standardcreator.js';
  9. import { getData } from '/tests/engine/_utils/model.js';
  10. describe( 'FormatEngine', () => {
  11. let editor, document;
  12. beforeEach( () => {
  13. editor = new Editor( null, {
  14. creator: StandardCreator,
  15. features: [ FormatEngine ]
  16. } );
  17. return editor.init().then( () => {
  18. document = editor.document;
  19. document.createRoot( 'main' );
  20. } );
  21. } );
  22. it( 'should be loaded', () => {
  23. expect( editor.plugins.get( FormatEngine ) ).to.be.instanceOf( FormatEngine );
  24. } );
  25. it( 'should set proper schema rules', () => {
  26. expect( document.schema.hasItem( 'heading1' ) ).to.be.true;
  27. expect( document.schema.hasItem( 'heading2' ) ).to.be.true;
  28. expect( document.schema.hasItem( 'heading3' ) ).to.be.true;
  29. expect( document.schema.check( { name: 'heading1', inside: '$root' } ) ).to.be.true;
  30. expect( document.schema.check( { name: '$inline', inside: 'heading1' } ) ).to.be.true;
  31. expect( document.schema.check( { name: 'heading2', inside: '$root' } ) ).to.be.true;
  32. expect( document.schema.check( { name: '$inline', inside: 'heading2' } ) ).to.be.true;
  33. expect( document.schema.check( { name: 'heading3', inside: '$root' } ) ).to.be.true;
  34. expect( document.schema.check( { name: '$inline', inside: 'heading3' } ) ).to.be.true;
  35. } );
  36. it( 'should convert heading1', () => {
  37. editor.setData( '<h2>foobar</h2>' );
  38. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<heading1>foobar</heading1>' );
  39. expect( editor.getData() ).to.equal( '<h2>foobar</h2>' );
  40. } );
  41. it( 'should convert heading2', () => {
  42. editor.setData( '<h3>foobar</h3>' );
  43. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<heading2>foobar</heading2>' );
  44. expect( editor.getData() ).to.equal( '<h3>foobar</h3>' );
  45. } );
  46. it( 'should convert heading3', () => {
  47. editor.setData( '<h4>foobar</h4>' );
  48. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<heading3>foobar</heading3>' );
  49. expect( editor.getData() ).to.equal( '<h4>foobar</h4>' );
  50. } );
  51. } );