8
0

formatsengine.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 FormatsEngine from '/ckeditor5/formats/formatsengine.js';
  7. import Paragraph from '/ckeditor5/paragraph/paragraph.js';
  8. import VirtualTestEditor from '/tests/ckeditor5/_utils/virtualtesteditor.js';
  9. import FormatsCommand from '/ckeditor5/formats/formatscommand.js';
  10. import { getData } from '/tests/engine/_utils/model.js';
  11. describe( 'FormatsEngine', () => {
  12. let editor, document;
  13. beforeEach( () => {
  14. return VirtualTestEditor.create( {
  15. features: [ FormatsEngine ]
  16. } )
  17. .then( newEditor => {
  18. editor = newEditor;
  19. document = editor.document;
  20. } );
  21. } );
  22. it( 'should be loaded', () => {
  23. expect( editor.plugins.get( FormatsEngine ) ).to.be.instanceOf( FormatsEngine );
  24. } );
  25. it( 'should load paragraph feature', () => {
  26. expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
  27. } );
  28. it( 'should set proper schema rules', () => {
  29. expect( document.schema.hasItem( 'heading1' ) ).to.be.true;
  30. expect( document.schema.hasItem( 'heading2' ) ).to.be.true;
  31. expect( document.schema.hasItem( 'heading3' ) ).to.be.true;
  32. expect( document.schema.check( { name: 'heading1', inside: '$root' } ) ).to.be.true;
  33. expect( document.schema.check( { name: '$inline', inside: 'heading1' } ) ).to.be.true;
  34. expect( document.schema.check( { name: 'heading2', inside: '$root' } ) ).to.be.true;
  35. expect( document.schema.check( { name: '$inline', inside: 'heading2' } ) ).to.be.true;
  36. expect( document.schema.check( { name: 'heading3', inside: '$root' } ) ).to.be.true;
  37. expect( document.schema.check( { name: '$inline', inside: 'heading3' } ) ).to.be.true;
  38. } );
  39. it( 'should register format command', () => {
  40. expect( editor.commands.has( 'format' ) ).to.be.true;
  41. const command = editor.commands.get( 'format' );
  42. expect( command ).to.be.instanceOf( FormatsCommand );
  43. } );
  44. it( 'should convert heading1', () => {
  45. editor.setData( '<h2>foobar</h2>' );
  46. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<heading1>foobar</heading1>' );
  47. expect( editor.getData() ).to.equal( '<h2>foobar</h2>' );
  48. } );
  49. it( 'should convert heading2', () => {
  50. editor.setData( '<h3>foobar</h3>' );
  51. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<heading2>foobar</heading2>' );
  52. expect( editor.getData() ).to.equal( '<h3>foobar</h3>' );
  53. } );
  54. it( 'should convert heading3', () => {
  55. editor.setData( '<h4>foobar</h4>' );
  56. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<heading3>foobar</heading3>' );
  57. expect( editor.getData() ).to.equal( '<h4>foobar</h4>' );
  58. } );
  59. } );