headingsengine.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import HeadingsEngine from '/ckeditor5/headings/headingsengine.js';
  6. import Paragraph from '/ckeditor5/paragraph/paragraph.js';
  7. import VirtualTestEditor from '/tests/core/_utils/virtualtesteditor.js';
  8. import HeadingsCommand from '/ckeditor5/headings/headingscommand.js';
  9. import { getData } from '/tests/engine/_utils/model.js';
  10. describe( 'HeadingsEngine', () => {
  11. let editor, document;
  12. beforeEach( () => {
  13. return VirtualTestEditor.create( {
  14. features: [ HeadingsEngine ]
  15. } )
  16. .then( newEditor => {
  17. editor = newEditor;
  18. document = editor.document;
  19. } );
  20. } );
  21. it( 'should be loaded', () => {
  22. expect( editor.plugins.get( HeadingsEngine ) ).to.be.instanceOf( HeadingsEngine );
  23. } );
  24. it( 'should load paragraph feature', () => {
  25. expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
  26. } );
  27. it( 'should set proper schema rules', () => {
  28. expect( document.schema.hasItem( 'heading1' ) ).to.be.true;
  29. expect( document.schema.hasItem( 'heading2' ) ).to.be.true;
  30. expect( document.schema.hasItem( 'heading3' ) ).to.be.true;
  31. expect( document.schema.check( { name: 'heading1', inside: '$root' } ) ).to.be.true;
  32. expect( document.schema.check( { name: '$inline', inside: 'heading1' } ) ).to.be.true;
  33. expect( document.schema.check( { name: 'heading2', inside: '$root' } ) ).to.be.true;
  34. expect( document.schema.check( { name: '$inline', inside: 'heading2' } ) ).to.be.true;
  35. expect( document.schema.check( { name: 'heading3', inside: '$root' } ) ).to.be.true;
  36. expect( document.schema.check( { name: '$inline', inside: 'heading3' } ) ).to.be.true;
  37. } );
  38. it( 'should register format command', () => {
  39. expect( editor.commands.has( 'headings' ) ).to.be.true;
  40. const command = editor.commands.get( 'headings' );
  41. expect( command ).to.be.instanceOf( HeadingsCommand );
  42. } );
  43. it( 'should convert heading1', () => {
  44. editor.setData( '<h2>foobar</h2>' );
  45. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<heading1>foobar</heading1>' );
  46. expect( editor.getData() ).to.equal( '<h2>foobar</h2>' );
  47. } );
  48. it( 'should convert heading2', () => {
  49. editor.setData( '<h3>foobar</h3>' );
  50. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<heading2>foobar</heading2>' );
  51. expect( editor.getData() ).to.equal( '<h3>foobar</h3>' );
  52. } );
  53. it( 'should convert heading3', () => {
  54. editor.setData( '<h4>foobar</h4>' );
  55. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<heading3>foobar</heading3>' );
  56. expect( editor.getData() ).to.equal( '<h4>foobar</h4>' );
  57. } );
  58. } );