italicengine.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 as getModelData } from '/tests/engine/_utils/model.js';
  9. import { getData as getViewData } from '/tests/engine/_utils/view.js';
  10. import AttributeCommand from '/ckeditor5/command/attributecommand.js';
  11. describe( 'ItalicEngine', () => {
  12. let editor, doc;
  13. beforeEach( () => {
  14. return VirtualTestEditor.create( {
  15. features: [ ItalicEngine ]
  16. } )
  17. .then( newEditor => {
  18. editor = newEditor;
  19. doc = editor.document;
  20. doc.schema.allow( { name: '$text', inside: '$root' } );
  21. } );
  22. } );
  23. it( 'should be loaded', () => {
  24. expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine );
  25. } );
  26. it( 'should set proper schema rules', () => {
  27. expect( doc.schema.check( { name: '$inline', attributes: [ 'italic' ] } ) ).to.be.true;
  28. } );
  29. describe( 'command', () => {
  30. it( 'should register italic command', () => {
  31. expect( editor.commands.has( 'italic' ) ).to.be.true;
  32. const command = editor.commands.get( 'italic' );
  33. expect( command ).to.be.instanceOf( AttributeCommand );
  34. expect( command ).to.have.property( 'attributeKey', 'italic' );
  35. } );
  36. } );
  37. describe( 'data pipeline conversions', () => {
  38. it( 'should convert <em> to italic attribute', () => {
  39. editor.setData( '<em>foo</em>bar' );
  40. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic=true>foo</$text>bar' );
  41. expect( editor.getData() ).to.equal( '<em>foo</em>bar' );
  42. } );
  43. it( 'should convert <i> to italic attribute', () => {
  44. editor.setData( '<i>foo</i>bar' );
  45. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic=true>foo</$text>bar' );
  46. expect( editor.getData() ).to.equal( '<em>foo</em>bar' );
  47. } );
  48. it( 'should convert font-weight:italic to italic attribute', () => {
  49. editor.setData( '<span style="font-style: italic;">foo</span>bar' );
  50. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic=true>foo</$text>bar' );
  51. expect( editor.getData() ).to.equal( '<em>foo</em>bar' );
  52. } );
  53. } );
  54. describe( 'editing pipeline conversion', () => {
  55. it( 'should convert paragraph', () => {
  56. // Workaround for setting model data: https://github.com/ckeditor/ckeditor5-engine/issues/455
  57. editor.setData( '<em>foo</em>bar' );
  58. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<em>foo</em>bar' );
  59. } );
  60. } );
  61. } );