italicengine.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. it( 'should be loaded', () => {
  23. expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine );
  24. } );
  25. it( 'should set proper schema rules', () => {
  26. expect( doc.schema.check( { name: '$inline', attributes: [ 'italic' ], inside: '$block' } ) ).to.be.true;
  27. } );
  28. describe( 'command', () => {
  29. it( 'should register italic command', () => {
  30. expect( editor.commands.has( 'italic' ) ).to.be.true;
  31. const command = editor.commands.get( 'italic' );
  32. expect( command ).to.be.instanceOf( ToggleAttributeCommand );
  33. expect( command ).to.have.property( 'attributeKey', 'italic' );
  34. } );
  35. } );
  36. describe( 'data pipeline conversions', () => {
  37. it( 'should convert <em> to italic attribute', () => {
  38. editor.setData( '<p><em>foo</em>bar</p>' );
  39. expect( getModelData( doc, { withoutSelection: true } ) )
  40. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  41. expect( editor.getData() ).to.equal( '<p><em>foo</em>bar</p>' );
  42. } );
  43. it( 'should convert <i> to italic attribute', () => {
  44. editor.setData( '<p><i>foo</i>bar</p>' );
  45. expect( getModelData( doc, { withoutSelection: true } ) )
  46. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  47. expect( editor.getData() ).to.equal( '<p><em>foo</em>bar</p>' );
  48. } );
  49. it( 'should convert font-weight:italic to italic attribute', () => {
  50. editor.setData( '<p><span style="font-style: italic;">foo</span>bar</p>' );
  51. expect( getModelData( doc, { withoutSelection: true } ) )
  52. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  53. expect( editor.getData() ).to.equal( '<p><em>foo</em>bar</p>' );
  54. } );
  55. } );
  56. describe( 'editing pipeline conversion', () => {
  57. it( 'should convert attribute', () => {
  58. setModelData( doc, '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  59. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><em>foo</em>bar</p>' );
  60. } );
  61. } );
  62. } );