italicengine.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import ItalicEngine from '../src/italicengine';
  6. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import ToggleAttributeCommand from '@ckeditor/ckeditor5-core/src/command/toggleattributecommand';
  9. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  11. describe( 'ItalicEngine', () => {
  12. let editor, doc;
  13. beforeEach( () => {
  14. return VirtualTestEditor.create( {
  15. plugins: [ Paragraph, ItalicEngine ]
  16. } )
  17. .then( newEditor => {
  18. editor = newEditor;
  19. doc = editor.document;
  20. } );
  21. } );
  22. afterEach( () => {
  23. return editor.destroy();
  24. } );
  25. it( 'should be loaded', () => {
  26. expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine );
  27. } );
  28. it( 'should set proper schema rules', () => {
  29. expect( doc.schema.check( { name: '$inline', attributes: [ 'italic' ], inside: '$root' } ) ).to.be.false;
  30. expect( doc.schema.check( { name: '$inline', attributes: [ 'italic' ], inside: '$block' } ) ).to.be.true;
  31. } );
  32. describe( 'command', () => {
  33. it( 'should register italic command', () => {
  34. const command = editor.commands.get( 'italic' );
  35. expect( command ).to.be.instanceOf( ToggleAttributeCommand );
  36. expect( command ).to.have.property( 'attributeKey', 'italic' );
  37. } );
  38. } );
  39. describe( 'data pipeline conversions', () => {
  40. it( 'should convert <em> to italic attribute', () => {
  41. editor.setData( '<p><em>foo</em>bar</p>' );
  42. expect( getModelData( doc, { withoutSelection: true } ) )
  43. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  44. expect( editor.getData() ).to.equal( '<p><i>foo</i>bar</p>' );
  45. } );
  46. it( 'should convert <i> to italic attribute', () => {
  47. editor.setData( '<p><i>foo</i>bar</p>' );
  48. expect( getModelData( doc, { withoutSelection: true } ) )
  49. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  50. expect( editor.getData() ).to.equal( '<p><i>foo</i>bar</p>' );
  51. } );
  52. it( 'should convert font-weight:italic to italic attribute', () => {
  53. editor.setData( '<p><span style="font-style: italic;">foo</span>bar</p>' );
  54. expect( getModelData( doc, { withoutSelection: true } ) )
  55. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  56. expect( editor.getData() ).to.equal( '<p><i>foo</i>bar</p>' );
  57. } );
  58. it( 'should be integrated with autoparagraphing', () => {
  59. // Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
  60. // https://github.com/ckeditor/ckeditor5-paragraph/issues/10
  61. editor.setData( '<em>foo</em>bar' );
  62. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
  63. expect( editor.getData() ).to.equal( '<p>foobar</p>' );
  64. } );
  65. } );
  66. describe( 'editing pipeline conversion', () => {
  67. it( 'should convert attribute', () => {
  68. setModelData( doc, '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  69. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><i>foo</i>bar</p>' );
  70. } );
  71. } );
  72. } );