italicengine.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. import ItalicEngine from 'ckeditor5/basic-styles/italicengine.js';
  6. import VirtualTestEditor from 'tests/core/_utils/virtualtesteditor.js';
  7. import { getData as getModelData, setData as setModelData } from 'ckeditor5/engine/dev-utils/model.js';
  8. import { getData as getViewData } from 'ckeditor5/engine/dev-utils/view.js';
  9. import ToggleAttributeCommand from 'ckeditor5/core/command/toggleattributecommand.js';
  10. describe( 'ItalicEngine', () => {
  11. let editor, doc;
  12. beforeEach( () => {
  13. return VirtualTestEditor.create( {
  14. features: [ ItalicEngine ]
  15. } )
  16. .then( newEditor => {
  17. editor = newEditor;
  18. doc = editor.document;
  19. doc.schema.allow( { name: '$text', inside: '$root' } );
  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' ] } ) ).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( '<em>foo</em>bar' );
  39. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic="true">foo</$text>bar' );
  40. expect( editor.getData() ).to.equal( '<em>foo</em>bar' );
  41. } );
  42. it( 'should convert <i> to italic attribute', () => {
  43. editor.setData( '<i>foo</i>bar' );
  44. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic="true">foo</$text>bar' );
  45. expect( editor.getData() ).to.equal( '<em>foo</em>bar' );
  46. } );
  47. it( 'should convert font-weight:italic to italic attribute', () => {
  48. editor.setData( '<span style="font-style: italic;">foo</span>bar' );
  49. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic="true">foo</$text>bar' );
  50. expect( editor.getData() ).to.equal( '<em>foo</em>bar' );
  51. } );
  52. } );
  53. describe( 'editing pipeline conversion', () => {
  54. it( 'should convert attribute', () => {
  55. setModelData( doc, '<$text italic="true">foo</$text>bar' );
  56. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<em>foo</em>bar' );
  57. } );
  58. } );
  59. } );