8
0

italicengine.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 AttributeCommand from '../src/attributecommand';
  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, model;
  13. beforeEach( () => {
  14. return VirtualTestEditor
  15. .create( {
  16. plugins: [ Paragraph, ItalicEngine ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. model = editor.model;
  21. } );
  22. } );
  23. afterEach( () => {
  24. return editor.destroy();
  25. } );
  26. it( 'should be loaded', () => {
  27. expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine );
  28. } );
  29. it( 'should set proper schema rules', () => {
  30. expect( model.schema.checkAttribute( [ '$root', '$block', '$text' ], 'italic' ) ).to.be.true;
  31. expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'italic' ) ).to.be.true;
  32. } );
  33. describe( 'command', () => {
  34. it( 'should register italic command', () => {
  35. const command = editor.commands.get( 'italic' );
  36. expect( command ).to.be.instanceOf( AttributeCommand );
  37. expect( command ).to.have.property( 'attributeKey', 'italic' );
  38. } );
  39. } );
  40. describe( 'data pipeline conversions', () => {
  41. it( 'should convert <em> to italic attribute', () => {
  42. editor.setData( '<p><em>foo</em>bar</p>' );
  43. expect( getModelData( model, { withoutSelection: true } ) )
  44. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  45. expect( editor.getData() ).to.equal( '<p><i>foo</i>bar</p>' );
  46. } );
  47. it( 'should convert <i> to italic attribute', () => {
  48. editor.setData( '<p><i>foo</i>bar</p>' );
  49. expect( getModelData( model, { withoutSelection: true } ) )
  50. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  51. expect( editor.getData() ).to.equal( '<p><i>foo</i>bar</p>' );
  52. } );
  53. it( 'should convert font-weight:italic to italic attribute', () => {
  54. editor.setData( '<p><span style="font-style: italic;">foo</span>bar</p>' );
  55. expect( getModelData( model, { withoutSelection: true } ) )
  56. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  57. expect( editor.getData() ).to.equal( '<p><i>foo</i>bar</p>' );
  58. } );
  59. it( 'should be integrated with autoparagraphing', () => {
  60. editor.setData( '<i>foo</i>bar' );
  61. expect( getModelData( model, { withoutSelection: true } ) )
  62. .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
  63. expect( editor.getData() ).to.equal( '<p><i>foo</i>bar</p>' );
  64. } );
  65. } );
  66. describe( 'editing pipeline conversion', () => {
  67. it( 'should convert attribute', () => {
  68. setModelData( model, '<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. } );