italicengine.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 ItalicEngine from '/ckeditor5/basic-styles/italicengine.js';
  7. import VirtualTestEditor from '/tests/ckeditor5/_utils/virtualtesteditor.js';
  8. import { getData } from '/tests/engine/_utils/model.js';
  9. import BuildModelConverterFor from '/ckeditor5/engine/conversion/model-converter-builder.js';
  10. import BuildViewConverterFor from '/ckeditor5/engine/conversion/view-converter-builder.js';
  11. import AttributeCommand from '/ckeditor5/command/attributecommand.js';
  12. describe( 'ItalicEngine', () => {
  13. let editor, document;
  14. beforeEach( () => {
  15. return VirtualTestEditor.create( {
  16. features: [ ItalicEngine ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. document = editor.document;
  21. // Register some block element for tests.
  22. document.schema.registerItem( 'p', '$block' );
  23. // Build converter from model to view for data and editing pipelines.
  24. BuildModelConverterFor( editor.data.modelToView, editor.editing.modelToView )
  25. .fromElement( 'p' )
  26. .toElement( 'p' );
  27. // Build converter from view to model for data and editing pipelines.
  28. BuildViewConverterFor( editor.data.viewToModel )
  29. .fromElement( 'p' )
  30. .toElement( 'p' );
  31. } );
  32. } );
  33. it( 'should be loaded', () => {
  34. expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine );
  35. } );
  36. it( 'should set proper schema rules', () => {
  37. expect( document.schema.check( { name: '$inline', attributes: [ 'italic' ] } ) ).to.be.true;
  38. } );
  39. it( 'should register bold command', () => {
  40. expect( editor.commands.has( 'italic' ) ).to.be.true;
  41. const command = editor.commands.get( 'italic' );
  42. expect( command ).to.be.instanceOf( AttributeCommand );
  43. expect( command.attributeKey ).to.equal( 'italic' );
  44. } );
  45. it( 'should convert <em> to italic attribute', () => {
  46. editor.setData( '<p><em>foobar</em></p>' );
  47. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text italic=true>foobar</$text></p>' );
  48. expect( editor.getData() ).to.equal( '<p><em>foobar</em></p>' );
  49. } );
  50. it( 'should convert <i> to italic attribute', () => {
  51. editor.setData( '<p><i>foobar</i></p>' );
  52. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text italic=true>foobar</$text></p>' );
  53. expect( editor.getData() ).to.equal( '<p><em>foobar</em></p>' );
  54. } );
  55. it( 'should convert font-style:italic to italic attribute', () => {
  56. editor.setData( '<p><span style="font-style: italic;">foobar</span></p>' );
  57. expect( getData( document, { withoutSelection: true } ) ).to.equal( '<p><$text italic=true>foobar</$text></p>' );
  58. expect( editor.getData() ).to.equal( '<p><em>foobar</em></p>' );
  59. } );
  60. } );